views:

22

answers:

1

Perhaps this is a stupid question, but I'm trying to use BGL's dijkstra_shortest_paths, and, in particular, to use a field of my Edge bundled property as the weightmap. My attempts have currently led to tens of pages of compiler errors, so I'm hoping that someone knows how to help me. This is essentially what my code looks like:

struct GraphEdge {
    float length;
    // other cruft
};
struct GraphVertex {
    ...
};
typedef boost::adjacency_list
<boost::vecS, boost::vecS, boost::directedS,
 GraphVertex, GraphEdge> GraphType;

I can populate the graph without any problems, however when it comes to calling dijkstra_shortest_paths, I get in trouble. I'd like to use the length field. Specifically, I'd like to know what's the bit of needed boost voodoo to go fit in a call like this:

GraphType m_graph;

vector<int> predecessor(num_vertices(m_graph));
vector<float> distances(num_vertices(m_graph), 0.0f);
vector<int> vertex_index_map(num_vertices(m_graph));
for (size_t i=0; i<vertex_index_map.size(); ++i) {
    vertex_index_map[i] = i;
}

dijkstra_shortest_paths(m_graph, vertex_from, predecessor, distances, 
                        weightmap, vertex_index_map, 
                        std::less<float>(), closed_plus<float>(), 
                        (std::numeric_limits<float>::max)(), 0.0f,
                        default_dijkstra_visitor());
// How do I write the right version of weightmap here?

such that weightmap will somehow associate a particular edge of my graph with the corresponding length field in the property. I'm sure there's an easy way to do this, but the documentation for BGL is incredibly opaque to me. If you can tell me where in the documentation the example is described, I'd be very happy as well.

Thank you in advance!

+1  A: 

In case anyone cares about this, using the named parameter version of the call seems to have worked, as follows:

    dijkstra_shortest_paths(m_graph, vertex_from,
                        weight_map(get(&TrafficGraphEdge::length, m_graph))
                        .distance_map(make_iterator_property_map(distances.begin(),
                                                                 get(vertex_index, m_graph))));

This is in the documentation, here. I still don't know how to use the "non-named parameter" version of the call, though.

Carlos Scheidegger