I've been spending quite a few days working with the boost graph library. As far as I understand, when considering VertexList and EdgeList storage :
vecS :
- possess an index, so can be access with it
- when removing vertices, iterator are invalidated
listS :
- no index
- does not invalidate iterator
It's a bit short but that's to the point for my problem. I need those index number and I want to be able to easily remove vertices later on.
I have a working algorithm with this graph structure :
typedef boost::adjacency_list<
boost::vecS, boost::vecS, boost::undirectedS,
topologicalmap::Intersection_Graph ,
boost::edge_weight_t,
boost::no_property > Graph_boost;
I have a custom structure Intersection_Graph
for my vertices that I need to use. Here I use vecS.
I want to use listS instead to be able to remove vertices. As well, I want to be able to use it later with Dijkstra algorithm.
I kind of understand that I need to have boost::vertex_index_t
in my list but I am really confused as to how to do it and keep my custom struct at the same time.
I tried something along those lines :
typedef boost::adjacency_list<
boost::listS, boost::listS, boost::undirectedS,
boost::property<boost::vertex_index_t, topologicalmap::Intersection_Graph>,
boost::edge_weight_t,
boost::no_property > Graph_boost;
But I can't even access my custom struct anymore. Plus, index access don't work.
I really need that index access capability since the algorithm my graph will depend on return the index of the parent node. I feel like I could get away with using a Vertex instead of indexes but it would imply a major re-writing of the code and I want to know if I can avoid it.
So my question is : is there any way to have listS behaving in a vecS like manner while keeping the advantages of listS ?
Please, bear with me if it sounds stupid. I'm quite confuse at the moment, so I might have say something stupid. If you need more information, just ask.
The interior properties formulation is:
Of course, unless you make
Intersection_Graph
behave like an integral type you cannot use it directly as the type of thevertex_index
property. It's also likely not what you wanted.This looks closer:
And it would declare two properties:
vertex_index_t
(typeint
)Intersection_Graph
). Note that bundled properties are implicitly accessible through thevertex_bundle_t
tag.Now with this in mind, everything should be plain sailing:
Live On Coliru
Which prints e.g. (random generated each run)
Notes:
the fact that the graph "knows"
vertex_index
now doesn't mean it gets maintained; you have to fill it yourself:you don't actually need to have
vertex_index
associated with your graph type, because you can pass it in as a named parameter to all relevant algorithms AFAIK. This includes constructing derived property maps that rely on a vertex_index (e.g.make_iterator_property_map
)Intersection_Graph
struct.vertex_descriptor
s instead of integral indexes.