Computes a minimum spanning forest for the given graph. A minimum spanning forest is a smallest subset of the graph's edges that still connects all the graph's connected components. Such a forest is not unique, but all minimum spanning forests will have the same cost. As opposed to a minimum spanning tree, a forest exists also if the original graph is not connnected. The forest will have the same number of connected components as the original graph.
The computed forest is returned in Forest, which is simply a list of the edges that form the forest. The ForestSize is the number of edges that constitute the forest. The ForestWeight is the total length of the forest's edges, according to DistanceArg.
DistanceArg refers to the graph's EdgeData information that was specified when the graph was constructed. If EdgeData is a simple number, then DistanceArg should be 0 and EdgeData will be taken as the length of the edge. If EdgeData is a compound data structure, DistanceArg should be a number between 1 and the arity of that structure and determines which argument of the EdgeData structure will be interpreted as the edge's length. Important: the distance information in EdgeData must be a non-negative number, and the numeric type (integer, float, etc) must be the same in all edges.
If DistanceArg is given as -1, then any EdgeData is ignored and the length of every edge is assumed to be equal to 1.
The direction of the graph's edges is ignored by this predicate.
The implementation uses Kruskal's algorithm which has a complexity of O(Nedges*log(Nedges)).
?- sample_graph(G), minimum_spanning_forest(G, 0, T, S, W). T = [e(2, 10, 1), e(4, 8, 1), e(9, 2, 1), e(7, 3, 2), ...] S = 8 W = 16