Re: [jgrapht-users] Documentation, implementation or me?
Brought to you by:
barak_naveh,
perfecthash
From: Jonathan C. <jon...@it...> - 2010-11-16 02:37:46
|
Exactly what I thought. But... is this really what a graph should be? I mean, there is no hint in the docs as far as I can see, and although I know it is not good practice to change things in a collection from the outside, it still seems like something you might want to do. In particular if the graph represents some meta level info... /J On 16 nov 2010, at 03.18, John Sichi wrote: > Hi Jonathan, > > s2 is a mutable object, and you changed it after adding it to the > graph. That's why you got unexpected results. > > See the section "Good keys" in this article: > > http://www.ibm.com/developerworks/java/library/j-jtp02183.html > > JVS > > On Mon, Nov 15, 2010 at 5:23 PM, Jonathan Cederberg > <jon...@it...> wrote: >> I am a huge fan of jgrapht. However, I have come across a problem with it. >> My understanding is that that the code below should work, but it doesn't. I >> have not dug into the source, but I can imagine that there is a hashcode >> issue, as it no longer seem to find the vertex that is there. >> I am not sure if I have read the docs wrong, programmed wrong, or if this is >> simply a bug. The latter seems unlikely though, since it is such a core >> feature that this type of problem should have been caught long ago. >> Thanks in advance for any help! >> /Jonathan >> >> import java.util.LinkedHashSet; >> import java.util.Set; >> import org.jgrapht.graph.DefaultEdge; >> import org.jgrapht.graph.SimpleGraph; >> public class Main { >> /** >> * @param args >> */ >> public static void main(String[] args) { >> SimpleGraph<Set<String>, DefaultEdge> sg = >> new SimpleGraph<Set<String>, DefaultEdge>(DefaultEdge.class); >> >> Set<String> s1, s2; >> s2 = new LinkedHashSet<String>(); >> s2.add("y"); >> s2.add("z"); >> >> sg.addVertex(s2); >> >> s2.remove("z"); >> >> // this is true, as expected >> assert(sg.vertexSet().size()==1) : "There is no vertex any more."; >> assert(sg.vertexSet().iterator().next()==s2) : "Not the same vertex!"; >> >> // but this is false! >> assert(sg.containsVertex(s2)) : "The vertex is gone!"; >> } >> } >> >> ------------------------------------------------------------------------------ >> Beautiful is writing same markup. Internet Explorer 9 supports >> standards for HTML5, CSS3, SVG 1.1, ECMAScript5, and DOM L2 & L3. >> Spend less time writing and rewriting code and more time creating great >> experiences on the web. Be a part of the beta today >> http://p.sf.net/sfu/msIE9-sfdev2dev >> _______________________________________________ >> jgrapht-users mailing list >> jgr...@li... >> https://lists.sourceforge.net/lists/listinfo/jgrapht-users >> >> |