#include <boost/graph/astar_search.hpp>
#include <boost/graph/grid_graph.hpp>
#include <iostream>
#include <vector>
using namespace boost;
typedef grid_graph<2> grid;
typedef graph_traits<grid> traits;
typedef traits::vertex_descriptor vertex_descriptor;
typedef traits::edge_descriptor edge_descriptor;
typedef double edge_weight_type;
struct zero_heuristic:public
boost::astar_heuristic<grid, edge_weight_type> {
edge_weight_type operator()(vertex_descriptor v) {
return 0;
}
};
int main (int argc, char const *argv[]) {
array<size_t, 2> sizes = {{ 3, 2 }};
grid g(sizes);
shared_array_property_map<edge_weight_type,
property_map<grid, edge_index_t>::const_type>
weight(num_edges(g), get(edge_index, g));
std::vector<vertex_descriptor> p(num_vertices(g));
std::vector<edge_weight_type> d(num_vertices(g));
vertex_descriptor start = vertex(0, g);
astar_search(g,
start,
zero_heuristic(),
weight_map(weight).
predecessor_map(&p[0]).distance_map(&d[0]) );
return 0;
}
It now fails to compile because of what looks like a missing put() functions for the distance and predecessor maps. The top of the error spew looks contains a distance map error that looks like this:
g++ -g -I/src/boost-trunk -c -o main.o main.cpp
/src/boost-trunk/boost/graph/astar_search.hpp: In function ‘void boost::astar_search(const VertexListGraph&, typename boost::graph_traits<G>::vertex_descriptor, AStarHeuristic, AStarVisitor, PredecessorMap, CostMap, DistanceMap, WeightMap, VertexIndexMap, ColorMap, CompareFunction, CombineFunction, CostInf, CostZero) [with VertexListGraph = boost::grid_graph<2ul, size_t, size_t>, AStarHeuristic = zero_heuristic, AStarVisitor = boost::astar_visitor<boost::null_visitor>, PredecessorMap = vertex_descriptor*, CostMap = boost::vector_property_map<edge_weight_type, boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, boost::array<size_t, 2ul>, size_t> >, DistanceMap = edge_weight_type*, WeightMap = boost::shared_array_property_map<edge_weight_type, boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, std::pair<boost::array<size_t, 2ul>, boost::array<size_t, 2ul> >, size_t> >, VertexIndexMap = boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, boost::array<size_t, 2ul>, size_t>, ColorMap = boost::vector_property_map<boost::default_color_type, boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, boost::array<size_t, 2ul>, size_t> >, CompareFunction = std::less<edge_weight_type>, CombineFunction = boost::closed_plus<edge_weight_type>, CostInf = double, CostZero = double]’:
/src/boost-trunk/boost/graph/astar_search.hpp:319: instantiated from ‘void boost::detail::astar_dispatch2(const VertexListGraph&, typename boost::graph_traits<G>::vertex_descriptor, AStarHeuristic, CostMap, DistanceMap, WeightMap, IndexMap, ColorMap, const Params&) [with VertexListGraph = boost::grid_graph<2ul, size_t, size_t>, AStarHeuristic = zero_heuristic, CostMap = boost::vector_property_map<edge_weight_type, boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, boost::array<size_t, 2ul>, size_t> >, DistanceMap = edge_weight_type*, WeightMap = boost::shared_array_property_map<edge_weight_type, boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, std::pair<boost::array<size_t, 2ul>, boost::array<size_t, 2ul> >, size_t> >, IndexMap = boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, boost::array<size_t, 2ul>, size_t>, ColorMap = boost::vector_property_map<boost::default_color_type, boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, boost::array<size_t, 2ul>, size_t> >, Params = boost::bgl_named_params<edge_weight_type*, boost::vertex_distance_t, boost::bgl_named_params<vertex_descriptor*, boost::vertex_predecessor_t, boost::bgl_named_params<boost::shared_array_property_map<edge_weight_type, boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, std::pair<boost::array<size_t, 2ul>, boost::array<size_t, 2ul> >, size_t> >, boost::edge_weight_t, boost::no_property> > >]’
/src/boost-trunk/boost/graph/astar_search.hpp:348: instantiated from ‘void boost::detail::astar_dispatch1(const VertexListGraph&, typename boost::graph_traits<G>::vertex_descriptor, AStarHeuristic, CostMap, DistanceMap, WeightMap, IndexMap, ColorMap, const Params&) [with VertexListGraph = boost::grid_graph<2ul, size_t, size_t>, AStarHeuristic = zero_heuristic, CostMap = boost::detail::error_property_not_found, DistanceMap = edge_weight_type*, WeightMap = boost::shared_array_property_map<edge_weight_type, boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, std::pair<boost::array<size_t, 2ul>, boost::array<size_t, 2ul> >, size_t> >, IndexMap = boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, boost::array<size_t, 2ul>, size_t>, ColorMap = boost::detail::error_property_not_found, Params = boost::bgl_named_params<edge_weight_type*, boost::vertex_distance_t, boost::bgl_named_params<vertex_descriptor*, boost::vertex_predecessor_t, boost::bgl_named_params<boost::shared_array_property_map<edge_weight_type, boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, std::pair<boost::array<size_t, 2ul>, boost::array<size_t, 2ul> >, size_t> >, boost::edge_weight_t, boost::no_property> > >]’
/src/boost-trunk/boost/graph/astar_search.hpp:370: instantiated from ‘void boost::astar_search(const VertexListGraph&, typename boost::graph_traits<G>::vertex_descriptor, AStarHeuristic, const boost::bgl_named_params<P, T, R>&) [with VertexListGraph = grid, AStarHeuristic = zero_heuristic, P = edge_weight_type*, T = boost::vertex_distance_t, R = boost::bgl_named_params<vertex_descriptor*, boost::vertex_predecessor_t, boost::bgl_named_params<boost::shared_array_property_map<edge_weight_type, boost::grid_graph_index_map<boost::grid_graph<2ul, size_t, size_t>, std::pair<boost::array<size_t, 2ul>, boost::array<size_t, 2ul> >, size_t> >, boost::edge_weight_t, boost::no_property> >]’
main.cpp:41: instantiated from here
/src/boost-trunk/boost/graph/astar_search.hpp:289: error: no matching function for call to ‘put(edge_weight_type*&, boost::array<size_t, 2ul>, double&)’
...
Further down there's another missing put function for the predecessor map.
...
...
I thought I didn't have to write my own put() functions if I was passing in distance and predecessor map objects external to the graph. Plus, if I did try to write my own put functions, they'd have to be able to look up vertex indexes from vertex descriptors, which means they need access to the graph object in order to call vertex(...), which means I can't use a simple vector.