Reputation: 1042
I am building a graph class based on the following suggestion: Modifying vertex properties in a Boost::Graph
Unfortunately, I realized an unexpected behavior. When using my own vertex-properties (for simplicity please ignore the edge properties), the built-in properties seem not to be used. So for example, when I have:
typedef adjacency_list<
setS, // disallow parallel edges
listS, // vertex container
undirectedS, // undirected graph
property<vertex_properties_t, VERTEXPROPERTIES>,
property<edge_properties_t, EDGEPROPERTIES>
> GraphContainer;
I can retrieve my custom properties without any problem, but when I want to retrieve the vertex_index-property I always get the same value for each vertex, meaning a value of 0. The nodes are distinct, which is confirmed by num_vertices(MyGraph). Then I thought that this might be due to missing the built-in properties, so I tried:
typedef adjacency_list<
setS, // disallow parallel edges
listS, // vertex container
undirectedS, // undirected graph
property<vertex_index_t, unsigned int , property< vertex_properties_t, VERTEXPROPERTIES> >,
property<edge_properties_t, EDGEPROPERTIES>
> GraphContainer;
Again, when wanting to retrieve the index of whatever vertex, I get a value of 0. Is this behavior normal? Does one have to set the built-in properties also, when using custom properties?
Upvotes: 1
Views: 1624
Reputation: 33637
Been a long time since I've used Boost.Graph, but Googling "vertex_index_t", in hit #5 Andrew Sutton says :
Just declaring a vertex index as a property (either bundled or interior, as here) won't buy you any new functionality. It just provides a place where you can assign an index for each vertex or edge. The problem that this half-solves is that nearly every algorithm in the distro requires a vertex index map (or edge index map, more rarely), and providing this will allow the default arguments to automatically extract a property map for vertices/edges.
It won't - or shouldn't??? automatically assign indices. Also, if you remove a vertex or edge, you may have to renumber vertices.
So seems the idea is to standardize the concept across algorithms that want to read the numbers, but you still have to do the writing yourself.
Upvotes: 2