copy a graph (adjacency_list) to another one

风格不统一 提交于 2019-12-04 08:23:17
Andrew Durward

Have you tried copy_graph?


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();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!