Exemplo n.º 1
0
 public DFSTEdge(DFSTNode start, DFSTNode end)
 {
     base();
     this.set_Start(start);
     this.set_End(end);
     return;
 }
Exemplo n.º 2
0
 private void DFSBuild(DFSTNode currentNode)
 {
     dummyVar0 = this.traversedNodes.Add(currentNode);
     dummyVar1 = this.currentPath.Add(currentNode);
     V_0       = LogicalFlowUtilities.GetTraversableSuccessors(currentNode.get_Construct()).GetEnumerator();
     try
     {
         while (V_0.MoveNext())
         {
             V_1 = V_0.get_Current();
             if (!this.constructToNodeMap.TryGetValue(V_1, out V_2))
             {
                 continue;
             }
             if (this.traversedNodes.Contains(V_2))
             {
                 if (!this.currentPath.Contains(V_2))
                 {
                     if (!this.IsAncestor(V_2, currentNode))
                     {
                         dummyVar10 = V_2.get_CrossEdgePredecessors().Add(currentNode);
                         dummyVar11 = currentNode.get_CrossEdgeSuccessors().Add(V_2);
                         dummyVar12 = this.theTree.get_CrossEdges().Add(new DFSTEdge(currentNode, V_2));
                     }
                     else
                     {
                         dummyVar7 = V_2.get_ForwardEdgePredecessors().Add(currentNode);
                         dummyVar8 = currentNode.get_ForwardEdgeSucessors().Add(V_2);
                         dummyVar9 = this.theTree.get_ForwardEdges().Add(new DFSTEdge(currentNode, V_2));
                     }
                 }
                 else
                 {
                     dummyVar4 = V_2.get_BackEdgePredecessors().Add(currentNode);
                     dummyVar5 = currentNode.get_BackEdgeSuccessors().Add(V_2);
                     dummyVar6 = this.theTree.get_BackEdges().Add(new DFSTEdge(currentNode, V_2));
                 }
             }
             else
             {
                 V_2.set_Predecessor(currentNode);
                 dummyVar2 = currentNode.get_TreeEdgeSuccessors().Add(V_2);
                 dummyVar3 = this.theTree.get_TreeEdges().Add(new DFSTEdge(currentNode, V_2));
                 this.DFSBuild(V_2);
             }
         }
     }
     finally
     {
         if (V_0 != null)
         {
             V_0.Dispose();
         }
     }
     dummyVar13 = this.currentPath.Remove(currentNode);
     this.theTree.get_ReversePostOrder().Add(currentNode);
     return;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Recursively traverses the nodes and adds them to the tree. Also determines the type of each edge.
        /// </summary>
        /// <param name="currentNode"></param>
        private void DFSBuild(DFSTNode currentNode)
        {
            traversedNodes.Add(currentNode);

            //The current path is the set of all nodes on the DFS tree path from the root to the current node.
            currentPath.Add(currentNode);

            foreach (ISingleEntrySubGraph successorConstruct in LogicalFlowUtilities.GetTraversableSuccessors(currentNode.Construct))
            {
                DFSTNode successor;
                if (!constructToNodeMap.TryGetValue(successorConstruct, out successor))
                {
                    //Special case for interval constructs
                    continue;
                }

                if (!traversedNodes.Contains(successor))
                {
                    //If the successor is not traversed then the edge between the two nodes is a tree edge.
                    successor.Predecessor = currentNode;
                    currentNode.TreeEdgeSuccessors.Add(successor);
                    theTree.TreeEdges.Add(new DFSTEdge(currentNode, successor));

                    //We continue the build from this successor.
                    DFSBuild(successor);
                }
                else if (currentPath.Contains(successor))
                {
                    //If the successor is traversed and is on the current path then the edge between the nodes is a back edge.
                    successor.BackEdgePredecessors.Add(currentNode);
                    currentNode.BackEdgeSuccessors.Add(successor);
                    theTree.BackEdges.Add(new DFSTEdge(currentNode, successor));
                }
                else if (IsAncestor(successor, currentNode))
                {
                    //If the successor is traversed and the current node is its ancestor, then the edge is a forward edge.
                    successor.ForwardEdgePredecessors.Add(currentNode);
                    currentNode.ForwardEdgeSucessors.Add(successor);
                    theTree.ForwardEdges.Add(new DFSTEdge(currentNode, successor));
                }
                else
                {
                    //Otherwise the edge between the nodes is a cross edge.
                    successor.CrossEdgePredecessors.Add(currentNode);
                    currentNode.CrossEdgeSuccessors.Add(successor);
                    theTree.CrossEdges.Add(new DFSTEdge(currentNode, successor));
                }
            }

            currentPath.Remove(currentNode);

            //Adding the nodes in post order.
            theTree.ReversePostOrder.Add(currentNode);
        }
Exemplo n.º 4
0
 private bool IsAncestor(DFSTNode node, DFSTNode supposedAncestor)
 {
     V_0 = (DFSTNode)node.get_Predecessor();
     while (V_0 != null)
     {
         if (V_0 == supposedAncestor)
         {
             return(true);
         }
         V_0 = (DFSTNode)V_0.get_Predecessor();
     }
     return(false);
 }
Exemplo n.º 5
0
        /// <summary>
        /// Builds the tree starting from the graph's entry.
        /// </summary>
        private void TraverseAndBuildTree()
        {
            theTree = new DFSTree(constructToNodeMap);

            DFSTNode root = constructToNodeMap[this.entry];

            DFSBuild(root);

            //Since the nodes were added in postorder we must reverse them to get ... the reverse postorder.
            theTree.ReversePostOrder.Reverse();
            theTree.ReversePostOrder.TrimExcess();

            AssignOrderIndices();
        }
Exemplo n.º 6
0
        /// <summary>
        /// Determines whether <paramref name="supposedAncestor"/> is on the tree path from the root to <paramref name="node"/>
        /// </summary>
        /// <param name="node"></param>
        /// <param name="supposedAncestor"></param>
        /// <returns></returns>
        private bool IsAncestor(DFSTNode node, DFSTNode supposedAncestor)
        {
            DFSTNode currentAncestor = (DFSTNode)node.Predecessor;

            while (currentAncestor != null)
            {
                if (currentAncestor == supposedAncestor)
                {
                    return(true);
                }

                currentAncestor = (DFSTNode)currentAncestor.Predecessor;
            }
            return(false);
        }
Exemplo n.º 7
0
 public List <DFSTNode> GetPath(DFSTNode ancestorNode, DFSTNode descenderNode)
 {
     V_0 = new List <DFSTNode>();
     V_1 = descenderNode;
     while (V_1 != null && V_1 != ancestorNode)
     {
         V_0.Add(V_1);
         V_1 = (DFSTNode)V_1.get_Predecessor();
     }
     if (V_1 == null)
     {
         throw new Exception("No path between the two nodes.");
     }
     V_0.Add(V_1);
     V_0.Reverse();
     return(V_0);
 }
Exemplo n.º 8
0
        /// <summary>
        /// Gets the path in the tree between two nodes. The <paramref name="ancestorNode"/>
        /// must be on the path from the root to the <paramref name="descenderNode"/>.
        /// </summary>
        /// <param name="ancestorNode"></param>
        /// <param name="descenderNode"></param>
        /// <returns></returns>
        public List <DFSTNode> GetPath(DFSTNode ancestorNode, DFSTNode descenderNode)
        {
            List <DFSTNode> path = new List <DFSTNode>();
            DFSTNode        currentNodeOnPath = descenderNode;

            while (currentNodeOnPath != null && currentNodeOnPath != ancestorNode)
            {
                path.Add(currentNodeOnPath);
                currentNodeOnPath = (DFSTNode)currentNodeOnPath.Predecessor;
            }

            if (currentNodeOnPath != null)
            {
                path.Add(currentNodeOnPath);
            }
            else
            {
                //sanity check
                throw new Exception("No path between the two nodes.");
            }

            path.Reverse();
            return(path);
        }
Exemplo n.º 9
0
 public DFSTEdge(DFSTNode start, DFSTNode end)
 {
     Start = start;
     End   = end;
 }