|
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