Re: [jgrapht-users] Troubless with references...
Brought to you by:
barak_naveh,
perfecthash
From: John V. S. <js...@gm...> - 2009-03-04 08:19:30
|
maria esther sanchez wrote: > Hello! I am having trouble with the references. I would like to know how > to duplicate, clone or copy a graph in with there are no references amog > them. I tryed this method: Graphs.addGraph(simpleGraph,graph)... but i > still have the same problem. If a modify a vertex from simplegrap, the > node that corresponds to graph is modified also. > How can i make a copy that does afect from the graph that i am copying, > and the other way arround. > Thank u for you help! Hi Maria, You can code this as follows: 1) create a Map<V,V> m 2) write a new cloneAllVertices like addAllVertices which does vPrime = v.clone(), adds an entry (v,vPrime) to m, and puts vPrime in the destination graph 3) write a new addAllEdgesForClones like addAllEdges which uses m to map each s and t to sPrime and tPrime before calling addEdge I forget how the interactions between generics and clone work out, but if you get a generic version of this working along with a unit test, please send it to me and I'll check it in as a new utility method on class org.jgrapht.Graphs. JVS |