如何使用 Jung 2 在图中用概率标记边
我对 Java 和 Jung 相当陌生。我正在编写一个程序,我需要在事件发生的边缘添加概率(意味着数据从第一个节点流向其他节点的事件的概率)。我有点困惑,Max-Flow 会为我解决这个问题,还是我需要使用其他选项,或者在 Jung 中没有选项可以做到这一点,在这种情况下,我需要自己编写它吗?在这方面的任何帮助将不胜感激。
问候, 瓦卡斯
I am fairly new to Java and Jung. I am writing a program where I need to add probabilities on edges of the event occurrence(means probability of the event that data will flow from first node to other). I am a little confuse that will Max-Flow do the trick for me or do I need to use some other option or there is no option to do it within Jung and in that case do I need to write it on my own? Any help in this regard will be appreciated.
regards,
waqas
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否打算设置边权重来表示某些事件的概率?最大流算法将使用您分配给每条边的“容量”来查找从源顶点到汇顶点的最大流路径。你到底想在这里做什么?
Do you intend to set the edge weights to represent the probabilities of certain events? The Max-Flow algorithm will use the "capacities" you assign to each edge to find the path of maximum flow from the source vertex to the sink vertex. What exactly are you trying to do here?
我不太确定你的最终目标是什么,所以我会尽力帮助你。
您可以首先通过定义自定义边缘和边缘工厂类来表示概率。我所做的是:
0。进口:
1。添加您的自定义类。他们的自定义边缘类可能类似于:
自定义边缘工厂是每次您以图形方式在画布上绘制边缘时实际创建边缘的东西,它可能看起来像:
2。告诉您的可视化查看器如何显示边缘标签;您需要在创建图形和 VisualizationViewer 对象 (vv) 的任何位置添加此内容:
现在,每次创建边时,它的标签都将采用“E0 0/0”形式, “E1 0/0”等等。
我将在我的博客 很快,如果您要在您正在从事的任何项目上花费大量时间,您就可以观看该空间。
I'm not very sure what your final aim is, so I'll try my best to help out.
You can first represent the probabilities by defining a custom Edge and Edge Factory classes. What I did was:
0. Imports:
1. Add in your custom classes. They custom edge class might be something like:
The custom edge factory is what actually creates your edges each time you draw them on the canvas graphically, it might look like:
2. Tell your visualization viewer how to display the edge labels; you'll need to add this in wherever you're creating your graph and VisualizationViewer object (vv):
Now everytime you create an edge, it's label will be of the form "E0 0/0", "E1 0/0" and so on.
I'll be posting detailed tutorials and code on my blog soon so you could watch that space if you're going to be spending significant time on whatever project you're working on.
看看您调用 setEdgeLabelTransformer 的方式,您需要向其传递一个 new Transformer(),就像我在编号为 2 的代码片段中所做的那样< /强>。
当您传递新的 ToStringLabeller() 时,您是在告诉查看器使用边缘对象的 toString() 方法进行标记。您需要传递一个自定义 Transformer,只需更正您的代码以使其看起来像我的那样就可以了。
Look at the way you're calling setEdgeLabelTransformer, you need to pass it a new Transformer(), like I've done in my code snippet numbered 2.
When you pass a new ToStringLabeller(), you're telling the viewer to label using the toString() method of the edge object. You'll need to pass a custom Transformer instead, just correct your code to look like mine and you'll be fine.