augment.hpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. {
  14. namespace detail
  15. {
  16. template < class Graph, class ResCapMap >
  17. filtered_graph< const Graph, is_residual_edge< ResCapMap > > residual_graph(
  18. const Graph& g, ResCapMap residual_capacity)
  19. {
  20. return filtered_graph< const Graph, is_residual_edge< ResCapMap > >(
  21. g, is_residual_edge< ResCapMap >(residual_capacity));
  22. }
  23. template < class Graph, class PredEdgeMap, class ResCapMap,
  24. class RevEdgeMap >
  25. inline void augment(const Graph& g,
  26. typename graph_traits< Graph >::vertex_descriptor src,
  27. typename graph_traits< Graph >::vertex_descriptor sink, PredEdgeMap p,
  28. ResCapMap residual_capacity, 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. {
  38. BOOST_USING_STD_MIN();
  39. delta = min BOOST_PREVENT_MACRO_SUBSTITUTION(
  40. delta, get(residual_capacity, e));
  41. u = source(e, g);
  42. e = get(p, u);
  43. } while (u != src);
  44. // push delta units of flow along the augmenting path
  45. e = get(p, sink);
  46. do
  47. {
  48. put(residual_capacity, e, get(residual_capacity, e) - delta);
  49. put(residual_capacity, get(reverse_edge, e),
  50. get(residual_capacity, get(reverse_edge, e)) + delta);
  51. u = source(e, g);
  52. e = get(p, u);
  53. } while (u != src);
  54. }
  55. } // namespace detail
  56. } // namespace boost
  57. #endif /* BOOST_GRAPH_AUGMENT_HPP */