| 
alpar@726
 | 
     1  | 
// -*- C++ -*-
  | 
| 
alpar@726
 | 
     2  | 
#ifndef HUGO_MAX_FLOW_NO_STACK_H
  | 
| 
alpar@726
 | 
     3  | 
#define HUGO_MAX_FLOW_NO_STACK_H
  | 
| 
alpar@726
 | 
     4  | 
  | 
| 
alpar@726
 | 
     5  | 
#include <vector>
  | 
| 
alpar@726
 | 
     6  | 
#include <queue>
  | 
| 
alpar@726
 | 
     7  | 
//#include <stack>
  | 
| 
alpar@726
 | 
     8  | 
  | 
| 
alpar@726
 | 
     9  | 
#include <hugo/graph_wrapper.h>
  | 
| 
alpar@726
 | 
    10  | 
#include <hugo/invalid.h>
  | 
| 
alpar@726
 | 
    11  | 
#include <hugo/maps.h>
  | 
| 
alpar@726
 | 
    12  | 
  | 
| 
alpar@726
 | 
    13  | 
/// \file
  | 
| 
alpar@726
 | 
    14  | 
/// \brief The same as max_flow.h, but without using stl stack for the active nodes. Only for test.
  | 
| 
alpar@726
 | 
    15  | 
/// \ingroup galgs
  | 
| 
alpar@726
 | 
    16  | 
  | 
| 
alpar@726
 | 
    17  | 
namespace hugo {
 | 
| 
alpar@726
 | 
    18  | 
  | 
| 
alpar@726
 | 
    19  | 
  /// \addtogroup galgs
  | 
| 
alpar@726
 | 
    20  | 
  /// @{                                                                                                                                        
 | 
| 
alpar@726
 | 
    21  | 
  ///Maximum flow algorithms class.
  | 
| 
alpar@726
 | 
    22  | 
  | 
| 
alpar@726
 | 
    23  | 
  ///This class provides various algorithms for finding a flow of
  | 
| 
alpar@726
 | 
    24  | 
  ///maximum value in a directed graph. The \e source node, the \e
  | 
| 
alpar@726
 | 
    25  | 
  ///target node, the \e capacity of the edges and the \e starting \e
  | 
| 
alpar@726
 | 
    26  | 
  ///flow value of the edges should be passed to the algorithm through the
  | 
| 
alpar@726
 | 
    27  | 
  ///constructor. It is possible to change these quantities using the
  | 
| 
alpar@726
 | 
    28  | 
  ///functions \ref resetSource, \ref resetTarget, \ref resetCap and
  | 
| 
alpar@726
 | 
    29  | 
  ///\ref resetFlow. Before any subsequent runs of any algorithm of
  | 
| 
alpar@726
 | 
    30  | 
  ///the class \ref resetFlow should be called. 
  | 
| 
alpar@726
 | 
    31  | 
  | 
| 
alpar@726
 | 
    32  | 
  ///After running an algorithm of the class, the actual flow value 
  | 
| 
alpar@726
 | 
    33  | 
  ///can be obtained by calling \ref flowValue(). The minimum
  | 
| 
alpar@726
 | 
    34  | 
  ///value cut can be written into a \c node map of \c bools by
  | 
| 
alpar@726
 | 
    35  | 
  ///calling \ref minCut. (\ref minMinCut and \ref maxMinCut writes
  | 
| 
alpar@726
 | 
    36  | 
  ///the inclusionwise minimum and maximum of the minimum value
  | 
| 
alpar@726
 | 
    37  | 
  ///cuts, resp.)                                                                                                                               
  | 
| 
alpar@726
 | 
    38  | 
  ///\param Graph The directed graph type the algorithm runs on.
  | 
| 
alpar@726
 | 
    39  | 
  ///\param Num The number type of the capacities and the flow values.
  | 
| 
alpar@726
 | 
    40  | 
  ///\param CapMap The capacity map type.
  | 
| 
alpar@726
 | 
    41  | 
  ///\param FlowMap The flow map type.                                                                                                           
  | 
| 
alpar@726
 | 
    42  | 
  ///\author Marton Makai, Jacint Szabo 
  | 
| 
alpar@726
 | 
    43  | 
  template <typename Graph, typename Num,
  | 
| 
alpar@726
 | 
    44  | 
	    typename CapMap=typename Graph::template EdgeMap<Num>,
  | 
| 
alpar@726
 | 
    45  | 
            typename FlowMap=typename Graph::template EdgeMap<Num> >
  | 
| 
alpar@726
 | 
    46  | 
  class MaxFlow {
 | 
| 
alpar@726
 | 
    47  | 
  protected:
  | 
| 
alpar@726
 | 
    48  | 
    typedef typename Graph::Node Node;
  | 
| 
alpar@726
 | 
    49  | 
    typedef typename Graph::NodeIt NodeIt;
  | 
| 
alpar@726
 | 
    50  | 
    typedef typename Graph::EdgeIt EdgeIt;
  | 
| 
alpar@726
 | 
    51  | 
    typedef typename Graph::OutEdgeIt OutEdgeIt;
  | 
| 
alpar@726
 | 
    52  | 
    typedef typename Graph::InEdgeIt InEdgeIt;
  | 
| 
alpar@726
 | 
    53  | 
  | 
| 
alpar@726
 | 
    54  | 
    //    typedef typename std::vector<std::stack<Node> > VecStack;
  | 
| 
alpar@726
 | 
    55  | 
    typedef typename std::vector<Node> VecFirst;
  | 
| 
alpar@726
 | 
    56  | 
    typedef typename Graph::template NodeMap<Node> NNMap;
  | 
| 
alpar@726
 | 
    57  | 
    typedef typename std::vector<Node> VecNode;
  | 
| 
alpar@726
 | 
    58  | 
  | 
| 
alpar@726
 | 
    59  | 
    const Graph* g;
  | 
| 
alpar@726
 | 
    60  | 
    Node s;
  | 
| 
alpar@726
 | 
    61  | 
    Node t;
  | 
| 
alpar@726
 | 
    62  | 
    const CapMap* capacity;
  | 
| 
alpar@726
 | 
    63  | 
    FlowMap* flow;
  | 
| 
alpar@726
 | 
    64  | 
    int n;      //the number of nodes of G
  | 
| 
alpar@726
 | 
    65  | 
    typedef ResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW;   
  | 
| 
alpar@726
 | 
    66  | 
    //typedef ExpResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW;
  | 
| 
alpar@726
 | 
    67  | 
    typedef typename ResGW::OutEdgeIt ResGWOutEdgeIt;
  | 
| 
alpar@726
 | 
    68  | 
    typedef typename ResGW::Edge ResGWEdge;
  | 
| 
alpar@726
 | 
    69  | 
    //typedef typename ResGW::template NodeMap<bool> ReachedMap;
  | 
| 
alpar@726
 | 
    70  | 
    typedef typename Graph::template NodeMap<int> ReachedMap;
  | 
| 
alpar@726
 | 
    71  | 
  | 
| 
alpar@726
 | 
    72  | 
  | 
| 
alpar@726
 | 
    73  | 
    //level works as a bool map in augmenting path algorithms and is
  | 
| 
alpar@726
 | 
    74  | 
    //used by bfs for storing reached information.  In preflow, it
  | 
| 
alpar@726
 | 
    75  | 
    //shows the levels of nodes.     
  | 
| 
alpar@726
 | 
    76  | 
    ReachedMap level;
  | 
| 
alpar@726
 | 
    77  | 
  | 
| 
alpar@726
 | 
    78  | 
    //excess is needed only in preflow
  | 
| 
alpar@726
 | 
    79  | 
    typename Graph::template NodeMap<Num> excess;
  | 
| 
alpar@726
 | 
    80  | 
  | 
| 
alpar@726
 | 
    81  | 
    // constants used for heuristics
  | 
| 
alpar@726
 | 
    82  | 
    static const int H0=20;
  | 
| 
alpar@726
 | 
    83  | 
    static const int H1=1;
  | 
| 
alpar@726
 | 
    84  | 
  | 
| 
alpar@726
 | 
    85  | 
  public:
  | 
| 
alpar@726
 | 
    86  | 
  | 
| 
alpar@726
 | 
    87  | 
    ///Indicates the property of the starting flow.
  | 
| 
alpar@726
 | 
    88  | 
  | 
| 
alpar@726
 | 
    89  | 
    ///Indicates the property of the starting flow. The meanings are as follows:
  | 
| 
alpar@726
 | 
    90  | 
    ///- \c ZERO_FLOW: constant zero flow
  | 
| 
alpar@726
 | 
    91  | 
    ///- \c GEN_FLOW: any flow, i.e. the sum of the in-flows equals to
  | 
| 
alpar@726
 | 
    92  | 
    ///the sum of the out-flows in every node except the \e source and
  | 
| 
alpar@726
 | 
    93  | 
    ///the \e target.
  | 
| 
alpar@726
 | 
    94  | 
    ///- \c PRE_FLOW: any preflow, i.e. the sum of the in-flows is at 
  | 
| 
alpar@726
 | 
    95  | 
    ///least the sum of the out-flows in every node except the \e source.
  | 
| 
alpar@726
 | 
    96  | 
    ///- \c NO_FLOW: indicates an unspecified edge map. \ref flow will be 
  | 
| 
alpar@726
 | 
    97  | 
    ///set to the constant zero flow in the beginning of the algorithm in this case.
  | 
| 
alpar@726
 | 
    98  | 
    enum FlowEnum{
 | 
| 
alpar@726
 | 
    99  | 
      ZERO_FLOW,
  | 
| 
alpar@726
 | 
   100  | 
      GEN_FLOW,
  | 
| 
alpar@726
 | 
   101  | 
      PRE_FLOW,
  | 
| 
alpar@726
 | 
   102  | 
      NO_FLOW
  | 
| 
alpar@726
 | 
   103  | 
    };
  | 
| 
alpar@726
 | 
   104  | 
  | 
| 
alpar@726
 | 
   105  | 
    enum StatusEnum {
 | 
| 
alpar@726
 | 
   106  | 
      AFTER_NOTHING,
  | 
| 
alpar@726
 | 
   107  | 
      AFTER_AUGMENTING,
  | 
| 
alpar@726
 | 
   108  | 
      AFTER_FAST_AUGMENTING, 
  | 
| 
alpar@726
 | 
   109  | 
      AFTER_PRE_FLOW_PHASE_1,      
  | 
| 
alpar@726
 | 
   110  | 
      AFTER_PRE_FLOW_PHASE_2
  | 
| 
alpar@726
 | 
   111  | 
    };
  | 
| 
alpar@726
 | 
   112  | 
  | 
| 
alpar@726
 | 
   113  | 
    /// Don not needle this flag only if necessary.
  | 
| 
alpar@726
 | 
   114  | 
    StatusEnum status;
  | 
| 
alpar@726
 | 
   115  | 
  | 
| 
alpar@726
 | 
   116  | 
//     int number_of_augmentations;
  | 
| 
alpar@726
 | 
   117  | 
  | 
| 
alpar@726
 | 
   118  | 
  | 
| 
alpar@726
 | 
   119  | 
//     template<typename IntMap>
  | 
| 
alpar@726
 | 
   120  | 
//     class TrickyReachedMap {
 | 
| 
alpar@726
 | 
   121  | 
//     protected:
  | 
| 
alpar@726
 | 
   122  | 
//       IntMap* map;
  | 
| 
alpar@726
 | 
   123  | 
//       int* number_of_augmentations;
  | 
| 
alpar@726
 | 
   124  | 
//     public:
  | 
| 
alpar@726
 | 
   125  | 
//       TrickyReachedMap(IntMap& _map, int& _number_of_augmentations) : 
  | 
| 
alpar@726
 | 
   126  | 
// 	map(&_map), number_of_augmentations(&_number_of_augmentations) { }
 | 
| 
alpar@726
 | 
   127  | 
//       void set(const Node& n, bool b) {
 | 
| 
alpar@726
 | 
   128  | 
// 	if (b)
  | 
| 
alpar@726
 | 
   129  | 
// 	  map->set(n, *number_of_augmentations);
  | 
| 
alpar@726
 | 
   130  | 
// 	else 
  | 
| 
alpar@726
 | 
   131  | 
// 	  map->set(n, *number_of_augmentations-1);
  | 
| 
alpar@726
 | 
   132  | 
//       }
  | 
| 
alpar@726
 | 
   133  | 
//       bool operator[](const Node& n) const { 
 | 
| 
alpar@726
 | 
   134  | 
// 	return (*map)[n]==*number_of_augmentations; 
  | 
| 
alpar@726
 | 
   135  | 
//       }
  | 
| 
alpar@726
 | 
   136  | 
//     };
  | 
| 
alpar@726
 | 
   137  | 
    
