dag_longest_paths.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright (C) 2002 Trustees of Indiana University
  2. // Distributed under the Boost Software License, Version 1.0.
  3. // (See accompanying file LICENSE_1_0.txt or copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. #include <boost/graph/adjacency_list.hpp>
  6. #include <boost/graph/dag_shortest_paths.hpp>
  7. #include <boost/property_map/vector_property_map.hpp>
  8. #include <boost/test/minimal.hpp>
  9. using namespace boost;
  10. #include <iostream>
  11. using namespace std;
  12. int test_main(int, char*[])
  13. {
  14. typedef adjacency_list<vecS, vecS, directedS, no_property,
  15. property<edge_weight_t, int> > Graph;
  16. Graph graph;
  17. (void)add_vertex(graph);
  18. (void)add_vertex(graph);
  19. (void)add_vertex(graph);
  20. (void)add_vertex(graph);
  21. Graph::edge_descriptor e;
  22. e = add_edge(0, 1, graph).first;
  23. put(edge_weight, graph, e, 1);
  24. e = add_edge(1, 2, graph).first;
  25. put(edge_weight, graph, e, 1);
  26. e = add_edge(3, 1, graph).first;
  27. put(edge_weight, graph, e, 5);
  28. vector_property_map<int> distance;
  29. dag_shortest_paths(graph, 0,
  30. distance_map(distance)
  31. .distance_compare(std::greater<int>())
  32. .distance_inf((std::numeric_limits<int>::min)())
  33. .distance_zero(0));
  34. cout << distance[2] << "\n";
  35. BOOST_CHECK(distance[2] == 2);
  36. return 0;
  37. }