将图表(adjacency_list)复制到另一个 [英] copy a graph (adjacency_list) to another one

查看:77
本文介绍了将图表(adjacency_list)复制到另一个的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将adjacency_list类型的图复制到adjacency_list类型的另一图?

How can I copy a graph of type adjacency_list to another one graph of type 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();

推荐答案

您是否尝试过很难知道问题出在什么地方而没有看到错误,但是如果我不得不猜测,我首先要确保您提供的是vertex_index映射到copy_graph的地图,因为使用setS用于顶点存储.根据您的先前的问题,您看起来像已经弄清楚了,所以我们只需要把它们放在一起.

Hard to know what the problem is without seeing the errors but if I had to guess, I'd first make sure you're providing a vertex_index map to copy_graph since it's not available by default when you use setS for vertex storage. Based on your earlier question, it looks like you've already got that figured out so we just need to bring it all together.

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

这篇关于将图表(adjacency_list)复制到另一个的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