COIN-OR::LEMON - Graph Library

Ticket #414: 30d5f950aa5f.patch

File 30d5f950aa5f.patch, 2.2 KB (added by Alpar Juttner, 13 years ago)
  • lemon/preflow.h

    # HG changeset patch
    # User Alpar Juttner <alpar@cs.elte.hu>
    # Date 1298666267 -3600
    # Node ID 30d5f950aa5f4347b3bef4e9ab7c01c3eb8f05c7
    # Parent  bb70ad62c95fd75d6bd134451a406df9bd0eda12
    Fix wrong initialization in Preflow (#414)
    
    diff --git a/lemon/preflow.h b/lemon/preflow.h
    a b  
    525525          if ((*_level)[u] == _level->maxLevel()) continue;
    526526          _flow->set(e, (*_capacity)[e]);
    527527          (*_excess)[u] += rem;
    528           if (u != _target && !_level->active(u)) {
    529             _level->activate(u);
    530           }
    531528        }
    532529      }
    533530      for (InArcIt e(_graph, _source); e != INVALID; ++e) {
     
    537534          if ((*_level)[v] == _level->maxLevel()) continue;
    538535          _flow->set(e, 0);
    539536          (*_excess)[v] += rem;
    540           if (v != _target && !_level->active(v)) {
    541             _level->activate(v);
    542           }
    543537        }
    544538      }
     539      for (NodeIt n(_graph); n != INVALID; ++n)
     540        if(n!=_source && n!=_target && _tolerance.positive((*_excess)[n]))
     541          _level->activate(n);
     542         
    545543      return true;
    546544    }
    547545
  • test/preflow_test.cc

    diff --git a/test/preflow_test.cc b/test/preflow_test.cc
    a b  
    151151  return true;
    152152}
    153153
     154void initFlowTest()
     155{
     156  DIGRAPH_TYPEDEFS(SmartDigraph);
     157 
     158  SmartDigraph g;
     159  SmartDigraph::ArcMap<int> cap(g),iflow(g);
     160  Node s=g.addNode(); Node t=g.addNode();
     161  Node n1=g.addNode(); Node n2=g.addNode();
     162  Arc a;
     163  a=g.addArc(s,n1); cap[a]=20; iflow[a]=20;
     164  a=g.addArc(n1,n2); cap[a]=10; iflow[a]=0;
     165  a=g.addArc(n2,t); cap[a]=20; iflow[a]=0;
     166
     167  Preflow<SmartDigraph> pre(g,cap,s,t);
     168  pre.init(iflow);
     169  pre.startFirstPhase();
     170  check(pre.flowValue() == 10, "The incorrect max flow value.");
     171  check(pre.minCut(s), "Wrong min cut (Node s).");
     172  check(pre.minCut(n1), "Wrong min cut (Node n1).");
     173  check(!pre.minCut(n2), "Wrong min cut (Node n2).");
     174  check(!pre.minCut(t), "Wrong min cut (Node t).");
     175}
     176
     177
    154178int main() {
    155179
    156180  typedef SmartDigraph Digraph;
     
    241265  check(preflow_test.flowValue() == min_cut_value,
    242266        "The max flow value or the three min cut values are incorrect.");
    243267
     268  initFlowTest();
     269 
    244270  return 0;
    245271}