예제 #1
0
        public static IBidirectionalGraph <TVertex, TaggedEdge <TVertex, TTag> > BuildMinimumSpanningTree <TVertex, TTag>(
            this IBidirectionalGraph <TVertex, TaggedEdge <TVertex, TTag> > graph,
            IEnumerable <TVertex> sources,
            IEnumerable <TVertex> targets,
            Func <TaggedEdge <TVertex, TTag>, double> weightFunc = null)
        {
            var subGraph = new BidirectionalGraph <TVertex, TaggedEdge <TVertex, TTag> >(false);

            foreach (var path in graph.GetAllPaths(sources, targets, weightFunc))
            {
                foreach (var segment in path)
                {
                    var edge = new TaggedEdge <TVertex, TTag>(segment.Source, segment.Target, segment.Tag);
                    subGraph.AddVerticesAndEdge(edge);
                }
            }
            return(subGraph);
        }