cycle_canceling_test.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //=======================================================================
  2. // Copyright 2013 University of Warsaw.
  3. // Authors: Piotr Wygocki
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. //=======================================================================
  9. #define BOOST_TEST_MODULE cycle_canceling_test
  10. #include <boost/test/unit_test.hpp>
  11. #include <boost/graph/cycle_canceling.hpp>
  12. #include <boost/graph/edmonds_karp_max_flow.hpp>
  13. #include "min_cost_max_flow_utils.hpp"
  14. BOOST_AUTO_TEST_CASE(cycle_canceling_def_test) {
  15. boost::SampleGraph::vertex_descriptor s,t;
  16. boost::SampleGraph::Graph g;
  17. boost::SampleGraph::getSampleGraph(g, s, t);
  18. boost::edmonds_karp_max_flow(g, s, t);
  19. boost::cycle_canceling(g);
  20. int cost = boost::find_flow_cost(g);
  21. BOOST_CHECK_EQUAL(cost, 29);
  22. }
  23. BOOST_AUTO_TEST_CASE(path_augmentation_def_test2) {
  24. boost::SampleGraph::vertex_descriptor s,t;
  25. boost::SampleGraph::Graph g;
  26. boost::SampleGraph::getSampleGraph2(g, s, t);
  27. boost::edmonds_karp_max_flow(g, s, t);
  28. boost::cycle_canceling(g);
  29. int cost = boost::find_flow_cost(g);
  30. BOOST_CHECK_EQUAL(cost, 7);
  31. }
  32. BOOST_AUTO_TEST_CASE(cycle_canceling_test) {
  33. boost::SampleGraph::vertex_descriptor s,t;
  34. typedef boost::SampleGraph::Graph Graph;
  35. boost::SampleGraph::Graph g;
  36. boost::SampleGraph::getSampleGraph(g, s, t);
  37. int N = num_vertices(g);
  38. std::vector<int> dist(N);
  39. typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor;
  40. std::vector<edge_descriptor> pred(N);
  41. boost::property_map<Graph, boost::vertex_index_t>::const_type idx = get(boost::vertex_index, g);
  42. boost::edmonds_karp_max_flow(g, s, t);
  43. boost::cycle_canceling(g, boost::distance_map(boost::make_iterator_property_map(dist.begin(), idx)).predecessor_map(boost::make_iterator_property_map(pred.begin(), idx)).vertex_index_map(idx));
  44. int cost = boost::find_flow_cost(g);
  45. BOOST_CHECK_EQUAL(cost, 29);
  46. }