1 | |
---|
2 | #include <boost/graph/adjacency_list.hpp> |
---|
3 | #include <boost/graph/dag_shortest_paths.hpp> |
---|
4 | #include <boost/vector_property_map.hpp> |
---|
5 | #include <boost/test/minimal.hpp> |
---|
6 | |
---|
7 | using namespace boost; |
---|
8 | |
---|
9 | #include <iostream> |
---|
10 | using namespace std; |
---|
11 | |
---|
12 | int test_main(int, char*[]) |
---|
13 | { |
---|
14 | typedef adjacency_list<vecS, vecS, directedS, no_property, |
---|
15 | property<edge_weight_t, int> > Graph; |
---|
16 | |
---|
17 | Graph graph; |
---|
18 | Graph::vertex_descriptor v1, v2, v3, v4; |
---|
19 | |
---|
20 | v1 = add_vertex(graph); |
---|
21 | v2 = add_vertex(graph); |
---|
22 | v3 = add_vertex(graph); |
---|
23 | v4 = add_vertex(graph); |
---|
24 | |
---|
25 | Graph::edge_descriptor e; |
---|
26 | |
---|
27 | e = add_edge(0, 1, graph).first; |
---|
28 | put(edge_weight, graph, e, 1); |
---|
29 | |
---|
30 | e = add_edge(1, 2, graph).first; |
---|
31 | put(edge_weight, graph, e, 1); |
---|
32 | |
---|
33 | e = add_edge(3, 1, graph).first; |
---|
34 | put(edge_weight, graph, e, 5); |
---|
35 | |
---|
36 | vector_property_map<int> distance; |
---|
37 | |
---|
38 | dag_shortest_paths(graph, 0, |
---|
39 | distance_map(distance) |
---|
40 | .distance_compare(std::greater<int>()) |
---|
41 | .distance_inf((std::numeric_limits<int>::min)()) |
---|
42 | .distance_zero(0)); |
---|
43 | |
---|
44 | cout << distance[2] << "\n"; |
---|
45 | |
---|
46 | BOOST_CHECK(distance[2] == 2); |
---|
47 | |
---|
48 | return 0; |
---|
49 | } |
---|
50 | |
---|
51 | |
---|
52 | |
---|