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 
10 #define BOOST_TEST_MODULE cycle_canceling_test
11 
12 #include <boost/test/unit_test.hpp>
13 
14 #include <boost/graph/cycle_canceling.hpp>
15 #include <boost/graph/edmonds_karp_max_flow.hpp>
16 
17 #include "min_cost_max_flow_utils.hpp"
18 
19 
BOOST_AUTO_TEST_CASE(cycle_canceling_def_test)20 BOOST_AUTO_TEST_CASE(cycle_canceling_def_test) {
21     boost::SampleGraph::vertex_descriptor s,t;
22     boost::SampleGraph::Graph g;
23     boost::SampleGraph::getSampleGraph(g, s, t);
24 
25     boost::edmonds_karp_max_flow(g, s, t);
26     boost::cycle_canceling(g);
27 
28     int cost = boost::find_flow_cost(g);
29     BOOST_CHECK_EQUAL(cost, 29);
30 }
31 
BOOST_AUTO_TEST_CASE(path_augmentation_def_test2)32 BOOST_AUTO_TEST_CASE(path_augmentation_def_test2) {
33     boost::SampleGraph::vertex_descriptor s,t;
34     boost::SampleGraph::Graph g;
35     boost::SampleGraph::getSampleGraph2(g, s, t);
36 
37     boost::edmonds_karp_max_flow(g, s, t);
38     boost::cycle_canceling(g);
39 
40     int cost =  boost::find_flow_cost(g);
41     BOOST_CHECK_EQUAL(cost, 7);
42 }
43 
BOOST_AUTO_TEST_CASE(cycle_canceling_test)44 BOOST_AUTO_TEST_CASE(cycle_canceling_test) {
45     boost::SampleGraph::vertex_descriptor s,t;
46     typedef boost::SampleGraph::Graph Graph;
47     boost::SampleGraph::Graph g;
48     boost::SampleGraph::getSampleGraph(g, s, t);
49 
50     int N = num_vertices(g);
51     std::vector<int> dist(N);
52     typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor;
53     std::vector<edge_descriptor> pred(N);
54 
55     boost::property_map<Graph, boost::vertex_index_t>::const_type idx = get(boost::vertex_index, g);
56 
57     boost::edmonds_karp_max_flow(g, s, t);
58     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));
59 
60     int cost = boost::find_flow_cost(g);
61     BOOST_CHECK_EQUAL(cost, 29);
62 }
63 
64