Boost logo

Boost Users :

Subject: Re: [Boost-users] Default weight map doesn't work for weighted grid graph in A-star search
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2010-07-06 18:35:04


On Tue, 6 Jul 2010, W.P. McNeill wrote:

> I checked out the Boost trunk from http://svn.boost.org/svn/boost/trunk and rebuilt the program below using those headers.  It builds and runs.  From now on
> unless I say otherwise, everything I do uses this version of Boost.
> Next I tried to add distance and predecessor maps for the output.  Following the astar-cities.cpp example, I implemented these as vectors.  The program now looks
> like this:
>
>
> #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:

You need to use iterator_property_map, not just a raw pointer, as your
property map (for distance and predecessor maps). You can also use more
shared_array_property_maps instead.

-- Jeremiah Willcock


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net