3D polylinine werden im Routing berücksichtigt

This commit is contained in:
2025-06-30 16:43:50 +02:00
parent 5258457851
commit e5ca9561dd
2 changed files with 62 additions and 20 deletions
+55 -19
View File
@@ -9,21 +9,27 @@ import matplotlib.pyplot as plt
from itertools import pairwise, combinations, permutations from itertools import pairwise, combinations, permutations
import re import re
from shapely.strtree import STRtree from shapely.strtree import STRtree
import math
import shapely
# Globale Variable, die in main aufgerufen wird und steuert ob Graphen in unittests gezeichnet werden # Globale Variable, die in main aufgerufen wird und steuert ob Graphen in unittests gezeichnet werden
draw = False draw = False
class PointSorter: class PointSorter:
def __init__(self): def __init__(self):
self._points_by_x = [] # [(x, y)] #self._points_by_x = [] # [(x, y)]
self._points_by_y = [] # [(y, x)] #self._points_by_y = [] # [(y, x)]
def add_point(self, x, y): self.points = []
bisect.insort(self._points_by_x, (x, y))
bisect.insort(self._points_by_y, (y, x)) def add_point(self, point:Point):
# bisect.insort(self._points_by_x, (x, y))
# bisect.insort(self._points_by_y, (y, x))
self.points.append(point)
def add_points(self, points:list[Point]): def add_points(self, points:list[Point]):
for p in points: for p in points:
self.add_point(p.x, p.y) self.add_point(p)
def query_box(self, x1, x2, y1, y2): def query_box(self, x1, x2, y1, y2):
# Suche nach x-Grenzen # Suche nach x-Grenzen
@@ -40,17 +46,19 @@ class PointSorter:
def get_sorted_by_x(self): def get_sorted_by_x(self):
# Sortiere nach x # Sortiere nach x
ret = list() # ret = list()
for (x,y) in self._points_by_x: # for (x,y) in self._points_by_x:
ret.append(Point(x,y)) # ret.append(Point(x,y))
return ret # return ret
return sorted(self.points, key = lambda p: p.x)
def get_sorted_by_y(self): def get_sorted_by_y(self):
# Sortiere nach y # # Sortiere nach y
ret = list() # ret = list()
for (y,x) in self._points_by_y: # for (y,x) in self._points_by_y:
ret.append(Point(x,y)) # ret.append(Point(x,y))
return ret # return ret
return sorted(self.points, key = lambda p: p.y)
def to_json(d, pretty: bool = True) -> str: def to_json(d, pretty: bool = True) -> str:
return json.dumps(d, indent=2 if pretty else None, default=str) #ensure_ascii false für darstellung von "ue" return json.dumps(d, indent=2 if pretty else None, default=str) #ensure_ascii false für darstellung von "ue"
@@ -290,6 +298,8 @@ class Anlage():
self._tunnel_lengths = dict() self._tunnel_lengths = dict()
#Container für alle Wege #Container für alle Wege
self._sensor2dist = dict() self._sensor2dist = dict()
# Container für Sensor Artikelnummern
self._sensor_artnrs = dict()
# Toleranzen zur Rack anbindung aneinander (Rack Snap) # Toleranzen zur Rack anbindung aneinander (Rack Snap)
self._tol_snap = tol_snap self._tol_snap = tol_snap
# Toleranzen zur Anbindung von Sensoren / Verteilern zu Racks # Toleranzen zur Anbindung von Sensoren / Verteilern zu Racks
@@ -543,7 +553,16 @@ class Anlage():
nid_start = self._nodeids.get_id(start) nid_start = self._nodeids.get_id(start)
nid_end = self._nodeids.get_id(end) nid_end = self._nodeids.get_id(end)
weight=start.distance(end) dx = start.x - end.x
dy = start.y - end.y
if shapely.has_z(start) and shapely.has_z(end):
dz = (getattr(start, "z", 0) - getattr(end, "z", 0))
else:
dz = 0.0
weight = math.sqrt(dx**2 + dy**2 + dz**2)
#weight=start.distance(end)
if re.match("v-.*", rname): if re.match("v-.*", rname):
color = "red" color = "red"
@@ -602,7 +621,8 @@ class Anlage():
ld = dict() ld = dict()
ld['id'] = f"{dname}-{sname}" ld['id'] = f"{dname}-{sname}"
ld['s_artinr'] = self._sensor_artnrs.get(sname, "") if len(self._sensor_artnrs) > 0:
ld['s_artinr'] = self._sensor_artnrs.get(sname, "")
ld["coords"]= [{"x":round(p.x,1), "y":round(p.y,1)} for p in pfad_coords] ld["coords"]= [{"x":round(p.x,1), "y":round(p.y,1)} for p in pfad_coords]
ld["length"]= round(pfad_length,1) ld["length"]= round(pfad_length,1)
#ld["nodes"]=pfad_nodes #ld["nodes"]=pfad_nodes
@@ -696,12 +716,28 @@ class TestPlant(unittest.TestCase):
'Rack_2-0': [Point(1, 8), Point(1, 0)], 'Rack_2-0': [Point(1, 8), Point(1, 0)],
'Rack_2-1': [Point(0, 10), Point(5, 10)]} 'Rack_2-1': [Point(0, 10), Point(5, 10)]}
# 10 |R2-1: ####################
# 9 |
# 8 | |
# 7 | |
# 6 | | #### R1-0
# 5 | | #
# 4 | | #
# 3 | | #
# 2 | | #
# 1 | |#
# 0 |-----#--------------------
# 0 1 2 3 4 5
point2rack = RackIDs() point2rack = RackIDs()
point2rack.add_racks(res_rack_seg) point2rack.add_racks(res_rack_seg)
self.assertEqual(point2rack.get_racks_from_point(Point(1, 0)), ["Rack_1-0", "Rack_2-0"]) t1 = set(point2rack.get_racks_from_point(Point(1, 0)))
self.assertEqual(point2rack.get_racks_from_point(Point(5, 6)), ["Rack_1-0"]) self.assertEqual(t1, set(["Rack_1-0", "Rack_2-0"]))
t2 = point2rack.get_racks_from_point(Point(5, 6))
self.assertEqual(t2, set(["Rack_1-0"]))
self.assertEqual(point2rack.get_points_from_rack("Rack_2-0"), [Point(1, 0), Point(1, 8)]) self.assertEqual(point2rack.get_points_from_rack("Rack_2-0"), [Point(1, 0), Point(1, 8)])
def test_add_point_interim(self): def test_add_point_interim(self):
+7 -1
View File
@@ -5,11 +5,13 @@ import heapq
import math import math
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import networkx as nx import networkx as nx
import shapely
from shapely.geometry import LineString, Point from shapely.geometry import LineString, Point
from shapely.ops import nearest_points from shapely.ops import nearest_points
from plant import Anlage from plant import Anlage
import configparser import configparser
# Funktionen # Funktionen
def load_json(jsonfilename): def load_json(jsonfilename):
with open(jsonfilename, encoding='utf-8') as fh: with open(jsonfilename, encoding='utf-8') as fh:
@@ -127,7 +129,11 @@ def prepare_data(rawdata:dict):
for rname,lp in racks.items(): for rname,lp in racks.items():
ltemp = list() ltemp = list()
for p in lp: for p in lp:
ltemp.append(Point(p)) if len(p) == 3:
pt = Point(p[0], p[1], p[2])
else:
pt = Point(p[0], p[1], 0.0)
ltemp.append(pt)
dracks[rname] = ltemp dracks[rname] = ltemp
mapping = rawdata["mappings"] mapping = rawdata["mappings"]