I am currently trying to define external properties of a boost graph. I use some bundled properties as internal ones:
struct VertexProperties
{
int demand;
};
struct EdgeProperties
{
uint capacity;
int cost;
};
typedef adjacency_list <vecS, vecS, bidirectionalS, VertexProperties, EdgeProperties> Graph;
However, during the algorithm I need some external properties, that is I want to be able to map edges/vertices of my graph to elements stored in a std::vector in such a way that I can access them via operator[] (Edge e). I am standing in front of the boost documentation without a clue. It seems like I need a property_map, but I don't know how to use these together with vectors. The only examples that I found so far concern maps from vertices to a vector, but as the vertices are unsigned ints this is trivial.
I am really frustrated by boost so far, I think it would have saved me a lot of time to implement and test a graph class by myself, I really don get this crazy template metaprogramming stuff...
You can create external property maps regardless of what internal and/or bundled properties are in your graph. Creating property maps on edges is somewhat more difficult because you need an
edge_index
map, andadjacency_list
doesn't have those by default;compressed_sparse_row_graph
does but its structure is mostly read-only after construction. You can either useassociative_property_map
on the edges, or create an edge index map as an internal property (if you don't change your graph too often), fill it, then use it to build the external property map (usingshared_array_property_map
, for example).