@@ -23,11 +23,9 @@ private BusbarSectionFinderTraverser() {
23
23
throw new UnsupportedOperationException ();
24
24
}
25
25
26
- private record NodePath (int startNode , List <SwitchInfo > traversedSwitches , SwitchInfo lastSwitch ) { }
27
-
28
26
public record SwitchInfo (String id , boolean isOpen ) { }
29
27
30
- public record BusbarSectionResult (String busbarSectionId , int depth , SwitchInfo lastSwitch ) { }
28
+ public record BusbarSectionResult (String busbarSectionId , int depth , SwitchInfo lastSwitch , boolean allSwitchesClosed ) { }
31
29
32
30
public static String findBusbarSectionId (Terminal terminal ) {
33
31
BusbarSectionResult result = getBusbarSectionResult (terminal );
@@ -37,7 +35,7 @@ public static String findBusbarSectionId(Terminal terminal) {
37
35
public static BusbarSectionResult getBusbarSectionResult (Terminal terminal ) {
38
36
VoltageLevel .NodeBreakerView view = terminal .getVoltageLevel ().getNodeBreakerView ();
39
37
int startNode = terminal .getNodeBreakerView ().getNode ();
40
- List <BusbarSectionResult > allResults = searchAllBusbars (view , startNode );
38
+ List <BusbarSectionResult > allResults = searchAllBusbars (terminal . getVoltageLevel () , startNode );
41
39
if (allResults .isEmpty ()) {
42
40
return null ;
43
41
}
@@ -63,106 +61,35 @@ private static BusbarSectionResult selectBestBusbar(List<BusbarSectionResult> re
63
61
return results .getFirst ();
64
62
}
65
63
66
- private static List <BusbarSectionResult > searchAllBusbars (VoltageLevel . NodeBreakerView view , int startNode ) {
64
+ private static List <BusbarSectionResult > searchAllBusbars (VoltageLevel voltageLevel , int startNode ) {
67
65
List <BusbarSectionResult > results = new ArrayList <>();
68
- // Set<Integer> visited = new HashSet<>();
69
- // Queue<NodePath> nodePathsToVisit = new LinkedList<>();
70
- // nodePathsToVisit.offer(new NodePath(startNode, new ArrayList<>(), null));
71
-
72
66
73
- view .getTerminal (startNode ).traverse (new Terminal .TopologyTraverser () {
67
+ voltageLevel . getNodeBreakerView () .getTerminal (startNode ).traverse (new Terminal .TopologyTraverser () {
74
68
int currentDepth = 0 ;
69
+ boolean allSwitchesClosed = true ;
75
70
SwitchInfo lastSwitch = null ;
76
71
@ Override
77
72
public TraverseResult traverse (Terminal terminal , boolean connected ) {
78
- //if (terminal.getVoltageLevel() != view.
73
+ if (terminal .getVoltageLevel () != voltageLevel )
74
+ return TraverseResult .TERMINATE_PATH ;
79
75
80
76
if (terminal .getConnectable () instanceof BusbarSection busbarSection ) {
81
- // add busbar section to the path
82
- results .add (new BusbarSectionResult (busbarSection .getId (), currentDepth , lastSwitch ));
77
+ results .add (new BusbarSectionResult (busbarSection .getId (), currentDepth , lastSwitch ,allSwitchesClosed ));
83
78
return TraverseResult .TERMINATE_PATH ;
84
79
}
85
- // currentDepth++;
86
80
return TraverseResult .CONTINUE ;
87
81
}
88
82
89
83
@ Override
90
84
public TraverseResult traverse (Switch aSwitch ) {
91
85
currentDepth ++;
92
86
lastSwitch = new SwitchInfo (aSwitch .getId (), aSwitch .isOpen ());
87
+ if (!aSwitch .isOpen ()) {
88
+ allSwitchesClosed = false ;
89
+ }
93
90
return TraverseResult .CONTINUE ;
94
91
}
95
92
}, TraversalType .BREADTH_FIRST );
96
-
97
- // while (!nodePathsToVisit.isEmpty()) {
98
- // NodePath currentNodePath = nodePathsToVisit.poll();
99
- // if (hasBeenVisited(currentNodePath.startNode(), visited)) {
100
- // continue;
101
- // }
102
- // visited.add(currentNodePath.startNode());
103
- // Optional<BusbarSectionResult> busbarSectionResult = findBusbarSectionAtNode(view, currentNodePath);
104
- // if (busbarSectionResult.isPresent()) {
105
- // results.add(busbarSectionResult.get());
106
- // } else {
107
- //// exploreAdjacentNodes(view, currentNodePath, visited, nodePathsToVisit);
108
- // }
109
- // }
110
93
return results ;
111
94
}
112
-
113
- private static boolean hasBeenVisited (int node , Set <Integer > visited ) {
114
- return visited .contains (node );
115
- }
116
-
117
- private static Optional <BusbarSectionResult > findBusbarSectionAtNode (VoltageLevel .NodeBreakerView view , NodePath currentNodePath ) {
118
- Optional <Terminal > nodeTerminal = view .getOptionalTerminal (currentNodePath .startNode ());
119
- if (nodeTerminal .isEmpty ()) {
120
- return Optional .empty ();
121
- }
122
- Terminal terminal = nodeTerminal .get ();
123
- if (terminal .getConnectable ().getType () == IdentifiableType .BUSBAR_SECTION ) {
124
- String busbarSectionId = terminal .getConnectable ().getId ();
125
- int depth = currentNodePath .traversedSwitches ().size ();
126
- SwitchInfo lastSwitch = currentNodePath .lastSwitch ();
127
- BusbarSection busbarSection = (BusbarSection ) terminal .getConnectable ();
128
- int busbarIndex = 1 ;
129
- int sectionIndex = 1 ;
130
- var busbarSectionPosition = busbarSection .getExtension (BusbarSectionPosition .class );
131
- if (busbarSectionPosition != null ) {
132
- busbarIndex = busbarSectionPosition .getBusbarIndex ();
133
- sectionIndex = busbarSectionPosition .getSectionIndex ();
134
- }
135
- return Optional .of (new BusbarSectionResult (busbarSectionId , depth , lastSwitch ));
136
- }
137
- return Optional .empty ();
138
- }
139
-
140
- private static void exploreAdjacentNodes (VoltageLevel .NodeBreakerView view , NodePath currentNodePath , Set <Integer > visited , Queue <NodePath > nodePathsToVisit ) {
141
- view .getSwitchStream ().forEach (sw -> {
142
- int node1 = view .getNode1 (sw .getId ());
143
- int node2 = view .getNode2 (sw .getId ());
144
- Optional <Integer > nextNode = getNextNodeIfAdjacent (currentNodePath .startNode (), node1 , node2 );
145
- if (nextNode .isPresent () && !visited .contains (nextNode .get ())) {
146
- NodePath newNodePath = createNodePath (currentNodePath , sw , nextNode .get ());
147
- nodePathsToVisit .offer (newNodePath );
148
- }
149
- });
150
- }
151
-
152
- private static Optional <Integer > getNextNodeIfAdjacent (int currentNode , int node1 , int node2 ) {
153
- if (node1 == currentNode ) {
154
- return Optional .of (node2 );
155
- }
156
- if (node2 == currentNode ) {
157
- return Optional .of (node1 );
158
- }
159
- return Optional .empty ();
160
- }
161
-
162
- private static NodePath createNodePath (NodePath currentNodePath , Switch sw , int nextNode ) {
163
- List <SwitchInfo > newPathSwitches = new ArrayList <>(currentNodePath .traversedSwitches ());
164
- SwitchInfo switchInfo = new SwitchInfo (sw .getId (), sw .isOpen ());
165
- newPathSwitches .add (switchInfo );
166
- return new NodePath (nextNode , newPathSwitches , switchInfo );
167
- }
168
95
}
0 commit comments