1 //=======================================================================
2 // Copyright 2001 Jeremy G. Siek, Andrew Lumsdaine, Lie-Quan Lee,
3 //
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 //=======================================================================
8 #include <boost/config.hpp>
9 #include <vector>
10 #include <deque>
11 #include <iostream>
12 #include <boost/graph/topological_sort.hpp>
13 #include <boost/graph/adjacency_list.hpp>
main()14 int main()
15 {
16 using namespace boost;
17 const char* tasks[]
18 = { "pick up kids from school", "buy groceries (and snacks)",
19 "get cash at ATM", "drop off kids at soccer practice",
20 "cook dinner", "pick up kids from soccer", "eat dinner" };
21 const int n_tasks = sizeof(tasks) / sizeof(char*);
22
23 adjacency_list< listS, vecS, directedS > g(n_tasks);
24
25 add_edge(0, 3, g);
26 add_edge(1, 3, g);
27 add_edge(1, 4, g);
28 add_edge(2, 1, g);
29 add_edge(3, 5, g);
30 add_edge(4, 6, g);
31 add_edge(5, 6, g);
32
33 std::deque< int > topo_order;
34
35 topological_sort(g, std::front_inserter(topo_order),
36 vertex_index_map(identity_property_map()));
37
38 int n = 1;
39 for (std::deque< int >::iterator i = topo_order.begin();
40 i != topo_order.end(); ++i, ++n)
41 std::cout << tasks[*i] << std::endl;
42
43 return EXIT_SUCCESS;
44 }
45