Iterating over vertices in a specific region in a graph

If I manually create a grid graph in BGL (using adjacency_list, not grid_graph), is there a way to iterate over vertices in a specified rectangular region? Say I make a 100x100 grid graph, how would I iterate over the the center 5x5 vertices? Thanks, David

On Sun, 22 Jan 2012, David Doria wrote:
If I manually create a grid graph in BGL (using adjacency_list, not grid_graph), is there a way to iterate over vertices in a specified rectangular region? Say I make a 100x100 grid graph, how would I iterate over the the center 5x5 vertices?
You would need to do that by hand; note that there is a function to convert from coordinates to graph vertices. -- Jeremiah Willcock

You would need to do that by hand; note that there is a function to convert from coordinates to graph vertices.
-- Jeremiah Willcock
Hi Jeremiah, You mean there is something more "built in" than this: ? #include "boost/graph/adjacency_list.hpp" #include "boost/graph/simple_point.hpp" namespace boost { enum vertex_coordinate_t { vertex_coordinate }; BOOST_INSTALL_PROPERTY(vertex, coordinate); }; int main(int argc, char *argv[]) { typedef boost::simple_point<float> PointType; typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::property< boost::vertex_coordinate_t, PointType > > Graph; Graph g; typedef typename boost::property_map<Graph, boost::vertex_coordinate_t>::type CoordinatePropertyMap; CoordinatePropertyMap coordinatePropertyMap = get(boost::vertex_coordinate, g); return 0; } (i.e. can you point me to the function you are talking about : ) ?) Also, the reason I am not using boost::grid_graph is that there are "holes" in my graph - i.e. not every integer coordinate has a vertex. Does the coordinate-to-vertex_descriptor function you are talking about handle the case when a vertex doesn't exist at the specified coordinate? Thanks, David

On Sun, 22 Jan 2012, David Doria wrote:
You would need to do that by hand; note that there is a function to convert from coordinates to graph vertices.
-- Jeremiah Willcock
Hi Jeremiah,
You mean there is something more "built in" than this: ?
#include "boost/graph/adjacency_list.hpp" #include "boost/graph/simple_point.hpp"
namespace boost { enum vertex_coordinate_t { vertex_coordinate }; BOOST_INSTALL_PROPERTY(vertex, coordinate); };
int main(int argc, char *argv[]) { typedef boost::simple_point<float> PointType;
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, boost::property< boost::vertex_coordinate_t, PointType > > Graph; Graph g;
typedef typename boost::property_map<Graph, boost::vertex_coordinate_t>::type CoordinatePropertyMap; CoordinatePropertyMap coordinatePropertyMap = get(boost::vertex_coordinate, g);
return 0; }
(i.e. can you point me to the function you are talking about : ) ?)
You can just make a boost::array with the coordinates and call that a vertex descriptor; that equivalence is used often enough that it probably needs to stay stable.
Also, the reason I am not using boost::grid_graph is that there are "holes" in my graph - i.e. not every integer coordinate has a vertex. Does the coordinate-to-vertex_descriptor function you are talking about handle the case when a vertex doesn't exist at the specified coordinate?
If you use a filtered_graph on top of the grid_graph, the trick I mentioned above will work, but you'd want to check the filter condition on the coordinates before using them in the filtered_graph. -- Jeremiah Willcock

If you use a filtered_graph on top of the grid_graph, the trick I mentioned above will work, but you'd want to check the filter condition on the coordinates before using them in the filtered_graph.
Thanks, I didn't know about filtered_graph. The example here http://www.boost.org/doc/libs/1_48_0/libs/graph/doc/filtered_graph.html shows how to filter edges - I made this example to show how to filter vertices by their vertex_descriptor: http://programmingexamples.net/wiki/CPP/Boost/BGL/FilteredGraph David
participants (2)
-
David Doria
-
Jeremiah Willcock