11from enum import Enum , auto
2- from typing import Dict , List , Set , Tuple
2+ from typing import Dict , List , Tuple
33
44import networkx as nx
55
66from ..model import (
7- DbrefGeoNode ,
87 Edge ,
98 GeoNode ,
109 Node ,
1110 Signal ,
1211 SignalDirection ,
1312 Topology ,
14- Wgs84GeoNode ,
1513)
1614
1715
@@ -44,11 +42,13 @@ def compare(
4442 topology_b : Topology ,
4543 compare_mode : CompareMode ,
4644 given_node_matching : Dict [Node , Node ] | None = None ,
47- exclude_ends_in_calculation : bool = False ,
45+ exclude_element_list = None ,
4846 skip_signals : bool = False ,
4947 ) -> CompareResult :
5048 if given_node_matching is None :
5149 given_node_matching = {}
50+ if exclude_element_list is None :
51+ exclude_element_list = []
5252
5353 result : CompareResult = CompareResult ()
5454
@@ -66,14 +66,14 @@ def compare(
6666 )
6767
6868 result .node_distance = Compare ._calc_distance_for_matching (
69- result .node_matching , exclude_ends_in_calculation
69+ result .node_matching , exclude_element_list
7070 )
7171 result .edge_length_difference = Compare ._calc_distance_for_matching (
72- result .edge_matching , exclude_ends_in_calculation , element_type = "edge"
72+ result .edge_matching , exclude_element_list , element_type = "edge"
7373 )
7474 if not skip_signals :
7575 result .signal_distance = Compare ._calc_distance_for_matching (
76- result .signal_matching , exclude_ends_in_calculation , element_type = "signal"
76+ result .signal_matching , exclude_element_list , element_type = "signal"
7777 )
7878 return result
7979
@@ -125,6 +125,7 @@ def __add_to_open_nodes(__node_a: Node, __node_b: Node):
125125 def __add_edges_to_matching (__edge_a : Edge , __edge_b : Edge ):
126126 if __edge_a in result .edge_matching .element_matching :
127127 if result .edge_matching .element_matching [__edge_a ] != __edge_b :
128+ print (f"bad edge { __edge_a .uuid } { __edge_b .uuid } " )
128129 raise ValueError (
129130 "Graph topology is isomorphic, but railway network graph differs (edge graph broken)"
130131 )
@@ -225,7 +226,7 @@ def _are_topologies_isomorphic(topology_a: Topology, topology_b: Topology):
225226 @staticmethod
226227 def _calc_distance_for_matching (
227228 matching : CompareMatching ,
228- exclude_ends_in_calculation ,
229+ exclude_element_list ,
229230 element_type : str = "node" ,
230231 ):
231232 if not matching .element_matching :
@@ -234,20 +235,16 @@ def _calc_distance_for_matching(
234235 distance_sum : float = 0.0
235236 for element_a in matching .element_matching :
236237 element_b = matching .element_matching [element_a ]
238+ if element_a in exclude_element_list or element_b in exclude_element_list :
239+ continue
237240
238241 if element_type == "node" :
239- if exclude_ends_in_calculation and not element_a .is_point ():
240- continue
241242 geo_node_a : GeoNode = element_a .geo_node
242243 geo_node_b : GeoNode = element_b .geo_node
243244 distance = abs (geo_node_a .get_distance_to_other_geo_node (geo_node_b ))
244245 print (f"From { element_a .uuid } to { element_b .uuid } : { distance } " )
245246 distance_sum += distance
246247 elif element_type == "edge" :
247- if exclude_ends_in_calculation and (
248- not element_a .node_a .is_point () or not element_a .node_b .is_point ()
249- ):
250- continue
251248 print (
252249 f"Edge { element_a .uuid } compared to { element_b .uuid } : { abs (element_a .length - element_b .length )} "
253250 )
0 commit comments