Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r76726 - in trunk/libs/graph: doc example
From: jewillco_at_[hidden]
Date: 2012-01-27 17:06:21


Author: jewillco
Date: 2012-01-27 17:06:21 EST (Fri, 27 Jan 2012)
New Revision: 76726
URL: http://svn.boost.org/trac/boost/changeset/76726

Log:
Added example from David Doria
Added:
   trunk/libs/graph/example/grid_graph_properties.cpp (contents, props changed)
Text files modified:
   trunk/libs/graph/doc/grid_graph.html | 2 +-
   trunk/libs/graph/example/Jamfile.v2 | 2 ++
   2 files changed, 3 insertions(+), 1 deletions(-)

Modified: trunk/libs/graph/doc/grid_graph.html
==============================================================================
--- trunk/libs/graph/doc/grid_graph.html (original)
+++ trunk/libs/graph/doc/grid_graph.html 2012-01-27 17:06:21 EST (Fri, 27 Jan 2012)
@@ -69,7 +69,7 @@
     <p>
       Defined in
       <a href="../../../boost/graph/grid_graph.hpp"><tt>boost/graph/grid_graph.hpp</tt></a>
- with all functions in the <tt>boost</tt> namespace. All examples are available in a single program file in libs/graph/example/grid_graph_example.cpp
+ with all functions in the <tt>boost</tt> namespace. A simple examples of creating and iterating over a grid_graph is available here libs/graph/example/grid_graph_example.cpp. An example of adding properties to a grid_graph is also available libs/graph/example/grid_graph_properties.cpp
     </p>
 
     <h4>Template Parameters</h4>

Modified: trunk/libs/graph/example/Jamfile.v2
==============================================================================
--- trunk/libs/graph/example/Jamfile.v2 (original)
+++ trunk/libs/graph/example/Jamfile.v2 2012-01-27 17:06:21 EST (Fri, 27 Jan 2012)
@@ -20,6 +20,7 @@
 exe bron_kerbosch_clique_number : bron_kerbosch_clique_number.cpp ;
 exe mcgregor_subgraphs_example : mcgregor_subgraphs_example.cpp ;
 exe grid_graph_example : grid_graph_example.cpp ;
+exe grid_graph_properties : grid_graph_properties.cpp ;
 exe bipartite_example : bipartite_example.cpp ;
 exe fr_layout : fr_layout.cpp ;
 exe canonical_ordering : canonical_ordering.cpp ;
@@ -33,3 +34,4 @@
 exe bfs-example : bfs-example.cpp ;
 exe bfs-example2 : bfs-example2.cpp ;
 exe dfs-example : dfs-example.cpp ;
+exe adjacency_list_io : adjacency_list_io.cpp ;

Added: trunk/libs/graph/example/grid_graph_properties.cpp
==============================================================================
--- (empty file)
+++ trunk/libs/graph/example/grid_graph_properties.cpp 2012-01-27 17:06:21 EST (Fri, 27 Jan 2012)
@@ -0,0 +1,40 @@
+//=======================================================================
+// Copyright 2012 David Doria
+// Authors: David Doria
+//
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//=======================================================================
+
+#include <iostream>
+#include <boost/array.hpp>
+#include <boost/graph/grid_graph.hpp>
+
+int main(int argc, char* argv[])
+{
+ // A 2D grid graph
+ typedef boost::grid_graph<2> GraphType;
+
+ // Create a 5x5 graph
+ const unsigned int dimension = 5;
+ boost::array<std::size_t, 2> lengths = { { dimension, dimension } };
+ GraphType graph(lengths);
+
+ // Get the index map of the grid graph
+ typedef boost::property_map<GraphType, boost::vertex_index_t>::const_type indexMapType;
+ indexMapType indexMap(get(boost::vertex_index, graph));
+
+ // Create a float for every node in the graph
+ boost::vector_property_map<float, indexMapType> dataMap(num_vertices(graph), indexMap);
+
+ // Associate the value 2.0 with the node at position (0,1) in the grid
+ boost::graph_traits<GraphType>::vertex_descriptor v = { { 0, 1 } };
+ put(dataMap, v, 2.0f);
+
+ // Get the data at the node at position (0,1) in the grid
+ float retrieved = get(dataMap, v);
+ std::cout << "Retrieved value: " << retrieved << std::endl;
+
+ return 0;
+}


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk