@@ -9,32 +9,44 @@ class Union:
99 def union (
1010 topology_a : Topology , node_matching : Dict [Node , Node ], topology_b : Topology = None
1111 ) -> Topology :
12- if not (
13- Union ._are_all_nodes_in_topology (topology_a , node_matching .keys ())
14- and Union ._are_all_nodes_in_topology (topology_b , node_matching .values ())
15- ):
16- raise ValueError (
17- "The node matching contains nodes, that are not inside the corresponding topology. Abort."
18- )
12+ if topology_b is None :
13+ if not (
14+ Union ._are_all_nodes_in_topology (topology_a , node_matching .keys ())
15+ and Union ._are_all_nodes_in_topology (topology_a , node_matching .values ())
16+ ):
17+ raise ValueError (
18+ "The node matching contains nodes, that are not inside the given topology. Abort."
19+ )
20+ else :
21+ if not (
22+ Union ._are_all_nodes_in_topology (topology_a , node_matching .keys ())
23+ and Union ._are_all_nodes_in_topology (topology_b , node_matching .values ())
24+ ):
25+ raise ValueError (
26+ "The node matching contains nodes, that are not inside the corresponding topology. Abort."
27+ )
1928
2029 if not Union ._are_all_nodes_ends (node_matching ):
2130 raise ValueError (
2231 "Some of the nodes in the matching are points. All nodes have to be ends. Abort."
2332 )
2433
25- topology_ab = Topology ()
26- OperationsHelper .copy_topology_metadata (topology_a , topology_ab )
27-
28- topology_ab .nodes .update (topology_a .nodes )
29- topology_ab .nodes .update (topology_b .nodes )
30- topology_ab .edges .update (topology_a .edges )
31- topology_ab .edges .update (topology_b .edges )
32- topology_ab .signals .update (topology_a .signals )
33- topology_ab .signals .update (topology_b .signals )
34- topology_ab .routes .update (topology_a .routes )
35- topology_ab .routes .update (topology_b .routes )
36- topology_ab .vacancy_sections .update (topology_a .vacancy_sections )
37- topology_ab .vacancy_sections .update (topology_b .vacancy_sections )
34+ topology_ab = topology_a
35+
36+ if topology_b is not None :
37+ topology_ab = Topology ()
38+ OperationsHelper .copy_topology_metadata (topology_a , topology_ab )
39+
40+ topology_ab .nodes .update (topology_a .nodes )
41+ topology_ab .nodes .update (topology_b .nodes )
42+ topology_ab .edges .update (topology_a .edges )
43+ topology_ab .edges .update (topology_b .edges )
44+ topology_ab .signals .update (topology_a .signals )
45+ topology_ab .signals .update (topology_b .signals )
46+ topology_ab .routes .update (topology_a .routes )
47+ topology_ab .routes .update (topology_b .routes )
48+ topology_ab .vacancy_sections .update (topology_a .vacancy_sections )
49+ topology_ab .vacancy_sections .update (topology_b .vacancy_sections )
3850
3951 for node_a , node_b in node_matching .items ():
4052 union_edge_a : Edge = node_a .connected_edges [0 ]
0 commit comments