Re: [jgrapht-users] problem with random graph generation
Brought to you by:
barak_naveh,
perfecthash
From: John S. <js...@gm...> - 2010-02-11 23:18:19
|
Hmmm, based on the stack dump I requested when I reproduced your infinite loop, here's what is happening: - you're using a graph which does not allow self-loops - you're using a vertex factory which always produces the same vertex (empty string) - hence you always have a self-loop due to non-distinct vertices - the generator keeps generating the self-loops and tossing them as invalid - the generator keeps going, hoping that it will eventually satisfy your request for 5 edges, but never does The fix is to supply a vertex factory which generates distinct vertices. Note that the existing unit tests in testsrc/org/jgrapht/generate/RandomGraphGeneratorTest.java use IntegerVertexFactory. The generator could be made safer by having it check that it actually generated the number of distinct vertices requested, and throwing an exception if this is not the case (before going into the edge-generation loop). JVS On Wed, Feb 10, 2010 at 7:20 AM, andrea pagani <pag...@gm...> wrote: > Hi everybody, > > I'm trying to generate random graphs using the provided set of functions in > JGrapht, actually the code im using is: > > > /*************************************************************************************************************************************************************/ > > RandomGraphGenerator<String, DefaultEdge> randomGenerator = new > RandomGraphGenerator<String, DefaultEdge>(5, 5); > Graph<String, DefaultEdge> randomGraph = new SimpleGraph<String, > DefaultEdge>(DefaultEdge.class); > VertexFactory<String> factory = new > ClassBasedVertexFactory<String>(String.class); > randomGenerator.generateGraph(randomGraph, factory, null); > > /***********************************************************************************************************************************************************/ > > it's just an example creating a random graph with 5 nodes and 5 edges. > > the program get stuck when invoking > "randomGenerator.generateGraph(randomGraph, factory, null);" any idea? > I think I miss something with the factory...help is really appreciated! > > Thanks in advance. > > > Best regards, > > Andrea > > ------------------------------------------------------------------------------ > SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, > Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW > http://p.sf.net/sfu/solaris-dev2dev > _______________________________________________ > jgrapht-users mailing list > jgr...@li... > https://lists.sourceforge.net/lists/listinfo/jgrapht-users > > |