COIN-OR::LEMON - Graph Library

Changeset 1222:a3fb216a267d in lemon-0.x for src


Ignore:
Timestamp:
03/17/05 11:43:57 (19 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1642
Message:

The first step toward function type interface to Preflow alg:

  • Naming changed to be closer in style to the BFD/DFS/Dijkstra triplet.
Location:
src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/preflow.h

    r1164 r1222  
    3838  ///This class provides an implementation of the \e preflow \e
    3939  ///algorithm producing a flow of maximum value in a directed
    40   ///graph. The preflow algorithms are the fastest max flow algorithms
     40  ///graph. The preflow algorithms are the fastest known max flow algorithms
    4141  ///up to now. The \e source node, the \e target node, the \e
    4242  ///capacity of the edges and the \e starting \e flow value of the
    4343  ///edges should be passed to the algorithm through the
    4444  ///constructor. It is possible to change these quantities using the
    45   ///functions \ref setSource, \ref setTarget, \ref setCap and \ref
     45  ///functions \ref source, \ref target, \ref setCap and \ref
    4646  ///setFlow.
    4747  ///
     
    5656  ///\param Graph The directed graph type the algorithm runs on.
    5757  ///\param Num The number type of the capacities and the flow values.
    58   ///\param CapMap The capacity map type.
     58  ///\param CapacityMap The capacity map type.
    5959  ///\param FlowMap The flow map type.
    6060  ///
    6161  ///\author Jacint Szabo
    6262  template <typename Graph, typename Num,
    63             typename CapMap=typename Graph::template EdgeMap<Num>,
     63            typename CapacityMap=typename Graph::template EdgeMap<Num>,
    6464            typename FlowMap=typename Graph::template EdgeMap<Num> >
    6565  class Preflow {
     
    7474    typedef typename std::vector<Node> VecNode;
    7575
    76     const Graph* g;
    77     Node s;
    78     Node t;
    79     const CapMap* capacity;
    80     FlowMap* flow;
    81     int n;      //the number of nodes of G
     76    const Graph* _g;
     77    Node _source;
     78    Node _target;
     79    const CapacityMap* _capacity;
     80    FlowMap* _flow;
     81    int _node_num;      //the number of nodes of G
    8282   
    8383    typename Graph::template NodeMap<int> level; 
     
    9292    ///Indicates the property of the starting flow map.
    9393
    94     ///Indicates the property of the starting flow map. The meanings are as follows:
     94    ///Indicates the property of the starting flow map.
     95    ///The meanings are as follows:
    9596    ///- \c ZERO_FLOW: constant zero flow
    9697    ///- \c GEN_FLOW: any flow, i.e. the sum of the in-flows equals to
     
    112113    ///Indicates the state of the preflow algorithm.
    113114
    114     ///Indicates the state of the preflow algorithm. The meanings are as follows:
    115     ///- \c AFTER_NOTHING: before running the algorithm or at an unspecified state.
     115    ///Indicates the state of the preflow algorithm.
     116    ///The meanings are as follows:
     117    ///- \c AFTER_NOTHING: before running the algorithm or
     118    ///  at an unspecified state.
    116119    ///- \c AFTER_PREFLOW_PHASE_1: right after running \c phase1
    117120    ///- \c AFTER_PREFLOW_PHASE_2: after running \ref phase2()
     
    134137    ///\param _s The source node.
    135138    ///\param _t The target node.
    136     ///\param _capacity The capacity of the edges.
    137     ///\param _flow The flow of the edges.
     139    ///\param _cap The capacity of the edges.
     140    ///\param _f The flow of the edges.
    138141    ///Except the graph, all of these parameters can be reset by
    139     ///calling \ref setSource, \ref setTarget, \ref setCap and \ref
     142    ///calling \ref source, \ref target, \ref setCap and \ref
    140143    ///setFlow, resp.
    141       Preflow(const Graph& _G, Node _s, Node _t,
    142               const CapMap& _capacity, FlowMap& _flow) :
    143         g(&_G), s(_s), t(_t), capacity(&_capacity),
    144         flow(&_flow), n(countNodes(_G)), level(_G), excess(_G,0),
     144      Preflow(const Graph& _gr, Node _s, Node _t,
     145              const CapacityMap& _cap, FlowMap& _f) :
     146        _g(&_gr), _source(_s), _target(_t), _capacity(&_cap),
     147        _flow(&_f), _node_num(countNodes(_gr)), level(_gr), excess(_gr,0),
    145148        flow_prop(NO_FLOW), status(AFTER_NOTHING) { }
    146149
     
    205208    void phase1()
    206209    {
    207       int heur0=(int)(H0*n);  //time while running 'bound decrease'
    208       int heur1=(int)(H1*n);  //time while running 'highest label'
     210      int heur0=(int)(H0*_node_num);  //time while running 'bound decrease'
     211      int heur1=(int)(H1*_node_num);  //time while running 'highest label'
    209212      int heur=heur1;         //starting time interval (#of relabels)
    210213      int numrelabel=0;
     
    217220      //nodes are above bound b.
    218221
    219       int k=n-2;  //bound on the highest level under n containing a node
     222      int k=_node_num-2;  //bound on the highest level under n containing a node
    220223      int b=k;    //bound on the highest level under n of an active node
    221224
    222       VecNode first(n, INVALID);
    223       NNMap next(*g, INVALID);
    224 
    225       NNMap left(*g, INVALID);
    226       NNMap right(*g, INVALID);
    227       VecNode level_list(n,INVALID);
     225      VecNode first(_node_num, INVALID);
     226      NNMap next(*_g, INVALID);
     227
     228      NNMap left(*_g, INVALID);
     229      NNMap right(*_g, INVALID);
     230      VecNode level_list(_node_num,INVALID);
    228231      //List of the nodes in level i<n, set to n.
    229232
     
    272275    //   stack 'active' on the active nodes on level i     
    273276    //   runs heuristic 'highest label' for H1*n relabels
    274     //   runs heuristic 'bound decrease' for H0*n relabels, starts with 'highest label'
     277    //   runs heuristic 'bound decrease' for H0*n relabels,
     278    //        starts with 'highest label'
    275279    //   Parameters H0 and H1 are initialized to 20 and 1.
    276280
     
    288292    {
    289293
    290       int k=n-2;  //bound on the highest level under n containing a node
     294      int k=_node_num-2;  //bound on the highest level under n containing a node
    291295      int b=k;    //bound on the highest level under n of an active node
    292296
    293297   
    294       VecNode first(n, INVALID);
    295       NNMap next(*g, INVALID);
    296       level.set(s,0);
     298      VecNode first(_node_num, INVALID);
     299      NNMap next(*_g, INVALID);
     300      level.set(_source,0);
    297301      std::queue<Node> bfs_queue;
    298       bfs_queue.push(s);
     302      bfs_queue.push(_source);
    299303
    300304      while ( !bfs_queue.empty() ) {
     
    304308        int l=level[v]+1;
    305309
    306         for(InEdgeIt e(*g,v); e!=INVALID; ++e) {
    307           if ( (*capacity)[e] <= (*flow)[e] ) continue;
    308           Node u=g->source(e);
    309           if ( level[u] >= n ) {
     310        for(InEdgeIt e(*_g,v); e!=INVALID; ++e) {
     311          if ( (*_capacity)[e] <= (*_flow)[e] ) continue;
     312          Node u=_g->source(e);
     313          if ( level[u] >= _node_num ) {
    310314            bfs_queue.push(u);
    311315            level.set(u, l);
     
    317321        }
    318322
    319         for(OutEdgeIt e(*g,v); e!=INVALID; ++e) {
    320           if ( 0 >= (*flow)[e] ) continue;
    321           Node u=g->target(e);
    322           if ( level[u] >= n ) {
     323        for(OutEdgeIt e(*_g,v); e!=INVALID; ++e) {
     324          if ( 0 >= (*_flow)[e] ) continue;
     325          Node u=_g->target(e);
     326          if ( level[u] >= _node_num ) {
    323327            bfs_queue.push(u);
    324328            level.set(u, l);
     
    330334        }
    331335      }
    332       b=n-2;
     336      b=_node_num-2;
    333337
    334338      while ( true ) {
     
    360364    /// the maximum flow already after running \ref phase1.
    361365    Num flowValue() const {
    362       return excess[t];
     366      return excess[_target];
    363367    }
    364368
     
    376380      switch ( status ) {
    377381        case AFTER_PREFLOW_PHASE_1:
    378         for(NodeIt v(*g); v!=INVALID; ++v) {
    379           if (level[v] < n) {
     382        for(NodeIt v(*_g); v!=INVALID; ++v) {
     383          if (level[v] < _node_num) {
    380384            M.set(v, false);
    381385          } else {
     
    403407
    404408      std::queue<Node> queue;
    405       M.set(s,true);
     409      M.set(_source,true);
    406410      queue.push(s);
    407411     
     
    410414        queue.pop();
    411415       
    412         for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) {
    413           Node v=g->target(e);
    414           if (!M[v] && (*flow)[e] < (*capacity)[e] ) {
     416        for(OutEdgeIt e(*_g,w) ; e!=INVALID; ++e) {
     417          Node v=_g->target(e);
     418          if (!M[v] && (*_flow)[e] < (*_capacity)[e] ) {
    415419            queue.push(v);
    416420            M.set(v, true);
     
    418422        }
    419423       
    420         for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) {
    421           Node v=g->source(e);
    422           if (!M[v] && (*flow)[e] > 0 ) {
     424        for(InEdgeIt e(*_g,w) ; e!=INVALID; ++e) {
     425          Node v=_g->source(e);
     426          if (!M[v] && (*_flow)[e] > 0 ) {
    423427            queue.push(v);
    424428            M.set(v, true);
     
    437441    void maxMinCut(_CutMap& M) const {
    438442
    439       for(NodeIt v(*g) ; v!=INVALID; ++v) M.set(v, true);
     443      for(NodeIt v(*_g) ; v!=INVALID; ++v) M.set(v, true);
    440444
    441445      std::queue<Node> queue;
    442446
    443       M.set(t,false);
    444       queue.push(t);
     447      M.set(_target,false);
     448      queue.push(_target);
    445449
    446450      while (!queue.empty()) {
     
    448452        queue.pop();
    449453
    450         for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) {
    451           Node v=g->source(e);
    452           if (M[v] && (*flow)[e] < (*capacity)[e] ) {
     454        for(InEdgeIt e(*_g,w) ; e!=INVALID; ++e) {
     455          Node v=_g->source(e);
     456          if (M[v] && (*_flow)[e] < (*_capacity)[e] ) {
    453457            queue.push(v);
    454458            M.set(v, false);
     
    456460        }
    457461
    458         for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) {
    459           Node v=g->target(e);
    460           if (M[v] && (*flow)[e] > 0 ) {
     462        for(OutEdgeIt e(*_g,w) ; e!=INVALID; ++e) {
     463          Node v=_g->target(e);
     464          if (M[v] && (*_flow)[e] > 0 ) {
    461465            queue.push(v);
    462466            M.set(v, false);
     
    470474    ///Sets the source node to \c _s.
    471475    ///
    472     void setSource(Node _s) {
    473       s=_s;
     476    void source(Node _s) {
     477      _source=_s;
    474478      if ( flow_prop != ZERO_FLOW ) flow_prop=NO_FLOW;
    475479      status=AFTER_NOTHING;
    476480    }
    477481
     482    ///Returns the source node.
     483
     484    ///Returns the source node.
     485    ///
     486    Node source() const {
     487      return _source;
     488    }
     489
    478490    ///Sets the target node to \c _t.
    479491
    480492    ///Sets the target node to \c _t.
    481493    ///
    482     void setTarget(Node _t) {
    483       t=_t;
     494    void target(Node _t) {
     495      _target=_t;
    484496      if ( flow_prop == GEN_FLOW ) flow_prop=PRE_FLOW;
    485497      status=AFTER_NOTHING;
    486498    }
    487499
     500    ///Returns the target node.
     501
     502    ///Returns the target node.
     503    ///
     504    Node target() const {
     505      return _target;
     506    }
     507
    488508    /// Sets the edge map of the capacities to _cap.
    489509
    490510    /// Sets the edge map of the capacities to _cap.
    491511    ///
    492     void setCap(const CapMap& _cap) {
    493       capacity=&_cap;
     512    void capacityMap(const CapacityMap& _cap) {
     513      _capacity=&_cap;
    494514      status=AFTER_NOTHING;
     515    }
     516    /// Returns a reference to to capacity map.
     517
     518    /// Returns a reference to to capacity map.
     519    ///
     520    const CapacityMap &capacityMap() const {
     521      return *_capacity;
    495522    }
    496523
     
    499526    /// Sets the edge map of the flows to _flow.
    500527    ///
    501     void setFlow(FlowMap& _flow) {
    502       flow=&_flow;
     528    void flowMap(FlowMap& _f) {
     529      _flow=&_f;
    503530      flow_prop=NO_FLOW;
    504531      status=AFTER_NOTHING;
    505532    }
    506 
     533     
     534    /// Returns a reference to to flow map.
     535
     536    /// Returns a reference to to flow map.
     537    ///
     538    const FlowMap &flowMap() const {
     539      return *_flow;
     540    }
    507541
    508542  private:
     
    512546      int lev=level[w];
    513547      Num exc=excess[w];
    514       int newlevel=n;       //bound on the next level of w
    515 
    516       for(OutEdgeIt e(*g,w) ; e!=INVALID; ++e) {
    517         if ( (*flow)[e] >= (*capacity)[e] ) continue;
    518         Node v=g->target(e);
     548      int newlevel=_node_num;       //bound on the next level of w
     549
     550      for(OutEdgeIt e(*_g,w) ; e!=INVALID; ++e) {
     551        if ( (*_flow)[e] >= (*_capacity)[e] ) continue;
     552        Node v=_g->target(e);
    519553
    520554        if( lev > level[v] ) { //Push is allowed now
    521555         
    522           if ( excess[v]<=0 && v!=t && v!=s ) {
     556          if ( excess[v]<=0 && v!=_target && v!=_source ) {
    523557            next.set(v,first[level[v]]);
    524558            first[level[v]]=v;
    525559          }
    526560
    527           Num cap=(*capacity)[e];
    528           Num flo=(*flow)[e];
     561          Num cap=(*_capacity)[e];
     562          Num flo=(*_flow)[e];
    529563          Num remcap=cap-flo;
    530564         
    531565          if ( remcap >= exc ) { //A nonsaturating push.
    532566           
    533             flow->set(e, flo+exc);
     567            _flow->set(e, flo+exc);
    534568            excess.set(v, excess[v]+exc);
    535569            exc=0;
     
    537571
    538572          } else { //A saturating push.
    539             flow->set(e, cap);
     573            _flow->set(e, cap);
    540574            excess.set(v, excess[v]+remcap);
    541575            exc-=remcap;
     
    545579
    546580      if ( exc > 0 ) {
    547         for(InEdgeIt e(*g,w) ; e!=INVALID; ++e) {
    548          
    549           if( (*flow)[e] <= 0 ) continue;
    550           Node v=g->source(e);
     581        for(InEdgeIt e(*_g,w) ; e!=INVALID; ++e) {
     582         
     583          if( (*_flow)[e] <= 0 ) continue;
     584          Node v=_g->source(e);
    551585
    552586          if( lev > level[v] ) { //Push is allowed now
    553587
    554             if ( excess[v]<=0 && v!=t && v!=s ) {
     588            if ( excess[v]<=0 && v!=_target && v!=_source ) {
    555589              next.set(v,first[level[v]]);
    556590              first[level[v]]=v;
    557591            }
    558592
    559             Num flo=(*flow)[e];
     593            Num flo=(*_flow)[e];
    560594
    561595            if ( flo >= exc ) { //A nonsaturating push.
    562596
    563               flow->set(e, flo-exc);
     597              _flow->set(e, flo-exc);
    564598              excess.set(v, excess[v]+exc);
    565599              exc=0;
     
    569603              excess.set(v, excess[v]+flo);
    570604              exc-=flo;
    571               flow->set(e,0);
     605              _flow->set(e,0);
    572606            }
    573607          } else if ( newlevel > level[v] ) newlevel = level[v];
     
    586620                        VecNode& level_list, NNMap& left, NNMap& right)
    587621    {
    588       for(NodeIt v(*g); v!=INVALID; ++v) level.set(v,n);
     622      for(NodeIt v(*_g); v!=INVALID; ++v) level.set(v,_node_num);
    589623      std::queue<Node> bfs_queue;
    590624     
     
    592626        //Reverse_bfs from t in the residual graph,
    593627        //to find the starting level.
    594         level.set(t,0);
    595         bfs_queue.push(t);
     628        level.set(_target,0);
     629        bfs_queue.push(_target);
    596630       
    597631        while ( !bfs_queue.empty() ) {
     
    601635          int l=level[v]+1;
    602636         
    603           for(InEdgeIt e(*g,v) ; e!=INVALID; ++e) {
    604             if ( (*capacity)[e] <= (*flow)[e] ) continue;
    605             Node w=g->source(e);
    606             if ( level[w] == n && w != s ) {
     637          for(InEdgeIt e(*_g,v) ; e!=INVALID; ++e) {
     638            if ( (*_capacity)[e] <= (*_flow)[e] ) continue;
     639            Node w=_g->source(e);
     640            if ( level[w] == _node_num && w != _source ) {
    607641              bfs_queue.push(w);
    608642              Node z=level_list[l];
     
    614648          }
    615649         
    616           for(OutEdgeIt e(*g,v) ; e!=INVALID; ++e) {
    617             if ( 0 >= (*flow)[e] ) continue;
    618             Node w=g->target(e);
    619             if ( level[w] == n && w != s ) {
     650          for(OutEdgeIt e(*_g,v) ; e!=INVALID; ++e) {
     651            if ( 0 >= (*_flow)[e] ) continue;
     652            Node w=_g->target(e);
     653            if ( level[w] == _node_num && w != _source ) {
    620654              bfs_queue.push(w);
    621655              Node z=level_list[l];
     
    632666      switch (flow_prop) {
    633667        case NO_FLOW: 
    634         for(EdgeIt e(*g); e!=INVALID; ++e) flow->set(e,0);
     668        for(EdgeIt e(*_g); e!=INVALID; ++e) _flow->set(e,0);
    635669        case ZERO_FLOW:
    636         for(NodeIt v(*g); v!=INVALID; ++v) excess.set(v,0);
     670        for(NodeIt v(*_g); v!=INVALID; ++v) excess.set(v,0);
    637671       
    638672        //Reverse_bfs from t, to find the starting level.
    639         level.set(t,0);
    640         bfs_queue.push(t);
     673        level.set(_target,0);
     674        bfs_queue.push(_target);
    641675       
    642676        while ( !bfs_queue.empty() ) {
     
    646680          int l=level[v]+1;
    647681         
    648           for(InEdgeIt e(*g,v) ; e!=INVALID; ++e) {
    649             Node w=g->source(e);
    650             if ( level[w] == n && w != s ) {
     682          for(InEdgeIt e(*_g,v) ; e!=INVALID; ++e) {
     683            Node w=_g->source(e);
     684            if ( level[w] == _node_num && w != _source ) {
    651685              bfs_queue.push(w);
    652686              Node z=level_list[l];
     
    660694       
    661695        //the starting flow
    662         for(OutEdgeIt e(*g,s) ; e!=INVALID; ++e) {
    663           Num c=(*capacity)[e];
     696        for(OutEdgeIt e(*_g,_source) ; e!=INVALID; ++e) {
     697          Num c=(*_capacity)[e];
    664698          if ( c <= 0 ) continue;
    665           Node w=g->target(e);
    666           if ( level[w] < n ) {
    667             if ( excess[w] <= 0 && w!=t ) { //putting into the stack
     699          Node w=_g->target(e);
     700          if ( level[w] < _node_num ) {
     701            if ( excess[w] <= 0 && w!=_target ) { //putting into the stack
    668702              next.set(w,first[level[w]]);
    669703              first[level[w]]=w;
    670704            }
    671             flow->set(e, c);
     705            _flow->set(e, c);
    672706            excess.set(w, excess[w]+c);
    673707          }
     
    676710
    677711        case GEN_FLOW:
    678         for(NodeIt v(*g); v!=INVALID; ++v) excess.set(v,0);
     712        for(NodeIt v(*_g); v!=INVALID; ++v) excess.set(v,0);
    679713        {
    680714          Num exc=0;
    681           for(InEdgeIt e(*g,t) ; e!=INVALID; ++e) exc+=(*flow)[e];
    682           for(OutEdgeIt e(*g,t) ; e!=INVALID; ++e) exc-=(*flow)[e];
    683           excess.set(t,exc);
     715          for(InEdgeIt e(*_g,_target) ; e!=INVALID; ++e) exc+=(*_flow)[e];
     716          for(OutEdgeIt e(*_g,_target) ; e!=INVALID; ++e) exc-=(*_flow)[e];
     717          excess.set(_target,exc);
    684718        }
    685719
    686720        //the starting flow
    687         for(OutEdgeIt e(*g,s); e!=INVALID; ++e) {
    688           Num rem=(*capacity)[e]-(*flow)[e];
     721        for(OutEdgeIt e(*_g,_source); e!=INVALID; ++e)  {
     722          Num rem=(*_capacity)[e]-(*_flow)[e];
    689723          if ( rem <= 0 ) continue;
    690           Node w=g->target(e);
    691           if ( level[w] < n ) {
    692             if ( excess[w] <= 0 && w!=t ) { //putting into the stack
     724          Node w=_g->target(e);
     725          if ( level[w] < _node_num ) {
     726            if ( excess[w] <= 0 && w!=_target ) { //putting into the stack
    693727              next.set(w,first[level[w]]);
    694728              first[level[w]]=w;
    695729            }   
    696             flow->set(e, (*capacity)[e]);
     730            _flow->set(e, (*_capacity)[e]);
    697731            excess.set(w, excess[w]+rem);
    698732          }
    699733        }
    700734       
    701         for(InEdgeIt e(*g,s); e!=INVALID; ++e) {
    702           if ( (*flow)[e] <= 0 ) continue;
    703           Node w=g->source(e);
    704           if ( level[w] < n ) {
    705             if ( excess[w] <= 0 && w!=t ) {
     735        for(InEdgeIt e(*_g,_source); e!=INVALID; ++e) {
     736          if ( (*_flow)[e] <= 0 ) continue;
     737          Node w=_g->source(e);
     738          if ( level[w] < _node_num ) {
     739            if ( excess[w] <= 0 && w!=_target ) {
    706740              next.set(w,first[level[w]]);
    707741              first[level[w]]=w;
    708742            } 
    709             excess.set(w, excess[w]+(*flow)[e]);
    710             flow->set(e, 0);
     743            excess.set(w, excess[w]+(*_flow)[e]);
     744            _flow->set(e, 0);
    711745          }
    712746        }
     
    715749        case PRE_FLOW: 
    716750        //the starting flow
    717         for(OutEdgeIt e(*g,s) ; e!=INVALID; ++e) {
    718           Num rem=(*capacity)[e]-(*flow)[e];
     751        for(OutEdgeIt e(*_g,_source) ; e!=INVALID; ++e) {
     752          Num rem=(*_capacity)[e]-(*_flow)[e];
    719753          if ( rem <= 0 ) continue;
    720           Node w=g->target(e);
    721           if ( level[w] < n ) flow->set(e, (*capacity)[e]);
     754          Node w=_g->target(e);
     755          if ( level[w] < _node_num ) _flow->set(e, (*_capacity)[e]);
    722756        }
    723757       
    724         for(InEdgeIt e(*g,s) ; e!=INVALID; ++e) {
    725           if ( (*flow)[e] <= 0 ) continue;
    726           Node w=g->source(e);
    727           if ( level[w] < n ) flow->set(e, 0);
     758        for(InEdgeIt e(*_g,_source) ; e!=INVALID; ++e) {
     759          if ( (*_flow)[e] <= 0 ) continue;
     760          Node w=_g->source(e);
     761          if ( level[w] < _node_num ) _flow->set(e, 0);
    728762        }
    729763       
    730764        //computing the excess
    731         for(NodeIt w(*g); w!=INVALID; ++w) {
     765        for(NodeIt w(*_g); w!=INVALID; ++w) {
    732766          Num exc=0;
    733           for(InEdgeIt e(*g,w); e!=INVALID; ++e) exc+=(*flow)[e];
    734           for(OutEdgeIt e(*g,w); e!=INVALID; ++e) exc-=(*flow)[e];
     767          for(InEdgeIt e(*_g,w); e!=INVALID; ++e) exc+=(*_flow)[e];
     768          for(OutEdgeIt e(*_g,w); e!=INVALID; ++e) exc-=(*_flow)[e];
    735769          excess.set(w,exc);
    736770         
    737771          //putting the active nodes into the stack
    738772          int lev=level[w];
    739             if ( exc > 0 && lev < n && Node(w) != t ) {
     773            if ( exc > 0 && lev < _node_num && Node(w) != _target ) {
    740774              next.set(w,first[lev]);
    741775              first[lev]=w;
     
    781815          Node v=level_list[++i];
    782816          while ( v!=INVALID ) {
    783             level.set(v,n);
     817            level.set(v,_node_num);
    784818            v=right[v];
    785819          }
     
    788822        }
    789823
    790         level.set(w,n);
     824        level.set(w,_node_num);
    791825        b=lev-1;
    792826        k=b;
     
    795829      } else {
    796830
    797         if ( newlevel == n ) level.set(w,n);
     831        if ( newlevel == _node_num ) level.set(w,_node_num);
    798832        else {
    799833          level.set(w,++newlevel);
  • src/test/preflow_test.cc

    r1215 r1222  
    5050  preflow_test.run();
    5151  preflow_test.flowValue();
    52   preflow_test.setSource(n);
    53   preflow_test.setFlow(flow);
     52  preflow_test.source(n);
     53  preflow_test.flowMap(flow);
    5454
    5555  preflow_test.phase1(PType::NO_FLOW);
     
    5757
    5858  preflow_test.phase2();
    59   preflow_test.setTarget(n);
    60   preflow_test.setCap(cap);
     59  preflow_test.target(n);
     60  preflow_test.capacityMap(cap);
    6161  preflow_test.minMinCut(cut);
    6262  preflow_test.maxMinCut(cut);
     
    130130
    131131  for(EdgeIt e(g); e!=INVALID; ++e) cap[e]=2*cap[e];
    132   preflow_test.setCap(cap); 
     132  preflow_test.capacityMap(cap); 
    133133
    134134  preflow_test.phase1(PType::PRE_FLOW);
     
    169169  }
    170170
    171   preflow_test.setFlow(flow);
     171  preflow_test.flowMap(flow);
    172172
    173173  NodeIt tmp1(g,s);
     
    179179  if ( tmp2 != INVALID ) t=tmp2;
    180180
    181   preflow_test.setSource(s);
    182   preflow_test.setTarget(t);
     181  preflow_test.source(s);
     182  preflow_test.target(t);
    183183 
    184184  preflow_test.run();
Note: See TracChangeset for help on using the changeset viewer.