I'm trying to copy an edge from a graph and add it to another (with all his vertices and properties), I make something like:
if (!dataG.empty())
{
auto const& gr = dataG.front(); // firslt graph in G_list
auto ep = edges(gr).first; //first edge in gr
vertex_t from = source(*ep, gr);
vertex_t to = target(*ep, gr);
boost::property_map<Graph, int VertexProperties::*>::type idmap = boost::get(&VertexProperties::id, testg);
boost::property_map<Graph, int VertexProperties::*>::type labelmap = boost::get(&VertexProperties::label, testg);
idmap[from] = gr[from].id;
labelmap[from] = gr[from].label;
boost::add_vertex(VertexProperties(idmap[from], labelmap[from]), testg);
idmap[to] = gr[to].id;
labelmap[to] = gr[to].label;
boost::add_vertex(VertexProperties(idmap[to], labelmap[to]), testg);
boost::add_edge(from, to, gr[*ep], testg);
}
and I got this error:
segmentation error core dumped
The full source is here http://pastebin.com/vzCDbTiB
Sample input: http://pastebin.com/g4cgaHJB
You want to insert the edge so the number of vertices gets automatically adjusted to accommodate the source and target for the edge.
Then, just copy the vertex properties by their bundles, no need to meddle with the member-specific maps (these are useful when you want to pass specific properties to e.g. algorithms).
Here's the simplified version:
Live sample:
Live On Coliru
Prints