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); }
/// <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(); }
/// <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; }
private GcTypeHeap TouchingInPlace(string typeNames) { if (String.IsNullOrEmpty(typeNames)) throw new ArgumentNullException("typeNames"); var filter = FilterHelper.ToFilter(typeNames); Console.WriteLine("filtering nodes not connected to type matching '{0}'", filter); var colors = new Dictionary<GcType, GraphColor>(this.graph.VertexCount); foreach (var type in this.graph.Vertices) colors.Add(type, GraphColor.White); var rgraph = new ReversedBidirectionalGraph<GcType, GcTypeEdge>(graph); foreach (var type in this.graph.Vertices) { if (filter.Match(type.Name)) { { // parents var dfs = new DepthFirstSearchAlgorithm<GcType, ReversedEdge<GcType, GcTypeEdge>>(rgraph, colors); dfs.Visit(type, -1); } { // children var dfs = new DepthFirstSearchAlgorithm<GcType, GcTypeEdge>(graph, colors); dfs.Visit(type, -1); } } } // remove all white vertices this.graph.RemoveVertexIf(t => colors[t] == GraphColor.White); Console.WriteLine("resulting {0} types, {1} edges", graph.VertexCount, graph.EdgeCount); return this; }