将图(adjacency_list)复制到另一个图
如何将 adjacency_list 类型的图复制到 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();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您尝试过 copy_graph 吗?
在没有看到错误的情况下很难知道问题是什么,但如果我不得不猜测,我首先确保您提供了到
copy_graph
的vertex_index
映射,因为它不是当您使用setS
进行顶点存储时,默认情况下可用。根据您的之前的问题,您看起来像我们已经弄清楚了这一点,所以我们只需要将它们整合在一起即可。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 tocopy_graph
since it's not available by default when you usesetS
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.