I managed to create my graph using the following bundled properties for vertices and edges:
struct vertexproperties
{
// index
int id;
// shortest distance to all other nodes
std::vector<float> dist_to;
// shortest distance from all other nodes
std::vector<float> dist_from;
// constructors (note: empty version is necessary for graph)
vertexproperties (int id) : id(id) {}
vertexproperties () : id() {}
};
and
struct edgeproperties
{
// weight
float weight;
// resources
std::vector<float> res;
// constructors (note: empty version is necessary for graph)
edgeproperties (float weight, int n_res) : weight(weight), res(n_res, 0) {}
edgeproperties () : weight(0.0), res() {}
};
and I've managed to create my graph satisfactorily using
typedef adjacency_list<listS, vecS, directedS, vertexproperties, edgeproperties> graph_t;
However, I have two questions: One regarding how to use the vector values as property maps when solving for shortest paths, for example with Dijkstra; and the other regarding the apparent necessity to use empty constructors in the vertexproperties
and edgeproperties
:
When, inspired by boost bundled properties documentation I try to use
dijkstra_shortest_paths(g, s, weight_map(get(&edgeproperties::res, g)));
to solve, I get errors of the form
test.cpp:180:41: error: invalid use of non-static data member ‘edgeproperties::res’
, which don't surprise me as I've just passed a vector, and not just a scalar.As I have no real idea to do this, I tried to remedy this using
get(&edgeproperties::res[0], g)
andget(&edgeproperties::res, g)[0]
and both don't work.The first question is how to do this?
It looks like it is necessary to provide the constructors
vertexproperties () : id() {}
andedgeproperties () : weight(0.0), res() {}
, which actually don't really make sense, as well as the non-empty ones.I hesitate to add them because they should never be used: id can only be 0 for one of the vertices, and has to be different for the others.
Therefore, I would like to know whether it is really necessary to provide these empty constructors and/or whether I'm doing something wrong there.