Skip to content

Commit 84b8d9a

Browse files
committed
fix
Signed-off-by: Etienne Homer <[email protected]>
1 parent 7a975c9 commit 84b8d9a

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/main/java/org/gridsuite/network/map/dto/definition/extension/BusbarSectionFinderTraverser.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
package org.gridsuite.network.map.dto.definition.extension;
88

99
import com.powsybl.iidm.network.*;
10-
import com.powsybl.iidm.network.extensions.BusbarSectionPosition;
1110
import com.powsybl.math.graph.TraversalType;
1211
import com.powsybl.math.graph.TraverseResult;
1312

@@ -33,7 +32,6 @@ public static String findBusbarSectionId(Terminal terminal) {
3332
}
3433

3534
public static BusbarSectionResult getBusbarSectionResult(Terminal terminal) {
36-
VoltageLevel.NodeBreakerView view = terminal.getVoltageLevel().getNodeBreakerView();
3735
int startNode = terminal.getNodeBreakerView().getNode();
3836
List<BusbarSectionResult> allResults = searchAllBusbars(terminal.getVoltageLevel(), startNode);
3937
if (allResults.isEmpty()) {
@@ -48,12 +46,12 @@ private static BusbarSectionResult selectBestBusbar(List<BusbarSectionResult> re
4846
return withoutSwitch.stream().min(Comparator.comparingInt(BusbarSectionResult::depth)
4947
.thenComparing(BusbarSectionResult::busbarSectionId)).orElse(null);
5048
}
51-
List<BusbarSectionResult> withClosedSwitch = results.stream().filter(r -> r.lastSwitch() != null && !r.lastSwitch().isOpen()).toList();
49+
List<BusbarSectionResult> withClosedSwitch = results.stream().filter(r -> r.allSwitchesClosed).toList();
5250
if (!withClosedSwitch.isEmpty()) {
5351
return withClosedSwitch.stream().min(Comparator.comparingInt(BusbarSectionResult::depth)
5452
.thenComparing(BusbarSectionResult::busbarSectionId)).orElse(null);
5553
}
56-
List<BusbarSectionResult> withOpenSwitch = results.stream().filter(r -> r.lastSwitch() != null && r.lastSwitch().isOpen()).toList();
54+
List<BusbarSectionResult> withOpenSwitch = results.stream().filter(r -> r.lastSwitch() != null && !r.lastSwitch().isOpen()).toList();
5755
if (!withOpenSwitch.isEmpty()) {
5856
return withOpenSwitch.stream().min(Comparator.comparingInt(BusbarSectionResult::depth)
5957
.thenComparing(BusbarSectionResult::busbarSectionId)).orElse(null);
@@ -70,21 +68,25 @@ private static List<BusbarSectionResult> searchAllBusbars(VoltageLevel voltageLe
7068
SwitchInfo lastSwitch = null;
7169
@Override
7270
public TraverseResult traverse(Terminal terminal, boolean connected) {
73-
if (terminal.getVoltageLevel() != voltageLevel)
71+
if (terminal.getVoltageLevel() != voltageLevel) {
7472
return TraverseResult.TERMINATE_PATH;
73+
}
7574

7675
if (terminal.getConnectable() instanceof BusbarSection busbarSection) {
77-
results.add(new BusbarSectionResult(busbarSection.getId(), currentDepth, lastSwitch,allSwitchesClosed));
76+
results.add(new BusbarSectionResult(busbarSection.getId(), currentDepth, lastSwitch, allSwitchesClosed));
7877
return TraverseResult.TERMINATE_PATH;
7978
}
8079
return TraverseResult.CONTINUE;
8180
}
8281

8382
@Override
8483
public TraverseResult traverse(Switch aSwitch) {
84+
if (aSwitch.getVoltageLevel() != voltageLevel) {
85+
return TraverseResult.TERMINATE_PATH;
86+
}
8587
currentDepth++;
8688
lastSwitch = new SwitchInfo(aSwitch.getId(), aSwitch.isOpen());
87-
if (!aSwitch.isOpen()) {
89+
if (aSwitch.isOpen()) {
8890
allSwitchesClosed = false;
8991
}
9092
return TraverseResult.CONTINUE;

0 commit comments

Comments
 (0)