我正在使用 JGraphT,我有两个 DirectedGraph
:g1
和 g2
。
如何将 g1
和 g2
合并到第三个图 g3
?
我需要 g3
是一个普通图,并且能够添加新的边和顶点。
最佳答案
终于找到了!
Graphs
类中有一个方法可以将第二个入口图添加到第一个入口图:
Graphs.addGraph(g1, g2);
Adds all the vertices and all the edges of the specified source graph to the specified destination graph. First all vertices of the source graph are added to the destination graph. Then every edge of the source graph is added to the destination graph. This method returns true if the destination graph has been modified as a result of this operation, otherwise it returns false.
我们可以阅读更多here .
关于java - 在 JGraphT 中合并图形,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13232450/