![](/img/trans.png)
[英]Copying from grid_graph to adjacency_list with boost::copy_graph
[英]copy a graph (adjacency_list) to another one
如何将adjacency_list类型的图复制到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();
您尝试过copy_graph吗?
很难知道问题出在哪里,而又看不到错误,但是如果我不得不猜测,我首先要确保您提供的是一个copy_graph
的vertex_index
映射,因为在将setS
用于顶点存储时默认情况下不可用。 根据您先前的问题 ,您似乎已经知道了这一点,因此我们只需要将它们整合在一起即可。
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();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.