Skip to content

Commit

Permalink
Fix bug: switches were not removed from index when all edges were rem…
Browse files Browse the repository at this point in the history
…oved (#1955)

Signed-off-by: VEDELAGO MIORA <[email protected]>
  • Loading branch information
miovd committed Jan 28, 2022
1 parent 6359356 commit 6a975fc
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ public void edgeRemoved(int e, SwitchImpl obj) {
}

@Override
public void allEdgesRemoved() {
public void allEdgesRemoved(Collection<SwitchImpl> obj) {
invalidateCache();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -528,18 +528,14 @@ public void edgeRemoved(int e, SwitchImpl aSwitch) {
}

@Override
public void allEdgesRemoved() {
List<String> removedSwitchesIds = new ArrayList<>(graph.getEdgeCount());
public void allEdgesRemoved(Collection<SwitchImpl> aSwitches) {
NetworkImpl network = getNetwork();
for (SwitchImpl s : graph.getEdgesObject()) {
if (s != null) {
network.getListeners().notifyBeforeRemoval(s);
removedSwitchesIds.add(s.getId());
network.getIndex().remove(s);
}
}
aSwitches.forEach(ss -> {
network.getListeners().notifyBeforeRemoval(ss);
network.getIndex().remove(ss);
});
switches.clear();
removedSwitchesIds.forEach(id -> network.getListeners().notifyAfterRemoval(id));
aSwitches.forEach(ss -> network.getListeners().notifyAfterRemoval(ss.getId()));
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import com.powsybl.iidm.network.*;
import com.powsybl.iidm.network.test.EurostagTutorialExample1Factory;
import com.powsybl.iidm.network.test.FictitiousSwitchFactory;
import com.powsybl.iidm.network.test.HvdcTestNetwork;
import com.powsybl.iidm.network.test.ThreeWindingsTransformerNetworkFactory;
import org.junit.Rule;
Expand Down Expand Up @@ -305,4 +306,24 @@ public void test3WTFailure() {
.build();
reducer.reduce(network);
}

@Test
public void testNodeBreaker() {
Network network = FictitiousSwitchFactory.create();

NetworkReducer reducer = NetworkReducer.builder()
.withNetworkPredicate(IdentifierNetworkPredicate.of("C"))
.build();
reducer.reduce(network);

assertEquals(1, network.getSubstationCount());
assertEquals(1, network.getVoltageLevelCount());
assertEquals(0, network.getTwoWindingsTransformerCount());
assertEquals(0, network.getLineCount());
assertEquals(0, network.getGeneratorCount());
assertEquals(2, network.getLoadCount());
assertEquals(0, network.getDanglingLineCount());
assertEquals(4, network.getSwitchCount());
assertEquals(1, network.getBusbarSectionCount());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package com.powsybl.math.graph;

import java.util.Collection;

/**
*
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand Down Expand Up @@ -43,7 +45,7 @@ public void edgeRemoved(int e, E obj) {
}

@Override
public void allEdgesRemoved() {
public void allEdgesRemoved(Collection<E> obj) {
// nothing to do
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,11 @@ public E removeEdge(int e) {

@Override
public void removeAllEdges() {
Collection<E> allEdges = edges.stream().map(Edge::getObject).filter(Objects::nonNull).collect(Collectors.toList());
edges.clear();
removedEdges.clear();
invalidateAdjacencyList();
notifyAllEdgesRemoved();
notifyAllEdgesRemoved(allEdges);
}

@Override
Expand Down Expand Up @@ -630,9 +631,9 @@ private void notifyEdgeRemoved(int e, E obj) {
}
}

private void notifyAllEdgesRemoved() {
private void notifyAllEdgesRemoved(Collection<E> obj) {
for (UndirectedGraphListener<V, E> l : listeners) {
l.allEdgesRemoved();
l.allEdgesRemoved(obj);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
*/
package com.powsybl.math.graph;

import java.util.Collection;

/**
*
* @author Geoffroy Jamgotchian <geoffroy.jamgotchian at rte-france.com>
Expand All @@ -24,5 +26,5 @@ public interface UndirectedGraphListener<V, E> {

void edgeRemoved(int e, E obj);

void allEdgesRemoved();
void allEdgesRemoved(Collection<E> obj);
}

0 comments on commit 6a975fc

Please sign in to comment.