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
BOOST_AUTO_TEST_CASE(cycle_canceling_def_test)19 BOOST_AUTO_TEST_CASE(cycle_canceling_def_test)
20 {
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 {
34 boost::SampleGraph::vertex_descriptor s, t;
35 boost::SampleGraph::Graph g;
36 boost::SampleGraph::getSampleGraph2(g, s, t);
37
38 boost::edmonds_karp_max_flow(g, s, t);
39 boost::cycle_canceling(g);
40
41 int cost = boost::find_flow_cost(g);
42 BOOST_CHECK_EQUAL(cost, 7);
43 }
44
BOOST_AUTO_TEST_CASE(cycle_canceling_test)45 BOOST_AUTO_TEST_CASE(cycle_canceling_test)
46 {
47 boost::SampleGraph::vertex_descriptor s, t;
48 typedef boost::SampleGraph::Graph Graph;
49 boost::SampleGraph::Graph g;
50 boost::SampleGraph::getSampleGraph(g, s, t);
51
52 int N = num_vertices(g);
53 std::vector< int > dist(N);
54 typedef boost::graph_traits< Graph >::edge_descriptor edge_descriptor;
55 std::vector< edge_descriptor > pred(N);
56
57 boost::property_map< Graph, boost::vertex_index_t >::const_type idx
58 = get(boost::vertex_index, g);
59
60 boost::edmonds_karp_max_flow(g, s, t);
61 boost::cycle_canceling(g,
62 boost::distance_map(
63 boost::make_iterator_property_map(dist.begin(), idx))
64 .predecessor_map(
65 boost::make_iterator_property_map(pred.begin(), idx))
66 .vertex_index_map(idx));
67
68 int cost = boost::find_flow_cost(g);
69 BOOST_CHECK_EQUAL(cost, 29);
70 }
71