如何在 JUNG 中合并两个图?
我必须要合并的图,即创建一个由图的边和节点的并集组成的新图(不重复)。 JUNG 中有可用的实现吗?还是我自己可以实现?
I have to graphs which I want to unite, that is, create a new graph composed by the union of both graph's edges and nodes (without repetition). Is there an implementation for that avaliable in JUNG or do I have do so on my own?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
JUNG 中没有实现这一点,但假设图、顶点和边具有相同类型,则大约有六行代码:
如果没有孤立的顶点(即,没有入射边);
addEdge()
将添加任何事件顶点。如果图形是有向的,您需要将上面的内容更改为
g.addEdge(e, g1.getSource(e), g1.getDest(e));
重复项将被默默忽略(如果您想知道添加是否有效果,请检查返回值)。
There isn't an implementation for that in JUNG, but it's about six lines of code assuming that the graphs, vertices, and edges are of the same types:
You can skip the vertex adding if there are no isolated vertices (i.e., vertices that have no incident edges);
addEdge()
will add any incident vertices.If the graph is directed, you'll want to change the above to
g.addEdge(e, g1.getSource(e), g1.getDest(e));
Duplicates are silently ignored (if you want to know whether an add had an effect, check the return value).