/// <summary>
		/// A depth first search algorithm on a directed graph
		/// </summary>
		/// <param name="g">The graph to traverse</param>
		/// <exception cref="ArgumentNullException">g is null</exception>
		public EdgeHeightFirstSearchAlgorithm(IBidirectionalVertexAndEdgeListGraph g)
		{
			if (g == null)
				throw new ArgumentNullException("g");
			visitedGraph = g;
			edgeColors = new EdgeColorDictionary();
		}
Exemplo n.º 2
0
        /// <summary>
        /// Records all the vertices that are part of the in-subtree of v
        /// </summary>
        /// <param name="g">visited graph</param>
        /// <param name="v">root vertex</param>
        /// <param name="maxDepth">Maximum exploration depth</param>
        /// <returns></returns>
        public static VertexCollection InVertexTree(
            IBidirectionalVertexAndEdgeListGraph g,
            IVertex v,
            int maxDepth
            )
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            if (v == null)
            {
                throw new ArgumentNullException("v");
            }

            HeightFirstSearchAlgorithm dfs = new HeightFirstSearchAlgorithm(g);

            dfs.BackEdge += new EdgeEventHandler(dfs_BackEdge);
            VertexRecorderVisitor vis = new VertexRecorderVisitor();

            vis.Vertices.Add(v);
            dfs.TreeEdge += new EdgeEventHandler(vis.RecordTarget);

            dfs.MaxDepth = maxDepth;
            dfs.Initialize();
            dfs.Visit(v, 0);

            return(vis.Vertices);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Records all the edges that are part of the subtree of v
        /// </summary>
        /// <param name="g">visited graph</param>
        /// <param name="e">root edge</param>
        /// <param name="maxDepth">maximum expolration depth</param>
        /// <returns></returns>
        public static EdgeCollection InEdgeTree(
            IBidirectionalVertexAndEdgeListGraph g,
            IEdge e,
            int maxDepth
            )
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            if (e == null)
            {
                throw new ArgumentNullException("e");
            }

            EdgeHeightFirstSearchAlgorithm dfs = new EdgeHeightFirstSearchAlgorithm(g);

            dfs.BackEdge += new EdgeEventHandler(dfs_BackEdge);
            EdgeRecorderVisitor vis = new EdgeRecorderVisitor();

            vis.Edges.Add(e);

            dfs.DiscoverTreeEdge += new EdgeEdgeEventHandler(vis.RecordTarget);

            dfs.MaxDepth = maxDepth;
            dfs.Initialize();
            dfs.Visit(e, 0);

            return(vis.Edges);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Construct a reversed graph adaptor
 /// </summary>
 /// <param name="g">Graph to adapt</param>
 public ReversedBidirectionalGraph(IBidirectionalVertexAndEdgeListGraph g)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     this.wrapped = g;
 }
 public ReversedBidirectionalGraph(IBidirectionalVertexAndEdgeListGraph g)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     this.wrapped = g;
 }
Exemplo n.º 6
0
 /// <summary>
 /// A depth first search algorithm on a directed graph
 /// </summary>
 /// <param name="g">The graph to traverse</param>
 /// <exception cref="ArgumentNullException">g is null</exception>
 public EdgeHeightFirstSearchAlgorithm(IBidirectionalVertexAndEdgeListGraph g)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     visitedGraph = g;
     edgeColors   = new EdgeColorDictionary();
 }
 public EdgeHeightFirstSearchAlgorithm(IBidirectionalVertexAndEdgeListGraph g)
 {
     this.maxDepth = 0x7fffffff;
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     this.visitedGraph = g;
     this.edgeColors = new EdgeColorDictionary();
 }
 public UndirectedDepthFirstSearchAlgorithm(IBidirectionalVertexAndEdgeListGraph g)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     this.visitedGraph = g;
     this.edgeColors = new EdgeColorDictionary();
     this.colors = new VertexColorDictionary();
 }
 public static VertexCollection InVertexTree(IBidirectionalVertexAndEdgeListGraph g, IVertex v, int maxDepth)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (v == null)
     {
         throw new ArgumentNullException("v");
     }
     HeightFirstSearchAlgorithm algorithm = new HeightFirstSearchAlgorithm(g);
     algorithm.BackEdge += new EdgeEventHandler(null, (IntPtr) dfs_BackEdge);
     VertexRecorderVisitor visitor = new VertexRecorderVisitor();
     visitor.Vertices.Add(v);
     algorithm.TreeEdge += new EdgeEventHandler(visitor, (IntPtr) this.RecordTarget);
     algorithm.MaxDepth = maxDepth;
     algorithm.Initialize();
     algorithm.Visit(v, 0);
     return visitor.Vertices;
 }
 public static EdgeCollection InEdgeTree(IBidirectionalVertexAndEdgeListGraph g, IEdge e, int maxDepth)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     EdgeHeightFirstSearchAlgorithm algorithm = new EdgeHeightFirstSearchAlgorithm(g);
     algorithm.BackEdge += new EdgeEventHandler(null, (IntPtr) dfs_BackEdge);
     EdgeRecorderVisitor visitor = new EdgeRecorderVisitor();
     visitor.Edges.Add(e);
     algorithm.DiscoverTreeEdge += new EdgeEdgeEventHandler(visitor, (IntPtr) this.RecordTarget);
     algorithm.MaxDepth = maxDepth;
     algorithm.Initialize();
     algorithm.Visit(e, 0);
     return visitor.Edges;
 }