private void depthFirstSearchAlgorithmItem_Click(object sender, System.EventArgs e) { if (this.netronPanel.Graph==null) throw new Exception("Generate a graph first"); // clear colors ResetVertexAndEdgeColors(); // create algorithm this.edgeColors=new EdgeColorDictionary(); foreach(IEdge edge in this.netronPanel.Graph.Edges) this.edgeColors[edge]=GraphColor.White; this.vertexColors = new VertexColorDictionary(); DepthFirstSearchAlgorithm dfs = new DepthFirstSearchAlgorithm( this.netronPanel.Graph, this.vertexColors); // create tracer LayoutAlgorithmTraverVisitor tracer = new LayoutAlgorithmTraverVisitor(this.netronPanel.Populator); // link to algo dfs.RegisterTreeEdgeBuilderHandlers(tracer); dfs.RegisterVertexColorizerHandlers(tracer); dfs.TreeEdge +=new EdgeEventHandler(dfs_TreeEdge); dfs.BackEdge +=new EdgeEventHandler(dfs_BackEdge); dfs.ForwardOrCrossEdge +=new EdgeEventHandler(dfs_ForwardOrCrossEdge); // add handler to tracers tracer.UpdateVertex +=new ShapeVertexEventHandler(tracer_UpdateVertex); tracer.UpdateEdge +=new ConnectionEdgeEventHandler(tracer_UpdateEdge); // running algorithm Thread thread = new Thread(new ThreadStart(dfs.Compute)); thread.Start(); }
/// <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; }