本文整理汇总了Java中org.jgrapht.alg.KruskalMinimumSpanningTree类的典型用法代码示例。如果您正苦于以下问题:Java KruskalMinimumSpanningTree类的具体用法?Java KruskalMinimumSpanningTree怎么用?Java KruskalMinimumSpanningTree使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
KruskalMinimumSpanningTree类属于org.jgrapht.alg包,在下文中一共展示了KruskalMinimumSpanningTree类的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printSpanningTree
import org.jgrapht.alg.KruskalMinimumSpanningTree; //导入依赖的package包/类
protected void printSpanningTree()
{
logger.info("In Spanning Tree " );
KruskalMinimumSpanningTree<DBCMVertex, DBCMEdge> ins = new KruskalMinimumSpanningTree<DBCMVertex, DBCMEdge>(graph);
logger.info("Number of vertices " + graph.vertexSet().size());
logger.info(" Edges " + ins.getEdgeSet().size());
Iterator <DBCMEdge> csIterator = ins.getEdgeSet().iterator();
int count = 0;
while(csIterator.hasNext())
{
DBCMEdge vert = csIterator.next();
//writeStatus("Set " + count + ">>>> " + vert.getProperty(Constants.EDGE_NAME));
//logger.info("Set " + count + ">>>> " + vert.getProperty(Constants.EDGE_NAME));
}
count++;
}
示例2: actionPerformed
import org.jgrapht.alg.KruskalMinimumSpanningTree; //导入依赖的package包/类
/**
* Method actionPerformed.
*
* @param e ActionEvent
*/
@Override
public void actionPerformed( ActionEvent e ) {
// gets the view from the playsheet
// gets the jGraphT graph
// runs the kruskal on it
// Creates the edges and sets it on the edge painter
// repaints it
// I cannot add this to the interface because not all of them will be forced to have it
// yes, which means the menu cannot be generic too - I understand
logger.debug( "Getting the base graph" );
Graph graph = ps.asSimpleGraph();
KruskalMinimumSpanningTree<SEMOSSVertex, SEMOSSEdge> kmst
= new KruskalMinimumSpanningTree<>( graph );
EdgeStrokeTransformer tx = (EdgeStrokeTransformer) ps.getView().getRenderContext()
.getEdgeStrokeTransformer();
tx.setSelected( kmst.getEdgeSet() );
// repaint it
ps.getView().repaint();
int originalSize = ps.getVisibleGraph().getEdgeCount();
int shortestPathSize = kmst.getEdgeSet().size();
GuiUtility.showMessage( "Minimum Spanning Tree uses " + shortestPathSize
+ " edges out of " + originalSize + " original edges" );
}
示例3: generateMinimalSpanningTree
import org.jgrapht.alg.KruskalMinimumSpanningTree; //导入依赖的package包/类
public Multigraph<GameRoom, NoDuplicateEdge> generateMinimalSpanningTree(Array<GameCell> cells, float remainingEdgesMultiplier) {
Gdx.app.log("GraphGenerator", "----------------- Generating minimal spanning tree -----------------");
Array<GameRoom> rooms = GameMap.extractRooms(cells);
ShortArray trianglesIndices = generateTrianglesIndices(cells);
Multigraph<GameRoom, NoDuplicateEdge> graph = getGraphFromTriangulation(trianglesIndices, rooms);
Set<NoDuplicateEdge> minEdges = new KruskalMinimumSpanningTree(graph).getMinimumSpanningTreeEdgeSet();
// Set<NoDuplicateEdge> minEdges = new PrimMinimumSpanningTree(graph).getMinimumSpanningTreeEdgeSet();
minimumSpanningTreeFromGraph(graph, minEdges, remainingEdgesMultiplier);
Gdx.app.log("GraphGenerator", " --> Graph is now a minimal spanning tree. Edge count: " + graph.edgeSet().size());
return graph;
}
示例4: getMST
import org.jgrapht.alg.KruskalMinimumSpanningTree; //导入依赖的package包/类
public KruskalMinimumSpanningTree<Room, Hallway> getMST() {
return new KruskalMinimumSpanningTree<Room, Hallway>(getFullGraph());
}
示例5: step2
import org.jgrapht.alg.KruskalMinimumSpanningTree; //导入依赖的package包/类
/**
* Find the minimal spanning tree, T1, of G1. (If there are several minimal spanning trees, pick an arbitrary one.)
* @param g1
* @return
*/
private WeightedMultigraph<Node, DefaultLink> step2(Pseudograph<Node, DefaultLink> g1) {
logger.debug("<enter");
KruskalMinimumSpanningTree<Node, DefaultLink> mst =
new KruskalMinimumSpanningTree<Node, DefaultLink>(g1);
// logger.debug("Total MST Cost: " + mst.getSpanningTreeCost());
Set<DefaultLink> edges = mst.getEdgeSet();
WeightedMultigraph<Node, DefaultLink> g2 =
new WeightedMultigraph<Node, DefaultLink>(DefaultLink.class);
List<DefaultLink> edgesSortedById = new ArrayList<DefaultLink>();
for (DefaultLink e : edges)
edgesSortedById.add(e);
Collections.sort(edgesSortedById);
for (DefaultLink edge : edgesSortedById) {
g2.addVertex(edge.getSource());
g2.addVertex(edge.getTarget());
g2.addEdge( edge.getSource(), edge.getTarget(), edge);
}
logger.debug("exit>");
return g2;
}
示例6: step4
import org.jgrapht.alg.KruskalMinimumSpanningTree; //导入依赖的package包/类
/**
* Find the minimal spanning tree, Ts, of Gs. (If there are several minimal spanning trees, pick an arbitrary one.)
* @param g3
* @return
*/
private WeightedMultigraph<Node, DefaultLink> step4(WeightedMultigraph<Node, DefaultLink> g3) {
logger.debug("<enter");
KruskalMinimumSpanningTree<Node, DefaultLink> mst =
new KruskalMinimumSpanningTree<Node, DefaultLink>(g3);
// logger.debug("Total MST Cost: " + mst.getSpanningTreeCost());
Set<DefaultLink> edges = mst.getEdgeSet();
WeightedMultigraph<Node, DefaultLink> g4 =
new WeightedMultigraph<Node, DefaultLink>(DefaultLink.class);
List<DefaultLink> edgesSortedById = new ArrayList<DefaultLink>();
for (DefaultLink e : edges)
edgesSortedById.add(e);
Collections.sort(edgesSortedById);
for (DefaultLink edge : edgesSortedById) {
g4.addVertex(edge.getSource());
g4.addVertex(edge.getTarget());
g4.addEdge( edge.getSource(), edge.getTarget(), edge);
}
logger.debug("exit>");
return g4;
}