diff -r 6c6c0eb89b47 -r 580b329c2a0c src/work/jacint/max_flow.h --- a/src/work/jacint/max_flow.h Mon May 10 16:52:51 2004 +0000 +++ b/src/work/jacint/max_flow.h Mon May 10 16:59:20 2004 +0000 @@ -44,7 +44,7 @@ #include #include -#include +#include #include #include #include @@ -55,7 +55,7 @@ namespace hugo { -// ///\author Marton Makai, Jacint Szabo + // ///\author Marton Makai, Jacint Szabo /// A class for computing max flows and related quantities. template , @@ -88,20 +88,20 @@ //In preflow, it shows levels of nodes. //typename Graph::template NodeMap level; typename Graph::template NodeMap excess; -// protected: -// MaxFlow() { } -// void set(const Graph& _G, Node _s, Node _t, const CapMap& _capacity, -// FlowMap& _flow) -// { -// g=&_G; -// s=_s; -// t=_t; -// capacity=&_capacity; -// flow=&_flow; -// n=_G.nodeNum; -// level.set (_G); //kellene vmi ilyesmi fv -// excess(_G,0); //itt is -// } + // protected: + // MaxFlow() { } + // void set(const Graph& _G, Node _s, Node _t, const CapMap& _capacity, + // FlowMap& _flow) + // { + // g=&_G; + // s=_s; + // t=_t; + // capacity=&_capacity; + // flow=&_flow; + // n=_G.nodeNum; + // level.set (_G); //kellene vmi ilyesmi fv + // excess(_G,0); //itt is + // } public: @@ -362,126 +362,127 @@ void preflowPreproc ( flowEnum fe, VecStack& active, - VecNode& level_list, NNMap& left, NNMap& right ) { + VecNode& level_list, NNMap& left, NNMap& right ) + { - std::queue bfs_queue; + std::queue bfs_queue; - switch ( fe ) { - case ZERO_FLOW: - { - //Reverse_bfs from t, to find the starting level. - level.set(t,0); - bfs_queue.push(t); + switch ( fe ) { + case ZERO_FLOW: + { + //Reverse_bfs from t, to find the starting level. + level.set(t,0); + bfs_queue.push(t); - while (!bfs_queue.empty()) { + while (!bfs_queue.empty()) { - Node v=bfs_queue.front(); - bfs_queue.pop(); - int l=level[v]+1; + Node v=bfs_queue.front(); + bfs_queue.pop(); + int l=level[v]+1; - InEdgeIt e; - for(g->first(e,v); g->valid(e); g->next(e)) { - Node w=g->tail(e); - if ( level[w] == n && w != s ) { - bfs_queue.push(w); - Node first=level_list[l]; - if ( g->valid(first) ) left.set(first,w); - right.set(w,first); - level_list[l]=w; - level.set(w, l); - } - } - } + InEdgeIt e; + for(g->first(e,v); g->valid(e); g->next(e)) { + Node w=g->tail(e); + if ( level[w] == n && w != s ) { + bfs_queue.push(w); + Node first=level_list[l]; + if ( g->valid(first) ) left.set(first,w); + right.set(w,first); + level_list[l]=w; + level.set(w, l); + } + } + } - //the starting flow - OutEdgeIt e; - for(g->first(e,s); g->valid(e); g->next(e)) - { - Num c=(*capacity)[e]; - if ( c <= 0 ) continue; - Node w=g->head(e); - if ( level[w] < n ) { - if ( excess[w] <= 0 && w!=t ) active[level[w]].push(w); - flow->set(e, c); - excess.set(w, excess[w]+c); - } - } - break; - } + //the starting flow + OutEdgeIt e; + for(g->first(e,s); g->valid(e); g->next(e)) + { + Num c=(*capacity)[e]; + if ( c <= 0 ) continue; + Node w=g->head(e); + if ( level[w] < n ) { + if ( excess[w] <= 0 && w!=t ) active[level[w]].push(w); + flow->set(e, c); + excess.set(w, excess[w]+c); + } + } + break; + } - case GEN_FLOW: - case PREFLOW: - { - //Reverse_bfs from t in the residual graph, - //to find the starting level. - level.set(t,0); - bfs_queue.push(t); + case GEN_FLOW: + case PREFLOW: + { + //Reverse_bfs from t in the residual graph, + //to find the starting level. + level.set(t,0); + bfs_queue.push(t); - while (!bfs_queue.empty()) { + while (!bfs_queue.empty()) { - Node v=bfs_queue.front(); - bfs_queue.pop(); - int l=level[v]+1; + Node v=bfs_queue.front(); + bfs_queue.pop(); + int l=level[v]+1; - InEdgeIt e; - for(g->first(e,v); g->valid(e); g->next(e)) { - if ( (*capacity)[e] <= (*flow)[e] ) continue; - Node w=g->tail(e); - if ( level[w] == n && w != s ) { - bfs_queue.push(w); - Node first=level_list[l]; - if ( g->valid(first) ) left.set(first,w); - right.set(w,first); - level_list[l]=w; - level.set(w, l); - } - } + InEdgeIt e; + for(g->first(e,v); g->valid(e); g->next(e)) { + if ( (*capacity)[e] <= (*flow)[e] ) continue; + Node w=g->tail(e); + if ( level[w] == n && w != s ) { + bfs_queue.push(w); + Node first=level_list[l]; + if ( g->valid(first) ) left.set(first,w); + right.set(w,first); + level_list[l]=w; + level.set(w, l); + } + } - OutEdgeIt f; - for(g->first(f,v); g->valid(f); g->next(f)) { - if ( 0 >= (*flow)[f] ) continue; - Node w=g->head(f); - if ( level[w] == n && w != s ) { - bfs_queue.push(w); - Node first=level_list[l]; - if ( g->valid(first) ) left.set(first,w); - right.set(w,first); - level_list[l]=w; - level.set(w, l); - } - } - } + OutEdgeIt f; + for(g->first(f,v); g->valid(f); g->next(f)) { + if ( 0 >= (*flow)[f] ) continue; + Node w=g->head(f); + if ( level[w] == n && w != s ) { + bfs_queue.push(w); + Node first=level_list[l]; + if ( g->valid(first) ) left.set(first,w); + right.set(w,first); + level_list[l]=w; + level.set(w, l); + } + } + } - //the starting flow - OutEdgeIt e; - for(g->first(e,s); g->valid(e); g->next(e)) - { - Num rem=(*capacity)[e]-(*flow)[e]; - if ( rem <= 0 ) continue; - Node w=g->head(e); - if ( level[w] < n ) { - if ( excess[w] <= 0 && w!=t ) active[level[w]].push(w); - flow->set(e, (*capacity)[e]); - excess.set(w, excess[w]+rem); - } - } + //the starting flow + OutEdgeIt e; + for(g->first(e,s); g->valid(e); g->next(e)) + { + Num rem=(*capacity)[e]-(*flow)[e]; + if ( rem <= 0 ) continue; + Node w=g->head(e); + if ( level[w] < n ) { + if ( excess[w] <= 0 && w!=t ) active[level[w]].push(w); + flow->set(e, (*capacity)[e]); + excess.set(w, excess[w]+rem); + } + } - InEdgeIt f; - for(g->first(f,s); g->valid(f); g->next(f)) - { - if ( (*flow)[f] <= 0 ) continue; - Node w=g->tail(f); - if ( level[w] < n ) { - if ( excess[w] <= 0 && w!=t ) active[level[w]].push(w); - excess.set(w, excess[w]+(*flow)[f]); - flow->set(f, 0); - } - } - break; - } //case PREFLOW - } - } //preflowPreproc + InEdgeIt f; + for(g->first(f,s); g->valid(f); g->next(f)) + { + if ( (*flow)[f] <= 0 ) continue; + Node w=g->tail(f); + if ( level[w] < n ) { + if ( excess[w] <= 0 && w!=t ) active[level[w]].push(w); + excess.set(w, excess[w]+(*flow)[f]); + flow->set(f, 0); + } + } + break; + } //case PREFLOW + } + } //preflowPreproc