0

I need to create a random graph from a few pre existing vertices. I didn't find a way to do this yet. Each tutorial is using the "VertexFactory" (which btw cannot be resolved even though importing org.jgraph.generate.*) to make up vertices while creating the graph. But I rather would like to generate the graph from already existing vertices. I'm especially interested in the WattsStragotz algorithm but I don't know yet. Is this possible with using the already written RandomGeneration classes of Jgrapht?

Thanks a lot

ICEBERG
  • 13
  • 6

1 Answers1

0

Yes you can do this, but now with vertices that have already been added to the graph. If, for whatever reason, you want to use pre-existing objects as your vertices, you could do something along the following lines:

  1. Put all your pre-existing vertex objects into a list
  2. Implement a custom Vertex supplier (the old VertexFactory has been taken out of commission in favor of the Supplier paradigm in the newer java versions). This vertex supplier iterates over your list of pre-defined vertices, and returns a new vertex each time the get() method of the supplier is invoked.
  3. Create a new graph with your custom vertex supplier. Have a look at this example on our wiki page.
  4. Invoke any of the random graph generators on the graph.
Joris Kinable
  • 2,232
  • 18
  • 29