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