views:

115

answers:

1

Hi,

I am building a graph class based on the following suggestion: http://stackoverflow.com/questions/671714/modifying-vertex-properties-in-a-boostgraph

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?

+1  A: 

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.

Hostile Fork
Thank you. Sometimes I overlook the most trivial but useful search terms.On top of this, I discovered the following default behavior, thanks to the answer of Vladimir Prus in http://comments.gmane.org/gmane.comp.lib.boost.user/5794 and permalink: http://permalink.gmane.org/gmane.comp.lib.boost.user/5797Basically, when using vecS as storage for the vertices, the vertex_index - property is automatically active and the values are automatically set too.
Shadow