public List<Set<Node>> getTopSortedSCCs() { SCCFindingVisitor<Node> visitor = new SCCFindingVisitor<Node>(); SCCBuilder<Node> builder = new SCCBuilder<Node>(this, visitor); builder.build(); List<Set<Node>> sccList = visitor.getSCCs(); Collections.reverse(sccList); return sccList; }
public boolean hasCycles() { // A directed graph has a cycle iff any of the following holds: // 1. It has a SCC of size > 1 // 2. It has a SCC of size = 1 that has a self loop. CycleTestingSCCVisitor<Node> visitor = new CycleTestingSCCVisitor<Node>(this); SCCBuilder<Node> builder = new SCCBuilder<Node>(this, visitor); try { builder.build(); } catch (GraphEntityVisitorException ex) { return true; } return false; }
public Set<Node> getNodesInCycles() { CycleFindingSCCVisitor<Node> visitor = new CycleFindingSCCVisitor<Node>(this); SCCBuilder<Node> builder = new SCCBuilder<Node>(this, visitor); builder.build(); return visitor.getNodesInCycles(); }