  | 
| 
alpar@726
 | 
   138  | 
    ///Constructor
  | 
| 
alpar@726
 | 
   139  | 
  | 
| 
alpar@726
 | 
   140  | 
    ///\todo Document, please.
  | 
| 
alpar@726
 | 
   141  | 
    ///
  | 
| 
alpar@726
 | 
   142  | 
    MaxFlow(const Graph& _G, Node _s, Node _t,
  | 
| 
marci@745
 | 
   143  | 
	    const CapMap& _capacity, FlowMap& _flow) :
  | 
| 
alpar@726
 | 
   144  | 
      g(&_G), s(_s), t(_t), capacity(&_capacity),
  | 
| 
alpar@726
 | 
   145  | 
      flow(&_flow), n(_G.nodeNum()), level(_G), excess(_G,0), 
  | 
| 
alpar@726
 | 
   146  | 
      status(AFTER_NOTHING) { }
 | 
| 
alpar@726
 | 
   147  | 
  | 
| 
alpar@726
 | 
   148  | 
    ///Runs a maximum flow algorithm.
  | 
| 
alpar@726
 | 
   149  | 
  | 
| 
alpar@726
 | 
   150  | 
    ///Runs a preflow algorithm, which is the fastest maximum flow
  | 
| 
alpar@726
 | 
   151  | 
    ///algorithm up-to-date. The default for \c fe is ZERO_FLOW.
  | 
| 
alpar@726
 | 
   152  | 
    ///\pre The starting flow must be
  | 
| 
alpar@726
 | 
   153  | 
    /// - a constant zero flow if \c fe is \c ZERO_FLOW,
  | 
| 
alpar@726
 | 
   154  | 
    /// - an arbitary flow if \c fe is \c GEN_FLOW,
  | 
| 
alpar@726
 | 
   155  | 
    /// - an arbitary preflow if \c fe is \c PRE_FLOW,
  | 
| 
alpar@726
 | 
   156  | 
    /// - any map if \c fe is NO_FLOW.
  | 
| 
alpar@726
 | 
   157  | 
    void run(FlowEnum fe=ZERO_FLOW) {
 | 
| 
alpar@726
 | 
   158  | 
      preflow(fe);
  | 
| 
alpar@726
 | 
   159  | 
    }
  | 
| 
alpar@726
 | 
   160  | 
  | 
| 
alpar@726
 | 
   161  | 
                                                                              
