Hi,
Maybe somebody can tell me if this behaviour is normal or if it's a bug.
I want to build a graph with a unique cycle (one edge, one vertex)
I use two classes MyVertex and MyEdge, a WeightedPseudograph (version
0.7.3 of jGraphT), and here is my test case :
v1 = new MyVertex();
graph.addVertex(v1);
graph.addEdge(v1,v1,new MyEdge());
==> build a graph with 1 vertex and 1 edge, vertex has degree 2 (that is
OK!)
v1 = new MyVertex();
v2 = new MyVertex(); // where n2.equals(n1)
graph.addVertex(v1);
graph.addVertex(v2);
graph.addEdge(v1,v2,new MyEdge());
==> build a graph with 1 vertex and 1 edge, vertex has degree 4 !
Seems like addVertex uses equals to compare vertices and add only one
vertex if v1!=v2 but v1.equals(v2)
That's fine for me
There is still 1 vertex after addEdge, but that time, the degreeOf
method returns 4 instead of 2
I find this code in AbstractBaseGraph (line 1109) :
if (source != target) {getEdgeContainer(target).addEdge(e);}
//here == is used, not equals
and also this (line 1125) :
if (getEdgeSource(e).equals(getEdgeTarget(e))) { degree += 2;}
Any help is welcome
Michaël
|