new TGraph DoBuildMSF <TGraph>(TGraph forest) where TGraph : BipartiteGraph <T>
        {
            DisjointSet <BipartiteGraphVertex <T> > set = new DisjointSet <BipartiteGraphVertex <T> >();

            foreach (var vertex in Data.GetUVertexList())
            {
                set.MakeSet(vertex);
                forest.U.CreateVertex(vertex.Value);
            }
            foreach (var vertex in Data.GetVVertexList())
            {
                set.MakeSet(vertex);
                forest.V.CreateVertex(vertex.Value);
            }
            var edgeList = Data.GetEdgeList();

            edgeList.Sort((x, y) => x.Weight.CompareTo(y.Weight));
            foreach (var edge in edgeList)
            {
                if (!set.AreEquivalent(edge.StartVertex, edge.EndVertex))
                {
                    set.Union(edge.StartVertex, edge.EndVertex);
                    forest.CreateEdge(forest.Data.GetUVertex(edge.StartVertex.Handle), forest.Data.GetVVertex(edge.EndVertex.Handle), edge.Weight);
                }
            }
            return(forest);
        }
Example #2
0
        protected internal TGraph DoBuildMSF <TGraph>(TGraph forest) where TGraph : UndirectedGraph <TValue, TVertex>
        {
            DisjointSet <TVertex> set = new DisjointSet <TVertex>();

            foreach (TVertex vertex in GetVertexList())
            {
                set.MakeSet(vertex);
                forest.CreateVertex(vertex.Value);
            }
            var edgeList = Data.GetEdgeList();

            edgeList.Sort((x, y) => x.Weight.CompareTo(y.Weight));
            foreach (Edge <TValue, TVertex> edge in edgeList)
            {
                if (!set.AreEquivalent(edge.StartVertex, edge.EndVertex))
                {
                    set.Union(edge.StartVertex, edge.EndVertex);
                    forest.CreateEdge(forest.GetVertex(edge.StartVertex.Handle), forest.GetVertex(edge.EndVertex.Handle), edge.Weight);
                }
            }
            return(forest);
        }