2012-02-13 108 views
5

如何将类型adjacency_list的图形复制到另一个类型为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(); 

回答

6

您试过copy_graph


很难知道问题是什么,而不会看到错误,但如果要我猜,我首先要确保你提供一个vertex_index地图copy_graph因为它是不可用时默认使用setS用于顶点存储。根据你的earlier question,看起来你已经弄清楚了,所以我们只需要把它们放在一起。

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(); 
+0

对于copy_graph,据说图类型必须是VertexListGraph的模型。就我而言,我说过它是一个adjacency_list。 – shn 2012-02-13 14:56:28

+1

@ user995434但是adjacency_list是VertexAndEdgeListGraph的一个模型,它是VertexListGraph的一种改进。因此,adjacency_list是VertexListGraph的模型。 – 2012-02-13 15:25:25

+0

你可以给我一个使用copy_graph()的小例子来说明我想做什么吗?它总是给我编译错误。提前致谢。 – shn 2012-02-13 21:20:41

相关问题