/// <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(); }
/// <summary> /// Create a undirected dfs algorithm /// </summary> /// <param name="g">Graph to search on.</param> public UndirectedDepthFirstSearchAlgorithm(IVertexAndEdgeListGraph g) { if(g == null) throw new ArgumentNullException("g"); m_VisitedGraph = g; m_EdgeColors=new EdgeColorDictionary(); m_Colors = new VertexColorDictionary(); }
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(); }
/// <summary> /// A depth first search algorithm on a directed graph /// </summary> /// <param name="g">The graph to traverse</param> /// <param name="colors">vertex color map</param> /// <exception cref="ArgumentNullException">g or colors are null</exception> public EdgeDepthFirstSearchAlgorithm( IEdgeListAndIncidenceGraph g, EdgeColorDictionary colors ) { if (g == null) throw new ArgumentNullException("g"); if (colors == null) throw new ArgumentNullException("Colors"); visitedGraph = g; edgeColors = colors; }
public EdgeDepthFirstSearchAlgorithm(IEdgeListAndIncidenceGraph g, EdgeColorDictionary colors) { this.maxDepth = 0x7fffffff; if (g == null) { throw new ArgumentNullException("g"); } if (colors == null) { throw new ArgumentNullException("Colors"); } this.visitedGraph = g; this.edgeColors = colors; }
public EdgeCollection[] AllMergedPaths() { EdgeCollection[] edgesArray = new EdgeCollection[this.EndPathEdges.Count]; EdgeColorDictionary colors = new EdgeColorDictionary(); IDictionaryEnumerator enumerator = this.EdgePredecessors.GetEnumerator(); while (enumerator.MoveNext()) { DictionaryEntry current = (DictionaryEntry) enumerator.Current; colors.set_Item((IEdge) current.Key, 0); colors.set_Item((IEdge) current.Value, 0); } for (int i = 0; i < this.EndPathEdges.Count; i++) { edgesArray[i] = this.MergedPath(this.EndPathEdges.get_Item(i), colors); } return edgesArray; }
private void edgeDepthFirstSearchItem_Click(object sender, System.EventArgs e) { if (this.netronPanel.Graph==null) throw new Exception("Generate a graph first"); if (this.netronPanel.Populator==null) throw new Exception("Populator should not be null."); ResetVertexAndEdgeColors(); // create algorithm this.vertexColors=null; this.edgeColors = new EdgeColorDictionary(); EdgeDepthFirstSearchAlgorithm edfs = new EdgeDepthFirstSearchAlgorithm(this.netronPanel.Graph,this.edgeColors); // create tracer LayoutAlgorithmTraverVisitor tracer = new LayoutAlgorithmTraverVisitor(this.netronPanel.Populator); // link to algo edfs.RegisterTreeEdgeBuilderHandlers(tracer); edfs.RegisterEdgeColorizerHandlers(tracer); // add handler to tracers tracer.UpdateVertex +=new ShapeVertexEventHandler(tracer_UpdateVertex); tracer.UpdateEdge +=new ConnectionEdgeEventHandler(tracer_UpdateEdge); // running algorithm Thread thread = new Thread(new ThreadStart(edfs.Compute)); thread.Start(); }
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(); }
private void breadthFirstSearchItem_Click(object sender, System.EventArgs e) { if (this.netronPanel.Graph==null) throw new Exception("Generate a graph first"); if (this.netronPanel.Populator==null) throw new Exception("Populator should not be null."); ResetVertexAndEdgeColors(); // create algorithm this.edgeColors=new EdgeColorDictionary(); foreach(IEdge edge in this.netronPanel.Graph.Edges) this.edgeColors[edge]=GraphColor.White; this.vertexColors = new VertexColorDictionary(); BreadthFirstSearchAlgorithm bfs = new BreadthFirstSearchAlgorithm( this.netronPanel.Graph, new VertexBuffer(), this.vertexColors); // create tracer LayoutAlgorithmTraverVisitor tracer = new LayoutAlgorithmTraverVisitor(this.netronPanel.Populator); // link to algo bfs.RegisterTreeEdgeBuilderHandlers(tracer); bfs.RegisterVertexColorizerHandlers(tracer); bfs.TreeEdge +=new EdgeEventHandler(dfs_TreeEdge); bfs.NonTreeEdge+=new EdgeEventHandler(dfs_BackEdge); bfs.BlackTarget +=new EdgeEventHandler(dfs_ForwardOrCrossEdge); // add handler to tracers tracer.UpdateVertex +=new ShapeVertexEventHandler(tracer_UpdateVertex); tracer.UpdateEdge +=new ConnectionEdgeEventHandler(tracer_UpdateEdge); // running algorithm VertexMethodCaller vm= new VertexMethodCaller( new ComputeVertexDelegate(bfs.Compute), Traversal.FirstVertex(this.netronPanel.Graph) ); Thread thread = new Thread(new ThreadStart(vm.Run)); thread.Start(); }
/// <summary> /// Returns the array of merged paths /// </summary> public EdgeCollection[] AllMergedPaths() { EdgeCollection[] es = new EdgeCollection[EndPathEdges.Count]; EdgeColorDictionary colors = new EdgeColorDictionary(); foreach(DictionaryEntry de in EdgePredecessors) { colors[(IEdge)de.Key]=GraphColor.White; colors[(IEdge)de.Value]=GraphColor.White; } for(int i=0;i<EndPathEdges.Count;++i) es[i] = MergedPath( EndPathEdges[i], colors ); return es; }
/// <summary> /// Create a merged path. /// </summary> /// <remarks> /// <para> /// This method creates an edge path that stops if an edge is not white /// or the edge has no more predecessors. /// </para> /// </remarks> /// <param name="se">end edge</param> /// <param name="colors">edge color dictionary</param> /// <returns>path to edge</returns> public EdgeCollection MergedPath(IEdge se,EdgeColorDictionary colors) { EdgeCollection path = new EdgeCollection(); IEdge ec = se; GraphColor c = colors[ec]; if (c!=GraphColor.White) return path; else colors[ec]=GraphColor.Black; path.Insert(0,ec); while (EdgePredecessors.Contains(ec)) { IEdge e = EdgePredecessors[ec]; c = colors[e]; if (c!=GraphColor.White) return path; else colors[e]=GraphColor.Black; path.Insert(0,e); ec=e; } return path; }
internal void WriteEdges(EdgeColorDictionary edgeColors, IEdgeEnumerable edges) { foreach(IEdge e in edges) { if (edgeColors[e]!=GraphColor.White) continue; Output.Write("{0} -> {1} [", e.Source.ID, e.Target.ID ); OnWriteEdge(e); OnFormatEdge(EdgeFormat,e); Output.WriteLine("];"); edgeColors[e]=GraphColor.Black; } }
internal void WriteClusters( VertexColorDictionary colors, EdgeColorDictionary edgeColors, IClusteredGraph parent ) { ++ClusterCount; foreach(IVertexAndEdgeListGraph g in parent.Clusters) { Output.Write("subgraph cluster{0}",ClusterCount.ToString()); Output.WriteLine(" {"); OnFormatCluster(g); if (g is IClusteredGraph) WriteClusters(colors,edgeColors, g as IClusteredGraph); if (parent.Colapsed) { // draw cluster // put vertices as black foreach(IVertex v in g.Vertices) { colors[v]=GraphColor.Black; } foreach(IEdge e in g.Edges) edgeColors[e]=GraphColor.Black; // add fake vertex } else { WriteVertices(colors,g.Vertices); WriteEdges(edgeColors,g.Edges); } Output.WriteLine("}"); } }
/// <summary> /// Generates the dot code to be rendered with GraphViz /// </summary> /// <param name="outputFileName">output file name</param> /// <returns>corrected output file name</returns> /// <remarks> /// The output filename extension is automatically matched with the /// output file type. /// </remarks> public string Write(string outputFileName) { if (outputFileName == null) throw new ArgumentNullException("outputFileName"); ClusterCount=0; m_StringWriter = new StringWriter(); Output.WriteLine("digraph G {"); String gf = GraphFormat.ToDot(); if (gf.Length > 0) Output.WriteLine(gf); String vf = CommonVertexFormat.ToDot(); if (vf.Length > 0) Output.WriteLine("node [{0}];",vf); String ef = CommonEdgeFormat.ToDot(); if (ef.Length > 0) Output.WriteLine("edge [{0}];",ef); OnWriteGraph(); // initialize vertex map VertexColorDictionary colors = new VertexColorDictionary(); foreach(IVertex v in VisitedGraph.Vertices) colors[v]=GraphColor.White; EdgeColorDictionary edgeColors = new EdgeColorDictionary(); foreach(IEdge e in VisitedGraph.Edges) edgeColors[e]=GraphColor.White; // write if (VisitedGraph is IClusteredGraph) WriteClusters(colors,edgeColors,VisitedGraph as IClusteredGraph); WriteVertices(colors,VisitedGraph.Vertices); WriteEdges(edgeColors,VisitedGraph.Edges); Output.WriteLine("}"); return m_Dot.Run(ImageType,Output.ToString(), outputFileName); }
public EdgeCollection MergedPath(IEdge se, EdgeColorDictionary colors) { EdgeCollection edges = new EdgeCollection(); IEdge edge = se; if (colors.get_Item(edge) == null) { colors.set_Item(edge, 1); edges.Insert(0, edge); while (this.EdgePredecessors.Contains(edge)) { IEdge edge2 = this.EdgePredecessors.get_Item(edge); if (colors.get_Item(edge2) != null) { return edges; } colors.set_Item(edge2, 1); edges.Insert(0, edge2); edge = edge2; } } return edges; }