PrimMinimumSpanningTree<V, E> mst = new PrimMinimumSpanningTree<V, E>( treeFactory, this.weights); Graph<V, E> subTree = mst.transform(component); if (subTree instanceof Tree) { TreeUtils.addSubTree(forest, (Tree<V, E>) subTree, null, null);
/** * @param graph the Graph to find MST in */ public Graph<V,E> apply(Graph<V,E> graph) { Set<E> unfinishedEdges = new HashSet<E>(graph.getEdges()); Graph<V,E> tree = treeFactory.get(); V root = findRoot(graph); if(graph.getVertices().contains(root)) { tree.addVertex(root); } else if(graph.getVertexCount() > 0) { // pick an arbitrary vertex to make root tree.addVertex(graph.getVertices().iterator().next()); } updateTree(tree, graph, unfinishedEdges); return tree; }
new PrimMinimumSpanningTree<V,E>(treeFactory, this.weights); Graph<V,E> subTree = mst.apply(component); if(subTree instanceof Tree) { TreeUtils.addSubTree(forest, (Tree<V,E>)subTree, null, null);
unfinishedEdges.remove(nextEdge); tree.addEdge(nextEdge, currentVertex, nextVertex); updateTree(tree, graph, unfinishedEdges);
unfinishedEdges.remove(nextEdge); tree.addEdge(nextEdge, currentVertex, nextVertex); updateTree(tree, graph, unfinishedEdges);
new PrimMinimumSpanningTree<V,E>(treeFactory, this.weights); Graph<V,E> subTree = mst.transform(component); if(subTree instanceof Tree) { TreeUtils.addSubTree(forest, (Tree<V,E>)subTree, null, null);
/** * @param graph the Graph to find MST in */ public Graph<V,E> transform(Graph<V,E> graph) { Set<E> unfinishedEdges = new HashSet<E>(graph.getEdges()); Graph<V,E> tree = treeFactory.create(); V root = findRoot(graph); if(graph.getVertices().contains(root)) { tree.addVertex(root); } else if(graph.getVertexCount() > 0) { // pick an arbitrary vertex to make root tree.addVertex(graph.getVertices().iterator().next()); } updateTree(tree, graph, unfinishedEdges); return tree; }
unfinishedEdges.remove(nextEdge); tree.addEdge(nextEdge, currentVertex, nextVertex); updateTree(tree, graph, unfinishedEdges);
/** * Calculate and return the minimum spanning free of the Graph top. * @param topo - the graph. * @return the "pruned" minimal spanning tree. */ private Graph<String, Link> calcMinimumSpanningTree(List<String> fabrics) { Topology topo = this.getFabricTopology(); if (topo == null) { LOG.error("Failed to read Fabric Topology!"); return null; } UndirectedSparseGraph<String, Link> graph = new UndirectedSparseGraph<>(); for (Node node : topo.getNode()) { graph.addVertex(node.getNodeId().getValue()); } if (topo.getLink() != null) for (Link link : topo.getLink()) { graph.addEdge(link, link.getSource().getSourceNode().getValue(), link.getDestination().getDestNode().getValue()); } PrimMinimumSpanningTree<String, Link> alg = new PrimMinimumSpanningTree<>(UndirectedSparseGraph.<String, Link>getFactory()); Graph<String, Link> miniTree = alg.transform(graph); return pruneTree(miniTree, fabrics); }
/** * @param graph * the Graph to find MST in */ @Override public Graph<V, E> transform(Graph<V, E> graph) { Set<E> unfinishedEdges = new HashSet<E>(graph.getEdges()); Graph<V, E> tree = treeFactory.create(); V root = findRoot(graph); if (graph.getVertices().contains(root)) { tree.addVertex(root); } else if (graph.getVertexCount() > 0) { // pick an arbitrary vertex to make root tree.addVertex(graph.getVertices().iterator().next()); } updateTree(tree, graph, unfinishedEdges); return tree; }