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 <deque> // to store the vertex ordering
9 #include <vector>
10 #include <list>
11 #include <iostream>
12 #include <boost/graph/vector_as_graph.hpp>
13 #include <boost/graph/topological_sort.hpp>
14
main()15 int main()
16 {
17 using namespace boost;
18 const char* tasks[]
19 = { "pick up kids from school", "buy groceries (and snacks)",
20 "get cash at ATM", "drop off kids at soccer practice",
21 "cook dinner", "pick up kids from soccer", "eat dinner" };
22 const int n_tasks = sizeof(tasks) / sizeof(char*);
23
24 std::vector< std::list< int > > g(n_tasks);
25 g[0].push_back(3);
26 g[1].push_back(3);
27 g[1].push_back(4);
28 g[2].push_back(1);
29 g[3].push_back(5);
30 g[4].push_back(6);
31 g[5].push_back(6);
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