How to add two edges having the same label but different endpoints?
For example, I want to add two edges having the same label 'label1', one from vertex v-1 to vertex v-2 and the other one from vertex v-2 to v-3.
Part of the code would be:
g.addEdge("label1","v-1","v-2");
g.addEdge("label1","v-2","v-3");
But JUNG does not allow to add two edges with the same label. It gives an error:
edge label1 already exists in this graph with endpoints [v-1, v-2] and cannot be added with endpoints [v-2, v-3]
How can I add two edges having the same label?
Thanks.
Edit:
I just read that there is a way to assign a weight value to an edge, that is by using EdgeWeightLabeller, but these weight values should be integers. So it does not seem to solve the problem.
Labels are not required to be the toString() of the edges; that's just the default. Take a look at PluggableRendererContext to see how to supply a Transformer that provides a property for each element of the graph.
I'd also check out the section in the JUNG 2 manual (on the wiki) that talks about user data: http://sourceforge.net/apps/trac/jung/wiki/JUNGManual#UserData
Here is an MCVE example.
The Result:
When I have this problem, I make my label String (your is already a String) and make its value like this: "ID_OF_FIRST_VERTEX:ID_OF_SECOND_VERTEX:EDGE_VALUE". Then, to display just a value, I do use transformation. Its simple, it just takes the edge_value from name of edge.
In this sample I use a separator ":".
Of course you dont have to use StringUtils from Apache Commons, a normal String.subString will work here as well.
Hope it helps.