# HG changeset patch # User deba # Date 1195652078 0 # Node ID 4c0a23bd70b521cb070e43992d53ff02111576d1 # Parent d9cfac0728699ff89c2874a691a24209fa510148 Bugfix in min cut computation diff -r d9cfac072869 -r 4c0a23bd70b5 lemon/elevator.h --- a/lemon/elevator.h Tue Nov 20 21:40:55 2007 +0000 +++ b/lemon/elevator.h Wed Nov 21 13:34:38 2007 +0000 @@ -50,11 +50,13 @@ template class Elevator { - private: + public: typedef Item Key; typedef int Value; + private: + typedef typename std::vector::iterator Vit; typedef typename ItemSetTraits::template Map::Type VitMap; typedef typename ItemSetTraits::template Map::Type IntMap; @@ -377,6 +379,16 @@ _level[i]=new_level; if(new_level>_highest_active) _highest_active=new_level; } + + ///Mark the node as it did not reach the max level + + ///Mark the node as it did not reach the max level. It sets the + ///level of the node to a low value, which is not connected to the + ///real levels of elevator. The node should be lifted previously + ///to the top level. + void markToBottom(Item i) { + _level[i] = - _max_level; + } ///Lift all nodes on and above a level to the top (and deactivate them). @@ -491,11 +503,13 @@ ///Graph::Edge, Graph::UEdge) template class LinkedElevator { - private: + public: typedef Item Key; typedef int Value; + private: + typedef typename ItemSetTraits:: template Map::Type ItemMap; typedef typename ItemSetTraits:: @@ -882,6 +896,16 @@ } } + ///Mark the node as it did not reach the max level + + ///Mark the node as it did not reach the max level. It sets the + ///level of the node to a low value, which is not connected to the + ///real levels of elevator. The node should be lifted previously + ///to the top level. + void markToBottom(Item i) { + _level[i] = - _max_level; + } + ///Lift all nodes on and above a level to the top (and deactivate them). ///This function lifts all nodes on and above level \c l to \c diff -r d9cfac072869 -r 4c0a23bd70b5 lemon/goldberg_tarjan.h --- a/lemon/goldberg_tarjan.h Tue Nov 20 21:40:55 2007 +0000 +++ b/lemon/goldberg_tarjan.h Wed Nov 21 13:34:38 2007 +0000 @@ -395,8 +395,8 @@ void createStructures() { _node_num = countNodes(_graph); - _max_tree_size = (double(_node_num) * double(_node_num)) / - double(countEdges(_graph)); + _max_tree_size = int((double(_node_num) * double(_node_num)) / + double(countEdges(_graph))); if (!_flow) { _flow = Traits::createFlowMap(_graph); @@ -827,7 +827,9 @@ _level->initFinish(); for (NodeIt n(_graph); n != INVALID; ++n) { - if ((*_excess)[n] > 0 && _target != n) { + if (!reached[n]) { + _level->markToBottom(n); + } else if ((*_excess)[n] > 0 && _target != n) { _level->activate(n); } } diff -r d9cfac072869 -r 4c0a23bd70b5 lemon/preflow.h --- a/lemon/preflow.h Tue Nov 20 21:40:55 2007 +0000 +++ b/lemon/preflow.h Wed Nov 21 13:34:38 2007 +0000 @@ -711,7 +711,7 @@ void startSecondPhase() { _phase = false; - typename Graph::template NodeMap reached(_graph, false); + typename Graph::template NodeMap reached(_graph); for (NodeIt n(_graph); n != INVALID; ++n) { reached.set(n, (*_level)[n] < _level->maxLevel()); } @@ -751,7 +751,9 @@ _level->initFinish(); for (NodeIt n(_graph); n != INVALID; ++n) { - if ((*_excess)[n] > 0 && _target != n) { + if (!reached[n]) { + _level->markToBottom(n); + } else if ((*_excess)[n] > 0 && _target != n) { _level->activate(n); } }