Wegsuche Methode implementiert
This commit is contained in:
+79
-6
@@ -162,18 +162,23 @@ class Anlage():
|
||||
def __init__(self, tol_snap=200, snap_step=10, tol_connect=2, tol_connect_step=0.5):
|
||||
# Container für alle Racks
|
||||
self._racks = RackIDs()
|
||||
# zuordnung zwischen KnotenID und Punkt
|
||||
self._nodeids = NodeIDs()
|
||||
# Container für alle Sensoren
|
||||
self._sensors = dict()
|
||||
self._sensor_onpoints = dict()
|
||||
# Container für alle Unterverteiler
|
||||
self._distributors = dict()
|
||||
self._distributors_onpoints = dict()
|
||||
#Container für alle Wege
|
||||
self._sensor2dist = dict()
|
||||
# Toleranzen zur Rack anbindung aneinander (Rack Snap)
|
||||
self._tol_snap = tol_snap
|
||||
self._snap_step = snap_step
|
||||
# Toleranzen zur Anbindung von Sensoren / Verteilern zu Racks
|
||||
self._tol_connect = tol_connect
|
||||
self._connect_step = tol_connect_step
|
||||
|
||||
|
||||
def set_racks(self, racks:dict[str, list[Point]]):
|
||||
return self._racks.add_racks(racks)
|
||||
@@ -214,6 +219,9 @@ class Anlage():
|
||||
for sname,pos in sensors.items():
|
||||
self.add_sensor(sname, pos)
|
||||
|
||||
def get_sensor_point(self, sname:str) -> Point:
|
||||
return self._sensors[sname]
|
||||
|
||||
def connect_sensors_to_racks(self):
|
||||
for sname, pos in self._sensors.items():
|
||||
rack_borders = self._racks.get_racks_borders()
|
||||
@@ -232,6 +240,9 @@ class Anlage():
|
||||
for dname,pos in distributors.items():
|
||||
self.add_distributor(dname, pos)
|
||||
|
||||
def get_distributor_point(self, dname:str) -> Point:
|
||||
return self._distributors[dname]
|
||||
|
||||
def connect_distributor_to_racks(self):
|
||||
for dname, pos in self._distributors.items():
|
||||
rack_borders = self._racks.get_racks_borders()
|
||||
@@ -444,7 +455,7 @@ class Anlage():
|
||||
|
||||
points.extend(self.get_points_from_sensors())
|
||||
|
||||
nodeids = NodeIDs(points)
|
||||
self._nodeids.add_points(points)
|
||||
|
||||
for p in points:
|
||||
if self.is_distributor(p):
|
||||
@@ -453,19 +464,19 @@ class Anlage():
|
||||
shape = "^"
|
||||
else:
|
||||
shape = "o"
|
||||
nid = nodeids.get_id(p)
|
||||
nid = self._nodeids.get_id(p)
|
||||
G.add_node(nid, shape=shape) # Knoten für Startpunkt
|
||||
|
||||
pos = dict()
|
||||
for node in G.nodes:
|
||||
point = nodeids.get_point(node)
|
||||
point = self._nodeids.get_point(node)
|
||||
pos[node] = (point.x, point.y)
|
||||
|
||||
for rname in self.get_rack_names():
|
||||
plist = self.get_points_from_rack(rname)
|
||||
for start, end in pairwise(plist):
|
||||
nid_start = nodeids.get_id(start)
|
||||
nid_end = nodeids.get_id(end)
|
||||
nid_start = self._nodeids.get_id(start)
|
||||
nid_end = self._nodeids.get_id(end)
|
||||
|
||||
if re.match("v-.*", rname):
|
||||
color = "red"
|
||||
@@ -476,9 +487,36 @@ class Anlage():
|
||||
G.add_edge(nid_start, nid_end, color=color, weight=start.distance(end))
|
||||
return pos
|
||||
|
||||
def map_distributor_to_sensors(self, dname:str, snamen:list[str]):
|
||||
''' Gibt zu einem Distributor die zugehörigen Sensoren an, die später zugeordnet werden.
|
||||
Dist_1: ["Sens_3, Sens_5, ...]
|
||||
'''
|
||||
for sname in snamen:
|
||||
self._sensor2dist[sname] = dname
|
||||
|
||||
def map_distributors_to_sensors(self, d2sensors:dict[str, list[str]]):
|
||||
''' Gibt zu einem dict mit Distributors die jeweils zugehörigen Sensoren aus.
|
||||
{Dist_1: ["Sens_3, Sens_5, ...]
|
||||
Dist_2: ["Sens_1, Sens_8, ...]}
|
||||
'''
|
||||
for dname, listofsensors in d2sensors.items():
|
||||
self.map_distributor_to_sensors(dname, listofsensors)
|
||||
|
||||
|
||||
def create_cable_path(self, G, sname, dname):
|
||||
quelle = self._nodeids.get_id(self.get_distributor_point(dname))
|
||||
ziel = self._nodeids.get_id(self.get_sensor_point(sname))
|
||||
pfad_nodes = nx.shortest_path(G, source=quelle, target=ziel, weight='weight')
|
||||
pfad_length = nx.shortest_path_length(G, source=1, target=5)
|
||||
|
||||
|
||||
def create_cable_paths(self, G):
|
||||
for sname, dname in self._sensor2dist:
|
||||
self.create_cable_path(G, sname, dname)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -628,5 +666,40 @@ class TestLinesweep(unittest.TestCase):
|
||||
plt.show()
|
||||
|
||||
|
||||
def test_Wegsuche(self):
|
||||
|
||||
rack_segs = {'Rack_1-0': [Point(0, 0), Point(0, 10)],
|
||||
'Rack_2-0': [Point(10, -2), Point(10, 5)],
|
||||
'Rack_2-1': [Point(0, 3), Point(10, 3)]}
|
||||
|
||||
sensors = {'Sens_1': Point(1, 1),
|
||||
'Sens_2': Point(2, 4),
|
||||
'Sens_3': Point(9, 2)}
|
||||
|
||||
distributors = {'Dist_1': Point(-1, 9),
|
||||
'Dist_2': Point(11, 0)}
|
||||
|
||||
mapping = {'Dist_1': ["Sens_1", "Sens_2"],
|
||||
'Dist_2': ["Sens_3"]}
|
||||
|
||||
an = Anlage()
|
||||
an.set_racks(rack_segs)
|
||||
an.add_sensors(sensors)
|
||||
an.connect_sensors_to_racks()
|
||||
an.add_distributors(distributors)
|
||||
an.connect_distributor_to_racks()
|
||||
an.map_distributors_to_sensors(mapping)
|
||||
|
||||
G3 = nx.Graph()
|
||||
pos = an.generate_graph(G3)
|
||||
|
||||
edge_colors = [G3[u][v].get('color', 'black') for u, v in G3.edges()]
|
||||
|
||||
nx.draw(G3, pos, with_labels=False, node_size=10, font_size=8, edge_color=edge_colors)
|
||||
plt.show()
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user