Beispiel #1
0
        private Subgraph FindSubgraph(Node node)
        {
            Subgraph subgraph = new Subgraph(graph);

            AddReachable(node, subgraph);

            return(subgraph);
        }
Beispiel #2
0
        /// <summary> Adds all nodes and edges reachable from this node to the subgraph.
        /// Uses an explicit stack to avoid a large depth of recursion.
        ///
        /// </summary>
        /// <param name="node">a node known to be in the subgraph
        /// </param>
        private void AddReachable(Node startNode, Subgraph subgraph)
        {
            Stack nodeStack = new Stack();

            nodeStack.Push(startNode);
            while (!(nodeStack.Count == 0))
            {
                Node node = (Node)nodeStack.Pop();
                AddEdges(node, nodeStack, subgraph);
            }
        }
Beispiel #3
0
        /// <summary> Adds the argument node and all its out edges to the subgraph.</summary>
        /// <param name="node">the node to add
        /// </param>
        /// <param name="nodeStack">the current set of nodes being traversed
        /// </param>
        private void AddEdges(Node node, Stack nodeStack, Subgraph subgraph)
        {
            node.Visited = true;

            for (IEnumerator i = ((DirectedEdgeStar)node.OutEdges).Iterator();
                 i.MoveNext();)
            {
                DirectedEdge de = (DirectedEdge)i.Current;

                subgraph.Add(de.Edge);
                Node toNode = de.ToNode;

                if (!toNode.Visited)
                {
                    nodeStack.Push(toNode);
                }
            }
        }