繁体   English   中英

如何使用Boost C ++复制图形?

[英]How to copy a graph using boost c++?

我在使用boost复制图形时遇到问题吗? 我的代码如下:它不允许我将IndexMap创建为类型。

template <class Graph>
int abc(Graph& G){

    typename graph_traits<Graph>::vertex_descriptor NodeID;

    typedef map<size_t, NodeID> IndexMap; //It doesn't let me to create NodeID type

    typedef map<NodeID, size_t> IndexMap;

    IndexMap mapIndex;

    associative_property_map<IndexMap> propmapIndex(mapIndex);

    Graph g1, g2;

    int i=0;
    BGL_FORALL_VERTICES(v, g2, Graph)
    {
       put(propmapIndex, v, i++);
    }

    g1.clear();
    copy_graph( g2, g1, vertex_index_map( propmapIndex ) );
    g2.clear();

}

int main(){

    typedef adjacency_list<listS, vecS, undirectedS, 
        WeightProperty, property<edge_color_t, default_color_type>  MyGraphType;
    typename graph_traits<MyGraphType>::adjacency_iterator ai, ai_end;

    typename graph_traits<MyGraphType>::vertex_descriptor Vertex;
    ...
    ...

    MyGraphType G;
    ... //addition of vertices and edges
    abc(G);

}

感谢您的帮助。

我猜

typename graph_traits<Graph>::vertex_descriptor NodeID;

应该

typedef typename graph_traits<Graph>::vertex_descriptor NodeID;

上面的变体是对类型为graph_traits<Graph>::vertex_descriptor的变量NodeID的声明,而后者是同一类型的typedef。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM