使用 JGraphT 更改顶点的内容
有没有一种方法可以更改顶点的内容,同时保留其所有边。我找不到,但似乎会提供一些东西。
Is there a method to change the contents of a vertex while keeping all its edges. I couldn't find one but it seems like something that would be provided.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
JGraphT 没有替换顶点的方法。您可以用它来做您想做的事:
JGraphT has no method for replacing a vertex. You can use this to do what you want:
改变顶点的内容是什么意思?顶点是用泛型创建的,这意味着您可以在其中放置任何对象,这意味着您可以提供一种方法来替换该对象的内容(如果该对象不是不可变的)。或者您想在那里放置一个全新的对象(全新的顶点)并保存旧对象的所有关系?然后您可能必须找到具有此顶点的边(
java.util.SetedgesOf(V vertex)
),删除它们(boolean removeEdge(E e)
),并替换为包含新顶点的新顶点 (E addEdge(V sourceVertex, V targetVertex)
)。What do you mean by changing contents of a vertex? Vertices are made with generics, which means you can put just any object there, which means it's up to you to provide a method to replace the contents of this object, if it is not immutable. Or do you want to put completely a new object there (completely new vertex) and save all relations of the old one? Then you would probably have to find edges with this vertex (
java.util.Set<E> edgesOf(V vertex)
), remove them (boolean removeEdge(E e)
), and replace with new ones, containing the new vertex (E addEdge(V sourceVertex, V targetVertex)
).