[英]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.