zoo
zoo

Reputation: 1911

Boost Graph Library - weight property from external vector

What am I doing wrong?

#include <vector>

#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/dijkstra_shortest_paths.hpp>

using namespace std;

typedef boost::adjacency_list<> Graph;

void dijkstra(Graph &g, vector<double> &edge_weights, int source, vector<double> &dist,   vector<int> &prev) {
boost::dijkstra_shortest_paths(g, source,
                                 boost::weight_map(boost::make_iterator_property_map(edge_weights.begin(), get(boost::edge_index, g))));

}

(Compile with: g++ main.cc -L/usr/local/boost/)

Error:

/usr/include/boost/graph/detail/adjacency_list.hpp:2665: error: invalid initialization of non-const reference of type ‘boost::detail::error_property_not_found&’ from a temporary of type ‘boost::detail::error_property_not_found’

I think the problem might be that there's no default mapping from edges to integers. If so, how do I define one?

Upvotes: 0

Views: 869

Answers (1)

Jeremiah Willcock
Jeremiah Willcock

Reputation: 30999

Your graph does not have an edge_index property, which you are using in your creation of the iterator_property_map. You will need to add such a property to your graph and fill it in. See Boost Graph Library: Bundled Properties and iterating across edges and edge_index zero for all edges? for what needs to be done.

Upvotes: 2

Related Questions