【问题标题】:How to copy a graph using boost c++?如何使用 boost c++ 复制图形?
【发布时间】:2014-01-26 03:28:39
【问题描述】:

我在使用 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);

}

感谢您的帮助。

【问题讨论】:

  • 以防万一这里没有人知道一个明确的答案,我过去在boost-users 上问过非常成功。

标签: c++ boost boost-graph


【解决方案1】:

我猜

typename graph_traits<Graph>::vertex_descriptor NodeID;

应该是

typedef typename graph_traits<Graph>::vertex_descriptor NodeID;

上面的变体是graph_traits&lt;Graph&gt;::vertex_descriptor类型的变量NodeID的声明,而后者是同一类型的typedef。

【讨论】:

  • 谢谢!!那个问题是固定的。但它仍然给我 BGL_FORALL_VERTICES(v, g2, Graph) 的问题。
  • @user3236678 由于Graph 是一个依赖名称,您需要使用BGL_FORALL_VERTICES_T(它在宏中使用typename)。
  • @cv_and_he 非常感谢!!
猜你喜欢
  • 2012-02-07
  • 1970-01-01
  • 2019-02-24
  • 2011-02-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-17
相关资源
最近更新 更多