1// Copyright (C) 2002 Trustees of Indiana University
2
3// Distributed under the Boost Software License, Version 1.0.
4// (See accompanying file LICENSE_1_0.txt or copy at
5// http://www.boost.org/LICENSE_1_0.txt)
6
7#include <boost/graph/adjacency_list.hpp>
8#include <boost/graph/dag_shortest_paths.hpp>
9#include <boost/property_map/vector_property_map.hpp>
10#include <boost/core/lightweight_test.hpp>
11
12using namespace boost;
13
14#include <iostream>
15using namespace std;
16
17int main(int, char*[])
18{
19 typedef adjacency_list< vecS, vecS, directedS, no_property,
20 property< edge_weight_t, int > >
21 Graph;
22
23 Graph graph;
24
25 (void)add_vertex(g_&: graph);
26 (void)add_vertex(g_&: graph);
27 (void)add_vertex(g_&: graph);
28 (void)add_vertex(g_&: graph);
29
30 Graph::edge_descriptor e;
31
32 e = add_edge(u: 0, v: 1, g_&: graph).first;
33 put(p: edge_weight, g&: graph, key: e, value: 1);
34
35 e = add_edge(u: 1, v: 2, g_&: graph).first;
36 put(p: edge_weight, g&: graph, key: e, value: 1);
37
38 e = add_edge(u: 3, v: 1, g_&: graph).first;
39 put(p: edge_weight, g&: graph, key: e, value: 5);
40
41 vector_property_map< int > distance;
42
43 dag_shortest_paths(g: graph, s: 0,
44 params: distance_map(p: distance)
45 .distance_compare(p: std::greater< int >())
46 .distance_inf(p: (std::numeric_limits< int >::min)())
47 .distance_zero(p: 0));
48
49 cout << distance[2] << "\n";
50
51 BOOST_TEST(distance[2] == 2);
52
53 return boost::report_errors();
54}
55

source code of boost/libs/graph/test/dag_longest_paths.cpp