Imported Upstream version 1.57.0
[platform/upstream/boost.git] / boost / graph / find_flow_cost.hpp
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 template<class Graph, class Capacity, class ResidualCapacity, class Weight>
17 typename property_traits<typename property_map < Graph, edge_capacity_t >::type>::value_type
18 find_flow_cost(const Graph & g, Capacity capacity, ResidualCapacity residual_capacity, Weight weight) {
19     typedef typename property_traits<typename property_map<Graph, edge_weight_t>::const_type>::value_type Cost;
20
21     Cost cost = 0;
22     BGL_FORALL_EDGES_T(e, g, Graph) {
23         if(get(capacity, e) > Cost(0)) {
24             cost +=  (get(capacity, e) - get(residual_capacity, e)) * get(weight, e);
25         } 
26     }
27     return cost;
28 }
29
30 template <class Graph, class P, class T, class R> 
31 typename property_traits<typename property_map < Graph, edge_capacity_t >::type>::value_type
32 find_flow_cost(const Graph & g,
33                const bgl_named_params<P, T, R>& params) {
34     return find_flow_cost(g,
35            choose_const_pmap(get_param(params, edge_capacity), g, edge_capacity),
36            choose_const_pmap(get_param(params, edge_residual_capacity), 
37                        g, edge_residual_capacity),
38            choose_const_pmap(get_param(params, edge_weight), g, edge_weight));
39 }
40
41 template <class Graph>
42 typename property_traits<typename property_map < Graph, edge_capacity_t >::type>::value_type
43 find_flow_cost(const Graph &g) {
44     bgl_named_params<int, buffer_param_t> params(0);
45     return find_flow_cost(g, params);
46 }
47
48
49 } //boost
50
51 #endif /* BOOST_GRAPH_FIND_FLOW_COST_HPP */
52