adjacency_list with VertexList different from vecS

后端 未结 2 1850
再見小時候
再見小時候 2021-01-22 09:30

I have two structs containing some fields: struct MyNodeData, and struct MyEdgeData. When I create a graph with VertexList as vecS, there is no problem to access the descriptor

相关标签:
2条回答
  • 2021-01-22 10:18

    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++);
    }
    
    0 讨论(0)
  • 2021-01-22 10:23

    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.

    0 讨论(0)
提交回复
热议问题