Discussion:
grid_graph vertex properties
David Doria
2012-01-23 15:20:24 UTC
Permalink
Since there is no VertexProperties template parameter on grid_graph,
is it correct that you cannot use interior properties, but must use
exterior properties?

Thanks,

David
Jeremiah Willcock
2012-01-23 16:12:09 UTC
Permalink
Post by David Doria
Since there is no VertexProperties template parameter on grid_graph,
is it correct that you cannot use interior properties, but must use
exterior properties?
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).

-- Jeremiah Willcock
David Doria
2012-01-23 17:22:28 UTC
Permalink
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);

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

Thanks,

David
Jeremiah Willcock
2012-01-23 19:53:19 UTC
Permalink
Post by David Doria
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.
#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
Post by David Doria
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
David Doria
2012-01-23 20:04:06 UTC
Permalink
Post by Jeremiah Willcock
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
Thanks, that seems to do it.

For posterity:
http://programmingexamples.net/wiki/CPP/Boost/BGL/GridGraphProperties

David
Jeremiah Willcock
2012-01-23 20:11:08 UTC
Permalink
Post by David Doria
Post by Jeremiah Willcock
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
Thanks, that seems to do it.
http://programmingexamples.net/wiki/CPP/Boost/BGL/GridGraphProperties
For future reference, that is the approach to build external property maps
for all types of graphs, not just grid graphs.

-- Jeremiah Willcock

Loading...