find_flow_cost.hpp 1.8 KB

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