Skip to content

Commit

Permalink
Null vertices test
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Dupuy <florian.dupuy@rte-france.com>
  • Loading branch information
flo-dup committed Jan 6, 2021
1 parent 21b7646 commit b442ee1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public List<Set<V>> getSmallComponents() {
sortedComponents = true;
connectedComponents.sort(Comparator.comparingInt(c -> -c.size()));
}
return connectedComponents.subList(1, connectedComponents.size());
return connectedComponents.isEmpty() ? Collections.emptyList() : connectedComponents.subList(1, connectedComponents.size());
}

private interface GraphProcess {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,10 @@
import org.slf4j.LoggerFactory;

import javax.inject.Provider;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.*;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.*;

/**
* @author Florian Dupuy <florian.dupuy at rte-france.com>
Expand All @@ -50,7 +46,6 @@ class OpenSecurityAnalysisGraphTest {
private static final Logger LOGGER = LoggerFactory.getLogger(OpenSecurityAnalysisGraphTest.class);

private Network network;
private List<List<LfContingency>> reference;
private ContingenciesProvider contingenciesProvider;
private SecurityAnalysisParameters securityAnalysisParameters;

Expand All @@ -69,7 +64,6 @@ void setUp() {
new OpenLoadFlowParameters().setSlackBusSelector(new FirstSlackBusSelector()));
securityAnalysisParameters = new SecurityAnalysisParameters().setLoadFlowParameters(lfParameters);

reference = getLoadFlowContingencies(() -> new NaiveGraphDecrementalConnectivity<>(LfBus::getNum));
LOGGER.info("Reference established (naive connectivity calculation) on test network containing {} branches", network.getBranchCount());
}

Expand All @@ -78,18 +72,44 @@ void testEvenShiloach() {
LOGGER.info("Test Even-Shiloach on test network containing {} branches", network.getBranchCount());
List<List<LfContingency>> lfContingencies = getLoadFlowContingencies(EvenShiloachGraphDecrementalConnectivity::new);
printResult(lfContingencies);
checkResult(lfContingencies);
checkResult(lfContingencies, computeReference());
}

@Test
void testMst() {
LOGGER.info("Test Minimum Spanning Tree on test network containing {} branches", network.getBranchCount());
List<List<LfContingency>> lfContingencies = getLoadFlowContingencies(MinimumSpanningTreeGraphDecrementalConnectivity::new);
printResult(lfContingencies);
checkResult(lfContingencies);
checkResult(lfContingencies, computeReference());
}

private void checkResult(List<List<LfContingency>> result) {
private List<List<LfContingency>> computeReference() {
return getLoadFlowContingencies(() -> new NaiveGraphDecrementalConnectivity<>(LfBus::getNum));
}

@Test
void testNullVertices() {
try {
network.getSwitch("B3").setOpen(true);
contingenciesProvider = n -> Collections.singletonList(
new Contingency("L1", new BranchContingency("L1")));
List<List<LfContingency>> reference = computeReference();
checkResult(getLoadFlowContingencies(MinimumSpanningTreeGraphDecrementalConnectivity::new), reference);
checkResult(getLoadFlowContingencies(EvenShiloachGraphDecrementalConnectivity::new), reference);

contingenciesProvider = n -> Collections.singletonList(
new Contingency("L2", new BranchContingency("L2")));
network.getSwitch("B3").setOpen(false);
network.getSwitch("B1").setOpen(true);
reference = computeReference();
checkResult(getLoadFlowContingencies(MinimumSpanningTreeGraphDecrementalConnectivity::new), reference);
checkResult(getLoadFlowContingencies(EvenShiloachGraphDecrementalConnectivity::new), reference);
} catch (NullPointerException e) {
fail();
}
}

private static void checkResult(List<List<LfContingency>> result, List<List<LfContingency>> reference) {
assertEquals(reference.size(), result.size());
for (int iNetwork = 0; iNetwork < result.size(); iNetwork++) {
assertEquals(reference.get(iNetwork).size(), result.get(iNetwork).size());
Expand Down

0 comments on commit b442ee1

Please sign in to comment.