How to add some edges with same weight?

868 Views Asked by At

Here is my code:

g = new SparseMultigraph<String, Double>();

g.addVertex("A");
g.addVertex("B");
g.addVertex("C"); 

g.addEdge(0.5, "A", "B"); 
g.addEdge(0.5, "B", "C"); 
g.addEdge(0.3, "A", "C"); 

System.out.println("The graph g = " + g.toString()); 

When I run I have this error:

edge 0.5 already exists in this graph with endpoints <A, B> and cannot be added with endpoints <B, C>

Is it possible to have two arcs with the same weight?

1

There are 1 best solutions below

0
On

Fundamentally, the problem is that you're trying to treat an edge weight--which may not be unique--as a unique handle for an edge.

The section on User Data in this manual outlines various options for associating data with graph elements (edges and nodes): http://sourceforge.net/apps/trac/jung/wiki/JUNGManual