diff --git a/iidm/iidm-modification/pom.xml b/iidm/iidm-modification/pom.xml index cb8ea49691f..3768d0ea77f 100644 --- a/iidm/iidm-modification/pom.xml +++ b/iidm/iidm-modification/pom.xml @@ -37,6 +37,11 @@ + + org.jgrapht + jgrapht-io + 1.5.2 + ${project.groupId} powsybl-iidm-api diff --git a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveFeederBay.java b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveFeederBay.java index 7872270d0c1..3bd7d41658f 100644 --- a/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveFeederBay.java +++ b/iidm/iidm-modification/src/main/java/com/powsybl/iidm/modification/topology/RemoveFeederBay.java @@ -17,9 +17,11 @@ import org.jgrapht.Graph; import org.jgrapht.alg.util.Pair; import org.jgrapht.graph.Pseudograph; +import org.jgrapht.nio.dot.DOTExporter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import java.io.File; import java.util.*; import static com.powsybl.iidm.modification.util.ModificationReports.*; @@ -93,6 +95,7 @@ private Graph createGraphFromTerminal(Terminal terminal) { graph.addEdge(node1, node2, sw != null ? sw : Pair.of(node1, node2)); return result; }); + new DOTExporter(i -> i.toString()).exportGraph(graph, new File("/tmp/graph.dot")); return graph; } @@ -200,6 +203,11 @@ private void searchConnectables(VoltageLevel.NodeBreakerView nbv, Graph graph, int originNode, Object edge, ReportNode reportNode) { + // in case of loops inside the traversed bay, the edge might have been already removed + if (!graph.containsEdge(edge)) { + return; + } + Integer oppositeNode = getOppositeNode(graph, originNode, edge); removeSwitchOrInternalConnection(nbv, graph, edge, reportNode); if (!isBusbarSection(nbv, oppositeNode)) { diff --git a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java index a8d5e77041b..9926d68ea40 100644 --- a/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java +++ b/iidm/iidm-modification/src/test/java/com/powsybl/iidm/modification/topology/RemoveVoltageLevelTest.java @@ -18,6 +18,7 @@ import org.junit.jupiter.api.Test; import java.io.IOException; +import java.nio.file.Path; import java.util.HashSet; import java.util.Set; @@ -52,6 +53,14 @@ public void afterRemoval(String id) { }); } + @Test + void testBug() throws IOException { + Network network = Network.read("/home/dupuyflo/Data/test-iidm.xiidm"); + String voltageLevelId = ".A.ZA 6"; + network.getVoltageLevel(voltageLevelId).exportTopology(Path.of("/tmp/x.dot")); + new RemoveVoltageLevelBuilder().withVoltageLevelId(voltageLevelId).build().apply(network); + } + @Test void testLoops() { Network network = Network.create("test", "test"); @@ -85,7 +94,7 @@ void testLoops() { new RemoveVoltageLevelBuilder().withVoltageLevelId(vl1.getId()).build().apply(network); - assertEquals(Set.of("bbs1", "bbs2", "Coupler", "d_l2_bbs2", "vl1", "d_l2_bbs1", "d_l1_bbs2", "line2", "line1", "d_l1_bbs1"), removedObjects); + assertEquals(Set.of("bbs1", "bbs2", "Coupler", "b_l2_bbs2_B", "b_l2_bbs2_A", "d_l2_bbs2", "vl1", "d_l2_bbs1", "d_l1_bbs2", "line2", "line1", "d_l1_bbs1"), removedObjects); assertNull(network.getVoltageLevel("vl1")); }