Exemplo n.º 1
0
        public Graph_AdjacencyList FindMinimumSpaningTree()
        {
            Graph_AdjacencyList minSpanTree = new Graph_AdjacencyList();

            //Select an arbitrary starting vertex
            int startingVertex = this.SelectRandomVertexInGraph();
            //Add the first vertex to the spanning tree
            minSpanTree.AddVertex(this.graph.Vertices[startingVertex].DeepCopy());

            //Examine edges crossing the boundary (where the tail is in the spanned vertices and the head is not)
            List<Edge<int>> crossingEdges = this.FindEdgesCrossingBoundary(minSpanTree.VertexIndices);
            while (crossingEdges.Count > 0)
            {
                //and find the one with the lowest cost
                crossingEdges.Sort();
                minSpanTree.AddVertex(new Vertex<int>(crossingEdges[0].Head));
                minSpanTree.AddUndirectedEdge(crossingEdges[0].Tail, crossingEdges[0].Head, crossingEdges[0].Weight);

                crossingEdges.Clear();
                crossingEdges = this.FindEdgesCrossingBoundary(minSpanTree.VertexIndices);
            }

            return minSpanTree;
        }
Exemplo n.º 2
0
 public static Graph_AdjacencyList DetermineMinimumSpanningTree_PrimmsAlg(Graph_AdjacencyList inputGraph)
 {
     return new Graph_Search.PrimsMinSpanTree(inputGraph).FindMinimumSpaningTree();
 }
Exemplo n.º 3
0
 public PrimsMinSpanTree(Graph_AdjacencyList graph)
 {
     this.graph = graph;
 }
Exemplo n.º 4
0
 public RandomizedContraction(Graph_AdjacencyList<Vertex<int>, int> graph)
 {
     this.graph = graph;
 }