RDG-Networks 0.2.3__py3-none-any.whl → 0.2.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {RDG_Networks-0.2.3.dist-info → RDG_Networks-0.2.5.dist-info}/METADATA +1 -1
- {RDG_Networks-0.2.3.dist-info → RDG_Networks-0.2.5.dist-info}/RECORD +8 -7
- RDG_networks/generate_line_segments_dynamic.py +17 -14
- RDG_networks/generate_line_segments_static.py +253 -0
- {RDG_Networks-0.2.3.dist-info → RDG_Networks-0.2.5.dist-info}/LICENSE.txt +0 -0
- {RDG_Networks-0.2.3.dist-info → RDG_Networks-0.2.5.dist-info}/WHEEL +0 -0
- {RDG_Networks-0.2.3.dist-info → RDG_Networks-0.2.5.dist-info}/entry_points.txt +0 -0
- {RDG_Networks-0.2.3.dist-info → RDG_Networks-0.2.5.dist-info}/top_level.txt +0 -0
@@ -3,12 +3,13 @@ RDG_networks/__init__.py,sha256=aCfGs87cJn0Tp5GqTpFXPOEfJPpR4Tnnz819Kk_0t84,661
|
|
3
3
|
RDG_networks/draw_segments.py,sha256=U53N5GXmQHWKdM1Q1faP_EGKjc6enOu2mcsunzSFpP0,984
|
4
4
|
RDG_networks/generate_line_network.py,sha256=lJ4rhObim3WcEQoebomewRQKWNJC5phFyFYRW7qjXIg,1127
|
5
5
|
RDG_networks/generate_line_segments.py,sha256=QV8_k7q6TD5c7Hcb2Ms_apEdWYw4XdLr7rdJgh49v4Q,9004
|
6
|
-
RDG_networks/generate_line_segments_dynamic.py,sha256=
|
6
|
+
RDG_networks/generate_line_segments_dynamic.py,sha256=GoIhGXYbcvjqR5BJCnkvAGp8QBpzsE1ZSbl2k9XAOGI,7531
|
7
|
+
RDG_networks/generate_line_segments_static.py,sha256=7KvHZi3krv-tAGydJR_gbMMmHKZ5azzrKcQe3fuWzCE,9265
|
7
8
|
RDG_networks/get_intersection_segments.py,sha256=mXB5qCy1oOps4Vu1mX6flW6v_4Xxc71YK41yOWjJX8o,2797
|
8
9
|
RDG_networks/sample_in_polygon.py,sha256=qpPpW-Da1vK8ZkVWMJ0zBsE8IgyMB619gCdybSkzKSQ,1605
|
9
|
-
RDG_Networks-0.2.
|
10
|
-
RDG_Networks-0.2.
|
11
|
-
RDG_Networks-0.2.
|
12
|
-
RDG_Networks-0.2.
|
13
|
-
RDG_Networks-0.2.
|
14
|
-
RDG_Networks-0.2.
|
10
|
+
RDG_Networks-0.2.5.dist-info/LICENSE.txt,sha256=BHUkX2GsdTr30sKmVZ1MLGR1njnx17EX_oUuuSVZZPE,598
|
11
|
+
RDG_Networks-0.2.5.dist-info/METADATA,sha256=df8uZ3On7aPNlvd59IvUkC2a0IvXktdRO6aaYLa4q0M,2422
|
12
|
+
RDG_Networks-0.2.5.dist-info/WHEEL,sha256=Xo9-1PvkuimrydujYJAjF7pCkriuXBpUPEjma1nZyJ0,92
|
13
|
+
RDG_Networks-0.2.5.dist-info/entry_points.txt,sha256=Htsh9jRabMCGHwXayUwZoSy-9IFGFrMB1X9hgyyr3_8,350
|
14
|
+
RDG_Networks-0.2.5.dist-info/top_level.txt,sha256=4gUUYafD5Al9V8ZSiViVGYHpRMMCsCBcGgCNodk9Syg,13
|
15
|
+
RDG_Networks-0.2.5.dist-info/RECORD,,
|
@@ -2,6 +2,7 @@ import numpy as np
|
|
2
2
|
import random
|
3
3
|
from shapely.geometry import LineString
|
4
4
|
from typing import List, Dict, Any, Tuple
|
5
|
+
import matplotlib.pyplot as plt
|
5
6
|
|
6
7
|
from .Classes import LineSegment
|
7
8
|
|
@@ -88,7 +89,7 @@ def update_for_border_intersections(lines: List[Dict[str, Any]]) -> List[Dict[st
|
|
88
89
|
|
89
90
|
return lines
|
90
91
|
|
91
|
-
def check_and_update_when_intersect(lines: List[Dict[str, Any]], epsilon: float) -> List[Dict[str, Any]]:
|
92
|
+
def check_and_update_when_intersect(lines: List[Dict[str, Any]], epsilon: float, dt: float) -> List[Dict[str, Any]]:
|
92
93
|
"""
|
93
94
|
Check for intersections between lines and update their properties accordingly.
|
94
95
|
|
@@ -99,36 +100,37 @@ def check_and_update_when_intersect(lines: List[Dict[str, Any]], epsilon: float)
|
|
99
100
|
Returns:
|
100
101
|
List[Dict[str, Any]]: The updated list of lines after handling intersections.
|
101
102
|
"""
|
103
|
+
|
102
104
|
for index1, j1 in enumerate(lines):
|
103
105
|
for index2, j2 in enumerate(lines):
|
104
106
|
if j1['id'][:-2] == j2['id'][:-2] or index2 < index1:
|
105
107
|
continue
|
106
|
-
|
108
|
+
|
107
109
|
if j1['growth_status'] == False and j2['growth_status'] == False:
|
108
110
|
continue
|
109
|
-
|
111
|
+
|
110
112
|
line1 = LineString([j1['start'], j1['end']])
|
111
113
|
line2 = LineString([j2['start'], j2['end']])
|
112
|
-
|
114
|
+
|
113
115
|
intersection_pt = line1.intersection(line2)
|
114
116
|
|
115
117
|
if not intersection_pt.is_empty:
|
116
118
|
d1 = np.linalg.norm(np.array(j1['start']) - np.array([intersection_pt.x, intersection_pt.y]))
|
117
119
|
d2 = np.linalg.norm(np.array(j2['start']) - np.array([intersection_pt.x, intersection_pt.y]))
|
118
120
|
|
119
|
-
arrival_1 = j1['introduction_time'] + d1 / epsilon
|
120
|
-
arrival_2 = j2['introduction_time'] + d2 / epsilon
|
121
|
+
arrival_1 = j1['introduction_time'] + d1 / epsilon * dt
|
122
|
+
arrival_2 = j2['introduction_time'] + d2 / epsilon * dt
|
121
123
|
|
122
124
|
if arrival_1 > arrival_2:
|
123
125
|
lines[index1]['end'] = (intersection_pt.x, intersection_pt.y)
|
124
126
|
lines[index1]['neighbors_initial'] = lines[index1]['neighbors_initial'] + [j2['id'][:-2]]
|
125
|
-
lines[index1]['growth_status'] = False
|
127
|
+
lines[index1]['growth_status'] = False
|
126
128
|
|
127
129
|
else:
|
128
130
|
lines[index2]['end'] = (intersection_pt.x, intersection_pt.y)
|
129
131
|
lines[index2]['neighbors_initial'] = lines[index2]['neighbors_initial'] + [j1['id'][:-2]]
|
130
132
|
lines[index2]['growth_status'] = False
|
131
|
-
|
133
|
+
|
132
134
|
return lines
|
133
135
|
|
134
136
|
def transform_to_standard_lines(lines: List[Dict[str, Any]]) -> List[LineSegment]:
|
@@ -173,7 +175,7 @@ def generate_line_segments_dynamic(size: int, dt: float, epsilon: float, time: f
|
|
173
175
|
"""
|
174
176
|
lines = []
|
175
177
|
line_id, t, t_total = 1, 0, 0
|
176
|
-
|
178
|
+
|
177
179
|
# Stop loop whenever we have enough lines and all lines have stopped growing
|
178
180
|
while len(lines) / 2 < size or np.any([item['growth_status'] for item in lines]):
|
179
181
|
|
@@ -185,17 +187,18 @@ def generate_line_segments_dynamic(size: int, dt: float, epsilon: float, time: f
|
|
185
187
|
if time == 0:
|
186
188
|
number_of_lines_to_add = size
|
187
189
|
else:
|
188
|
-
number_of_lines_to_add = int(t
|
190
|
+
number_of_lines_to_add = int(t / time)
|
191
|
+
|
189
192
|
for _ in range(number_of_lines_to_add):
|
190
193
|
lines = add_new_line(lines, line_id, t_total, angles=angles)
|
191
194
|
line_id += 1
|
192
|
-
|
193
|
-
|
195
|
+
|
196
|
+
t = 0
|
194
197
|
|
195
198
|
lines = grow_lines(lines, epsilon)
|
196
199
|
lines = update_for_border_intersections(lines)
|
197
|
-
lines = check_and_update_when_intersect(lines, epsilon)
|
198
|
-
|
200
|
+
lines = check_and_update_when_intersect(lines, epsilon, dt)
|
201
|
+
|
199
202
|
lines = transform_to_standard_lines(lines)
|
200
203
|
|
201
204
|
return lines
|
@@ -0,0 +1,253 @@
|
|
1
|
+
import matplotlib.pyplot as plt
|
2
|
+
import numpy as np
|
3
|
+
import math
|
4
|
+
import random
|
5
|
+
import os
|
6
|
+
import sys
|
7
|
+
import networkx as nx
|
8
|
+
|
9
|
+
from .Classes import LineSegment
|
10
|
+
|
11
|
+
def minDistance_line_point(A, B, E):
|
12
|
+
# vector AB
|
13
|
+
AB = np.array(B) - np.array(A)
|
14
|
+
EB = np.array(B) - np.array(E)
|
15
|
+
AE = np.array(E) - np.array(A)
|
16
|
+
|
17
|
+
# Calculating the dot product
|
18
|
+
AB_BE = np.dot(AB, EB)
|
19
|
+
AB_AE = np.dot(AB, AE)
|
20
|
+
|
21
|
+
# Case 1
|
22
|
+
if (AB_BE > 0):
|
23
|
+
# Finding the magnitude
|
24
|
+
y = E[1] - B[1]
|
25
|
+
x = E[0] - B[0]
|
26
|
+
reqAns = np.sqrt(x * x + y * y)
|
27
|
+
|
28
|
+
# Case 2
|
29
|
+
elif (AB_AE < 0):
|
30
|
+
y = E[1] - A[1]
|
31
|
+
x = E[0] - A[0]
|
32
|
+
reqAns = np.sqrt(x * x + y * y)
|
33
|
+
|
34
|
+
# Case 3
|
35
|
+
else:
|
36
|
+
reqAns = np.linalg.outer(AB, AE) / np.linalg.norm(AB)
|
37
|
+
|
38
|
+
return reqAns
|
39
|
+
|
40
|
+
def doLinesIntersect(line1, line2):
|
41
|
+
"""
|
42
|
+
Check if two lines intersect and return the intersection point.
|
43
|
+
|
44
|
+
Args:
|
45
|
+
- line1 (Line): The first line segment.
|
46
|
+
- line2 (Line): The second line segment.
|
47
|
+
|
48
|
+
Returns:
|
49
|
+
- intersect (bool): True if the lines intersect, False otherwise.
|
50
|
+
- intersection_point (tuple or None): The intersection point (x, y) if lines intersect, None otherwise.
|
51
|
+
"""
|
52
|
+
|
53
|
+
x1, y1 = line1[0]
|
54
|
+
v1, w1 = (np.cos(line1[1]), np.sin(line1[1]))
|
55
|
+
|
56
|
+
x2, y2 = line2[0]
|
57
|
+
v2, w2 = (np.cos(line2[1]), np.sin(line2[1]))
|
58
|
+
|
59
|
+
determinant = v1 * w2 - v2 * w1
|
60
|
+
|
61
|
+
if determinant == 0:
|
62
|
+
return False, (None, None)
|
63
|
+
|
64
|
+
t1 = ((x2 - x1) * w2 - (y2 - y1) * v2) / determinant
|
65
|
+
t2 = ((x2 - x1) * w1 - (y2 - y1) * v1) / determinant
|
66
|
+
|
67
|
+
intersect_x = x1 + v1 * t1
|
68
|
+
intersect_y = y2 + w2 * t2
|
69
|
+
|
70
|
+
if -1e-6 < intersect_x < 1 + 1e-6 and -1e-6 < intersect_y < 1 + 1e-6:
|
71
|
+
return True, (intersect_x, intersect_y)
|
72
|
+
else:
|
73
|
+
return False, (None, None)
|
74
|
+
|
75
|
+
def seeds(number_of_lines, radius = 0.015, number_of_trials = 10000):
|
76
|
+
Line = {}
|
77
|
+
line_id = 0
|
78
|
+
|
79
|
+
nucleation_points = [(0,0), (1,0), (1,1), (0,1)]
|
80
|
+
angle = [0,np.pi/2, np.pi, 3*np.pi/2]
|
81
|
+
|
82
|
+
Line = {'b1':[ (0,0), 0], 'b2':[ (1,0), np.pi/2], 'b3':[ (1,1), np.pi], 'b4':[ (0,1), 3*np.pi/2] }
|
83
|
+
|
84
|
+
for i in range(number_of_lines):
|
85
|
+
new_points = (random.uniform(0,1), random.uniform(0,1))
|
86
|
+
|
87
|
+
line_new_point = []
|
88
|
+
for j in range(len(nucleation_points)):
|
89
|
+
start = (np.cos(angle[i])*10+nucleation_points[i][0], np.sin(angle[i])*10+nucleation_points[i][1])
|
90
|
+
end = (-np.cos(angle[i])*10+nucleation_points[i][0], -np.sin(angle[i])*10+nucleation_points[i][1])
|
91
|
+
line_new_point += [minDistance_line_point(start, end, new_points)]
|
92
|
+
|
93
|
+
trial = 0
|
94
|
+
while sum(np.array(line_new_point) < radius) != 0 or np.sum( np.sqrt(np.sum((np.array(nucleation_points) - np.array(new_points))**2, axis = 1)) < radius) != 0:
|
95
|
+
new_points = (random.uniform(0,1), random.uniform(0,1))
|
96
|
+
|
97
|
+
line_new_point = []
|
98
|
+
for j in range(len(nucleation_points)):
|
99
|
+
start = (np.cos(angle[i])*10+nucleation_points[i][0], np.sin(angle[i])*10+nucleation_points[i][1])
|
100
|
+
end = (-np.cos(angle[i])*10+nucleation_points[i][0], -np.sin(angle[i])*10+nucleation_points[i][1])
|
101
|
+
line_new_point += [minDistance_line_point(start, end, new_points)]
|
102
|
+
|
103
|
+
trial += 1
|
104
|
+
|
105
|
+
if trial > number_of_trials:
|
106
|
+
break
|
107
|
+
|
108
|
+
if trial <= number_of_trials:
|
109
|
+
nucleation_points += [new_points]
|
110
|
+
angles = [0, np.pi/4, np.pi/2, 3*np.pi/4]
|
111
|
+
angle_new = random.uniform(0, 2*np.pi) #random.choice(angles)#np.pi #random.uniform(0, 2*np.pi)
|
112
|
+
angle += [angle_new]
|
113
|
+
Line[line_id] = [ new_points ,angle_new]
|
114
|
+
line_id += 1
|
115
|
+
else:
|
116
|
+
print('jammed')
|
117
|
+
break
|
118
|
+
|
119
|
+
#number of Line
|
120
|
+
print("Number of line: ", len(Line))
|
121
|
+
|
122
|
+
return(Line)
|
123
|
+
|
124
|
+
def all_intersection(Line):
|
125
|
+
intersections_dict = {}
|
126
|
+
|
127
|
+
for k,v in Line.items():
|
128
|
+
#intersections_dict[k] = {}
|
129
|
+
intersections_dict[k] = {'back':{}, 'front':{}}
|
130
|
+
|
131
|
+
for kk,vv in Line.items():
|
132
|
+
intersect, (intersect_x, intersect_y) = doLinesIntersect(v ,vv)
|
133
|
+
|
134
|
+
if intersect:
|
135
|
+
segment_length = np.sqrt( (v[0][0] - intersect_x)**2 + (v[0][1] - intersect_y)**2)
|
136
|
+
|
137
|
+
if intersect_x < v[0][0]:
|
138
|
+
intersections_dict[k]['back'][kk] = [(intersect_x, intersect_y), segment_length]
|
139
|
+
else:
|
140
|
+
if intersect_x == v[0][0] and intersect_y < v[0][1]:
|
141
|
+
intersections_dict[k]['back'][kk] = [(intersect_x, intersect_y), segment_length]
|
142
|
+
else:
|
143
|
+
intersections_dict[k]['front'][kk] = [(intersect_x, intersect_y), segment_length]
|
144
|
+
intersections_dict[k]['back'] = dict(sorted(intersections_dict[k]['back'].items(), key=lambda e:e[1], reverse = True))
|
145
|
+
intersections_dict[k]['front'] = dict(sorted(intersections_dict[k]['front'].items(), key=lambda e:e[1]))
|
146
|
+
|
147
|
+
return intersections_dict
|
148
|
+
|
149
|
+
def transform_to_standard_lines(segments):
|
150
|
+
|
151
|
+
data = []
|
152
|
+
for s in segments:
|
153
|
+
start = (s[3], s[4])
|
154
|
+
end = (s[5], s[6])
|
155
|
+
line = LineSegment(start=start, end=end, id=s[0], neighbors_initial=[s[1], s[2]], neighbors=None)
|
156
|
+
data.append(line)
|
157
|
+
|
158
|
+
return data
|
159
|
+
|
160
|
+
def static_line_graph_generation(Line, intersections_dict):
|
161
|
+
borders = ['b1', 'b2', 'b3', 'b4']
|
162
|
+
segments = []
|
163
|
+
edges = []
|
164
|
+
|
165
|
+
for k,v in Line.items():
|
166
|
+
if k not in borders:
|
167
|
+
#front
|
168
|
+
for kk_f, vv_f in intersections_dict[k]['front'].items():
|
169
|
+
try:
|
170
|
+
d_k_kk = intersections_dict[kk_f]['back'][k][1]
|
171
|
+
front_coordinate = intersections_dict[kk_f]['back'][k][0]
|
172
|
+
front_id = kk_f
|
173
|
+
where = 'back'
|
174
|
+
except:
|
175
|
+
d_k_kk = intersections_dict[kk_f]['front'][k][1]
|
176
|
+
front_coordinate = intersections_dict[kk_f]['front'][k][0]
|
177
|
+
front_id = kk_f
|
178
|
+
where = 'front'
|
179
|
+
|
180
|
+
if vv_f[1] > d_k_kk:
|
181
|
+
#check kk neighbors
|
182
|
+
boolean = []
|
183
|
+
for kkk, vvv in intersections_dict[kk_f][where].items():
|
184
|
+
if vvv[1] < d_k_kk:
|
185
|
+
try:
|
186
|
+
d_kk_kkk = intersections_dict[kkk]['back'][kk_f][1]
|
187
|
+
except:
|
188
|
+
d_kk_kkk = intersections_dict[kkk]['front'][kk_f][1]
|
189
|
+
|
190
|
+
if d_kk_kkk > vvv[1]:
|
191
|
+
boolean += [0]
|
192
|
+
else:
|
193
|
+
boolean += [1]
|
194
|
+
|
195
|
+
#print(k,kk, boolean)
|
196
|
+
|
197
|
+
if sum(boolean) == 0:
|
198
|
+
#print(k, kk, front_coordinate)
|
199
|
+
break
|
200
|
+
|
201
|
+
#back
|
202
|
+
for kk_b, vv_b in intersections_dict[k]['back'].items():
|
203
|
+
try:
|
204
|
+
d_k_kk = intersections_dict[kk_b]['back'][k][1]
|
205
|
+
back_coordinate = intersections_dict[kk_b]['back'][k][0]
|
206
|
+
back_id = kk_b
|
207
|
+
where = 'back'
|
208
|
+
except:
|
209
|
+
d_k_kk = intersections_dict[kk_b]['front'][k][1]
|
210
|
+
back_coordinate = intersections_dict[kk_b]['front'][k][0]
|
211
|
+
back_id = kk_b
|
212
|
+
where = 'front'
|
213
|
+
|
214
|
+
if vv_b[1] > d_k_kk:
|
215
|
+
#check kk neighbors
|
216
|
+
boolean = []
|
217
|
+
for kkk, vvv in intersections_dict[kk_b][where].items():
|
218
|
+
if vvv[1] < d_k_kk:
|
219
|
+
#print(vvv[1], d_k_kk)
|
220
|
+
try:
|
221
|
+
d_kk_kkk = intersections_dict[kkk]['back'][kk_b][1]
|
222
|
+
except:
|
223
|
+
d_kk_kkk = intersections_dict[kkk]['front'][kk_b][1]
|
224
|
+
|
225
|
+
if d_kk_kkk > vvv[1]:
|
226
|
+
boolean += [0]
|
227
|
+
else:
|
228
|
+
boolean += [1]
|
229
|
+
#print(k,kk, boolean)
|
230
|
+
|
231
|
+
|
232
|
+
if sum(boolean) == 0:
|
233
|
+
#print(k, kk, back_coordinate)
|
234
|
+
break
|
235
|
+
|
236
|
+
|
237
|
+
try:
|
238
|
+
if k!= kk_f and k!= kk_b and kk_f != kk_b and (k, kk_f) not in edges and (kk_f, k) not in edges and (k, kk_b) not in edges and (kk_b, k) not in edges:
|
239
|
+
segments+= [[k, kk_f, kk_b, front_coordinate[0], front_coordinate[1], back_coordinate[0], back_coordinate[1]]]
|
240
|
+
edges += [(k,kk_f)]
|
241
|
+
edges += [(k,kk_b)]
|
242
|
+
except:
|
243
|
+
None
|
244
|
+
|
245
|
+
return segments
|
246
|
+
|
247
|
+
def generate_line_segments_static(size, seed_loc=None):
|
248
|
+
if seed_loc is None:
|
249
|
+
seed_loc = seeds(size, 0.0)
|
250
|
+
segments = static_line_graph_generation(seed_loc, all_intersection(seed_loc))
|
251
|
+
segments = transform_to_standard_lines(segments)
|
252
|
+
|
253
|
+
return segments
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|