How to copy graph to JUNG 2.0 structure?

in JUNG 1.7.6, the copy () function (myGraph.copy ()) was for this purpose, but in JUNG 2.0 this function no longer exists. I could not find any other way to create a copy of the graph object. I would be very happy if someone could help me. A workaround would be nice.

Thank you so much!

+3
source share
3 answers

The code below is generic, so you should replace Vit Ewith Stringfor Graph<String, String>.

    Graph<V, E> src;
    Graph<V, E> dest;

    for (V v : src.getVertices())
        dest.addVertex(v);

    for (E e : src.getEdges())
        dest.addEdge(e, src.getIncidentVertices(e));
+7
source

You can copy the graph manually by iterating over all vertices and all edges and adding them to the new graph. See getVertices () in the API

0
source

You can make a simple copy of the vertices and edges that will create a new graph, but the objects inside will be passed by reference so you can use this cloning library https://code.google.com/p/cloning/

and do a deep copy:

Cloner cloner = new Cloner();
Graph<V, E> clonedGraph = cloner.deepClone(graph);
0
source

All Articles