加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 为boost :: graph :: copy_graph提供顶点映射参数

发布时间:2020-12-16 09:52:45 所属栏目:百科 来源:网络整理
导读:增强功能 boost::graph::copy_graph template class VertexListGraph,class MutableGraph void copy_graph(const VertexListGraph G,MutableGraph G_copy,const bgl_named_paramsP,T,R params = all defaults) 列表参数说明 UTIL / OUT:orig_to_copy(Orig2C
增强功能 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)

列表参数说明
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
}

解决方法

像这样的东西:

typedef boost::graph_traits<graph_t>::vertex_descriptor vertex_t;
typedef boost::property_map<graph_t,boost::vertex_index_t>::type index_map_t;

//for simple adjacency_list<> this type would be more efficient:
typedef boost::iterator_property_map<typename std::vector<vertex_t>::iterator,index_map_t,vertex_t,vertex_t&> IsoMap;

//maps vertices of g to vertices of g_copy
std::vector<vertex_t> isoValues( num_vertices(g));    
IsoMap mapV( isoValues.begin());

boost::copy_graph( g,boost::orig_to_copy(mapV) ); //means g_copy += g

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读