Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Merge graphs in JGraphT

Tags:

java

jgrapht

I'm using JGraphT and I have two DirectedGraph : g1 and g2.

How can I merge g1 and g2 to a third graph g3? I need g3 be a normal graph and has the ability to add new edges and vertices.

like image 319
masoud Avatar asked Dec 26 '22 15:12

masoud


1 Answers

Finally I found it !

There is a method in Graphs class that adds the second entry graph to the first entry graph:

Graphs.addGraph(g1, g2);

Adds all the vertices and all the edges of the specified source graph to the specified destination graph. First all vertices of the source graph are added to the destination graph. Then every edge of the source graph is added to the destination graph. This method returns true if the destination graph has been modified as a result of this operation, otherwise it returns false.

We can read more here.

like image 160
masoud Avatar answered Jan 07 '23 23:01

masoud