private void GenerateSpanningTree()
        {
            _spanningTree = new BidirectionalGraph <TVertex, Edge <TVertex> >(false);
            _spanningTree.AddVertexRange(VisitedGraph.Vertices);
            IQueue <TVertex> vb = new QuickGraph.Collections.Queue <TVertex>();

            if (VisitedGraph.VertexCount > 0)
            {
                vb.Enqueue(VisitedGraph.Vertices.OrderBy(v => VisitedGraph.InDegree(v)).First());
            }
            switch (Parameters.SpanningTreeGeneration)
            {
            case SpanningTreeGeneration.BFS:
                var bfsAlgo = new BreadthFirstSearchAlgorithm <TVertex, TEdge>(VisitedGraph, vb, new Dictionary <TVertex, GraphColor>());
                bfsAlgo.TreeEdge += e => _spanningTree.AddEdge(new Edge <TVertex>(e.Source, e.Target));
                bfsAlgo.Compute();
                break;

            case SpanningTreeGeneration.DFS:
                var dfsAlgo = new DepthFirstSearchAlgorithm <TVertex, TEdge>(VisitedGraph);
                dfsAlgo.TreeEdge += e => _spanningTree.AddEdge(new Edge <TVertex>(e.Source, e.Target));
                dfsAlgo.Compute();
                break;
            }
        }
Exemplo n.º 2
0
        private BidirectionalGraph <FrameworkElement, Edge> GenerateSpanningTree(BidirectionalGraph <FrameworkElement, Edge> graph)
        {
            var spanningTree = new BidirectionalGraph <FrameworkElement, Edge>(false);

            spanningTree.AddVertexRange(graph.Vertices.ToList());
            IQueue <FrameworkElement> vb = new QuickGraph.Collections.Queue <FrameworkElement>();

            vb.Enqueue(graph.Vertices.OrderBy(graph.InDegree).First());
            //switch (Parameters.SpanningTreeGeneration)
            //{
            //    case SpanningTreeGeneration.BFS:
            var bfsAlgo = new DepthFirstSearchAlgorithm <FrameworkElement, Edge>(graph);

            bfsAlgo.TreeEdge += e => spanningTree.AddEdge(e);
            bfsAlgo.Compute();
            //        break;
            //    case SpanningTreeGeneration.DFS:
            //        var dfsAlgo = new DepthFirstSearchAlgorithm<TVertex, TEdge>(VisitedGraph);
            //        dfsAlgo.TreeEdge += e => spanningTree.AddEdge(new Edge<TVertex>(e.Source, e.Target));
            //        dfsAlgo.Compute();
            //        break;
            //}
            return(spanningTree);
        }