Re: [jgrapht-users] Unexpected behavior for addVertex
Brought to you by:
barak_naveh,
perfecthash
From: Szabolcs B. <bes...@gm...> - 2015-10-22 20:01:37
|
Hi Ajay, Did you override the equals and hashCode methods in your costum node and edge classes? Üdvözlettel, Besenyei Szabolcs 2015-10-22 19:05 GMT+02:00 Ajay L <aja...@gm...>: > Hi all, > > Please refer to code snippet below. > > SimpleDirectedWeightedGraph<CustomNode, CustomWeightedEdge> graph = new > SimpleDirectedWeightedGraph<CustomNode, CustomWeightedEdge>( > CustomWeightedEdge.class); > > CustomNode node1 = new CustomNode("node1"); > graph.addVertex(node1); > CustomNode node1Copy = new CustomNode("node1"); > System.out.println(node1.equals(node1Copy)); > System.out.println(graph.addVertex(node1)); > System.out.println(graph.addVertex(node1Copy)); > > When run, this produces true, false, true > > As per addVertex documentation - "Adds the specified vertex to this graph > if not already present. More formally, adds the specified vertex, v, to > this graph if this graph contains no vertex u such that u.equals(v). If > this graph already contains such vertex, the call leaves this graph > unchanged and returns false. In combination with the restriction on > constructors, this ensures that graphs never contain duplicate vertices" > > So why is addVertex call on node1Copy returning true. What am I missing? > > Using latest jgrapht release 0.9.1 > > Thanks > Ajay > > > ------------------------------------------------------------------------------ > > _______________________________________________ > jgrapht-users mailing list > jgr...@li... > https://lists.sourceforge.net/lists/listinfo/jgrapht-users > > |