void Build() { if (data != null) { return; } AdjancenceArray <T> adjancenceArray = new AdjancenceArray <T>(graph); int[] nodeStocks = new int[graph.NodesCount]; int usedNodesCount = 0; bool[] usedNodesFlag = new bool[graph.NodesCount]; for (int node = 0; node < graph.NodesCount; ++node) { for (int adjancentNode = 0; adjancentNode < graph.NodesCount; ++adjancentNode) { if (adjancenceArray.HasEdge(node, adjancentNode)) { ++nodeStocks[adjancentNode]; } } } NodeStack <NodeStack <int> > skewStack = new NodeStack <NodeStack <int> >(); while (usedNodesCount < usedNodesFlag.Length) { skewStack.Push(new NodeStack <int>()); for (int node = 0; node < graph.NodesCount; ++node) { if (!usedNodesFlag[node] && nodeStocks[node] == 0) { skewStack.Top.Push(node); } } if (skewStack.Top.size == 0) { throw new Exception("Cycles found in graph"); } usedNodesCount += skewStack.Top.size; for (Node <int> node = skewStack.Top.top; node != null; node = node.next) { usedNodesFlag[node.value] = true; for (int adjancentNode = 0; adjancentNode < graph.NodesCount; ++adjancentNode) { if (!usedNodesFlag[adjancentNode] && adjancenceArray.Data[node.value, adjancentNode] != null) { --nodeStocks[adjancentNode]; } } } } data = Util.SkewListToArray(skewStack); }
public int[] TarjanRecursive() { NodeColors[] nodeColors = new NodeColors[Data.NodesCount]; NodeStack <int> stack = new NodeStack <int>(); if (!TarjanRecursiveStart(stack, nodeColors)) { throw new Exception("Invalid data for Tarjan"); } return(Util.ListToArray <int>(stack)); }
public bool TarjanRecursiveStart(NodeStack <int> stack, NodeColors[] nodeColors) { for (int node = 0; node < Data.NodesCount; ++node) { if (nodeColors[node] == NodeColors.White) { if (!TarjanRecursiveDSF(node, stack, nodeColors)) { return(false); } } } return(true); }
public ArticulationNodes(AdjancenceVector <T> graph) { this.graph = graph; order = 0; pre = new int[graph.NodesCount]; low = new int[graph.NodesCount]; Array.Fill(pre, -1); stack = new NodeStack <int>(); data = null; }
public TarjanStrongConnected(AdjancenceVector <T> graph) { this.graph = graph; order = 0; pre = new int[graph.NodesCount]; low = new int[graph.NodesCount]; stack = new NodeStack <int>(); Array.Fill(pre, -1); skewStackQueue = new NodeStack <NodeQueue <int> >(); data = null; }
public bool TarjanRecursiveDSF(int node, NodeStack <int> stack, NodeColors[] nodeColors) { nodeColors[node] = NodeColors.Gray; (int, T)[] adjancentNodes = Data.Data[node];