How to access BGL vertex_descriptor as int

I have an adjacency list as shown below. At this point, I need to access the vertex_descriptor as an int type. How can I do this tvertex source = ...; int source_as_int = ???source??? tvertex source = ...; int source_as_int = ???source??? I remember how I came across this issue before and solved it, but I don’t remember how the BGL documentation is useless, using it as a reference, they should try to look at Javadocs and get to know it.

Another possibility is to use a possible member function like vertex_descriptor or some other global BGL function for this purpose ... no one ever knows where to look for it and they seem like a random choice between global functions or member functions, a complete rejection intuitive design if you ask me.

 typedef adjacency_list_traits<setS, setS, bidirectionalS> ttraits; typedef adjacency_list<setS, setS, bidirectionalS, // vertex properties property<vertex_color_t, default_color_type>, // edge properties property<edge_capacity_t, int, property<edge_residual_capacity_t, int, property<edge_reverse_t, ttraits::edge_descriptor> > >, no_property, vecS> tbgl_adjlist_bidir; typedef graph_traits<tbgl_adjlist_bidir>::vertex_descriptor tvertex; typedef graph_traits<tbgl_adjlist_bidir>::edge_descriptor tedge; typedef property_map<tbgl_adjlist_bidir, edge_capacity_t>::type tedge_capacity_map; typedef property_map<tbgl_adjlist_bidir, edge_reverse_t>::type treverse_edge_map; typedef property_map<tbgl_adjlist_bidir, vertex_color_t>::type tvertex_color_map; typedef graph_traits<tbgl_adjlist_bidir>::out_edge_iterator tout_edge_iterator; typedef graph_traits<tbgl_adjlist_bidir>::in_edge_iterator tin_edge_iterator; 
+4
source share
3 answers

OK, I get it. Adding the vertex property vertex_index_t solves the problem. Then I can access the int index of this vertex as follows:

 typedef adjacency_list_traits<setS, vecS, bidirectionalS> ttraits; typedef adjacency_list<setS, vecS, bidirectionalS, // vertex properties property<vertex_index_t, int, property<vertex_color_t, default_color_type> >, // edge properties property<edge_capacity_t, int, property<edge_residual_capacity_t, int, property<edge_reverse_t, ttraits::edge_descriptor> > >, no_property, vecS> tbgl_adjlist_bidir; typedef graph_traits<tbgl_adjlist_bidir>::vertex_descriptor tvertex; typedef graph_traits<tbgl_adjlist_bidir>::edge_descriptor tedge; typedef property_map<tbgl_adjlist_bidir, edge_capacity_t>::type tedge_capacity_map; typedef property_map<tbgl_adjlist_bidir, edge_reverse_t>::type treverse_edge_map; typedef property_map<tbgl_adjlist_bidir, vertex_color_t>::type tvertex_color_map; typedef property_map<tbgl_adjlist_bidir, vertex_index_t>::type tvertex_index_map; typedef graph_traits<tbgl_adjlist_bidir>::vertex_iterator tvertex_iterator; typedef graph_traits<tbgl_adjlist_bidir>::edge_iterator tedge_iterator; typedef graph_traits<tbgl_adjlist_bidir>::out_edge_iterator tout_edge_iterator; typedef graph_traits<tbgl_adjlist_bidir>::in_edge_iterator tin_edge_iterator; 

then I use it as follows:

  tbgl_adjlist_bidir bgl_adjlist_bidir; // ... tvertex_index_map indices = get(vertex_index, bgl_adjlist_bidir); // ... tvertex source; // ... int source_as_int = indices[source]; 
+4
source

The type of a vertex_descriptor depends on the basic structure of the VertexListS -template adjacency_list . The only case I know about where the descriptor is is int when the VertexList type is vecS . But keep in mind: if you choose vecS , since your VertexList-Type descriptors all (saved) can become invalid when you change the structure of your graph (as described in the Iterator and stability / invalidity descriptor ).

+1
source

Can I interest you in using custom vertices and border types? They are much easier to work with in your own code. As for invoking BGL algorithms, you can use Related Properties .

+1
source

All Articles