为vert :: graph :: copy_graph提供顶点映射参数

hoo*_*och 3 c++ boost parameter-passing boost-graph

boost函数boost :: graph :: copy_graph

 template <class VertexListGraph, class MutableGraph>  void
 copy_graph(const VertexListGraph& G, MutableGraph& G_copy,
     const bgl_named_params<P, T, R>& params = all defaults)
Run Code Online (Sandbox Code Playgroud)

在参数描述中列出 UTIL/OUT: orig_to_copy(Orig2CopyMap c)了从复制中的顶点到原始顶点的映射.我需要这个映射!

(在http://www.boost.org/doc/libs/1_55_0/libs/graph/doc/copy_graph.html上滚动到底部)

如何访问/提供最后一个参数orig_to_copy?你能给出一个代码示例,即为我完成这段代码吗?

void doSomething(graph_t& g){
  graph_t g_copy;
  copy_graph(g, g_copy, [...???...]);
  // here I would like to access the Orig2CopyMap
}
Run Code Online (Sandbox Code Playgroud)

hoo*_*och 5

在这里找到了这个解决方案:http://d.hatena.ne.jp/gununu/20111006/1317880754

void doSomething(graph_t& g){
    typedef graph_t::vertex_descriptor vertex_t;
    typedef std::map<vertex_t, vertex_t> vertex_map_t;
    vertex_map_t vertexMap;
    // this boost type is needed around the map
    associative_property_map<vertex_map_t> vertexMapWrapper(vertexMap);
    graph_t g_copy;
    copy_graph(g, g_copy, boost::orig_to_copy(vertexMapWrapper));
    std::cout << "mapping from copy to original: " << std::endl;
    for(auto& iter : vertexMap){
        std::cout << iter.first << " -> " << iter.second << std::endl;
    }
}
Run Code Online (Sandbox Code Playgroud)