lemon/circulation.h
changeset 2542 faaa54ec4520
parent 2533 aea952a1af99
child 2553 bfced05fa852
equal deleted inserted replaced
9:13493fa23c3d 10:2c5d07506663
   401 	_flow->set(e, (*_lo)[e]);
   401 	_flow->set(e, (*_lo)[e]);
   402 	_excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_flow)[e]);
   402 	_excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_flow)[e]);
   403 	_excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_flow)[e]);
   403 	_excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_flow)[e]);
   404       }
   404       }
   405 
   405 
   406       typename Graph::template NodeMap<bool> reached(_g, false);
       
   407 
       
   408 
       
   409       // global relabeling tested, but in general case it provides
   406       // global relabeling tested, but in general case it provides
   410       // worse performance for random graphs
   407       // worse performance for random graphs
   411       _level->initStart();
   408       _level->initStart();
   412       for(NodeIt n(_g);n!=INVALID;++n)
   409       for(NodeIt n(_g);n!=INVALID;++n)
   413 	_level->initAddItem(n);
   410 	_level->initAddItem(n);
   434 	  _flow->set(e, (*_up)[e]);
   431 	  _flow->set(e, (*_up)[e]);
   435 	  _excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_up)[e]);
   432 	  _excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_up)[e]);
   436 	  _excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_up)[e]);
   433 	  _excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_up)[e]);
   437 	} else if (_tol.positive((*_excess)[_g.target(e)] + (*_lo)[e])) {
   434 	} else if (_tol.positive((*_excess)[_g.target(e)] + (*_lo)[e])) {
   438 	  _flow->set(e, (*_lo)[e]);
   435 	  _flow->set(e, (*_lo)[e]);
   439 	  _excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_up)[e]);
   436 	  _excess->set(_g.target(e), (*_excess)[_g.target(e)] + (*_lo)[e]);
   440 	  _excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_up)[e]);
   437 	  _excess->set(_g.source(e), (*_excess)[_g.source(e)] - (*_lo)[e]);
   441 	} else {
   438 	} else {
   442 	  Value fc = -(*_excess)[_g.target(e)];
   439 	  Value fc = -(*_excess)[_g.target(e)];
   443 	  _flow->set(e, fc);
   440 	  _flow->set(e, fc);
   444 	  _excess->set(_g.target(e), 0);
   441 	  _excess->set(_g.target(e), 0);
   445 	  _excess->set(_g.source(e), (*_excess)[_g.source(e)] - fc);
   442 	  _excess->set(_g.source(e), (*_excess)[_g.source(e)] - fc);
   469       Node last_activated=INVALID;
   466       Node last_activated=INVALID;
   470       while((act=_level->highestActive())!=INVALID) {
   467       while((act=_level->highestActive())!=INVALID) {
   471 	int actlevel=(*_level)[act];
   468 	int actlevel=(*_level)[act];
   472 	int mlevel=_node_num;
   469 	int mlevel=_node_num;
   473 	Value exc=(*_excess)[act];
   470 	Value exc=(*_excess)[act];
   474 	
   471 
   475 	for(OutEdgeIt e(_g,act);e!=INVALID; ++e) {
   472 	for(OutEdgeIt e(_g,act);e!=INVALID; ++e) {
   476 	  Node v = _g.target(e);
   473 	  Node v = _g.target(e);
   477 	  Value fc=(*_up)[e]-(*_flow)[e];
   474 	  Value fc=(*_up)[e]-(*_flow)[e];
   478 	  if(!_tol.positive(fc)) continue;
   475 	  if(!_tol.positive(fc)) continue;
   479 	  if((*_level)[v]<actlevel) {
   476 	  if((*_level)[v]<actlevel) {
   486 	      _level->deactivate(act);
   483 	      _level->deactivate(act);
   487 	      goto next_l;
   484 	      goto next_l;
   488 	    }
   485 	    }
   489 	    else {
   486 	    else {
   490 	      _flow->set(e, (*_up)[e]);
   487 	      _flow->set(e, (*_up)[e]);
   491 	      _excess->set(v, (*_excess)[v] + exc);
   488 	      _excess->set(v, (*_excess)[v] + fc);
   492 	      if(!_level->active(v) && _tol.positive((*_excess)[v]))
   489 	      if(!_level->active(v) && _tol.positive((*_excess)[v]))
   493 		_level->activate(v);
   490 		_level->activate(v);
   494 	      exc-=fc;
   491 	      exc-=fc;
   495 	    }
   492 	    }
   496 	  } 
   493 	  }