编程语言
首页 > 编程语言> > java – JGraphT中的合并图

java – JGraphT中的合并图

作者:互联网

我正在使用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
来源: https://codeday.me/bug/20190613/1231258.html