How can I copy a graph of type adjacency_list to another one graph of type adjacency_list ?
typedef adjacency_list<setS, setS, undirectedS, NodeDataStruct, EdgeDataStruct> MyGraph;
MyGraph g1, g2;
// processing g1: adding vertices and edges ...
// processing g2: adding some vertices and edges ...
g1.clear();
g1 = g2 // this gives an execution error (exception)
g1 = MyGraph(g2); // this also gives an execution error
g2.clear();
Have you tried copy_graph ?
Hard to know what the problem is without seeing the errors but if I had to guess, I'd first make sure you're providing a vertex_index
map to copy_graph
since it's not available by default when you use setS
for vertex storage. Based on your earlier question , it looks like you've already got that figured out so we just need to bring it all together.
typedef adjacency_list<setS, setS, undirectedS, NodeDataStruct, EdgeDataStruct> MyGraph;
typedef MyGraph::vertex_descriptor NodeID;
typedef map<NodeID, size_t> IndexMap;
IndexMap mapIndex;
associative_property_map<IndexMap> propmapIndex(mapIndex);
MyGraph g1, g2;
// processing g1: adding vertices and edges ...
// processing g2: adding some vertices and edges ...
int i=0;
BGL_FORALL_VERTICES(v, g2, MyGraph)
{
put(propmapIndex, v, i++);
}
g1.clear();
copy_graph( g2, g1, vertex_index_map( propmapIndex ) );
g2.clear();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.