find_flow_cost.hpp 1.8 KB

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