unfinishedEdges.remove(nextEdge); forest.addEdge(nextEdge, currentVertex, nextVertex); updateForest(forest.getVertices(), unfinishedEdges); V anotherRoot = leftovers.iterator().next(); forest.addVertex(anotherRoot); updateForest(forest.getVertices(), unfinishedEdges);
unfinishedEdges.remove(nextEdge); forest.addEdge(nextEdge, currentVertex, nextVertex); updateForest(forest.getVertices(), unfinishedEdges); V anotherRoot = leftovers.iterator().next(); forest.addVertex(anotherRoot); updateForest(forest.getVertices(), unfinishedEdges);
unfinishedEdges.remove(nextEdge); forest.addEdge(nextEdge, currentVertex, nextVertex); updateForest(forest.getVertices(), unfinishedEdges); V anotherRoot = leftovers.iterator().next(); forest.addVertex(anotherRoot); updateForest(forest.getVertices(), unfinishedEdges);
this.forest.addVertex(root); updateForest(forest.getVertices(), unfinishedEdges);
this.forest.addVertex(root); updateForest(forest.getVertices(), unfinishedEdges);
this.forest.addVertex(root); updateForest(forest.getVertices(), unfinishedEdges);
/** * Creates a minimum spanning forest from the supplied graph, populating the * supplied Forest, which must be empty. * If the supplied root is null, or not present in the Graph, * then an arbitrary Graph vertex will be selected as the root. * If the Minimum Spanning Tree does not include all vertices of the * Graph, then a leftover vertex is selected as a root, and another * tree is created * @param graph the Graph to find MST in * @param forest the Forest to populate. Must be empty * @param root first Tree root, may be null */ @SuppressWarnings("unchecked") public MinimumSpanningForest(Graph<V, E> graph, Forest<V,E> forest, V root) { if(forest.getVertexCount() != 0) { throw new IllegalArgumentException("Supplied Forest must be empty"); } this.graph = graph; this.forest = forest; this.weights = (Function<E, Double>) Functions.constant(1.0); Set<E> unfinishedEdges = new HashSet<E>(graph.getEdges()); if(graph.getVertices().contains(root)) { this.forest.addVertex(root); } updateForest(forest.getVertices(), unfinishedEdges); }
/** * Creates a minimum spanning forest from the supplied graph, populating the * supplied Forest, which must be empty. * If the supplied root is null, or not present in the Graph, * then an arbitrary Graph vertex will be selected as the root. * If the Minimum Spanning Tree does not include all vertices of the * Graph, then a leftover vertex is selected as a root, and another * tree is created * @param graph the Graph to find MST in * @param forest the Forest to populate. Must be empty * @param root first Tree root, may be null */ @SuppressWarnings("unchecked") public MinimumSpanningForest(Graph<V, E> graph, Forest<V,E> forest, V root) { if(forest.getVertexCount() != 0) { throw new IllegalArgumentException("Supplied Forest must be empty"); } this.graph = graph; this.forest = forest; this.weights = LazyMap.decorate(new HashMap<E,Double>(), new ConstantTransformer(1.0)); Set<E> unfinishedEdges = new HashSet<E>(graph.getEdges()); if(graph.getVertices().contains(root)) { this.forest.addVertex(root); } updateForest(forest.getVertices(), unfinishedEdges); }
this.forest.addVertex(root); updateForest(forest.getVertices(), unfinishedEdges);