Update contrib.
1 //=======================================================================
2 // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7 //=======================================================================
10 * © Portions copyright (c) 2006-2007 Nokia Corporation. All rights reserved.
14 #include <boost/graph/adjacency_list.hpp>
15 #include <boost/graph/breadth_first_search.hpp>
16 #include <boost/pending/indirect_cmp.hpp>
17 #include <boost/pending/integer_range.hpp>
22 #include "std_log_result.h"
23 #define LOG_FILENAME_LINE __FILE__, __LINE__
26 using namespace boost;
27 template < typename TimeMap > class bfs_time_visitor:public default_bfs_visitor {
28 typedef typename property_traits < TimeMap >::value_type T;
30 bfs_time_visitor(TimeMap tmap, T & t):m_timemap(tmap), m_time(t) { }
31 template < typename Vertex, typename Graph >
32 void discover_vertex(Vertex u, const Graph & g) const
34 put(m_timemap, u, m_time++);
44 using namespace boost;
45 // Select the graph type we wish to use
46 typedef adjacency_list < vecS, vecS, undirectedS > graph_t;
47 // Set up the vertex IDs and names
48 enum { r, s, t, u, v, w, x, y, N };
49 const char *name = "rstuvwxy";
50 // Specify the edges in the graph
51 typedef std::pair < int, int >E;
52 E edge_array[] = { E(r, s), E(r, v), E(s, w), E(w, r), E(w, t),
53 E(w, x), E(x, t), E(t, u), E(x, y), E(u, y)
55 // Create the graph object
56 const int n_edges = sizeof(edge_array) / sizeof(E);
57 #if defined(BOOST_MSVC) && BOOST_MSVC <= 1300
58 // VC++ has trouble with the edge iterator constructor
60 for (std::size_t j = 0; j < n_edges; ++j)
61 add_edge(edge_array[j].first, edge_array[j].second, g);
63 typedef graph_traits<graph_t>::vertices_size_type v_size_t;
64 graph_t g(edge_array, edge_array + n_edges, v_size_t(N));
68 typedef graph_traits < graph_t >::vertex_descriptor Vertex;
69 typedef graph_traits < graph_t >::vertices_size_type Size;
72 // a vector to hold the discover time property for each vertex
73 std::vector < Size > dtime(num_vertices(g));
76 bfs_time_visitor < Size * >vis(&dtime[0], time);
77 breadth_first_search(g, vertex(s, g), visitor(vis));
79 // Use std::sort to order the vertices by their discover time
80 std::vector<graph_traits<graph_t>::vertices_size_type > discover_order(N);
81 integer_range < int >range(0, N);
82 std::copy(range.begin(), range.end(), discover_order.begin());
83 std::sort(discover_order.begin(), discover_order.end(),
84 indirect_cmp < Iiter, std::less < Size > >(&dtime[0]));
86 std::cout << "order of discovery: ";
87 for (int i = 0; i < N; ++i)
88 std::cout << name[discover_order[i]] << " ";
89 std::cout << std::endl;
92 std_log(LOG_FILENAME_LINE,"[End Test Case ]");
93 testResultXml("bfs-example");