8
8
9
9
import com .powsybl .iidm .network .*;
10
10
import com .powsybl .iidm .network .extensions .BusbarSectionPosition ;
11
+ import com .powsybl .math .graph .TraversalType ;
12
+ import com .powsybl .math .graph .TraverseResult ;
11
13
12
14
import java .util .*;
13
15
@@ -25,7 +27,7 @@ private record NodePath(int startNode, List<SwitchInfo> traversedSwitches, Switc
25
27
26
28
public record SwitchInfo (String id , boolean isOpen ) { }
27
29
28
- public record BusbarSectionResult (String busbarSectionId , int depth , SwitchInfo lastSwitch , int busbarIndex , int sectionIndex ) { }
30
+ public record BusbarSectionResult (String busbarSectionId , int depth , SwitchInfo lastSwitch ) { }
29
31
30
32
public static String findBusbarSectionId (Terminal terminal ) {
31
33
BusbarSectionResult result = getBusbarSectionResult (terminal );
@@ -46,42 +48,65 @@ private static BusbarSectionResult selectBestBusbar(List<BusbarSectionResult> re
46
48
List <BusbarSectionResult > withoutSwitch = results .stream ().filter (r -> r .lastSwitch () == null ).toList ();
47
49
if (!withoutSwitch .isEmpty ()) {
48
50
return withoutSwitch .stream ().min (Comparator .comparingInt (BusbarSectionResult ::depth )
49
- .thenComparingInt (BusbarSectionResult ::busbarIndex )
50
- .thenComparingInt (BusbarSectionResult ::sectionIndex )).orElse (null );
51
+ .thenComparing (BusbarSectionResult ::busbarSectionId )).orElse (null );
51
52
}
52
53
List <BusbarSectionResult > withClosedSwitch = results .stream ().filter (r -> r .lastSwitch () != null && !r .lastSwitch ().isOpen ()).toList ();
53
54
if (!withClosedSwitch .isEmpty ()) {
54
55
return withClosedSwitch .stream ().min (Comparator .comparingInt (BusbarSectionResult ::depth )
55
- .thenComparingInt (BusbarSectionResult ::busbarIndex )
56
- .thenComparingInt (BusbarSectionResult ::sectionIndex )).orElse (null );
56
+ .thenComparing (BusbarSectionResult ::busbarSectionId )).orElse (null );
57
57
}
58
58
List <BusbarSectionResult > withOpenSwitch = results .stream ().filter (r -> r .lastSwitch () != null && r .lastSwitch ().isOpen ()).toList ();
59
59
if (!withOpenSwitch .isEmpty ()) {
60
60
return withOpenSwitch .stream ().min (Comparator .comparingInt (BusbarSectionResult ::depth )
61
- .thenComparingInt (BusbarSectionResult ::busbarIndex )
62
- .thenComparingInt (BusbarSectionResult ::sectionIndex )).orElse (null );
61
+ .thenComparing (BusbarSectionResult ::busbarSectionId )).orElse (null );
63
62
}
64
63
return results .getFirst ();
65
64
}
66
65
67
66
private static List <BusbarSectionResult > searchAllBusbars (VoltageLevel .NodeBreakerView view , int startNode ) {
68
67
List <BusbarSectionResult > results = new ArrayList <>();
69
- Set <Integer > visited = new HashSet <>();
70
- Queue <NodePath > nodePathsToVisit = new LinkedList <>();
71
- nodePathsToVisit .offer (new NodePath (startNode , new ArrayList <>(), null ));
72
- while (!nodePathsToVisit .isEmpty ()) {
73
- NodePath currentNodePath = nodePathsToVisit .poll ();
74
- if (hasBeenVisited (currentNodePath .startNode (), visited )) {
75
- continue ;
68
+ // Set<Integer> visited = new HashSet<>();
69
+ // Queue<NodePath> nodePathsToVisit = new LinkedList<>();
70
+ // nodePathsToVisit.offer(new NodePath(startNode, new ArrayList<>(), null));
71
+
72
+
73
+ view .getTerminal (startNode ).traverse (new Terminal .TopologyTraverser () {
74
+ int currentDepth = 0 ;
75
+ SwitchInfo lastSwitch = null ;
76
+ @ Override
77
+ public TraverseResult traverse (Terminal terminal , boolean connected ) {
78
+ //if (terminal.getVoltageLevel() != view.
79
+
80
+ if (terminal .getConnectable () instanceof BusbarSection busbarSection ) {
81
+ // add busbar section to the path
82
+ results .add (new BusbarSectionResult (busbarSection .getId (), currentDepth , lastSwitch ));
83
+ return TraverseResult .TERMINATE_PATH ;
84
+ }
85
+ // currentDepth++;
86
+ return TraverseResult .CONTINUE ;
76
87
}
77
- visited . add ( currentNodePath . startNode ());
78
- Optional < BusbarSectionResult > busbarSectionResult = findBusbarSectionAtNode ( view , currentNodePath );
79
- if ( busbarSectionResult . isPresent () ) {
80
- results . add ( busbarSectionResult . get ()) ;
81
- } else {
82
- exploreAdjacentNodes ( view , currentNodePath , visited , nodePathsToVisit ) ;
88
+
89
+ @ Override
90
+ public TraverseResult traverse ( Switch aSwitch ) {
91
+ currentDepth ++ ;
92
+ lastSwitch = new SwitchInfo ( aSwitch . getId (), aSwitch . isOpen ());
93
+ return TraverseResult . CONTINUE ;
83
94
}
84
- }
95
+ }, 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
+ // }
85
110
return results ;
86
111
}
87
112
@@ -107,7 +132,7 @@ private static Optional<BusbarSectionResult> findBusbarSectionAtNode(VoltageLeve
107
132
busbarIndex = busbarSectionPosition .getBusbarIndex ();
108
133
sectionIndex = busbarSectionPosition .getSectionIndex ();
109
134
}
110
- return Optional .of (new BusbarSectionResult (busbarSectionId , depth , lastSwitch , busbarIndex , sectionIndex ));
135
+ return Optional .of (new BusbarSectionResult (busbarSectionId , depth , lastSwitch ));
111
136
}
112
137
return Optional .empty ();
113
138
}
0 commit comments