Fix issue in graph splitter

Fix #657
This commit is contained in:
Alexey Andreev 2023-02-17 20:42:27 +01:00
parent f40cb430fa
commit df7b3957e9
2 changed files with 52 additions and 0 deletions

View File

@ -310,6 +310,9 @@ class IrreducibleGraphSplitter {
} }
copyMap[node] = copyIndex; copyMap[node] = copyIndex;
int realNodeCount = realNodes[node].size(); int realNodeCount = realNodes[node].size();
if (node == top) {
realNodeCount -= realNodesCopies.length;
}
subgraphRealNodes[copyIndex] = Arrays.copyOfRange(realNodesCopies, realNodeCopiesIndex, subgraphRealNodes[copyIndex] = Arrays.copyOfRange(realNodesCopies, realNodeCopiesIndex,
realNodeCopiesIndex + realNodeCount); realNodeCopiesIndex + realNodeCount);
realNodeCopiesIndex += realNodeCount; realNodeCopiesIndex += realNodeCount;

View File

@ -327,6 +327,55 @@ public class GraphTest {
assertTrue("Should be equivalent", isEquivalent(backend, graph)); assertTrue("Should be equivalent", isEquivalent(backend, graph));
} }
@Test
public void irreducibleGraphSplit7() {
var builder = new GraphBuilder();
addEdges(builder, 0, 35);
addEdges(builder, 1, 28);
addEdges(builder, 2, 25);
addEdges(builder, 3, 2, 15);
addEdges(builder, 4, 27);
addEdges(builder, 5, 13, 14);
addEdges(builder, 6, 8, 31);
addEdges(builder, 7, 11, 12);
addEdges(builder, 9, 10, 33);
addEdges(builder, 11, 27);
addEdges(builder, 12, 5);
addEdges(builder, 13, 26);
addEdges(builder, 14, 3);
addEdges(builder, 15, 23);
addEdges(builder, 16, 2, 24);
addEdges(builder, 17, 22);
addEdges(builder, 18, 23);
addEdges(builder, 19, 21, 34);
addEdges(builder, 20, 22);
addEdges(builder, 22, 18, 19);
addEdges(builder, 23, 16, 17);
addEdges(builder, 24);
addEdges(builder, 25, 1, 38);
addEdges(builder, 26, 4, 29);
addEdges(builder, 27, 6, 30);
addEdges(builder, 28, 36, 37);
addEdges(builder, 29, 3);
addEdges(builder, 30, 5);
addEdges(builder, 31, 7);
addEdges(builder, 32, 7);
addEdges(builder, 33, 7);
addEdges(builder, 34, 20);
addEdges(builder, 35, 9, 32);
var graph = builder.build();
var backend = new DefaultGraphSplittingBackend(graph);
var weights = new int[graph.size()];
Arrays.fill(weights, 1);
GraphUtils.splitIrreducibleGraph(graph, weights, backend);
var result = backend.getGraph();
assertTrue("Should be irreducible", GraphUtils.isIrreducible(graph));
assertFalse("Should be reducible", GraphUtils.isIrreducible(result));
assertTrue("Should be equivalent", isEquivalent(backend, graph));
}
private static void addEdges(GraphBuilder builder, int from, int... to) { private static void addEdges(GraphBuilder builder, int from, int... to) {
for (int target : to) { for (int target : to) {
builder.addEdge(from, target); builder.addEdge(from, target);