Search code examples
javaalgorithmjung

Jung2: how to connect all nodes at once


I would like to ask is there any way to connect all nodes using one and simple method from Jung2 API. I would like to get full graph for the nodes that I did place on my canvas.


Solution

  • Generating a complete graph for a given set of nodes is pretty trivial (and also fairly uncommon), so JUNG doesn't provide a method to do this. The code would look something like this:

    for (V v : g.getVertices()) {
      for (V w: g.getVertices()) {
        g.addEdge(createEdge(), v, w);
      }
    }
    

    (You'd need to supply an implementation of createEdge().)