I am looking for a way to merge multiple Graphs into a single Graph using LEMON. If it can not be done, I'd also be interested in solutions using Boost Graph Library.
The background is, that I want to define smaller structural units as graphs, annotate them with properties and add multiple copies of them together to create more complex structures.
In the example below, I have 3 graphs g1
,g2
. and g3
consisting of a single vertex. I want to combine them into a single graph and be able to add edges to connect the vertices inside the resulting graph. However, I don't know how to specify the copyGraph
function correctly so that all vertices of g1
, g2
, and g3
end up in the same graph at the end. Also, if g1
etc. contained multiple connected vertices, these edges should remain intact.
The example also contains a fourth graph gTest
which looks like the result I want to achieve. However, gTest
here is created from scratch and not by combining the previously exisiting graphs. This is for demonstration/clarification and produces the following graphic:
To compile the code using g++, use
g++ -lemon main.cpp
#include <lemon/list_graph.h>
#include <lemon/graph_to_eps.h>
int main()
{
using namespace lemon;
typedef dim2::Point<int> Point;
ListGraph g1;
ListGraph::NodeMap<Point> coords1(g1);
ListGraph::Node n1 = g1.addNode();
coords1[n1] = Point(10,20);
ListGraph g2;
ListGraph::NodeMap<Point> coords2(g2);
ListGraph::Node n2 = g2.addNode();
coords2[n2] = Point(20,20);
ListGraph g3;
ListGraph::NodeMap<Point> coords3(g3);
ListGraph::Node n3 = g3.addNode();
coords3[n3] = Point(15,25);
// pseudo-code of the copy-operation:
// copyGraph(g1, g3);
// copyGraph(g2, g3);
//
// g3.addEdge(n1,n3)
// g3.addEdge(n2,n3)
// Result should look similar to what the following produces
ListGraph gTest;
ListGraph::NodeMap<Point> coordsTest(gTest);
ListGraph::Node n1Test = gTest.addNode();
coordsTest[n1Test] = Point(10,20);
ListGraph::Node n2Test = gTest.addNode();
coordsTest[n2Test] = Point(20,20);
ListGraph::Node n3Test = gTest.addNode();
coordsTest[n3Test] = Point(15,25);
ListGraph::Edge e1Test = gTest.addEdge(n3Test, n1Test);
ListGraph::Edge e2Test = gTest.addEdge(n3Test, n2Test);
graphToEps(gTest, "gTest.eps")
.coords(coordsTest)
.nodeTexts(coordsTest)
.run();
return 0;
}