Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
        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();
        }