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 <vector>
9 #include <string>
10 #include <iostream>
11 #include <boost/graph/stanford_graph.hpp>
12 #include <boost/graph/topological_sort.hpp>
13
main()14 int main()
15 {
16 using namespace boost;
17 const int n_vertices = 7;
18 Graph* sgb_g = gb_new_graph(n_vertices);
19
20 const char* tasks[]
21 = { "pick up kids from school", "buy groceries (and snacks)",
22 "get cash at ATM", "drop off kids at soccer practice",
23 "cook dinner", "pick up kids from soccer", "eat dinner" };
24 const int n_tasks = sizeof(tasks) / sizeof(char*);
25
26 gb_new_arc(sgb_g->vertices + 0, sgb_g->vertices + 3, 0);
27 gb_new_arc(sgb_g->vertices + 1, sgb_g->vertices + 3, 0);
28 gb_new_arc(sgb_g->vertices + 1, sgb_g->vertices + 4, 0);
29 gb_new_arc(sgb_g->vertices + 2, sgb_g->vertices + 1, 0);
30 gb_new_arc(sgb_g->vertices + 3, sgb_g->vertices + 5, 0);
31 gb_new_arc(sgb_g->vertices + 4, sgb_g->vertices + 6, 0);
32 gb_new_arc(sgb_g->vertices + 5, sgb_g->vertices + 6, 0);
33
34 typedef graph_traits< Graph* >::vertex_descriptor vertex_t;
35 std::vector< vertex_t > topo_order;
36 topological_sort(sgb_g, std::back_inserter(topo_order),
37 vertex_index_map(get(vertex_index, sgb_g)));
38 int n = 1;
39 for (std::vector< vertex_t >::reverse_iterator i = topo_order.rbegin();
40 i != topo_order.rend(); ++i, ++n)
41 std::cout << n << ": " << tasks[get(vertex_index, sgb_g)[*i]]
42 << std::endl;
43
44 gb_recycle(sgb_g);
45 return EXIT_SUCCESS;
46 }
47