adjacency_list with VertexList different from vecS

强颜欢笑 提交于 2019-12-01 23:38:01

Currently, you just need to provide an associative property map.

<...>
typedef Graph::vertex_descriptor NodeID;

typedef map<NodeID, size_t> IndexMap;
IndexMap mapIndex;
associative_property_map<IndexMap> propmapIndex(mapIndex);
<...>

// indexing all vertices
int i=0;
BGL_FORALL_VERTICES(v, g, Graph)
{
   put(propmapIndex, v, i++);
}

But I usually need to add/delete edges and vertices from my graph.

Removing vertices and edges is possible with vecS, setS and listS. Just call remove_vertex\remove_edge with the vertex\edge descriptor. In all above containers, removing \ adding a vertex \ edge will invalidate the iterator. This means that after you had modified the graph, you'll have to call vertices(g) again. In most containers, modifying the container invalidates iterators to it. In listS, adding a vertex may not invalidate the iterator, but this is implementation specific and should not be relied on.

You could add a vertex_id property to the graph, thus allowing you to get access to the vertex descriptors whenever.

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