Internal(GraphAdapter<N, E> adapter) { this.adapter = adapter; this.basic = new GraphBasicQueries<>(adapter); if (isEnabled(Feature.SHOW_CYCLES)) { this.cycles = new GraphCycles<>(adapter); } else { this.cycles = null; } }
@Test public void test() { final TestGraph g = new TestGraph(); final GraphCycles<TestGraphNode, TestGraphEdge> gc = new GraphCycles<>(g); final GraphTransitiveReduction<TestGraphNode, TestGraphEdge> gtr = new GraphTransitiveReduction<>(g); gtr.setEnabled(GraphBase.Feature.DEBUG, true); gtr.setPrefix(getClass().getSimpleName() + "-"); final int max = 10; for (int index = 0; index < 3; index++) { final int base = index * 100; for (int i1 = base; i1 < base + max; i1++) { for (int i2 = i1 + 1; i2 < base + max; i2++) { g.getOrCreateEdge(i1, i2); } } } gtr.printToGvIfDebug(g, "init"); final GraphAdapter<TestGraphNode, TestGraphEdge> reduction = gtr.computeTransitiveReduction(); gtr.printToGvIfDebug(reduction, "reduction"); final GraphCycles<TestGraphNode, TestGraphEdge> gctr = new GraphCycles<>(reduction); for (final TestGraphNode source : g.getNodes()) { for (final TestGraphNode target : g.getNodes()) { assertTrue(gc.areConnected(source, target) == gctr.areConnected(source, target)); } } } }
final TestGraph g = new TestGraph(); final GraphBasicQueries<TestGraphNode, TestGraphEdge> gbq = new GraphBasicQueries<>(g); final GraphCycles<TestGraphNode, TestGraphEdge> gc = new GraphCycles<>(g); gbq.setPrefix(getClass().getSimpleName() + "-"); final InvertedGraph<TestGraphNode, TestGraphEdge> ig = new InvertedGraph<>(g); final GraphCycles<TestGraphNode, TestGraphEdge> igc = new GraphCycles<>(ig);
public static void main(String[] args) { final TestGraph g = new TestGraph(); final TestGraphNode n1 = g.createNode("N1"); final TestGraphNode n2 = g.createNode("N2"); final TestGraphNode n3 = g.createNode("N3"); final TestGraphNode n4 = g.createNode("N4"); final TestGraphNode n5 = g.createNode("N5"); g.createEdge("E12", n1, n2); g.createEdge("E21", n2, n1); g.createEdge("E13", n1, n3); g.createEdge("E34", n3, n4); g.createEdge("E45", n4, n5); g.createEdge("E54", n5, n4); GraphPrinter.print(g, true, System.out); final GraphCycles<TestGraphNode, TestGraphEdge> cycles = new GraphCycles<>(g); cycles.setEnabled(Feature.DEBUG, true); cycles.setEnabled(Feature.VERBOSE, true); System.out.println(cycles.containsCycles()); for (final TestGraphNode node : g.getNodes()) { System.out.println(node + ": " + cycles.nodeIsCycleMember(node)); } final ExplicitSubGraph<TestGraphNode, TestGraphEdge> kernel = cycles.computeCyclesMembers(); GraphPrinter.print(kernel, true, System.out); } }
@Test public void testAreConnected() { final TestGraph g = new TestGraph(); final GraphCycles<TestGraphNode, TestGraphEdge> gc = new GraphCycles<>(g); gc.setEnabled(GraphBase.Feature.DEBUG, true); gc.setPrefix(getClass().getSimpleName() + "-");