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 #ifndef BOOST_GRAPH_FIND_FLOW_COST_HPP
10 #define BOOST_GRAPH_FIND_FLOW_COST_HPP
11 
12 #include <boost/graph/iteration_macros.hpp>
13 
14 namespace boost
15 {
16 
17 template < class Graph, class Capacity, class ResidualCapacity, class Weight >
find_flow_cost(const Graph & g,Capacity capacity,ResidualCapacity residual_capacity,Weight weight)18 typename property_traits< Weight >::value_type find_flow_cost(const Graph& g,
19     Capacity capacity, ResidualCapacity residual_capacity, Weight weight)
20 {
21     typedef typename property_traits< Weight >::value_type Cost;
22 
23     Cost cost = 0;
24     BGL_FORALL_EDGES_T(e, g, Graph)
25     {
26         if (get(capacity, e) > Cost(0))
27         {
28             cost += (get(capacity, e) - get(residual_capacity, e))
29                 * get(weight, e);
30         }
31     }
32     return cost;
33 }
34 
35 template < class Graph, class P, class T, class R >
find_flow_cost(const Graph & g,const bgl_named_params<P,T,R> & params)36 typename detail::edge_weight_value< Graph, P, T, R >::type find_flow_cost(
37     const Graph& g, const bgl_named_params< P, T, R >& params)
38 {
39     return find_flow_cost(g,
40         choose_const_pmap(get_param(params, edge_capacity), g, edge_capacity),
41         choose_const_pmap(get_param(params, edge_residual_capacity), g,
42             edge_residual_capacity),
43         choose_const_pmap(get_param(params, edge_weight), g, edge_weight));
44 }
45 
46 template < class Graph >
47 typename property_traits<
48     typename property_map< Graph, edge_capacity_t >::type >::value_type
find_flow_cost(const Graph & g)49 find_flow_cost(const Graph& g)
50 {
51     bgl_named_params< int, buffer_param_t > params(0);
52     return find_flow_cost(g, params);
53 }
54 
55 } // boost
56 
57 #endif /* BOOST_GRAPH_FIND_FLOW_COST_HPP */
58