Ticket #5737: grid_graph_example.cpp

File grid_graph_example.cpp, 1.1 KB (added by Lau Yang Hao <lauyh@…>, 11 years ago)
Line 
1//=======================================================================
2// Copyright 2009 Trustees of Indiana University.
3// Authors: Michael Hansen, Andrew Lumsdaine
4//
5// Distributed under the Boost Software License, Version 1.0. (See
6// accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt)
8//=======================================================================
9
10#include <iostream>
11#include <boost/array.hpp>
12#include <boost/graph/grid_graph.hpp>
13
14#define DIMENSIONS 1
15using namespace boost;
16
17typedef grid_graph<DIMENSIONS> Graph;
18typedef graph_traits<Graph> Traits;
19
20// Define a simple function to print vertices
21void print_vertex(Traits::vertex_descriptor vertex_to_print) {
22 std::cout << "(" << vertex_to_print[0] << ")" << std::endl;
23}
24
25int main(int argc, char* argv[]) {
26
27 // Define a grid_graph
28 boost::array<std::size_t, 1> lengths = { { 1 } };
29 Graph graph(lengths, true);
30
31 // Start with the first vertex in the graph
32 Traits::vertex_descriptor first_vertex = vertex(0, graph);
33
34 // Print the previous vertex in dimension 0 (wraps)
35 print_vertex(graph.previous(first_vertex, 0)); // prints "(1)"
36}