コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: GraphvizAlgorithm.cs プロジェクト: tmauldin/mb-unit
        /// <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));
        }
コード例 #3
0
ファイル: MainForm.cs プロジェクト: tmauldin/mb-unit
        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();
        }
コード例 #4
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();
 }
コード例 #5
0
 /// <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();
 }
コード例 #6
0
ファイル: MainForm.cs プロジェクト: tmauldin/mb-unit
        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();
        }
コード例 #7
0
        /// <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;
        }
コード例 #8
0
        /// <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);
        }
コード例 #9
0
ファイル: GraphvizAlgorithm.cs プロジェクト: tmauldin/mb-unit
        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("}");
            }
        }
コード例 #10
0
ファイル: MainForm.cs プロジェクト: tmauldin/mb-unit
        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();
        }
コード例 #11
0
ファイル: GraphvizAlgorithm.cs プロジェクト: tmauldin/mb-unit
        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;
            }
        }