Skip to content

Commit 7cd598c

Browse files
committed
save
Signed-off-by: Etienne Homer <[email protected]>
1 parent 28dc2d2 commit 7cd598c

File tree

1 file changed

+47
-22
lines changed

1 file changed

+47
-22
lines changed

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

Lines changed: 47 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88

99
import com.powsybl.iidm.network.*;
1010
import com.powsybl.iidm.network.extensions.BusbarSectionPosition;
11+
import com.powsybl.math.graph.TraversalType;
12+
import com.powsybl.math.graph.TraverseResult;
1113

1214
import java.util.*;
1315

@@ -25,7 +27,7 @@ private record NodePath(int startNode, List<SwitchInfo> traversedSwitches, Switc
2527

2628
public record SwitchInfo(String id, boolean isOpen) { }
2729

28-
public record BusbarSectionResult(String busbarSectionId, int depth, SwitchInfo lastSwitch, int busbarIndex, int sectionIndex) { }
30+
public record BusbarSectionResult(String busbarSectionId, int depth, SwitchInfo lastSwitch) { }
2931

3032
public static String findBusbarSectionId(Terminal terminal) {
3133
BusbarSectionResult result = getBusbarSectionResult(terminal);
@@ -46,42 +48,65 @@ private static BusbarSectionResult selectBestBusbar(List<BusbarSectionResult> re
4648
List<BusbarSectionResult> withoutSwitch = results.stream().filter(r -> r.lastSwitch() == null).toList();
4749
if (!withoutSwitch.isEmpty()) {
4850
return withoutSwitch.stream().min(Comparator.comparingInt(BusbarSectionResult::depth)
49-
.thenComparingInt(BusbarSectionResult::busbarIndex)
50-
.thenComparingInt(BusbarSectionResult::sectionIndex)).orElse(null);
51+
.thenComparing(BusbarSectionResult::busbarSectionId)).orElse(null);
5152
}
5253
List<BusbarSectionResult> withClosedSwitch = results.stream().filter(r -> r.lastSwitch() != null && !r.lastSwitch().isOpen()).toList();
5354
if (!withClosedSwitch.isEmpty()) {
5455
return withClosedSwitch.stream().min(Comparator.comparingInt(BusbarSectionResult::depth)
55-
.thenComparingInt(BusbarSectionResult::busbarIndex)
56-
.thenComparingInt(BusbarSectionResult::sectionIndex)).orElse(null);
56+
.thenComparing(BusbarSectionResult::busbarSectionId)).orElse(null);
5757
}
5858
List<BusbarSectionResult> withOpenSwitch = results.stream().filter(r -> r.lastSwitch() != null && r.lastSwitch().isOpen()).toList();
5959
if (!withOpenSwitch.isEmpty()) {
6060
return withOpenSwitch.stream().min(Comparator.comparingInt(BusbarSectionResult::depth)
61-
.thenComparingInt(BusbarSectionResult::busbarIndex)
62-
.thenComparingInt(BusbarSectionResult::sectionIndex)).orElse(null);
61+
.thenComparing(BusbarSectionResult::busbarSectionId)).orElse(null);
6362
}
6463
return results.getFirst();
6564
}
6665

6766
private static List<BusbarSectionResult> searchAllBusbars(VoltageLevel.NodeBreakerView view, int startNode) {
6867
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;
7687
}
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;
8394
}
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+
// }
85110
return results;
86111
}
87112

@@ -107,7 +132,7 @@ private static Optional<BusbarSectionResult> findBusbarSectionAtNode(VoltageLeve
107132
busbarIndex = busbarSectionPosition.getBusbarIndex();
108133
sectionIndex = busbarSectionPosition.getSectionIndex();
109134
}
110-
return Optional.of(new BusbarSectionResult(busbarSectionId, depth, lastSwitch, busbarIndex, sectionIndex));
135+
return Optional.of(new BusbarSectionResult(busbarSectionId, depth, lastSwitch));
111136
}
112137
return Optional.empty();
113138
}

0 commit comments

Comments
 (0)