public Kruskal(IGraph graph, Func <Arc, TCost> cost, Func <Node, int> maxDegree = null) { Graph = graph; Cost = cost; MaxDegree = maxDegree; Forest = new HashSet <Arc>(); Degree = new Dictionary <Node, int>(); foreach (Node item in Graph.Nodes()) { Degree[item] = 0; } List <Arc> list = Enumerable.ToList <Arc>(Graph.Arcs(ArcFilter.All)); list.Sort((Arc a, Arc b) => Cost(a).CompareTo(Cost(b))); arcEnumerator = list.GetEnumerator(); arcsToGo = Graph.NodeCount() - new ConnectedComponents(Graph, ConnectedComponents.Flags.None).Count; components = new DisjointSet <Node>(); }
private DisjointSet <Node> components; // The components of the current spanning forest. public Kruskal(IGraph graph, Func <Arc, TCost> cost, Func <Node, int> maxDegree = null) { Graph = graph; Cost = cost; MaxDegree = maxDegree; Forest = new HashSet <Arc>(); Degree = new Dictionary <Node, int>(); foreach (var node in Graph.Nodes()) { Degree[node] = 0; } List <Arc> arcs = Graph.Arcs().ToList(); arcs.Sort((a, b) => Cost(a).CompareTo(Cost(b))); arcEnumerator = arcs.GetEnumerator(); arcsToGo = Graph.NodeCount() - new ConnectedComponents(Graph).Count; components = new DisjointSet <Node>(); }
public ContractedGraph(IGraph graph) { this.graph = graph; nodeGroups = new DisjointSet <Node>(); Reset(); }