File: grid_graph_properties.cpp

package info (click to toggle)
boost1.55 1.55.0%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 487,824 kB
  • ctags: 673,349
  • sloc: cpp: 2,098,430; xml: 106,036; ansic: 46,744; python: 32,427; sh: 11,864; cs: 2,121; asm: 1,640; makefile: 984; perl: 714; yacc: 456; php: 132; fortran: 43; sql: 13; csh: 6
file content (40 lines) | stat: -rw-r--r-- 1,380 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
}