예제 #1
0
파일: Graph.cs 프로젝트: microsoft/exsim
 /// <summary>
 /// Traverses the graph using a specific navigator starting at a given vertex
 /// </summary>
 /// <param name="vertex">The focal vertex</param>
 public virtual void Navigate(
     object vertex,
     GraphVisitor visitor,
     GraphNavigator navigator)
 {
     navigator.Navigate(vertex, visitor);
 }
예제 #2
0
        /// <summary>
        /// Navigates the graph from a focal vertex to predecessors.
        /// </summary>
        /// <param name="graph">The graph to navigate</param>
        /// <param name="vertex">The vertex to start at</param>
        /// <param name="visitor">The visitor to call at each vertex</param>
        public static void NavigateGraph(
            Graph graph,
            object vertex,
            GraphVisitor visitor)
        {
            GraphNavigator n = new BackwardGraphNavigator(graph);

            n.Navigate(vertex, visitor);
        }
예제 #3
0
        /// <summary>
        /// Navigates a graph starting at a given focal vertex
        /// </summary>
        /// <param name="vertex">The vertex to start at</param>
        /// <param name="visitor">The visitor to call for each vertex</param>
        public virtual void Navigate(
            object rootVertex,
            GraphVisitor visitor)
        {
            Queue <EdgeItem> wl = new Queue <EdgeItem>();

            // Set the navigator being used for this visitor
            visitor.Navigator = this;

            // Add the focal vertex to the work list
            GetNext(rootVertex, wl);

            // Until the work list is empty...
            while (wl.Count > 0)
            {
                // Set the current edge item and target vertex
                this.currentEdgeItem = wl.Dequeue();
                this.currentVertex   = GetDirectionOrientedTargetFromEdge(currentEdgeItem.Edge);

                try
                {
                    // If the visitor returns false, then we should stop our navigation
                    if (!visitor.Visit(currentVertex))
                    {
                        break;
                    }

                    // We've finished visiting...
                    visitor.PostVisit(currentVertex);
                }
                catch (Exception e)
                {
                    if (e is SkipChildrenException || e.InnerException is SkipChildrenException)
                    {
                        continue;
                    }
                }

                // Apply constraints to this vertex now that it's been visited
                ApplyConstraints(currentVertex);

                // If we fail to get the next elements, then we should stop our navigation
                if (!GetNext(currentVertex, wl))
                {
                    break;
                }
            }
        }
예제 #4
0
파일: Graph.cs 프로젝트: microsoft/exsim
 /// <summary>
 /// Traverses the graph visiting successors starting at a given vertex
 /// </summary>
 /// <param name="vertex">The focal vertex</param>
 public virtual void Navigate(
     object vertex,
     GraphVisitor visitor)
 {
     ForwardGraphNavigator.NavigateGraph(this, vertex, visitor);
 }