Boost logo

Boost Users :

Subject: [Boost-users] [BGL] Confusion about iterator_property_map and initialization of OffsetMap
From: Cedric Laczny (cedric.laczny_at_[hidden])
Date: 2011-04-01 04:03:26


I have modified the astar-cities.cpp example to use an external rank_map based
on iterator_property_map.
The following should give you an idea:

  vector<cost> v_vec(num_vertices(g), 0.0);

  typedef property_map< mygraph_t, vertex_index_t>::type VertexIndexMap;
  VertexIndexMap v_index = get(vertex_index, g); // Initialization of interest
  // Create the external property map
  typedef iterator_property_map< std::vector< cost >::iterator, VertexIndexMap
> CostMap;
  CostMap c_map(v_vec.begin(), v_index);

and the function-call of astar_search is as follows:

      (g, start,
       distance_heuristic<mygraph_t, cost, location*, const char**>
        (locations, goal, name),
       rank_map(c_map)); // Here we use the "global" cost map

Basically, the code is the same as in the example, with only the addition of
the explicit rank_map.

Now I am fairly confused that the function call seems to behave the same if I
have "get(vertex_index, g)" and if I don't have it.
This comes unexpected to me as I would think that it needs OffsetMap (v_index)
to correctly find the index in the random access container (v_vec). But when I
simply declare an object it is not yet initialized and will not contain any
meaningfull offsets (not using "get(vertex_index, g)").
So why does it work, when the map is not initialized? Or what am I missing
here please?



Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at