Exemplo n.º 1
0
        public override HashSet <CGraphNode> Visit(CGraphNode node)
        {
            CCharRangeSet  set;
            CIt_Successors it = new CIt_Successors(node);

            for (it.Begin(); !it.End(); it.Next())
            {
                CGraphEdge edge = m_graph.Edge(node, it.M_CurrentItem);
                set = m_graph.GetFAEdgeInfo(edge);
                if (set != null && set.IsCharInSet(m_character))
                {
                    m_outputSet.Add(it.M_CurrentItem);
                }
            }
            return(m_outputSet);
        }
        /// <summary>
        /// The Visit method refers to the action the algorithm performs to a specific edge
        /// Most of the times the Visit function is called recursively.
        /// </summary>
        /// <param name="edge"></param>
        /// <returns>
        /// The parameter refers to the type of the return result
        /// </returns>
        public override CGraphEdge Visit(CGraphEdge edge)
        {
            CIt_Successors itn = new CIt_Successors(edge.M_Target);
            CGraphEdge     visitedEdge;

            // Mark the edge as visited
            SetColor(edge, 1);

            for (itn.Begin(); !itn.End(); itn.Next())
            {
                //visitedEdge = Edge(edge.M_Target, itn.M_CurrentItem);
                //if (Color(visitedEdge) == 0) {
                //    Visit(visitedEdge);
                //}
            }
            return(edge);
        }
        public override CGraphNode Visit(CGraphNode node)
        {
            CIt_Successors it = new CIt_Successors(node);

            // Paint the node gray (1) at first visit
            SetColor(node, 1);

            // EVENT : Raising on OnNodeEnter
            OnProcessBefore(new ProcessBeforeEventArgs()
            {
                M_Node = node
            });

            // Visit adjacent nodes
            for (it.Begin(); !it.End(); it.Next())
            {
                if (Color(it.M_CurrentItem) == 0)
                {
                    // VISIT WHITE NODES
                    OnProcessSuccBefore(new ProcessSuccBeforeEventArgs()
                    {
                        M_Node = node, M_Successor = it.M_CurrentItem
                    });
                    Visit(it.M_CurrentItem);
                    OnProcessSuccAfter(new ProcessSuccAfterEventArgs()
                    {
                        M_Node = node, M_Successor = it.M_CurrentItem
                    });
                }
                else
                {
                    // EVENT : Raise the OnBypassingNode event
                    OnBypassNode(EventArgs.Empty);
                }
            }
            // Paint the node black (2) when all adjacent nodes are visited
            SetColor(node, 2);

            // EVENT : Raising on OnNodeExit
            OnProcessAfter(new ProcessAfterEventArgs()
            {
                M_Node = node
            });

            return(node);
        }
        public override CGraphNode Visit(CGraphNode node)
        {
            CGraphEdge newSTedge;

            // Paint the node gray (1) at first visit
            SetColor(node, 1);

            SetPreOrderNumber(m_Mappping.DerivedNode(node), ++m_preorderCounter);

            CIt_Successors it = new CIt_Successors(node);

            for (it.Begin(); !it.End(); it.Next())
            {
                if (Color(it.M_CurrentItem) == 0)
                {
                    Visit(it.M_CurrentItem);
                    newSTedge = m_dfsSpanningTree.AddGraphEdge(m_Mappping.DerivedNode(node), m_Mappping.DerivedNode(it.M_CurrentItem), EdgeTypeDFS.tree);
                    m_Mappping.SetOriginalToDerivedEdge(m_sourceGraphs[0].Edge(node, it.M_CurrentItem), newSTedge);
                }
                else if (PreOrderNumber(m_Mappping.DerivedNode(node)) < PreOrderNumber(m_Mappping.DerivedNode(it.M_CurrentItem)))
                {
                    // The successor has already been visited from another path prior to the current node
                    newSTedge = m_dfsSpanningTree.AddGraphEdge(m_Mappping.DerivedNode(node), m_Mappping.DerivedNode(it.M_CurrentItem), EdgeTypeDFS.forward);
                    m_Mappping.SetOriginalToDerivedEdge(m_sourceGraphs[0].Edge(node, it.M_CurrentItem), newSTedge);
                }
                else if (PostOrderNumber(m_Mappping.DerivedNode(it.M_CurrentItem)) == 0)
                {
                    // The successor (which is an actual predecessor) has already been visited and not assigned a postorder number
                    // which means that both nodes have been visited from the same path. Hence it is a backedge and not a cross edge...
                    newSTedge = m_dfsSpanningTree.AddGraphEdge(m_Mappping.DerivedNode(node), m_Mappping.DerivedNode(it.M_CurrentItem), EdgeTypeDFS.back);
                    m_Mappping.SetOriginalToDerivedEdge(m_sourceGraphs[0].Edge(node, it.M_CurrentItem), newSTedge);
                }
                else
                {
                    //...otherwise it is a cross edge
                    newSTedge = m_dfsSpanningTree.AddGraphEdge(m_Mappping.DerivedNode(node), m_Mappping.DerivedNode(it.M_CurrentItem), EdgeTypeDFS.cross);
                    m_Mappping.SetOriginalToDerivedEdge(m_sourceGraphs[0].Edge(node, it.M_CurrentItem), newSTedge);
                }
            }

            SetPostOrderNumber(m_Mappping.DerivedNode(node), ++m_postorderCounter);

            return(node);
        }
        public override int Visit(CGraphNode node)
        {
            m_time++;
            SetArrival(node, m_time);
            SetColor(node, NodeColor.NC_GRAY);
            CIt_Successors si = new CIt_Successors(node);

            for (si.Begin(); !si.End(); si.Next())
            {
                if (Color(si.M_CurrentItem) == NodeColor.NC_WHITE)
                {
                    Visit(si.M_CurrentItem);
                }
            }
            SetColor(node, NodeColor.NC_BLACK);
            m_time++;
            SetDeparture(node, m_time);
            return(0);
        }
Exemplo n.º 6
0
        public override HashSet <CGraphNode> Visit(CGraphNode node)
        {
            m_outputSet.Add(node);

            //1.For each successor scan the nodes that have outgoing e transitions
            CIt_Successors it = new CIt_Successors(node);

            for (it.Begin(); !it.End(); it.Next())
            {
                //Find the edge between node and its successor
                CGraphEdge edge = m_graph.Edge(node, it.M_CurrentItem);

                //if the edge label is e then visit the successor and append the output set including this successor
                if (TransitionLabel(edge) == null)
                {
                    Visit(it.M_CurrentItem);
                }
            }
            //
            return(m_outputSet);
        }