public static void CloneOutVertexTree(IVertexListGraph g, ISerializableVertexAndEdgeListGraph sub, IVertex v, int maxDepth)
 {
     if (g == null)
     {
         throw new ArgumentNullException("g");
     }
     if (sub == null)
     {
         throw new ArgumentNullException("sub");
     }
     if (v == null)
     {
         throw new ArgumentNullException("v");
     }
     DepthFirstSearchAlgorithm algorithm = new DepthFirstSearchAlgorithm(g);
     PopulatorVisitor visitor = new PopulatorVisitor(sub);
     algorithm.StartVertex += new VertexEventHandler(visitor, (IntPtr) this.StartVertex);
     algorithm.TreeEdge += new EdgeEventHandler(visitor, (IntPtr) this.TreeEdge);
     algorithm.MaxDepth = maxDepth;
     algorithm.Initialize();
     algorithm.Visit(v, 0);
 }
        public static void CloneOutVertexTree(
            IVertexListGraph g,
            ISerializableVertexAndEdgeListGraph sub,
            IVertex v,
            int maxDepth
            )
        {
            if (g==null)
                throw new ArgumentNullException("g");
            if (sub==null)
                throw new ArgumentNullException("sub");
            if (v==null)
                throw new ArgumentNullException("v");

            DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(g);

            PopulatorVisitor pop = new PopulatorVisitor(sub);
            dfs.StartVertex += new VertexEventHandler(pop.StartVertex);
            dfs.TreeEdge += new EdgeEventHandler(pop.TreeEdge);

            dfs.MaxDepth = maxDepth;
            dfs.Initialize();
            dfs.Visit(v,0);
        }
Example #3
0
		/// <summary>
		/// Checks that the sub graph rooted at <paramref name="ref"/> does not have cyclies
		/// </summary>
		/// <param name="g">graph to test</param>
		/// <exception cref="ArgumentNullException">g is a null reference</exception>
		/// <exception cref="NonAcyclicGraphException">graph contains a cycle</exception>
		public static void CheckAcyclic(IVertexListGraph g, IVertex root)
		{
			if (g==null)
				throw new ArgumentNullException("g");
			if (root==null)
				throw new ArgumentNullException("root");

			DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(g);
			dfs.BackEdge +=new EdgeEventHandler(dfs_BackEdge);
			dfs.Initialize();
			dfs.Visit(root,0);
			dfs.Compute();
		}
Example #4
0
		/// <summary>
		/// Computes the leaves from the <paramref name="root"/> vertex.
		/// </summary>
		/// <param name="g">graph containing the vertex</param>
		/// <param name="root">root of the tree</param>
		/// <returns>leaf vertices</returns>
		public static IVertexEnumerable Sinks(
			IVertexListGraph g,
			IVertex root
			)
		{
			if (g==null)
				throw new ArgumentNullException("g");
			if (root==null)
				throw new ArgumentNullException("root");

			DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(g);
			SinkRecorderVisitor sinks = new SinkRecorderVisitor(g);

			dfs.RegisterVertexColorizerHandlers(sinks);
			dfs.Initialize();
			dfs.Visit(root,0);

			return sinks.Sinks;
		}
        /// <summary>
        /// Records all the vertices that are part of the out-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 OutVertexTree(
            IVertexListGraph g,
            IVertex v,
            int maxDepth
            )
        {
            if (g==null)
                throw new ArgumentNullException("g");
            if (v==null)
                throw new ArgumentNullException("v");

            DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm(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;
        }