  | 
| 
alpar@726
 | 
   162  | 
    ///Runs a preflow algorithm.  
  | 
| 
alpar@726
 | 
   163  | 
  | 
| 
alpar@726
 | 
   164  | 
    ///Runs a preflow algorithm. The preflow algorithms provide the
  | 
| 
alpar@726
 | 
   165  | 
    ///fastest way to compute a maximum flow in a directed graph.
  | 
| 
alpar@726
 | 
   166  | 
    ///\pre The starting flow must be
  | 
| 
alpar@726
 | 
   167  | 
    /// - a constant zero flow if \c fe is \c ZERO_FLOW,
  | 
| 
alpar@726
 | 
   168  | 
    /// - an arbitary flow if \c fe is \c GEN_FLOW,
  | 
| 
alpar@726
 | 
   169  | 
    /// - an arbitary preflow if \c fe is \c PRE_FLOW,
  | 
| 
alpar@726
 | 
   170  | 
    /// - any map if \c fe is NO_FLOW.
  | 
| 
alpar@726
 | 
   171  | 
    ///
  | 
| 
alpar@726
 | 
   172  | 
    ///\todo NO_FLOW should be the default flow.
  | 
| 
alpar@726
 | 
   173  | 
    void preflow(FlowEnum fe) {
 | 
| 
alpar@726
 | 
   174  | 
      preflowPhase1(fe);
  | 
| 
alpar@726
 | 
   175  | 
      preflowPhase2();
  | 
| 
alpar@726
 | 
   176  | 
    }
  | 
| 
alpar@726
 | 
   177  | 
    // Heuristics:
  | 
| 
alpar@726
 | 
   178  | 
    //   2 phase
  | 
| 
alpar@726
 | 
   179  | 
    //   gap
  | 
| 
alpar@726
 | 
   180  | 
    //   list 'level_list' on the nodes on level i implemented by hand
  | 
| 
alpar@726
 | 
   181  | 
    //   stack 'active' on the active nodes on level i                                                                                    
  | 
| 
alpar@726
 | 
   182  | 
    //   runs heuristic 'highest label' for H1*n relabels
  | 
| 
alpar@726
 | 
   183  | 
    //   runs heuristic 'bound decrease' for H0*n relabels, starts with 'highest label'
  | 
| 
alpar@726
 | 
   184  | 
    //   Parameters H0 and H1 are initialized to 20 and 1.
  | 
| 
alpar@726
 | 
   185  | 
  | 
| 
alpar@726
 | 
   186  | 
    ///Runs the first phase of the preflow algorithm.
  | 
| 
alpar@726
 | 
   187  | 
  | 
| 
alpar@726
 | 
   188  | 
    ///The preflow algorithm consists of two phases, this method runs the
  | 
| 
alpar@726
 | 
   189  | 
    ///first phase. After the first phase the maximum flow value and a
  | 
| 
alpar@726
 | 
   190  | 
    ///minimum value cut can already be computed, though a maximum flow
  | 
| 
alpar@726
 | 
   191  | 
    ///is net yet obtained. So after calling this method \ref flowValue
  | 
| 
alpar@726
 | 
   192  | 
    ///and \ref actMinCut gives proper results.
  | 
| 
alpar@726
 | 
   193  | 
    ///\warning: \ref minCut, \ref minMinCut and \ref maxMinCut do not
  | 
| 
alpar@726
 | 
   194  | 
    ///give minimum value cuts unless calling \ref preflowPhase2.
  | 
| 
alpar@726
 | 
   195  | 
    ///\pre The starting flow must be
  | 
| 
alpar@726
 | 
   196  | 
    /// - a constant zero flow if \c fe is \c ZERO_FLOW,
  | 
| 
alpar@726
 | 
   197  | 
    /// - an arbitary flow if \c fe is \c GEN_FLOW,
  | 
| 
alpar@726
 | 
   198  | 
    /// - an arbitary preflow if \c fe is \c PRE_FLOW,
  | 
| 
alpar@726
 | 
   199  | 
    /// - any map if \c fe is NO_FLOW.
  | 
| 
alpar@726
 | 
   200  | 
    void preflowPhase1(FlowEnum fe)
  | 
| 
alpar@726
 | 
   201  | 
    {
 | 
| 
alpar@726
 | 
   202  | 
  | 
| 
alpar@726
 | 
   203  | 
      int heur0=(int)(H0*n);  //time while running 'bound decrease'
  | 
| 
alpar@726
 | 
   204  | 
      int heur1=(int)(H1*n);  //time while running 'highest label'
  | 
| 
alpar@726
 | 
   205  | 
      int heur=heur1;         //starting time interval (#of relabels)
  | 
| 
alpar@726
 | 
   206  | 
      int numrelabel=0;
  | 
| 
alpar@726
 | 
   207  | 
  | 
| 
alpar@726
 | 
   208  | 
      bool what_heur=1;
  | 
| 
alpar@726
 | 
   209  | 
      //It is 0 in case 'bound decrease' and 1 in case 'highest label'
  | 
| 
alpar@726
 | 
   210  | 
  | 
| 
alpar@726
 | 
   211  | 
      bool end=false;
  | 
| 
alpar@726
 | 
   212  | 
      //Needed for 'bound decrease', true means no active nodes are above bound
  | 
| 
alpar@726
 | 
   213  | 
      //b.
  | 
| 
alpar@726
 | 
   214  | 
  | 
| 
alpar@726
 | 
   215  | 
      int k=n-2;  //bound on the highest level under n containing a node
  | 
| 
alpar@726
 | 
   216  | 
      int b=k;    //bound on the highest level under n of an active node
  | 
| 
alpar@726
 | 
   217  | 
  | 
| 
alpar@726
 | 
   218  | 
      VecFirst first(n, INVALID);
  | 
| 
alpar@726
 | 
   219  | 
      NNMap next(*g, INVALID); //maybe INVALID is not needed
  | 
| 
alpar@726
 | 
   220  | 
  | 
| 
alpar@726
 | 
   221  | 
      NNMap left(*g, INVALID);
  | 
| 
alpar@726
 | 
   222  | 
      NNMap right(*g, INVALID);
  | 
| 
alpar@726
 | 
   223  | 
      VecNode level_list(n,INVALID);
  | 
| 
alpar@726
 | 
   224  | 
      //List of the nodes in level i<n, set to n.
  | 
| 
alpar@726
 | 
   225  | 
  | 
| 
alpar@726
 | 
   226  | 
      NodeIt v;
  | 
| 
alpar@726
 | 
   227  | 
      for(g->first(v); g->valid(v); g->next(v)) level.set(v,n);
  | 
| 
alpar@726
 | 
   228  | 
      //setting each node to level n
  | 
| 
alpar@726
 | 
   229  | 
  | 
| 
alpar@726
 | 
   230  | 
      if ( fe == NO_FLOW ) {
 | 
| 
alpar@726
 | 
   231  | 
	EdgeIt e;
  | 
| 
alpar@726
 | 
   232  | 
	for(g->first(e); g->valid(e); g->next(e)) flow->set(e,0);
  | 
| 
alpar@726
 | 
   233  | 
      }
  | 
| 
alpar@726
 | 
   234  | 
  | 
| 
alpar@726
 | 
   235  | 
      switch (fe) { //computing the excess
 | 
| 
alpar@726
 | 
   236  | 
      case PRE_FLOW:
  | 
| 
alpar@726
 | 
   237  | 
	{
 | 
| 
alpar@726
 | 
   238  | 
	  NodeIt v;
  | 
| 
alpar@726
 | 
   239  | 
	  for(g->first(v); g->valid(v); g->next(v)) {
 | 
| 
alpar@726
 | 
   240  | 
	    Num exc=0;
  | 
| 
alpar@726
 | 
   241  | 
  | 
| 
alpar@726
 | 
   242  | 
	    InEdgeIt e;
  | 
| 
alpar@726
 | 
   243  | 
	    for(g->first(e,v); g->valid(e); g->next(e)) exc+=(*flow)[e];
  | 
| 
alpar@726
 | 
   244  | 
	    OutEdgeIt f;
  | 
| 
alpar@726
 | 
   245  | 
	    for(g->first(f,v); g->valid(f); g->next(f)) exc-=(*flow)[f];
  | 
| 
alpar@726
 | 
   246  | 
  | 
| 
alpar@726
 | 
   247  | 
	    excess.set(v,exc);
  | 
| 
alpar@726
 | 
   248  | 
  | 
| 
alpar@726
 | 
   249  | 
	    //putting the active nodes into the stack
  | 
| 
alpar@726
 | 
   250  | 
	    int lev=level[v];
  | 
| 
alpar@726
 | 
   251  | 
	    if ( exc > 0 && lev < n && v != t ) 
  | 
| 
alpar@726
 | 
   252  | 
	      {
 | 
| 
alpar@726
 | 
   253  | 
		next.set(v,first[lev]);
  | 
| 
alpar@726
 | 
   254  | 
		first[lev]=v;
  | 
| 
alpar@726
 | 
   255  | 
	      }
  | 
| 
alpar@726
 | 
   256  | 
	  }
  | 
| 
alpar@726
 | 
   257  | 
	  break;
  | 
| 
alpar@726
 | 
   258  | 
	}
  | 
| 
alpar@726
 | 
   259  | 
      case GEN_FLOW:
  | 
| 
alpar@726
 | 
   260  | 
	{
 | 
| 
alpar@726
 | 
   261  | 
	  NodeIt v;
  | 
| 
alpar@726
 | 
   262  | 
	  for(g->first(v); g->valid(v); g->next(v)) excess.set(v,0);
  | 
| 
alpar@726
 | 
   263  | 
  | 
| 
alpar@726
 | 
   264  | 
	  Num exc=0;
  | 
| 
alpar@726
 | 
   265  | 
	  InEdgeIt e;
  | 
| 
alpar@726
 | 
   266  | 
	  for(g->first(e,t); g->valid(e); g->next(e)) exc+=(*flow)[e];
  | 
| 
alpar@726
 | 
   267  | 
	  OutEdgeIt f;
  | 
| 
alpar@726
 | 
   268  | 
	  for(g->first(f,t); g->valid(f); g->next(f)) exc-=(*flow)[f];
  | 
| 
alpar@726
 | 
   269  | 
	  excess.set(t,exc);
  | 
| 
alpar@726
 | 
   270  | 
	  break;
  | 
| 
alpar@726
 | 
   271  | 
	}
  | 
| 
alpar@726
 | 
   272  | 
      case ZERO_FLOW:
  | 
| 
alpar@726
 | 
   273  | 
      case NO_FLOW:
  | 
| 
alpar@726
 | 
   274  | 
	{
 | 
| 
alpar@726
 | 
   275  | 
	  NodeIt v;
  | 
| 
alpar@726
 | 
   276  | 
	  for(g->first(v); g->valid(v); g->next(v)) excess.set(v,0);
  | 
| 
alpar@726
 | 
   277  | 
	  break;
  | 
| 
alpar@726
 | 
   278  | 
	}
  | 
| 
alpar@726
 | 
   279  | 
      }
  | 
| 
alpar@726
 | 
   280  | 
  | 
| 
marci@745
 | 
   281  | 
      preflowPreproc(fe, next, first, level_list, left, right);
  | 
| 
alpar@726
 | 
   282  | 
      //End of preprocessing
  | 
| 
alpar@726
 | 
   283  | 
  | 
| 
alpar@726
 | 
   284  | 
  | 
| 
alpar@726
 | 
   285  | 
      //Push/relabel on the highest level active nodes.
  | 
| 
alpar@726
 | 
   286  | 
      while ( true ) {
 | 
| 
alpar@726
 | 
   287  | 
	if ( b == 0 ) {
 | 
| 
alpar@726
 | 
   288  | 
	  if ( !what_heur && !end && k > 0 ) {
 | 
| 
alpar@726
 | 
   289  | 
	    b=k;
  | 
| 
alpar@726
 | 
   290  | 
	    end=true;
  | 
| 
alpar@726
 | 
   291  | 
	  } else break;
  | 
| 
alpar@726
 | 
   292  | 
	}
  | 
| 
alpar@726
 | 
   293  | 
  | 
| 
marci@745
 | 
   294  | 
	if ( !g->valid(first[b]) ) --b;
  | 
| 
alpar@726
 | 
   295  | 
	else {
 | 
| 
alpar@726
 | 
   296  | 
	  end=false;
  | 
| 
alpar@726
 | 
   297  | 
	  Node w=first[b];
  | 
| 
alpar@726
 | 
   298  | 
	  first[b]=next[w];
  | 
| 
marci@745
 | 
   299  | 
	  int newlevel=push(w, next, first);
  | 
| 
marci@745
 | 
   300  | 
	  if ( excess[w] > 0 ) relabel(w, newlevel, next, first, level_list,
  | 
| 
alpar@726
 | 
   301  | 
				       left, right, b, k, what_heur);
  | 
| 
alpar@726
 | 
   302  | 
  | 
| 
alpar@726
 | 
   303  | 
	  ++numrelabel;
  | 
| 
alpar@726
 | 
   304  | 
	  if ( numrelabel >= heur ) {
 | 
| 
alpar@726
 | 
   305  | 
	    numrelabel=0;
  | 
| 
alpar@726
 | 
   306  | 
	    if ( what_heur ) {
 | 
| 
alpar@726
 | 
   307  | 
	      what_heur=0;
  | 
| 
alpar@726
 | 
   308  | 
	      heur=heur0;
  | 
| 
alpar@726
 | 
   309  | 
	      end=false;
  | 
| 
alpar@726
 | 
   310  | 
	    } else {
 | 
| 
alpar@726
 | 
   311  | 
	      what_heur=1;
  | 
| 
alpar@726
 | 
   312  | 
	      heur=heur1;
  | 
| 
alpar@726
 | 
   313  | 
	      b=k;
  | 
| 
alpar@726
 | 
   314  | 
	    }
  | 
| 
alpar@726
 | 
   315  | 
	  }
  | 
| 
alpar@726
 | 
   316  | 
	}
  | 
| 
alpar@726
 | 
   317  | 
      }
  | 
| 
alpar@726
 | 
   318  | 
  | 
| 
alpar@726
 | 
   319  | 
      status=AFTER_PRE_FLOW_PHASE_1;
  | 
| 
alpar@726
 | 
   320  | 
    }
  | 
| 
alpar@726
 | 
   321  | 
  | 
| 
alpar@726
 | 
   322  | 
  | 
| 
alpar@726
 | 
   323  | 
    ///Runs the second phase of the preflow algorithm.
  | 
| 
alpar@726
 | 
   324  | 
  | 
| 
alpar@726
 | 
   325  | 
    ///The preflow algorithm consists of two phases, this method runs
  | 
| 
alpar@726
 | 
   326  | 
    ///the second phase. After calling \ref preflowPhase1 and then
  | 
| 
alpar@726
 | 
   327  | 
    ///\ref preflowPhase2 the methods \ref flowValue, \ref minCut,
  | 
| 
alpar@726
 | 
   328  | 
    ///\ref minMinCut and \ref maxMinCut give proper results.
  | 
| 
alpar@726
 | 
   329  | 
    ///\pre \ref preflowPhase1 must be called before.
  | 
| 
alpar@726
 | 
   330  | 
    void preflowPhase2()
  | 
| 
alpar@726
 | 
   331  | 
    {
 | 
| 
alpar@726
 | 
   332  | 
  | 
| 
alpar@726
 | 
   333  | 
      int k=n-2;  //bound on the highest level under n containing a node
  | 
| 
alpar@726
 | 
   334  | 
      int b=k;    //bound on the highest level under n of an active node
  | 
| 
alpar@726
 | 
   335  | 
  | 
| 
alpar@726
 | 
   336  | 
    
  | 
| 
alpar@726
 | 
   337  | 
      VecFirst first(n, INVALID);
  | 
| 
alpar@726
 | 
   338  | 
      NNMap next(*g, INVALID); //maybe INVALID is not needed
  | 
| 
alpar@726
 | 
   339  | 
      level.set(s,0);
  | 
| 
alpar@726
 | 
   340  | 
      std::queue<Node> bfs_queue;
  | 
| 
alpar@726
 | 
   341  | 
      bfs_queue.push(s);
  | 
| 
alpar@726
 | 
   342  | 
  | 
| 
alpar@726
 | 
   343  | 
      while (!bfs_queue.empty()) {
 | 
| 
alpar@726
 | 
   344  | 
  | 
| 
alpar@726
 | 
   345  | 
	Node v=bfs_queue.front();
  | 
| 
alpar@726
 | 
   346  | 
	bfs_queue.pop();
  | 
| 
alpar@726
 | 
   347  | 
	int l=level[v]+1;
  | 
| 
alpar@726
 | 
   348  | 
  | 
| 
alpar@726
 | 
   349  | 
	InEdgeIt e;
  | 
| 
alpar@726
 | 
   350  | 
	for(g->first(e,v); g->valid(e); g->next(e)) {
 | 
| 
alpar@726
 | 
   351  | 
	  if ( (*capacity)[e] <= (*flow)[e] ) continue;
  | 
| 
alpar@726
 | 
   352  | 
	  Node u=g->tail(e);
  | 
| 
alpar@726
 | 
   353  | 
	  if ( level[u] >= n ) {
 | 
| 
alpar@726
 | 
   354  | 
	    bfs_queue.push(u);
  | 
| 
alpar@726
 | 
   355  | 
	    level.set(u, l);
  | 
| 
alpar@726
 | 
   356  | 
	    if ( excess[u] > 0 ) {
 | 
| 
alpar@726
 | 
   357  | 
	      next.set(u,first[l]);
  | 
| 
alpar@726
 | 
   358  | 
	      first[l]=u;
  | 
| 
alpar@726
 | 
   359  | 
	    }
  | 
| 
alpar@726
 | 
   360  | 
	  }
  | 
| 
alpar@726
 | 
   361  | 
	}
  | 
| 
alpar@726
 | 
   362  | 
  | 
| 
alpar@726
 | 
   363  | 
	OutEdgeIt f;
  | 
| 
alpar@726
 | 
   364  | 
	for(g->first(f,v); g->valid(f); g->next(f)) {
 | 
| 
alpar@726
 | 
   365  | 
	  if ( 0 >= (*flow)[f] ) continue;
  | 
| 
alpar@726
 | 
   366  | 
	  Node u=g->head(f);
  | 
| 
alpar@726
 | 
   367  | 
	  if ( level[u] >= n ) {
 | 
| 
alpar@726
 | 
   368  | 
	    bfs_queue.push(u);
  | 
| 
alpar@726
 | 
   369  | 
	    level.set(u, l);
  | 
| 
alpar@726
 | 
   370  | 
	    if ( excess[u] > 0 ) {
 | 
| 
alpar@726
 | 
   371  | 
	      next.set(u,first[l]);
  | 
| 
alpar@726
 | 
   372  | 
	      first[l]=u;
  | 
| 
alpar@726
 | 
   373  | 
	    }
  | 
| 
alpar@726
 | 
   374  | 
	  }
  | 
| 
alpar@726
 | 
   375  | 
	}
  | 
| 
alpar@726
 | 
   376  | 
      }
  | 
| 
alpar@726
 | 
   377  | 
      b=n-2;
  | 
| 
alpar@726
 | 
   378  | 
  | 
| 
alpar@726
 | 
   379  | 
      while ( true ) {
 | 
| 
alpar@726
 | 
   380  | 
  | 
| 
alpar@726
 | 
   381  | 
	if ( b == 0 ) break;
  | 
| 
alpar@726
 | 
   382  | 
  | 
| 
marci@745
 | 
   383  | 
	if ( !g->valid(first[b]) ) --b;
  | 
| 
alpar@726
 | 
   384  | 
	else {
 | 
| 
alpar@726
 | 
   385  | 
  | 
| 
alpar@726
 | 
   386  | 
	  Node w=first[b];
  | 
| 
alpar@726
 | 
   387  | 
	  first[b]=next[w];
  | 
| 
alpar@726
 | 
   388  | 
	  int newlevel=push(w,next, first/*active*/);
  | 
| 
alpar@726
 | 
   389  | 
  | 
| 
alpar@726
 | 
   390  | 
	  //relabel
  | 
| 
alpar@726
 | 
   391  | 
	  if ( excess[w] > 0 ) {
 | 
| 
alpar@726
 | 
   392  | 
	    level.set(w,++newlevel);
  | 
| 
alpar@726
 | 
   393  | 
	    next.set(w,first[newlevel]);
  | 
| 
alpar@726
 | 
   394  | 
	    first[newlevel]=w;
  | 
| 
alpar@726
 | 
   395  | 
	    b=newlevel;
  | 
| 
alpar@726
 | 
   396  | 
	  }
  | 
| 
alpar@726
 | 
   397  | 
	}  // if stack[b] is nonempty
  | 
| 
alpar@726
 | 
   398  | 
      } // while(true)
  | 
| 
alpar@726
 | 
   399  | 
  | 
| 
alpar@726
 | 
   400  | 
      status=AFTER_PRE_FLOW_PHASE_2;
  | 
| 
alpar@726
 | 
   401  | 
    }
  | 
| 
alpar@726
 | 
   402  | 
  | 
| 
alpar@726
 | 
   403  | 
  | 
| 
alpar@726
 | 
   404  | 
    /// Returns the maximum value of a flow.
  | 
| 
alpar@726
 | 
   405  | 
  | 
| 
alpar@726
 | 
   406  | 
    /// Returns the maximum value of a flow, by counting the 
  | 
| 
alpar@726
 | 
   407  | 
    /// over-flow of the target node \ref t.
  | 
| 
alpar@726
 | 
   408  | 
    /// It can be called already after running \ref preflowPhase1.
  | 
| 
alpar@726
 | 
   409  | 
    Num flowValue() const {
 | 
| 
alpar@726
 | 
   410  | 
      Num a=0;
  | 
| 
alpar@735
 | 
   411  | 
      for(InEdgeIt e(*g,t);g->valid(e);g->next(e)) a+=(*flow)[e];
  | 
| 
alpar@735
 | 
   412  | 
      for(OutEdgeIt e(*g,t);g->valid(e);g->next(e)) a-=(*flow)[e];
  | 
| 
marci@745
 | 
   413  | 
      return a;
  | 
| 
alpar@726
 | 
   414  | 
      //marci figyu: excess[t] epp ezt adja preflow 1. fazisa utan   
  | 
| 
alpar@726
 | 
   415  | 
    }
  | 
| 
marci@745
 | 
   416  | 
    Num flowValue2() const {
 | 
| 
marci@745
 | 
   417  | 
      return excess[t];
  | 
| 
marci@745
 | 
   418  | 
//       Num a=0;
  | 
| 
marci@745
 | 
   419  | 
//       for(InEdgeIt e(*g,t);g->valid(e);g->next(e)) a+=(*flow)[e];
  | 
| 
marci@745
 | 
   420  | 
//       for(OutEdgeIt e(*g,t);g->valid(e);g->next(e)) a-=(*flow)[e];
  | 
| 
marci@745
 | 
   421  | 
//       return a;
  | 
| 
marci@745
 | 
   422  | 
//       //marci figyu: excess[t] epp ezt adja preflow 1. fazisa utan  
  | 
| 
marci@745
 | 
   423  | 
      
  | 
| 
marci@745
 | 
   424  | 
    }
  | 
| 
alpar@726
 | 
   425  | 
  | 
| 
alpar@726
 | 
   426  | 
    ///Returns a minimum value cut after calling \ref preflowPhase1.
  | 
| 
alpar@726
 | 
   427  | 
  | 
| 
alpar@726
 | 
   428  | 
    ///After the first phase of the preflow algorithm the maximum flow
  | 
| 
alpar@726
 | 
   429  | 
    ///value and a minimum value cut can already be computed. This
  | 
| 
alpar@726
 | 
   430  | 
    ///method can be called after running \ref preflowPhase1 for
  | 
| 
alpar@726
 | 
   431  | 
    ///obtaining a minimum value cut.
  | 
| 
alpar@726
 | 
   432  | 
    /// \warning Gives proper result only right after calling \ref
  | 
| 
alpar@726
 | 
   433  | 
    /// preflowPhase1.
  | 
| 
alpar@726
 | 
   434  | 
    /// \todo We have to make some status variable which shows the
  | 
| 
alpar@726
 | 
   435  | 
    /// actual state
  | 
| 
alpar@726
 | 
   436  | 
    /// of the class. This enables us to determine which methods are valid
  | 
| 
alpar@726
 | 
   437  | 
    /// for MinCut computation
  | 
| 
alpar@726
 | 
   438  | 
    template<typename _CutMap>
  | 
| 
alpar@726
 | 
   439  | 
    void actMinCut(_CutMap& M) const {
 | 
| 
alpar@726
 | 
   440  | 
      NodeIt v;
  | 
| 
alpar@726
 | 
   441  | 
      switch (status) {
 | 
| 
alpar@726
 | 
   442  | 
      case AFTER_PRE_FLOW_PHASE_1:
  | 
| 
alpar@726
 | 
   443  | 
	for(g->first(v); g->valid(v); g->next(v)) {
 | 
| 
alpar@726
 | 
   444  | 
	  if (level[v] < n) {
 | 
| 
alpar@726
 | 
   445  | 
	    M.set(v, false);
  | 
| 
alpar@726
 | 
   446  | 
	  } else {
 | 
| 
alpar@726
 | 
   447  | 
	    M.set(v, true);
  | 
| 
alpar@726
 | 
   448  | 
	  }
  | 
| 
alpar@726
 | 
   449  | 
	}
  | 
| 
alpar@726
 | 
   450  | 
	break;
  | 
| 
alpar@726
 | 
   451  | 
      case AFTER_PRE_FLOW_PHASE_2:
  | 
| 
alpar@726
 | 
   452  | 
      case AFTER_NOTHING:
  | 
| 
marci@745
 | 
   453  | 
      case AFTER_AUGMENTING:
  | 
| 
marci@745
 | 
   454  | 
      case AFTER_FAST_AUGMENTING:
  | 
| 
alpar@726
 | 
   455  | 
	minMinCut(M);
  | 
| 
alpar@726
 | 
   456  | 
	break;
  | 
| 
alpar@726
 | 
   457  | 
      }
  | 
| 
alpar@726
 | 
   458  | 
    }
  | 
| 
alpar@726
 | 
   459  | 
  | 
| 
alpar@726
 | 
   460  | 
    ///Returns the inclusionwise minimum of the minimum value cuts.
  | 
| 
alpar@726
 | 
   461  | 
  | 
| 
alpar@726
 | 
   462  | 
    ///Sets \c M to the characteristic vector of the minimum value cut
  | 
| 
alpar@726
 | 
   463  | 
    ///which is inclusionwise minimum. It is computed by processing
  | 
| 
alpar@726
 | 
   464  | 
    ///a bfs from the source node \c s in the residual graph.
  | 
| 
alpar@726
 | 
   465  | 
    ///\pre M should be a node map of bools initialized to false.
  | 
| 
alpar@726
 | 
   466  | 
    ///\pre \c flow must be a maximum flow.
  | 
| 
alpar@726
 | 
   467  | 
    template<typename _CutMap>
  | 
| 
alpar@726
 | 
   468  | 
    void minMinCut(_CutMap& M) const {
 | 
| 
alpar@726
 | 
   469  | 
      std::queue<Node> queue;
  | 
| 
alpar@726
 | 
   470  | 
  | 
| 
alpar@726
 | 
   471  | 
      M.set(s,true);
  | 
| 
alpar@726
 | 
   472  | 
      queue.push(s);
  | 
| 
alpar@726
 | 
   473  | 
  | 
| 
alpar@726
 | 
   474  | 
      while (!queue.empty()) {
 | 
| 
alpar@726
 | 
   475  | 
        Node w=queue.front();
  | 
| 
alpar@726
 | 
   476  | 
	queue.pop();
  | 
| 
alpar@726
 | 
   477  | 
  | 
| 
alpar@726
 | 
   478  | 
	OutEdgeIt e;
  | 
| 
alpar@726
 | 
   479  | 
	for(g->first(e,w) ; g->valid(e); g->next(e)) {
 | 
| 
alpar@726
 | 
   480  | 
	  Node v=g->head(e);
  | 
| 
alpar@726
 | 
   481  | 
	  if (!M[v] && (*flow)[e] < (*capacity)[e] ) {
 | 
| 
alpar@726
 | 
   482  | 
	    queue.push(v);
  | 
| 
alpar@726
 | 
   483  | 
	    M.set(v, true);
  | 
| 
alpar@726
 | 
   484  | 
	  }
  | 
| 
alpar@726
 | 
   485  | 
	}
  | 
| 
alpar@726
 | 
   486  | 
  | 
| 
alpar@726
 | 
   487  | 
	InEdgeIt f;
  | 
| 
alpar@726
 | 
   488  | 
	for(g->first(f,w) ; g->valid(f); g->next(f)) {
 | 
| 
alpar@726
 | 
   489  | 
	  Node v=g->tail(f);
  | 
| 
alpar@726
 | 
   490  | 
	  if (!M[v] && (*flow)[f] > 0 ) {
 | 
| 
alpar@726
 | 
   491  | 
	    queue.push(v);
  | 
| 
alpar@726
 | 
   492  | 
	    M.set(v, true);
  | 
| 
alpar@726
 | 
   493  | 
	  }
  | 
| 
alpar@726
 | 
   494  | 
	}
  | 
| 
alpar@726
 | 
   495  | 
      }
  | 
| 
alpar@726
 | 
   496  | 
    }
  | 
| 
alpar@726
 | 
   497  | 
  | 
| 
alpar@726
 | 
   498  | 
    ///Returns the inclusionwise maximum of the minimum value cuts.
  | 
| 
alpar@726
 | 
   499  | 
  | 
| 
alpar@726
 | 
   500  | 
    ///Sets \c M to the characteristic vector of the minimum value cut
  | 
| 
alpar@726
 | 
   501  | 
    ///which is inclusionwise maximum. It is computed by processing a
  | 
| 
alpar@726
 | 
   502  | 
    ///backward bfs from the target node \c t in the residual graph.
  | 
| 
alpar@726
 | 
   503  | 
    ///\pre M should be a node map of bools initialized to false.
  | 
| 
alpar@726
 | 
   504  | 
    ///\pre \c flow must be a maximum flow. 
  | 
| 
alpar@726
 | 
   505  | 
    template<typename _CutMap>
  | 
| 
alpar@726
 | 
   506  | 
    void maxMinCut(_CutMap& M) const {
 | 
| 
alpar@726
 | 
   507  | 
  | 
| 
alpar@726
 | 
   508  | 
      NodeIt v;
  | 
| 
alpar@726
 | 
   509  | 
      for(g->first(v) ; g->valid(v); g->next(v)) {
 | 
| 
alpar@726
 | 
   510  | 
	M.set(v, true);
  | 
| 
alpar@726
 | 
   511  | 
      }
  | 
| 
alpar@726
 | 
   512  | 
  | 
| 
alpar@726
 | 
   513  | 
      std::queue<Node> queue;
  | 
| 
alpar@726
 | 
   514  | 
  | 
| 
alpar@726
 | 
   515  | 
      M.set(t,false);
  | 
| 
alpar@726
 | 
   516  | 
      queue.push(t);
  | 
| 
alpar@726
 | 
   517  | 
  | 
| 
alpar@726
 | 
   518  | 
      while (!queue.empty()) {
 | 
| 
alpar@726
 | 
   519  | 
        Node w=queue.front();
  | 
| 
alpar@726
 | 
   520  | 
	queue.pop();
  | 
| 
alpar@726
 | 
   521  | 
  | 
| 
alpar@726
 | 
   522  | 
	InEdgeIt e;
  | 
| 
alpar@726
 | 
   523  | 
	for(g->first(e,w) ; g->valid(e); g->next(e)) {
 | 
| 
alpar@726
 | 
   524  | 
	  Node v=g->tail(e);
  | 
| 
alpar@726
 | 
   525  | 
	  if (M[v] && (*flow)[e] < (*capacity)[e] ) {
 | 
| 
alpar@726
 | 
   526  | 
	    queue.push(v);
  | 
| 
alpar@726
 | 
   527  | 
	    M.set(v, false);
  | 
| 
alpar@726
 | 
   528  | 
	  }
  | 
| 
alpar@726
 | 
   529  | 
	}
  | 
| 
alpar@726
 | 
   530  | 
  | 
| 
alpar@726
 | 
   531  | 
	OutEdgeIt f;
  | 
| 
alpar@726
 | 
   532  | 
	for(g->first(f,w) ; g->valid(f); g->next(f)) {
 | 
| 
alpar@726
 | 
   533  | 
	  Node v=g->head(f);
  | 
| 
alpar@726
 | 
   534  | 
	  if (M[v] && (*flow)[f] > 0 ) {
 | 
| 
alpar@726
 | 
   535  | 
	    queue.push(v);
  | 
| 
alpar@726
 | 
   536  | 
	    M.set(v, false);
  | 
| 
alpar@726
 | 
   537  | 
	  }
  | 
| 
alpar@726
 | 
   538  | 
	}
  | 
| 
alpar@726
 | 
   539  | 
      }
  | 
| 
alpar@726
 | 
   540  | 
    }
  | 
| 
alpar@726
 | 
   541  | 
  | 
| 
alpar@726
 | 
   542  | 
    ///Returns a minimum value cut.
  | 
| 
alpar@726
 | 
   543  | 
  | 
| 
alpar@726
 | 
   544  | 
    ///Sets \c M to the characteristic vector of a minimum value cut.
  | 
| 
alpar@726
 | 
   545  | 
    ///\pre M should be a node map of bools initialized to false.
  | 
| 
alpar@726
 | 
   546  | 
    ///\pre \c flow must be a maximum flow.    
  | 
| 
alpar@726
 | 
   547  | 
    template<typename CutMap>
  | 
| 
alpar@726
 | 
   548  | 
    void minCut(CutMap& M) const { minMinCut(M); }
 | 
| 
alpar@726
 | 
   549  | 
  | 
| 
alpar@726
 | 
   550  | 
    ///Resets the source node to \c _s.
  | 
| 
alpar@726
 | 
   551  | 
  | 
| 
alpar@726
 | 
   552  | 
    ///Resets the source node to \c _s.
  | 
| 
alpar@726
 | 
   553  | 
    /// 
  | 
| 
alpar@726
 | 
   554  | 
    void resetSource(Node _s) { s=_s; status=AFTER_NOTHING; }
 | 
| 
alpar@726
 | 
   555  | 
  | 
| 
alpar@726
 | 
   556  | 
    ///Resets the target node to \c _t.
  | 
| 
alpar@726
 | 
   557  | 
  | 
| 
alpar@726
 | 
   558  | 
    ///Resets the target node to \c _t.
  | 
| 
alpar@726
 | 
   559  | 
    ///
  | 
| 
alpar@726
 | 
   560  | 
    void resetTarget(Node _t) { t=_t; status=AFTER_NOTHING; }
 | 
| 
alpar@726
 | 
   561  | 
  | 
| 
alpar@726
 | 
   562  | 
    /// Resets the edge map of the capacities to _cap.
  | 
| 
alpar@726
 | 
   563  | 
  | 
| 
alpar@726
 | 
   564  | 
    /// Resets the edge map of the capacities to _cap.
  | 
| 
alpar@726
 | 
   565  | 
    /// 
  | 
| 
alpar@726
 | 
   566  | 
    void resetCap(const CapMap& _cap)
  | 
| 
alpar@726
 | 
   567  | 
    { capacity=&_cap; status=AFTER_NOTHING; }
 | 
| 
alpar@726
 | 
   568  | 
  | 
| 
alpar@726
 | 
   569  | 
    /// Resets the edge map of the flows to _flow.
  | 
| 
alpar@726
 | 
   570  | 
  | 
| 
alpar@726
 | 
   571  | 
    /// Resets the edge map of the flows to _flow.
  | 
| 
alpar@726
 | 
   572  | 
    /// 
  | 
| 
alpar@726
 | 
   573  | 
    void resetFlow(FlowMap& _flow) { flow=&_flow; status=AFTER_NOTHING; }
 | 
| 
alpar@726
 | 
   574  | 
  | 
| 
alpar@726
 | 
   575  | 
  | 
| 
alpar@726
 | 
   576  | 
  private:
  | 
| 
alpar@726
 | 
   577  | 
  | 
| 
alpar@726
 | 
   578  | 
    int push(Node w, NNMap& next, VecFirst& first) {
 | 
| 
alpar@726
 | 
   579  | 
  | 
| 
alpar@726
 | 
   580  | 
      int lev=level[w];
  | 
| 
alpar@726
 | 
   581  | 
      Num exc=excess[w];
  | 
| 
alpar@726
 | 
   582  | 
      int newlevel=n;       //bound on the next level of w
  | 
| 
alpar@726
 | 
   583  | 
  | 
| 
alpar@726
 | 
   584  | 
      OutEdgeIt e;
  | 
| 
alpar@726
 | 
   585  | 
      for(g->first(e,w); g->valid(e); g->next(e)) {
 | 
| 
alpar@726
 | 
   586  | 
  | 
| 
alpar@726
 | 
   587  | 
	if ( (*flow)[e] >= (*capacity)[e] ) continue;
  | 
| 
alpar@726
 | 
   588  | 
	Node v=g->head(e);
  | 
| 
alpar@726
 | 
   589  | 
  | 
| 
alpar@726
 | 
   590  | 
	if( lev > level[v] ) { //Push is allowed now
 | 
| 
alpar@726
 | 
   591  | 
  | 
| 
alpar@726
 | 
   592  | 
	  if ( excess[v]<=0 && v!=t && v!=s ) {
 | 
| 
alpar@726
 | 
   593  | 
	    next.set(v,first[level[v]]);
  | 
| 
alpar@726
 | 
   594  | 
	    first[level[v]]=v;
  | 
| 
alpar@726
 | 
   595  | 
	  }
  | 
| 
alpar@726
 | 
   596  | 
  | 
| 
alpar@726
 | 
   597  | 
	  Num cap=(*capacity)[e];
  | 
| 
alpar@726
 | 
   598  | 
	  Num flo=(*flow)[e];
  | 
| 
alpar@726
 | 
   599  | 
	  Num remcap=cap-flo;
  | 
| 
alpar@726
 | 
   600  | 
  | 
| 
alpar@726
 | 
   601  | 
	  if ( remcap >= exc ) { //A nonsaturating push.
 | 
| 
alpar@726
 | 
   602  | 
  | 
| 
alpar@726
 | 
   603  | 
	    flow->set(e, flo+exc);
  | 
| 
alpar@726
 | 
   604  | 
	    excess.set(v, excess[v]+exc);
  | 
| 
alpar@726
 | 
   605  | 
	    exc=0;
  | 
| 
alpar@726
 | 
   606  | 
	    break;
  | 
| 
alpar@726
 | 
   607  | 
  | 
| 
alpar@726
 | 
   608  | 
	  } else { //A saturating push.
 | 
| 
alpar@726
 | 
   609  | 
	    flow->set(e, cap);
  | 
| 
alpar@726
 | 
   610  | 
	    excess.set(v, excess[v]+remcap);
  | 
| 
alpar@726
 | 
   611  | 
	    exc-=remcap;
  | 
| 
alpar@726
 | 
   612  | 
	  }
  | 
| 
alpar@726
 | 
   613  | 
	} else if ( newlevel > level[v] ) newlevel = level[v];
  | 
| 
alpar@726
 | 
   614  | 
      } //for out edges wv
  | 
| 
alpar@726
 | 
   615  | 
  | 
| 
alpar@726
 | 
   616  | 
      if ( exc > 0 ) {
 | 
| 
alpar@726
 | 
   617  | 
	InEdgeIt e;
  | 
| 
alpar@726
 | 
   618  | 
	for(g->first(e,w); g->valid(e); g->next(e)) {
 | 
| 
alpar@726
 | 
   619  | 
  | 
| 
alpar@726
 | 
   620  | 
	  if( (*flow)[e] <= 0 ) continue;
  | 
| 
alpar@726
 | 
   621  | 
	  Node v=g->tail(e);
  | 
| 
alpar@726
 | 
   622  | 
  | 
| 
alpar@726
 | 
   623  | 
	  if( lev > level[v] ) { //Push is allowed now
 | 
| 
alpar@726
 | 
   624  | 
  | 
| 
alpar@726
 | 
   625  | 
	    if ( excess[v]<=0 && v!=t && v!=s ) {
 | 
| 
alpar@726
 | 
   626  | 
	      next.set(v,first[level[v]]);
  | 
| 
alpar@726
 | 
   627  | 
	      first[level[v]]=v;
  | 
| 
alpar@726
 | 
   628  | 
	    }
  | 
| 
alpar@726
 | 
   629  | 
  | 
| 
alpar@726
 | 
   630  | 
	    Num flo=(*flow)[e];
  | 
| 
alpar@726
 | 
   631  | 
  | 
| 
alpar@726
 | 
   632  | 
	    if ( flo >= exc ) { //A nonsaturating push.
 | 
| 
alpar@726
 | 
   633  | 
  | 
| 
alpar@726
 | 
   634  | 
	      flow->set(e, flo-exc);
  | 
| 
alpar@726
 | 
   635  | 
	      excess.set(v, excess[v]+exc);
  | 
| 
alpar@726
 | 
   636  | 
	      exc=0;
  | 
| 
alpar@726
 | 
   637  | 
	      break;
  | 
| 
alpar@726
 | 
   638  | 
	    } else {  //A saturating push.
 | 
| 
alpar@726
 | 
   639  | 
  | 
| 
alpar@726
 | 
   640  | 
	      excess.set(v, excess[v]+flo);
  | 
| 
alpar@726
 | 
   641  | 
	      exc-=flo;
  | 
| 
alpar@726
 | 
   642  | 
	      flow->set(e,0);
  | 
| 
alpar@726
 | 
   643  | 
	    }
  | 
| 
alpar@726
 | 
   644  | 
	  } else if ( newlevel > level[v] ) newlevel = level[v];
  | 
| 
alpar@726
 | 
   645  | 
	} //for in edges vw
  | 
| 
alpar@726
 | 
   646  | 
  | 
| 
alpar@726
 | 
   647  | 
      } // if w still has excess after the out edge for cycle
  | 
| 
alpar@726
 | 
   648  | 
  | 
| 
alpar@726
 | 
   649  | 
      excess.set(w, exc);
  | 
| 
alpar@726
 | 
   650  | 
  | 
| 
alpar@726
 | 
   651  | 
      return newlevel;
  | 
| 
alpar@726
 | 
   652  | 
    }
  | 
| 
alpar@726
 | 
   653  | 
  | 
| 
alpar@726
 | 
   654  | 
  | 
| 
alpar@726
 | 
   655  | 
    void preflowPreproc(FlowEnum fe, NNMap& next, VecFirst& first,
  | 
| 
alpar@726
 | 
   656  | 
			VecNode& level_list, NNMap& left, NNMap& right)
  | 
| 
alpar@726
 | 
   657  | 
    {
 | 
| 
alpar@726
 | 
   658  | 
      std::queue<Node> bfs_queue;
  | 
| 
alpar@726
 | 
   659  | 
  | 
| 
alpar@726
 | 
   660  | 
      switch (fe) {
 | 
| 
alpar@726
 | 
   661  | 
      case NO_FLOW:   //flow is already set to const zero in this case
  | 
| 
alpar@726
 | 
   662  | 
      case ZERO_FLOW:
  | 
| 
alpar@726
 | 
   663  | 
	{
 | 
| 
alpar@726
 | 
   664  | 
	  //Reverse_bfs from t, to find the starting level.
  | 
| 
alpar@726
 | 
   665  | 
	  level.set(t,0);
  | 
| 
alpar@726
 | 
   666  | 
	  bfs_queue.push(t);
  | 
| 
alpar@726
 | 
   667  | 
  | 
| 
alpar@726
 | 
   668  | 
	  while (!bfs_queue.empty()) {
 | 
| 
alpar@726
 | 
   669  | 
  | 
| 
alpar@726
 | 
   670  | 
	    Node v=bfs_queue.front();
  | 
| 
alpar@726
 | 
   671  | 
	    bfs_queue.pop();
  | 
| 
alpar@726
 | 
   672  | 
	    int l=level[v]+1;
  | 
| 
alpar@726
 | 
   673  | 
  | 
| 
alpar@726
 | 
   674  | 
	    InEdgeIt e;
  | 
| 
alpar@726
 | 
   675  | 
	    for(g->first(e,v); g->valid(e); g->next(e)) {
 | 
| 
alpar@726
 | 
   676  | 
	      Node w=g->tail(e);
  | 
| 
alpar@726
 | 
   677  | 
	      if ( level[w] == n && w != s ) {
 | 
| 
alpar@726
 | 
   678  | 
		bfs_queue.push(w);
  | 
| 
alpar@726
 | 
   679  | 
		Node z=level_list[l];
  | 
| 
alpar@726
 | 
   680  | 
		if ( g->valid(z) ) left.set(z,w);
  | 
| 
alpar@726
 | 
   681  | 
		right.set(w,z);
  | 
| 
alpar@726
 | 
   682  | 
		level_list[l]=w;
  | 
| 
alpar@726
 | 
   683  | 
		level.set(w, l);
  | 
| 
alpar@726
 | 
   684  | 
	      }
  | 
| 
alpar@726
 | 
   685  | 
	    }
  | 
| 
alpar@726
 | 
   686  | 
	  }
  | 
| 
alpar@726
 | 
   687  | 
  | 
| 
alpar@726
 | 
   688  | 
	  //the starting flow
  | 
| 
alpar@726
 | 
   689  | 
	  OutEdgeIt e;
  | 
| 
alpar@726
 | 
   690  | 
	  for(g->first(e,s); g->valid(e); g->next(e))
  | 
| 
alpar@726
 | 
   691  | 
	    {
 | 
| 
alpar@726
 | 
   692  | 
	      Num c=(*capacity)[e];
  | 
| 
alpar@726
 | 
   693  | 
	      if ( c <= 0 ) continue;
  | 
| 
alpar@726
 | 
   694  | 
	      Node w=g->head(e);
  | 
| 
alpar@726
 | 
   695  | 
	      if ( level[w] < n ) {
 | 
| 
alpar@726
 | 
   696  | 
		if ( excess[w] <= 0 && w!=t ) 
  | 
| 
alpar@726
 | 
   697  | 
		  {
 | 
| 
alpar@726
 | 
   698  | 
		    next.set(w,first[level[w]]);
  | 
| 
alpar@726
 | 
   699  | 
		    first[level[w]]=w;
  | 
| 
alpar@726
 | 
   700  | 
		  }
  | 
| 
alpar@726
 | 
   701  | 
		flow->set(e, c);
  | 
| 
alpar@726
 | 
   702  | 
		excess.set(w, excess[w]+c);
  | 
| 
alpar@726
 | 
   703  | 
	      }
  | 
| 
alpar@726
 | 
   704  | 
	    }
  | 
| 
alpar@726
 | 
   705  | 
	  break;
  | 
| 
alpar@726
 | 
   706  | 
	}
  | 
| 
alpar@726
 | 
   707  | 
  | 
| 
alpar@726
 | 
   708  | 
      case GEN_FLOW:
  | 
| 
alpar@726
 | 
   709  | 
      case PRE_FLOW:
  | 
| 
alpar@726
 | 
   710  | 
	{
 | 
| 
alpar@726
 | 
   711  | 
	  //Reverse_bfs from t in the residual graph,
  | 
| 
alpar@726
 | 
   712  | 
	  //to find the starting level.
  | 
| 
alpar@726
 | 
   713  | 
	  level.set(t,0);
  | 
| 
alpar@726
 | 
   714  | 
	  bfs_queue.push(t);
  | 
| 
alpar@726
 | 
   715  | 
  | 
| 
alpar@726
 | 
   716  | 
	  while (!bfs_queue.empty()) {
 | 
| 
alpar@726
 | 
   717  | 
  | 
| 
alpar@726
 | 
   718  | 
	    Node v=bfs_queue.front();
  | 
| 
alpar@726
 | 
   719  | 
	    bfs_queue.pop();
  | 
| 
alpar@726
 | 
   720  | 
	    int l=level[v]+1;
  | 
| 
alpar@726
 | 
   721  | 
  | 
| 
alpar@726
 | 
   722  | 
	    InEdgeIt e;
  | 
| 
alpar@726
 | 
   723  | 
	    for(g->first(e,v); g->valid(e); g->next(e)) {
 | 
| 
alpar@726
 | 
   724  | 
	      if ( (*capacity)[e] <= (*flow)[e] ) continue;
  | 
| 
alpar@726
 | 
   725  | 
	      Node w=g->tail(e);
  | 
| 
alpar@726
 | 
   726  | 
	      if ( level[w] == n && w != s ) {
 | 
| 
alpar@726
 | 
   727  | 
		bfs_queue.push(w);
  | 
| 
alpar@726
 | 
   728  | 
		Node z=level_list[l];
  | 
| 
alpar@726
 | 
   729  | 
		if ( g->valid(z) ) left.set(z,w);
  | 
| 
alpar@726
 | 
   730  | 
		right.set(w,z);
  | 
| 
alpar@726
 | 
   731  | 
		level_list[l]=w;
  | 
| 
alpar@726
 | 
   732  | 
		level.set(w, l);
  | 
| 
alpar@726
 | 
   733  | 
	      }
  | 
| 
alpar@726
 | 
   734  | 
	    }
  | 
| 
alpar@726
 | 
   735  | 
  | 
| 
alpar@726
 | 
   736  | 
	    OutEdgeIt f;
  | 
| 
alpar@726
 | 
   737  | 
	    for(g->first(f,v); g->valid(f); g->next(f)) {
 | 
| 
alpar@726
 | 
   738  | 
	      if ( 0 >= (*flow)[f] ) continue;
  | 
| 
alpar@726
 | 
   739  | 
	      Node w=g->head(f);
  | 
| 
alpar@726
 | 
   740  | 
	      if ( level[w] == n && w != s ) {
 | 
| 
alpar@726
 | 
   741  | 
		bfs_queue.push(w);
  | 
| 
alpar@726
 | 
   742  | 
		Node z=level_list[l];
  | 
| 
alpar@726
 | 
   743  | 
		if ( g->valid(z) ) left.set(z,w);
  | 
| 
alpar@726
 | 
   744  | 
		right.set(w,z);
  | 
| 
alpar@726
 | 
   745  | 
		level_list[l]=w;
  | 
| 
alpar@726
 | 
   746  | 
		level.set(w, l);
  | 
| 
alpar@726
 | 
   747  | 
	      }
  | 
| 
alpar@726
 | 
   748  | 
	    }
  | 
| 
alpar@726
 | 
   749  | 
	  }
  | 
| 
alpar@726
 | 
   750  | 
  | 
| 
alpar@726
 | 
   751  | 
  | 
| 
alpar@726
 | 
   752  | 
	  //the starting flow
  | 
| 
alpar@726
 | 
   753  | 
	  OutEdgeIt e;
  | 
| 
alpar@726
 | 
   754  | 
	  for(g->first(e,s); g->valid(e); g->next(e))
  | 
| 
alpar@726
 | 
   755  | 
	    {
 | 
| 
alpar@726
 | 
   756  | 
	      Num rem=(*capacity)[e]-(*flow)[e];
  | 
| 
alpar@726
 | 
   757  | 
	      if ( rem <= 0 ) continue;
  | 
| 
alpar@726
 | 
   758  | 
	      Node w=g->head(e);
  | 
| 
alpar@726
 | 
   759  | 
	      if ( level[w] < n ) {
 | 
| 
alpar@726
 | 
   760  | 
		if ( excess[w] <= 0 && w!=t )
  | 
| 
alpar@726
 | 
   761  | 
		  {
 | 
| 
alpar@726
 | 
   762  | 
		    next.set(w,first[level[w]]);
  | 
| 
alpar@726
 | 
   763  | 
		    first[level[w]]=w;
  | 
| 
alpar@726
 | 
   764  | 
		  }   
  | 
| 
alpar@726
 | 
   765  | 
		flow->set(e, (*capacity)[e]);
  | 
| 
alpar@726
 | 
   766  | 
		excess.set(w, excess[w]+rem);
  | 
| 
alpar@726
 | 
   767  | 
	      }
  | 
| 
alpar@726
 | 
   768  | 
	    }
  | 
| 
alpar@726
 | 
   769  | 
  | 
| 
alpar@726
 | 
   770  | 
	  InEdgeIt f;
  | 
| 
alpar@726
 | 
   771  | 
	  for(g->first(f,s); g->valid(f); g->next(f))
  | 
| 
alpar@726
 | 
   772  | 
	    {
 | 
| 
alpar@726
 | 
   773  | 
	      if ( (*flow)[f] <= 0 ) continue;
  | 
| 
alpar@726
 | 
   774  | 
	      Node w=g->tail(f);
  | 
| 
alpar@726
 | 
   775  | 
	      if ( level[w] < n ) {
 | 
| 
alpar@726
 | 
   776  | 
		if ( excess[w] <= 0 && w!=t )
  | 
| 
alpar@726
 | 
   777  | 
		  {
 | 
| 
alpar@726
 | 
   778  | 
		    next.set(w,first[level[w]]);
  | 
| 
alpar@726
 | 
   779  | 
		    first[level[w]]=w;
  | 
| 
alpar@726
 | 
   780  | 
		  }   
  | 
| 
alpar@726
 | 
   781  | 
		excess.set(w, excess[w]+(*flow)[f]);
  | 
| 
alpar@726
 | 
   782  | 
		flow->set(f, 0);
  | 
| 
alpar@726
 | 
   783  | 
	      }
  | 
| 
alpar@726
 | 
   784  | 
	    }
  | 
| 
alpar@726
 | 
   785  | 
	  break;
  | 
| 
alpar@726
 | 
   786  | 
	} //case PRE_FLOW
  | 
| 
alpar@726
 | 
   787  | 
      }
  | 
| 
alpar@726
 | 
   788  | 
    } //preflowPreproc
  | 
| 
alpar@726
 | 
   789  | 
  | 
| 
alpar@726
 | 
   790  | 
  | 
| 
alpar@726
 | 
   791  | 
  | 
| 
alpar@726
 | 
   792  | 
    void relabel(Node w, int newlevel, NNMap& next, VecFirst& first,
  | 
| 
alpar@726
 | 
   793  | 
		 VecNode& level_list, NNMap& left,
  | 
| 
alpar@726
 | 
   794  | 
		 NNMap& right, int& b, int& k, bool what_heur )
  | 
| 
alpar@726
 | 
   795  | 
    {
 | 
| 
alpar@726
 | 
   796  | 
  | 
| 
alpar@726
 | 
   797  | 
      Num lev=level[w];
  | 
| 
alpar@726
 | 
   798  | 
  | 
| 
alpar@726
 | 
   799  | 
      Node right_n=right[w];
  | 
| 
alpar@726
 | 
   800  | 
      Node left_n=left[w];
  | 
| 
alpar@726
 | 
   801  | 
  | 
| 
alpar@726
 | 
   802  | 
      //unlacing starts
  | 
| 
alpar@726
 | 
   803  | 
      if ( g->valid(right_n) ) {
 | 
| 
alpar@726
 | 
   804  | 
	if ( g->valid(left_n) ) {
 | 
| 
alpar@726
 | 
   805  | 
	  right.set(left_n, right_n);
  | 
| 
alpar@726
 | 
   806  | 
	  left.set(right_n, left_n);
  | 
| 
alpar@726
 | 
   807  | 
	} else {
 | 
| 
alpar@726
 | 
   808  | 
	  level_list[lev]=right_n;
  | 
| 
alpar@726
 | 
   809  | 
	  left.set(right_n, INVALID);
  | 
| 
alpar@726
 | 
   810  | 
	}
  | 
| 
alpar@726
 | 
   811  | 
      } else {
 | 
| 
alpar@726
 | 
   812  | 
	if ( g->valid(left_n) ) {
 | 
| 
alpar@726
 | 
   813  | 
	  right.set(left_n, INVALID);
  | 
| 
alpar@726
 | 
   814  | 
	} else {
 | 
| 
alpar@726
 | 
   815  | 
	  level_list[lev]=INVALID;
  | 
| 
alpar@726
 | 
   816  | 
	}
  | 
| 
alpar@726
 | 
   817  | 
      }
  | 
| 
alpar@726
 | 
   818  | 
      //unlacing ends
  | 
| 
alpar@726
 | 
   819  | 
  | 
| 
alpar@726
 | 
   820  | 
      if ( !g->valid(level_list[lev]) ) {
 | 
| 
alpar@726
 | 
   821  | 
  | 
| 
alpar@726
 | 
   822  | 
	//gapping starts
  | 
| 
alpar@726
 | 
   823  | 
	for (int i=lev; i!=k ; ) {
 | 
| 
alpar@726
 | 
   824  | 
	  Node v=level_list[++i];
  | 
| 
alpar@726
 | 
   825  | 
	  while ( g->valid(v) ) {
 | 
| 
alpar@726
 | 
   826  | 
	    level.set(v,n);
  | 
| 
alpar@726
 | 
   827  | 
	    v=right[v];
  | 
| 
alpar@726
 | 
   828  | 
	  }
  | 
| 
alpar@726
 | 
   829  | 
	  level_list[i]=INVALID;
  | 
| 
alpar@726
 | 
   830  | 
	  if ( !what_heur ) first[i]=INVALID;
  | 
| 
alpar@726
 | 
   831  | 
	}
  | 
| 
alpar@726
 | 
   832  | 
  | 
| 
alpar@726
 | 
   833  | 
	level.set(w,n);
  | 
| 
alpar@726
 | 
   834  | 
	b=lev-1;
  | 
| 
alpar@726
 | 
   835  | 
	k=b;
  | 
| 
alpar@726
 | 
   836  | 
	//gapping ends
  | 
| 
alpar@726
 | 
   837  | 
  | 
| 
alpar@726
 | 
   838  | 
      } else {
 | 
| 
alpar@726
 | 
   839  | 
  | 
| 
alpar@726
 | 
   840  | 
	if ( newlevel == n ) level.set(w,n);
  | 
| 
alpar@726
 | 
   841  | 
	else {
 | 
| 
alpar@726
 | 
   842  | 
	  level.set(w,++newlevel);
  | 
| 
alpar@726
 | 
   843  | 
	  next.set(w,first[newlevel]);
  | 
| 
alpar@726
 | 
   844  | 
	  first[newlevel]=w;
  | 
| 
alpar@726
 | 
   845  | 
	  if ( what_heur ) b=newlevel;
  | 
| 
alpar@726
 | 
   846  | 
	  if ( k < newlevel ) ++k;      //now k=newlevel
  | 
| 
alpar@726
 | 
   847  | 
	  Node z=level_list[newlevel];
  | 
| 
alpar@726
 | 
   848  | 
	  if ( g->valid(z) ) left.set(z,w);
  | 
| 
alpar@726
 | 
   849  | 
	  right.set(w,z);
  | 
| 
alpar@726
 | 
   850  | 
	  left.set(w,INVALID);
  | 
| 
alpar@726
 | 
   851  | 
	  level_list[newlevel]=w;
  | 
| 
alpar@726
 | 
   852  | 
	}
  | 
| 
alpar@726
 | 
   853  | 
      }
  | 
| 
alpar@726
 | 
   854  | 
    } //relabel
  | 
| 
alpar@726
 | 
   855  | 
  };  //class MaxFlow
  | 
| 
alpar@726
 | 
   856  | 
} //namespace hugo
  | 
| 
alpar@726
 | 
   857  | 
  | 
| 
alpar@726
 | 
   858  | 
#endif //HUGO_MAX_FLOW_H
  | 
| 
alpar@726
 | 
   859  | 
  | 
| 
alpar@726
 | 
   860  | 
  | 
| 
alpar@726
 | 
   861  | 
  | 
| 
alpar@726
 | 
   862  | 
  |