Boost logo

Boost Users :

Subject: Re: [Boost-users] grid_graph vertex properties
From: Jeremiah Willcock (jewillco_at_[hidden])
Date: 2012-01-23 14:53:19


On Mon, 23 Jan 2012, David Doria wrote:

>> Yes, that is correct.  Both vertex and edge index maps exist, though, so it
>> is easy to use external properties for both of those (unlike edge properties
>> for adjacency_list).
>
> Hm, I've been playing with this for a while now and I don't seem to
> understand how to add something to the vertex index map.
>
> This compiles, but I think it is creating a new map:
>
> #include <iostream>
> #include <boost/array.hpp>
> #include <boost/graph/grid_graph.hpp>
>
> int main(int argc, char* argv[])
> {
> typedef boost::grid_graph<2> GraphType;
>
> const unsigned int dimension = 5;
> boost::array<std::size_t, 2> lengths = { { dimension, dimension } };
> GraphType graph(lengths);
>
> boost::graph_traits<GraphType>::vertex_descriptor v = { { 0, 1 } };
>
> std::vector<float> vertexData(dimension * dimension, 0);
>
> boost::grid_graph_index_map<GraphType,
> boost::graph_traits<GraphType>::vertex_descriptor, float>
> myMap(graph);

This should just be (something like):

typedef boost::property_map<GraphType, boost::vertex_index_t>::const_type
indexMapType;

indexMapType indexMap(get(boost::vertex_index, graph));

boost::iterator_property_map<std::vector<float>::iterator, indexMapType>
myMap(vertexData.begin(), indexMap);

// grid_graph_index_map is internal

> float retrieved = get(myMap, v);
> std::cout << "Retrieved: " << retrieved << std::endl;
>
> }
>
> Could you demonstrate how to do this? We should really add this to the
> grid_graph documentation :)

-- 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