augment.hpp 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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_AUGMENT_HPP
  10. #define BOOST_GRAPH_AUGMENT_HPP
  11. #include <boost/graph/filtered_graph.hpp>
  12. namespace boost {
  13. namespace detail {
  14. template <class Graph, class ResCapMap>
  15. filtered_graph<const Graph, is_residual_edge<ResCapMap> >
  16. residual_graph(const Graph& g, ResCapMap residual_capacity) {
  17. return filtered_graph<const Graph, is_residual_edge<ResCapMap> >
  18. (g, is_residual_edge<ResCapMap>(residual_capacity));
  19. }
  20. template <class Graph, class PredEdgeMap, class ResCapMap,
  21. class RevEdgeMap>
  22. inline void
  23. augment(const Graph& g,
  24. typename graph_traits<Graph>::vertex_descriptor src,
  25. typename graph_traits<Graph>::vertex_descriptor sink,
  26. PredEdgeMap p,
  27. ResCapMap residual_capacity,
  28. RevEdgeMap reverse_edge)
  29. {
  30. typename graph_traits<Graph>::edge_descriptor e;
  31. typename graph_traits<Graph>::vertex_descriptor u;
  32. typedef typename property_traits<ResCapMap>::value_type FlowValue;
  33. // find minimum residual capacity along the augmenting path
  34. FlowValue delta = (std::numeric_limits<FlowValue>::max)();
  35. e = get(p, sink);
  36. do {
  37. BOOST_USING_STD_MIN();
  38. delta = min BOOST_PREVENT_MACRO_SUBSTITUTION(delta, get(residual_capacity, e));
  39. u = source(e, g);
  40. e = get(p, u);
  41. } while (u != src);
  42. // push delta units of flow along the augmenting path
  43. e = get(p, sink);
  44. do {
  45. put(residual_capacity, e, get(residual_capacity, e) - delta);
  46. put(residual_capacity, get(reverse_edge, e), get(residual_capacity, get(reverse_edge, e)) + delta);
  47. u = source(e, g);
  48. e = get(p, u);
  49. } while (u != src);
  50. }
  51. } // namespace detail
  52. } //namespace boost
  53. #endif /* BOOST_GRAPH_AUGMENT_HPP */