1.1 --- a/src/work/makefile Tue Aug 17 10:24:19 2004 +0000
1.2 +++ b/src/work/makefile Tue Aug 17 11:20:16 2004 +0000
1.3 @@ -1,5 +1,5 @@
1.4 INCLUDEDIRS ?= -I.. -I. -I./{marci,jacint,alpar,klao,akos}
1.5 -CXXFLAGS = -g -O3 -W -Wall $(INCLUDEDIRS) -ansi -pedantic
1.6 +CXXFLAGS = -g -O2 -W -Wall $(INCLUDEDIRS) -ansi -pedantic
1.7
1.8 BINARIES ?= bin_heap_demo
1.9
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/src/work/marci/augmenting_flow.h Tue Aug 17 11:20:16 2004 +0000
2.3 @@ -0,0 +1,1477 @@
2.4 +// -*- C++ -*-
2.5 +#ifndef HUGO_AUGMENTING_FLOW_H
2.6 +#define HUGO_AUGMENTING_FLOW_H
2.7 +
2.8 +#include <vector>
2.9 +#include <queue>
2.10 +#include <stack>
2.11 +#include <iostream>
2.12 +
2.13 +#include <hugo/graph_wrapper.h>
2.14 +#include <bfs_dfs.h>
2.15 +#include <hugo/invalid.h>
2.16 +#include <hugo/maps.h>
2.17 +#include <for_each_macros.h>
2.18 +
2.19 +/// \file
2.20 +/// \brief Maximum flow algorithms.
2.21 +/// \ingroup galgs
2.22 +
2.23 +namespace hugo {
2.24 +
2.25 + /// \addtogroup galgs
2.26 + /// @{
2.27 + ///Maximum flow algorithms class.
2.28 +
2.29 + ///This class provides various algorithms for finding a flow of
2.30 + ///maximum value in a directed graph. The \e source node, the \e
2.31 + ///target node, the \e capacity of the edges and the \e starting \e
2.32 + ///flow value of the edges should be passed to the algorithm through the
2.33 + ///constructor. It is possible to change these quantities using the
2.34 + ///functions \ref resetSource, \ref resetTarget, \ref resetCap and
2.35 + ///\ref resetFlow. Before any subsequent runs of any algorithm of
2.36 + ///the class \ref resetFlow should be called.
2.37 +
2.38 + ///After running an algorithm of the class, the actual flow value
2.39 + ///can be obtained by calling \ref flowValue(). The minimum
2.40 + ///value cut can be written into a \c node map of \c bools by
2.41 + ///calling \ref minCut. (\ref minMinCut and \ref maxMinCut writes
2.42 + ///the inclusionwise minimum and maximum of the minimum value
2.43 + ///cuts, resp.)
2.44 + ///\param Graph The directed graph type the algorithm runs on.
2.45 + ///\param Num The number type of the capacities and the flow values.
2.46 + ///\param CapMap The capacity map type.
2.47 + ///\param FlowMap The flow map type.
2.48 + ///\author Marton Makai, Jacint Szabo
2.49 +// template <typename Graph, typename Num,
2.50 +// typename CapMap=typename Graph::template EdgeMap<Num>,
2.51 +// typename FlowMap=typename Graph::template EdgeMap<Num> >
2.52 +// class MaxFlow {
2.53 +// protected:
2.54 +// typedef typename Graph::Node Node;
2.55 +// typedef typename Graph::NodeIt NodeIt;
2.56 +// typedef typename Graph::EdgeIt EdgeIt;
2.57 +// typedef typename Graph::OutEdgeIt OutEdgeIt;
2.58 +// typedef typename Graph::InEdgeIt InEdgeIt;
2.59 +
2.60 +// typedef typename std::vector<std::stack<Node> > VecStack;
2.61 +// typedef typename Graph::template NodeMap<Node> NNMap;
2.62 +// typedef typename std::vector<Node> VecNode;
2.63 +
2.64 +// const Graph* g;
2.65 +// Node s;
2.66 +// Node t;
2.67 +// const CapMap* capacity;
2.68 +// FlowMap* flow;
2.69 +// int n; //the number of nodes of G
2.70 +// typedef ResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW;
2.71 +// //typedef ExpResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW;
2.72 +// typedef typename ResGW::OutEdgeIt ResGWOutEdgeIt;
2.73 +// typedef typename ResGW::Edge ResGWEdge;
2.74 +// //typedef typename ResGW::template NodeMap<bool> ReachedMap;
2.75 +// typedef typename Graph::template NodeMap<int> ReachedMap;
2.76 +
2.77 +
2.78 +// //level works as a bool map in augmenting path algorithms and is
2.79 +// //used by bfs for storing reached information. In preflow, it
2.80 +// //shows the levels of nodes.
2.81 +// ReachedMap level;
2.82 +
2.83 +// //excess is needed only in preflow
2.84 +// typename Graph::template NodeMap<Num> excess;
2.85 +
2.86 +// //fixme
2.87 +// // protected:
2.88 +// // MaxFlow() { }
2.89 +// // void set(const Graph& _G, Node _s, Node _t, const CapMap& _capacity,
2.90 +// // FlowMap& _flow)
2.91 +// // {
2.92 +// // g=&_G;
2.93 +// // s=_s;
2.94 +// // t=_t;
2.95 +// // capacity=&_capacity;
2.96 +// // flow=&_flow;
2.97 +// // n=_G.nodeNum;
2.98 +// // level.set (_G); //kellene vmi ilyesmi fv
2.99 +// // excess(_G,0); //itt is
2.100 +// // }
2.101 +
2.102 +// // constants used for heuristics
2.103 +// static const int H0=20;
2.104 +// static const int H1=1;
2.105 +
2.106 +// public:
2.107 +
2.108 +// ///Indicates the property of the starting flow.
2.109 +
2.110 +// ///Indicates the property of the starting flow. The meanings are as follows:
2.111 +// ///- \c ZERO_FLOW: constant zero flow
2.112 +// ///- \c GEN_FLOW: any flow, i.e. the sum of the in-flows equals to
2.113 +// ///the sum of the out-flows in every node except the \e source and
2.114 +// ///the \e target.
2.115 +// ///- \c PRE_FLOW: any preflow, i.e. the sum of the in-flows is at
2.116 +// ///least the sum of the out-flows in every node except the \e source.
2.117 +// ///- \c NO_FLOW: indicates an unspecified edge map. \ref flow will be
2.118 +// ///set to the constant zero flow in the beginning of the algorithm in this case.
2.119 +// enum FlowEnum{
2.120 +// ZERO_FLOW,
2.121 +// GEN_FLOW,
2.122 +// PRE_FLOW,
2.123 +// NO_FLOW
2.124 +// };
2.125 +
2.126 +// enum StatusEnum {
2.127 +// AFTER_NOTHING,
2.128 +// AFTER_AUGMENTING,
2.129 +// AFTER_FAST_AUGMENTING,
2.130 +// AFTER_PRE_FLOW_PHASE_1,
2.131 +// AFTER_PRE_FLOW_PHASE_2
2.132 +// };
2.133 +
2.134 +// /// Don not needle this flag only if necessary.
2.135 +// StatusEnum status;
2.136 +// // int number_of_augmentations;
2.137 +
2.138 +
2.139 +// // template<typename IntMap>
2.140 +// // class TrickyReachedMap {
2.141 +// // protected:
2.142 +// // IntMap* map;
2.143 +// // int* number_of_augmentations;
2.144 +// // public:
2.145 +// // TrickyReachedMap(IntMap& _map, int& _number_of_augmentations) :
2.146 +// // map(&_map), number_of_augmentations(&_number_of_augmentations) { }
2.147 +// // void set(const Node& n, bool b) {
2.148 +// // if (b)
2.149 +// // map->set(n, *number_of_augmentations);
2.150 +// // else
2.151 +// // map->set(n, *number_of_augmentations-1);
2.152 +// // }
2.153 +// // bool operator[](const Node& n) const {
2.154 +// // return (*map)[n]==*number_of_augmentations;
2.155 +// // }
2.156 +// // };
2.157 +
2.158 +// MaxFlow(const Graph& _G, Node _s, Node _t, const CapMap& _capacity,
2.159 +// FlowMap& _flow) :
2.160 +// g(&_G), s(_s), t(_t), capacity(&_capacity),
2.161 +// flow(&_flow), n(_G.nodeNum()), level(_G), excess(_G,0),
2.162 +// status(AFTER_NOTHING) { }
2.163 +
2.164 +// ///Runs a maximum flow algorithm.
2.165 +
2.166 +// ///Runs a preflow algorithm, which is the fastest maximum flow
2.167 +// ///algorithm up-to-date. The default for \c fe is ZERO_FLOW.
2.168 +// ///\pre The starting flow must be
2.169 +// /// - a constant zero flow if \c fe is \c ZERO_FLOW,
2.170 +// /// - an arbitary flow if \c fe is \c GEN_FLOW,
2.171 +// /// - an arbitary preflow if \c fe is \c PRE_FLOW,
2.172 +// /// - any map if \c fe is NO_FLOW.
2.173 +// void run(FlowEnum fe=ZERO_FLOW) {
2.174 +// preflow(fe);
2.175 +// }
2.176 +
2.177 +
2.178 +// ///Runs a preflow algorithm.
2.179 +
2.180 +// ///Runs a preflow algorithm. The preflow algorithms provide the
2.181 +// ///fastest way to compute a maximum flow in a directed graph.
2.182 +// ///\pre The starting flow must be
2.183 +// /// - a constant zero flow if \c fe is \c ZERO_FLOW,
2.184 +// /// - an arbitary flow if \c fe is \c GEN_FLOW,
2.185 +// /// - an arbitary preflow if \c fe is \c PRE_FLOW,
2.186 +// /// - any map if \c fe is NO_FLOW.
2.187 +// void preflow(FlowEnum fe) {
2.188 +// preflowPhase1(fe);
2.189 +// preflowPhase2();
2.190 +// }
2.191 +// // Heuristics:
2.192 +// // 2 phase
2.193 +// // gap
2.194 +// // list 'level_list' on the nodes on level i implemented by hand
2.195 +// // stack 'active' on the active nodes on level i
2.196 +// // runs heuristic 'highest label' for H1*n relabels
2.197 +// // runs heuristic 'bound decrease' for H0*n relabels, starts with 'highest label'
2.198 +// // Parameters H0 and H1 are initialized to 20 and 1.
2.199 +
2.200 +// ///Runs the first phase of the preflow algorithm.
2.201 +
2.202 +// ///The preflow algorithm consists of two phases, this method runs the
2.203 +// ///first phase. After the first phase the maximum flow value and a
2.204 +// ///minimum value cut can already be computed, though a maximum flow
2.205 +// ///is net yet obtained. So after calling this method \ref flowValue
2.206 +// ///and \ref actMinCut gives proper results.
2.207 +// ///\warning: \ref minCut, \ref minMinCut and \ref maxMinCut do not
2.208 +// ///give minimum value cuts unless calling \ref preflowPhase2.
2.209 +// ///\pre The starting flow must be
2.210 +// /// - a constant zero flow if \c fe is \c ZERO_FLOW,
2.211 +// /// - an arbitary flow if \c fe is \c GEN_FLOW,
2.212 +// /// - an arbitary preflow if \c fe is \c PRE_FLOW,
2.213 +// /// - any map if \c fe is NO_FLOW.
2.214 +// void preflowPhase1(FlowEnum fe);
2.215 +
2.216 +// ///Runs the second phase of the preflow algorithm.
2.217 +
2.218 +// ///The preflow algorithm consists of two phases, this method runs
2.219 +// ///the second phase. After calling \ref preflowPhase1 and then
2.220 +// ///\ref preflowPhase2 the methods \ref flowValue, \ref minCut,
2.221 +// ///\ref minMinCut and \ref maxMinCut give proper results.
2.222 +// ///\pre \ref preflowPhase1 must be called before.
2.223 +// void preflowPhase2();
2.224 +
2.225 +// /// Returns the maximum value of a flow.
2.226 +
2.227 +// /// Returns the maximum value of a flow, by counting the
2.228 +// /// over-flow of the target node \ref t.
2.229 +// /// It can be called already after running \ref preflowPhase1.
2.230 +// Num flowValue() const {
2.231 +// Num a=0;
2.232 +// FOR_EACH_INC_LOC(InEdgeIt, e, *g, t) a+=(*flow)[e];
2.233 +// FOR_EACH_INC_LOC(OutEdgeIt, e, *g, t) a-=(*flow)[e];
2.234 +// return a;
2.235 +// //marci figyu: excess[t] epp ezt adja preflow 1. fazisa utan
2.236 +// }
2.237 +
2.238 +// ///Returns a minimum value cut after calling \ref preflowPhase1.
2.239 +
2.240 +// ///After the first phase of the preflow algorithm the maximum flow
2.241 +// ///value and a minimum value cut can already be computed. This
2.242 +// ///method can be called after running \ref preflowPhase1 for
2.243 +// ///obtaining a minimum value cut.
2.244 +// /// \warning Gives proper result only right after calling \ref
2.245 +// /// preflowPhase1.
2.246 +// /// \todo We have to make some status variable which shows the
2.247 +// /// actual state
2.248 +// /// of the class. This enables us to determine which methods are valid
2.249 +// /// for MinCut computation
2.250 +// template<typename _CutMap>
2.251 +// void actMinCut(_CutMap& M) const {
2.252 +// NodeIt v;
2.253 +// switch (status) {
2.254 +// case AFTER_PRE_FLOW_PHASE_1:
2.255 +// for(g->first(v); g->valid(v); g->next(v)) {
2.256 +// if (level[v] < n) {
2.257 +// M.set(v, false);
2.258 +// } else {
2.259 +// M.set(v, true);
2.260 +// }
2.261 +// }
2.262 +// break;
2.263 +// case AFTER_PRE_FLOW_PHASE_2:
2.264 +// case AFTER_NOTHING:
2.265 +// case AFTER_AUGMENTING:
2.266 +// case AFTER_FAST_AUGMENTING:
2.267 +// minMinCut(M);
2.268 +// break;
2.269 +// // case AFTER_AUGMENTING:
2.270 +// // for(g->first(v); g->valid(v); g->next(v)) {
2.271 +// // if (level[v]) {
2.272 +// // M.set(v, true);
2.273 +// // } else {
2.274 +// // M.set(v, false);
2.275 +// // }
2.276 +// // }
2.277 +// // break;
2.278 +// // case AFTER_FAST_AUGMENTING:
2.279 +// // for(g->first(v); g->valid(v); g->next(v)) {
2.280 +// // if (level[v]==number_of_augmentations) {
2.281 +// // M.set(v, true);
2.282 +// // } else {
2.283 +// // M.set(v, false);
2.284 +// // }
2.285 +// // }
2.286 +// // break;
2.287 +// }
2.288 +// }
2.289 +
2.290 +// ///Returns the inclusionwise minimum of the minimum value cuts.
2.291 +
2.292 +// ///Sets \c M to the characteristic vector of the minimum value cut
2.293 +// ///which is inclusionwise minimum. It is computed by processing
2.294 +// ///a bfs from the source node \c s in the residual graph.
2.295 +// ///\pre M should be a node map of bools initialized to false.
2.296 +// ///\pre \c flow must be a maximum flow.
2.297 +// template<typename _CutMap>
2.298 +// void minMinCut(_CutMap& M) const {
2.299 +// std::queue<Node> queue;
2.300 +
2.301 +// M.set(s,true);
2.302 +// queue.push(s);
2.303 +
2.304 +// while (!queue.empty()) {
2.305 +// Node w=queue.front();
2.306 +// queue.pop();
2.307 +
2.308 +// OutEdgeIt e;
2.309 +// for(g->first(e,w) ; g->valid(e); g->next(e)) {
2.310 +// Node v=g->head(e);
2.311 +// if (!M[v] && (*flow)[e] < (*capacity)[e] ) {
2.312 +// queue.push(v);
2.313 +// M.set(v, true);
2.314 +// }
2.315 +// }
2.316 +
2.317 +// InEdgeIt f;
2.318 +// for(g->first(f,w) ; g->valid(f); g->next(f)) {
2.319 +// Node v=g->tail(f);
2.320 +// if (!M[v] && (*flow)[f] > 0 ) {
2.321 +// queue.push(v);
2.322 +// M.set(v, true);
2.323 +// }
2.324 +// }
2.325 +// }
2.326 +// }
2.327 +
2.328 +// ///Returns the inclusionwise maximum of the minimum value cuts.
2.329 +
2.330 +// ///Sets \c M to the characteristic vector of the minimum value cut
2.331 +// ///which is inclusionwise maximum. It is computed by processing a
2.332 +// ///backward bfs from the target node \c t in the residual graph.
2.333 +// ///\pre M should be a node map of bools initialized to false.
2.334 +// ///\pre \c flow must be a maximum flow.
2.335 +// template<typename _CutMap>
2.336 +// void maxMinCut(_CutMap& M) const {
2.337 +
2.338 +// NodeIt v;
2.339 +// for(g->first(v) ; g->valid(v); g->next(v)) {
2.340 +// M.set(v, true);
2.341 +// }
2.342 +
2.343 +// std::queue<Node> queue;
2.344 +
2.345 +// M.set(t,false);
2.346 +// queue.push(t);
2.347 +
2.348 +// while (!queue.empty()) {
2.349 +// Node w=queue.front();
2.350 +// queue.pop();
2.351 +
2.352 +// InEdgeIt e;
2.353 +// for(g->first(e,w) ; g->valid(e); g->next(e)) {
2.354 +// Node v=g->tail(e);
2.355 +// if (M[v] && (*flow)[e] < (*capacity)[e] ) {
2.356 +// queue.push(v);
2.357 +// M.set(v, false);
2.358 +// }
2.359 +// }
2.360 +
2.361 +// OutEdgeIt f;
2.362 +// for(g->first(f,w) ; g->valid(f); g->next(f)) {
2.363 +// Node v=g->head(f);
2.364 +// if (M[v] && (*flow)[f] > 0 ) {
2.365 +// queue.push(v);
2.366 +// M.set(v, false);
2.367 +// }
2.368 +// }
2.369 +// }
2.370 +// }
2.371 +
2.372 +// ///Returns a minimum value cut.
2.373 +
2.374 +// ///Sets \c M to the characteristic vector of a minimum value cut.
2.375 +// ///\pre M should be a node map of bools initialized to false.
2.376 +// ///\pre \c flow must be a maximum flow.
2.377 +// template<typename CutMap>
2.378 +// void minCut(CutMap& M) const { minMinCut(M); }
2.379 +
2.380 +// ///Resets the source node to \c _s.
2.381 +
2.382 +// ///Resets the source node to \c _s.
2.383 +// ///
2.384 +// void resetSource(Node _s) { s=_s; status=AFTER_NOTHING; }
2.385 +
2.386 +// ///Resets the target node to \c _t.
2.387 +
2.388 +// ///Resets the target node to \c _t.
2.389 +// ///
2.390 +// void resetTarget(Node _t) { t=_t; status=AFTER_NOTHING; }
2.391 +
2.392 +// /// Resets the edge map of the capacities to _cap.
2.393 +
2.394 +// /// Resets the edge map of the capacities to _cap.
2.395 +// ///
2.396 +// void resetCap(const CapMap& _cap) { capacity=&_cap; status=AFTER_NOTHING; }
2.397 +
2.398 +// /// Resets the edge map of the flows to _flow.
2.399 +
2.400 +// /// Resets the edge map of the flows to _flow.
2.401 +// ///
2.402 +// void resetFlow(FlowMap& _flow) { flow=&_flow; status=AFTER_NOTHING; }
2.403 +
2.404 +
2.405 +// private:
2.406 +
2.407 +// int push(Node w, VecStack& active) {
2.408 +
2.409 +// int lev=level[w];
2.410 +// Num exc=excess[w];
2.411 +// int newlevel=n; //bound on the next level of w
2.412 +
2.413 +// OutEdgeIt e;
2.414 +// for(g->first(e,w); g->valid(e); g->next(e)) {
2.415 +
2.416 +// if ( (*flow)[e] >= (*capacity)[e] ) continue;
2.417 +// Node v=g->head(e);
2.418 +
2.419 +// if( lev > level[v] ) { //Push is allowed now
2.420 +
2.421 +// if ( excess[v]<=0 && v!=t && v!=s ) {
2.422 +// int lev_v=level[v];
2.423 +// active[lev_v].push(v);
2.424 +// }
2.425 +
2.426 +// Num cap=(*capacity)[e];
2.427 +// Num flo=(*flow)[e];
2.428 +// Num remcap=cap-flo;
2.429 +
2.430 +// if ( remcap >= exc ) { //A nonsaturating push.
2.431 +
2.432 +// flow->set(e, flo+exc);
2.433 +// excess.set(v, excess[v]+exc);
2.434 +// exc=0;
2.435 +// break;
2.436 +
2.437 +// } else { //A saturating push.
2.438 +// flow->set(e, cap);
2.439 +// excess.set(v, excess[v]+remcap);
2.440 +// exc-=remcap;
2.441 +// }
2.442 +// } else if ( newlevel > level[v] ) newlevel = level[v];
2.443 +// } //for out edges wv
2.444 +
2.445 +// if ( exc > 0 ) {
2.446 +// InEdgeIt e;
2.447 +// for(g->first(e,w); g->valid(e); g->next(e)) {
2.448 +
2.449 +// if( (*flow)[e] <= 0 ) continue;
2.450 +// Node v=g->tail(e);
2.451 +
2.452 +// if( lev > level[v] ) { //Push is allowed now
2.453 +
2.454 +// if ( excess[v]<=0 && v!=t && v!=s ) {
2.455 +// int lev_v=level[v];
2.456 +// active[lev_v].push(v);
2.457 +// }
2.458 +
2.459 +// Num flo=(*flow)[e];
2.460 +
2.461 +// if ( flo >= exc ) { //A nonsaturating push.
2.462 +
2.463 +// flow->set(e, flo-exc);
2.464 +// excess.set(v, excess[v]+exc);
2.465 +// exc=0;
2.466 +// break;
2.467 +// } else { //A saturating push.
2.468 +
2.469 +// excess.set(v, excess[v]+flo);
2.470 +// exc-=flo;
2.471 +// flow->set(e,0);
2.472 +// }
2.473 +// } else if ( newlevel > level[v] ) newlevel = level[v];
2.474 +// } //for in edges vw
2.475 +
2.476 +// } // if w still has excess after the out edge for cycle
2.477 +
2.478 +// excess.set(w, exc);
2.479 +
2.480 +// return newlevel;
2.481 +// }
2.482 +
2.483 +
2.484 +// void preflowPreproc(FlowEnum fe, VecStack& active,
2.485 +// VecNode& level_list, NNMap& left, NNMap& right)
2.486 +// {
2.487 +// std::queue<Node> bfs_queue;
2.488 +
2.489 +// switch (fe) {
2.490 +// case NO_FLOW: //flow is already set to const zero in this case
2.491 +// case ZERO_FLOW:
2.492 +// {
2.493 +// //Reverse_bfs from t, to find the starting level.
2.494 +// level.set(t,0);
2.495 +// bfs_queue.push(t);
2.496 +
2.497 +// while (!bfs_queue.empty()) {
2.498 +
2.499 +// Node v=bfs_queue.front();
2.500 +// bfs_queue.pop();
2.501 +// int l=level[v]+1;
2.502 +
2.503 +// InEdgeIt e;
2.504 +// for(g->first(e,v); g->valid(e); g->next(e)) {
2.505 +// Node w=g->tail(e);
2.506 +// if ( level[w] == n && w != s ) {
2.507 +// bfs_queue.push(w);
2.508 +// Node first=level_list[l];
2.509 +// if ( g->valid(first) ) left.set(first,w);
2.510 +// right.set(w,first);
2.511 +// level_list[l]=w;
2.512 +// level.set(w, l);
2.513 +// }
2.514 +// }
2.515 +// }
2.516 +
2.517 +// //the starting flow
2.518 +// OutEdgeIt e;
2.519 +// for(g->first(e,s); g->valid(e); g->next(e))
2.520 +// {
2.521 +// Num c=(*capacity)[e];
2.522 +// if ( c <= 0 ) continue;
2.523 +// Node w=g->head(e);
2.524 +// if ( level[w] < n ) {
2.525 +// if ( excess[w] <= 0 && w!=t ) active[level[w]].push(w);
2.526 +// flow->set(e, c);
2.527 +// excess.set(w, excess[w]+c);
2.528 +// }
2.529 +// }
2.530 +// break;
2.531 +// }
2.532 +
2.533 +// case GEN_FLOW:
2.534 +// case PRE_FLOW:
2.535 +// {
2.536 +// //Reverse_bfs from t in the residual graph,
2.537 +// //to find the starting level.
2.538 +// level.set(t,0);
2.539 +// bfs_queue.push(t);
2.540 +
2.541 +// while (!bfs_queue.empty()) {
2.542 +
2.543 +// Node v=bfs_queue.front();
2.544 +// bfs_queue.pop();
2.545 +// int l=level[v]+1;
2.546 +
2.547 +// InEdgeIt e;
2.548 +// for(g->first(e,v); g->valid(e); g->next(e)) {
2.549 +// if ( (*capacity)[e] <= (*flow)[e] ) continue;
2.550 +// Node w=g->tail(e);
2.551 +// if ( level[w] == n && w != s ) {
2.552 +// bfs_queue.push(w);
2.553 +// Node first=level_list[l];
2.554 +// if ( g->valid(first) ) left.set(first,w);
2.555 +// right.set(w,first);
2.556 +// level_list[l]=w;
2.557 +// level.set(w, l);
2.558 +// }
2.559 +// }
2.560 +
2.561 +// OutEdgeIt f;
2.562 +// for(g->first(f,v); g->valid(f); g->next(f)) {
2.563 +// if ( 0 >= (*flow)[f] ) continue;
2.564 +// Node w=g->head(f);
2.565 +// if ( level[w] == n && w != s ) {
2.566 +// bfs_queue.push(w);
2.567 +// Node first=level_list[l];
2.568 +// if ( g->valid(first) ) left.set(first,w);
2.569 +// right.set(w,first);
2.570 +// level_list[l]=w;
2.571 +// level.set(w, l);
2.572 +// }
2.573 +// }
2.574 +// }
2.575 +
2.576 +
2.577 +// //the starting flow
2.578 +// OutEdgeIt e;
2.579 +// for(g->first(e,s); g->valid(e); g->next(e))
2.580 +// {
2.581 +// Num rem=(*capacity)[e]-(*flow)[e];
2.582 +// if ( rem <= 0 ) continue;
2.583 +// Node w=g->head(e);
2.584 +// if ( level[w] < n ) {
2.585 +// if ( excess[w] <= 0 && w!=t ) active[level[w]].push(w);
2.586 +// flow->set(e, (*capacity)[e]);
2.587 +// excess.set(w, excess[w]+rem);
2.588 +// }
2.589 +// }
2.590 +
2.591 +// InEdgeIt f;
2.592 +// for(g->first(f,s); g->valid(f); g->next(f))
2.593 +// {
2.594 +// if ( (*flow)[f] <= 0 ) continue;
2.595 +// Node w=g->tail(f);
2.596 +// if ( level[w] < n ) {
2.597 +// if ( excess[w] <= 0 && w!=t ) active[level[w]].push(w);
2.598 +// excess.set(w, excess[w]+(*flow)[f]);
2.599 +// flow->set(f, 0);
2.600 +// }
2.601 +// }
2.602 +// break;
2.603 +// } //case PRE_FLOW
2.604 +// }
2.605 +// } //preflowPreproc
2.606 +
2.607 +
2.608 +
2.609 +// void relabel(Node w, int newlevel, VecStack& active,
2.610 +// VecNode& level_list, NNMap& left,
2.611 +// NNMap& right, int& b, int& k, bool what_heur )
2.612 +// {
2.613 +
2.614 +// //FIXME jacint: ez mitol num
2.615 +// // Num lev=level[w];
2.616 +// int lev=level[w];
2.617 +
2.618 +// Node right_n=right[w];
2.619 +// Node left_n=left[w];
2.620 +
2.621 +// //unlacing starts
2.622 +// if ( g->valid(right_n) ) {
2.623 +// if ( g->valid(left_n) ) {
2.624 +// right.set(left_n, right_n);
2.625 +// left.set(right_n, left_n);
2.626 +// } else {
2.627 +// level_list[lev]=right_n;
2.628 +// left.set(right_n, INVALID);
2.629 +// }
2.630 +// } else {
2.631 +// if ( g->valid(left_n) ) {
2.632 +// right.set(left_n, INVALID);
2.633 +// } else {
2.634 +// level_list[lev]=INVALID;
2.635 +// }
2.636 +// }
2.637 +// //unlacing ends
2.638 +
2.639 +// if ( !g->valid(level_list[lev]) ) {
2.640 +
2.641 +// //gapping starts
2.642 +// for (int i=lev; i!=k ; ) {
2.643 +// Node v=level_list[++i];
2.644 +// while ( g->valid(v) ) {
2.645 +// level.set(v,n);
2.646 +// v=right[v];
2.647 +// }
2.648 +// level_list[i]=INVALID;
2.649 +// if ( !what_heur ) {
2.650 +// while ( !active[i].empty() ) {
2.651 +// active[i].pop(); //FIXME: ezt szebben kene
2.652 +// }
2.653 +// }
2.654 +// }
2.655 +
2.656 +// level.set(w,n);
2.657 +// b=lev-1;
2.658 +// k=b;
2.659 +// //gapping ends
2.660 +
2.661 +// } else {
2.662 +
2.663 +// if ( newlevel == n ) level.set(w,n);
2.664 +// else {
2.665 +// level.set(w,++newlevel);
2.666 +// active[newlevel].push(w);
2.667 +// if ( what_heur ) b=newlevel;
2.668 +// if ( k < newlevel ) ++k; //now k=newlevel
2.669 +// Node first=level_list[newlevel];
2.670 +// if ( g->valid(first) ) left.set(first,w);
2.671 +// right.set(w,first);
2.672 +// left.set(w,INVALID);
2.673 +// level_list[newlevel]=w;
2.674 +// }
2.675 +// }
2.676 +
2.677 +// } //relabel
2.678 +
2.679 +// };
2.680 +
2.681 +
2.682 +
2.683 +// template <typename Graph, typename Num, typename CapMap, typename FlowMap>
2.684 +// void MaxFlow<Graph, Num, CapMap, FlowMap>::preflowPhase1(FlowEnum fe)
2.685 +// {
2.686 +
2.687 +// int heur0=(int)(H0*n); //time while running 'bound decrease'
2.688 +// int heur1=(int)(H1*n); //time while running 'highest label'
2.689 +// int heur=heur1; //starting time interval (#of relabels)
2.690 +// int numrelabel=0;
2.691 +
2.692 +// bool what_heur=1;
2.693 +// //It is 0 in case 'bound decrease' and 1 in case 'highest label'
2.694 +
2.695 +// bool end=false;
2.696 +// //Needed for 'bound decrease', true means no active nodes are above bound
2.697 +// //b.
2.698 +
2.699 +// int k=n-2; //bound on the highest level under n containing a node
2.700 +// int b=k; //bound on the highest level under n of an active node
2.701 +
2.702 +// VecStack active(n);
2.703 +
2.704 +// NNMap left(*g, INVALID);
2.705 +// NNMap right(*g, INVALID);
2.706 +// VecNode level_list(n,INVALID);
2.707 +// //List of the nodes in level i<n, set to n.
2.708 +
2.709 +// NodeIt v;
2.710 +// for(g->first(v); g->valid(v); g->next(v)) level.set(v,n);
2.711 +// //setting each node to level n
2.712 +
2.713 +// if ( fe == NO_FLOW ) {
2.714 +// EdgeIt e;
2.715 +// for(g->first(e); g->valid(e); g->next(e)) flow->set(e,0);
2.716 +// }
2.717 +
2.718 +// switch (fe) { //computing the excess
2.719 +// case PRE_FLOW:
2.720 +// {
2.721 +// NodeIt v;
2.722 +// for(g->first(v); g->valid(v); g->next(v)) {
2.723 +// Num exc=0;
2.724 +
2.725 +// InEdgeIt e;
2.726 +// for(g->first(e,v); g->valid(e); g->next(e)) exc+=(*flow)[e];
2.727 +// OutEdgeIt f;
2.728 +// for(g->first(f,v); g->valid(f); g->next(f)) exc-=(*flow)[f];
2.729 +
2.730 +// excess.set(v,exc);
2.731 +
2.732 +// //putting the active nodes into the stack
2.733 +// int lev=level[v];
2.734 +// if ( exc > 0 && lev < n && v != t ) active[lev].push(v);
2.735 +// }
2.736 +// break;
2.737 +// }
2.738 +// case GEN_FLOW:
2.739 +// {
2.740 +// NodeIt v;
2.741 +// for(g->first(v); g->valid(v); g->next(v)) excess.set(v,0);
2.742 +
2.743 +// Num exc=0;
2.744 +// InEdgeIt e;
2.745 +// for(g->first(e,t); g->valid(e); g->next(e)) exc+=(*flow)[e];
2.746 +// OutEdgeIt f;
2.747 +// for(g->first(f,t); g->valid(f); g->next(f)) exc-=(*flow)[f];
2.748 +// excess.set(t,exc);
2.749 +// break;
2.750 +// }
2.751 +// case ZERO_FLOW:
2.752 +// case NO_FLOW:
2.753 +// {
2.754 +// NodeIt v;
2.755 +// for(g->first(v); g->valid(v); g->next(v)) excess.set(v,0);
2.756 +// break;
2.757 +// }
2.758 +// }
2.759 +
2.760 +// preflowPreproc(fe, active, level_list, left, right);
2.761 +// //End of preprocessing
2.762 +
2.763 +
2.764 +// //Push/relabel on the highest level active nodes.
2.765 +// while ( true ) {
2.766 +// if ( b == 0 ) {
2.767 +// if ( !what_heur && !end && k > 0 ) {
2.768 +// b=k;
2.769 +// end=true;
2.770 +// } else break;
2.771 +// }
2.772 +
2.773 +// if ( active[b].empty() ) --b;
2.774 +// else {
2.775 +// end=false;
2.776 +// Node w=active[b].top();
2.777 +// active[b].pop();
2.778 +// int newlevel=push(w,active);
2.779 +// if ( excess[w] > 0 ) relabel(w, newlevel, active, level_list,
2.780 +// left, right, b, k, what_heur);
2.781 +
2.782 +// ++numrelabel;
2.783 +// if ( numrelabel >= heur ) {
2.784 +// numrelabel=0;
2.785 +// if ( what_heur ) {
2.786 +// what_heur=0;
2.787 +// heur=heur0;
2.788 +// end=false;
2.789 +// } else {
2.790 +// what_heur=1;
2.791 +// heur=heur1;
2.792 +// b=k;
2.793 +// }
2.794 +// }
2.795 +// }
2.796 +// }
2.797 +
2.798 +// status=AFTER_PRE_FLOW_PHASE_1;
2.799 +// }
2.800 +
2.801 +
2.802 +
2.803 +// template <typename Graph, typename Num, typename CapMap, typename FlowMap>
2.804 +// void MaxFlow<Graph, Num, CapMap, FlowMap>::preflowPhase2()
2.805 +// {
2.806 +
2.807 +// int k=n-2; //bound on the highest level under n containing a node
2.808 +// int b=k; //bound on the highest level under n of an active node
2.809 +
2.810 +// VecStack active(n);
2.811 +// level.set(s,0);
2.812 +// std::queue<Node> bfs_queue;
2.813 +// bfs_queue.push(s);
2.814 +
2.815 +// while (!bfs_queue.empty()) {
2.816 +
2.817 +// Node v=bfs_queue.front();
2.818 +// bfs_queue.pop();
2.819 +// int l=level[v]+1;
2.820 +
2.821 +// InEdgeIt e;
2.822 +// for(g->first(e,v); g->valid(e); g->next(e)) {
2.823 +// if ( (*capacity)[e] <= (*flow)[e] ) continue;
2.824 +// Node u=g->tail(e);
2.825 +// if ( level[u] >= n ) {
2.826 +// bfs_queue.push(u);
2.827 +// level.set(u, l);
2.828 +// if ( excess[u] > 0 ) active[l].push(u);
2.829 +// }
2.830 +// }
2.831 +
2.832 +// OutEdgeIt f;
2.833 +// for(g->first(f,v); g->valid(f); g->next(f)) {
2.834 +// if ( 0 >= (*flow)[f] ) continue;
2.835 +// Node u=g->head(f);
2.836 +// if ( level[u] >= n ) {
2.837 +// bfs_queue.push(u);
2.838 +// level.set(u, l);
2.839 +// if ( excess[u] > 0 ) active[l].push(u);
2.840 +// }
2.841 +// }
2.842 +// }
2.843 +// b=n-2;
2.844 +
2.845 +// while ( true ) {
2.846 +
2.847 +// if ( b == 0 ) break;
2.848 +
2.849 +// if ( active[b].empty() ) --b;
2.850 +// else {
2.851 +// Node w=active[b].top();
2.852 +// active[b].pop();
2.853 +// int newlevel=push(w,active);
2.854 +
2.855 +// //relabel
2.856 +// if ( excess[w] > 0 ) {
2.857 +// level.set(w,++newlevel);
2.858 +// active[newlevel].push(w);
2.859 +// b=newlevel;
2.860 +// }
2.861 +// } // if stack[b] is nonempty
2.862 +// } // while(true)
2.863 +
2.864 +// status=AFTER_PRE_FLOW_PHASE_2;
2.865 +// }
2.866 +
2.867 +
2.868 + template <typename Graph, typename Num,
2.869 + typename CapMap=typename Graph::template EdgeMap<Num>,
2.870 + typename FlowMap=typename Graph::template EdgeMap<Num> >
2.871 + class AugmentingFlow {
2.872 + protected:
2.873 + typedef typename Graph::Node Node;
2.874 + typedef typename Graph::NodeIt NodeIt;
2.875 + typedef typename Graph::EdgeIt EdgeIt;
2.876 + typedef typename Graph::OutEdgeIt OutEdgeIt;
2.877 + typedef typename Graph::InEdgeIt InEdgeIt;
2.878 +
2.879 +// typedef typename std::vector<std::stack<Node> > VecStack;
2.880 +// typedef typename Graph::template NodeMap<Node> NNMap;
2.881 +// typedef typename std::vector<Node> VecNode;
2.882 +
2.883 + const Graph* g;
2.884 + Node s;
2.885 + Node t;
2.886 + const CapMap* capacity;
2.887 + FlowMap* flow;
2.888 +// int n; //the number of nodes of G
2.889 + typedef ResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW;
2.890 + //typedef ExpResGraphWrapper<const Graph, Num, CapMap, FlowMap> ResGW;
2.891 + typedef typename ResGW::OutEdgeIt ResGWOutEdgeIt;
2.892 + typedef typename ResGW::Edge ResGWEdge;
2.893 + //typedef typename ResGW::template NodeMap<bool> ReachedMap;
2.894 + typedef typename Graph::template NodeMap<int> ReachedMap;
2.895 +
2.896 +
2.897 + //level works as a bool map in augmenting path algorithms and is
2.898 + //used by bfs for storing reached information. In preflow, it
2.899 + //shows the levels of nodes.
2.900 + ReachedMap level;
2.901 +
2.902 + //excess is needed only in preflow
2.903 +// typename Graph::template NodeMap<Num> excess;
2.904 +
2.905 + //fixme
2.906 +// protected:
2.907 + // MaxFlow() { }
2.908 + // void set(const Graph& _G, Node _s, Node _t, const CapMap& _capacity,
2.909 + // FlowMap& _flow)
2.910 + // {
2.911 + // g=&_G;
2.912 + // s=_s;
2.913 + // t=_t;
2.914 + // capacity=&_capacity;
2.915 + // flow=&_flow;
2.916 + // n=_G.nodeNum;
2.917 + // level.set (_G); //kellene vmi ilyesmi fv
2.918 + // excess(_G,0); //itt is
2.919 + // }
2.920 +
2.921 + // constants used for heuristics
2.922 +// static const int H0=20;
2.923 +// static const int H1=1;
2.924 +
2.925 + public:
2.926 +
2.927 + ///Indicates the property of the starting flow.
2.928 +
2.929 + ///Indicates the property of the starting flow. The meanings are as follows:
2.930 + ///- \c ZERO_FLOW: constant zero flow
2.931 + ///- \c GEN_FLOW: any flow, i.e. the sum of the in-flows equals to
2.932 + ///the sum of the out-flows in every node except the \e source and
2.933 + ///the \e target.
2.934 + ///- \c PRE_FLOW: any preflow, i.e. the sum of the in-flows is at
2.935 + ///least the sum of the out-flows in every node except the \e source.
2.936 + ///- \c NO_FLOW: indicates an unspecified edge map. \ref flow will be
2.937 + ///set to the constant zero flow in the beginning of the algorithm in this case.
2.938 + enum FlowEnum{
2.939 + ZERO_FLOW,
2.940 + GEN_FLOW,
2.941 + PRE_FLOW,
2.942 + NO_FLOW
2.943 + };
2.944 +
2.945 + enum StatusEnum {
2.946 + AFTER_NOTHING,
2.947 + AFTER_AUGMENTING,
2.948 + AFTER_FAST_AUGMENTING,
2.949 + AFTER_PRE_FLOW_PHASE_1,
2.950 + AFTER_PRE_FLOW_PHASE_2
2.951 + };
2.952 +
2.953 + /// Don not needle this flag only if necessary.
2.954 + StatusEnum status;
2.955 + int number_of_augmentations;
2.956 +
2.957 +
2.958 + template<typename IntMap>
2.959 + class TrickyReachedMap {
2.960 + protected:
2.961 + IntMap* map;
2.962 + int* number_of_augmentations;
2.963 + public:
2.964 + TrickyReachedMap(IntMap& _map, int& _number_of_augmentations) :
2.965 + map(&_map), number_of_augmentations(&_number_of_augmentations) { }
2.966 + void set(const Node& n, bool b) {
2.967 + if (b)
2.968 + map->set(n, *number_of_augmentations);
2.969 + else
2.970 + map->set(n, *number_of_augmentations-1);
2.971 + }
2.972 + bool operator[](const Node& n) const {
2.973 + return (*map)[n]==*number_of_augmentations;
2.974 + }
2.975 + };
2.976 +
2.977 + AugmentingFlow(const Graph& _G, Node _s, Node _t, const CapMap& _capacity,
2.978 + FlowMap& _flow) :
2.979 + g(&_G), s(_s), t(_t), capacity(&_capacity),
2.980 + flow(&_flow), //n(_G.nodeNum()),
2.981 + level(_G), //excess(_G,0),
2.982 + status(AFTER_NOTHING), number_of_augmentations(0) { }
2.983 +
2.984 + /// Starting from a flow, this method searches for an augmenting path
2.985 + /// according to the Edmonds-Karp algorithm
2.986 + /// and augments the flow on if any.
2.987 + /// The return value shows if the augmentation was succesful.
2.988 + bool augmentOnShortestPath();
2.989 + bool augmentOnShortestPath2();
2.990 +
2.991 + /// Starting from a flow, this method searches for an augmenting blocking
2.992 + /// flow according to Dinits' algorithm and augments the flow on if any.
2.993 + /// The blocking flow is computed in a physically constructed
2.994 + /// residual graph of type \c Mutablegraph.
2.995 + /// The return value show sif the augmentation was succesful.
2.996 + template<typename MutableGraph> bool augmentOnBlockingFlow();
2.997 +
2.998 + /// The same as \c augmentOnBlockingFlow<MutableGraph> but the
2.999 + /// residual graph is not constructed physically.
2.1000 + /// The return value shows if the augmentation was succesful.
2.1001 + bool augmentOnBlockingFlow2();
2.1002 +
2.1003 + template<typename _CutMap>
2.1004 + void actMinCut(_CutMap& M) const {
2.1005 + NodeIt v;
2.1006 + switch (status) {
2.1007 + case AFTER_PRE_FLOW_PHASE_1:
2.1008 +// std::cout << "AFTER_PRE_FLOW_PHASE_1" << std::endl;
2.1009 +// for(g->first(v); g->valid(v); g->next(v)) {
2.1010 +// if (level[v] < n) {
2.1011 +// M.set(v, false);
2.1012 +// } else {
2.1013 +// M.set(v, true);
2.1014 +// }
2.1015 +// }
2.1016 + break;
2.1017 + case AFTER_PRE_FLOW_PHASE_2:
2.1018 +// std::cout << "AFTER_PRE_FLOW_PHASE_2" << std::endl;
2.1019 + break;
2.1020 + case AFTER_NOTHING:
2.1021 +// std::cout << "AFTER_NOTHING" << std::endl;
2.1022 + minMinCut(M);
2.1023 + break;
2.1024 + case AFTER_AUGMENTING:
2.1025 +// std::cout << "AFTER_AUGMENTING" << std::endl;
2.1026 + for(g->first(v); g->valid(v); g->next(v)) {
2.1027 + if (level[v]) {
2.1028 + M.set(v, true);
2.1029 + } else {
2.1030 + M.set(v, false);
2.1031 + }
2.1032 + }
2.1033 + break;
2.1034 + case AFTER_FAST_AUGMENTING:
2.1035 +// std::cout << "AFTER_FAST_AUGMENTING" << std::endl;
2.1036 + for(g->first(v); g->valid(v); g->next(v)) {
2.1037 + if (level[v]==number_of_augmentations) {
2.1038 + M.set(v, true);
2.1039 + } else {
2.1040 + M.set(v, false);
2.1041 + }
2.1042 + }
2.1043 + break;
2.1044 + }
2.1045 + }
2.1046 +
2.1047 + template<typename _CutMap>
2.1048 + void minMinCut(_CutMap& M) const {
2.1049 + std::queue<Node> queue;
2.1050 +
2.1051 + M.set(s,true);
2.1052 + queue.push(s);
2.1053 +
2.1054 + while (!queue.empty()) {
2.1055 + Node w=queue.front();
2.1056 + queue.pop();
2.1057 +
2.1058 + OutEdgeIt e;
2.1059 + for(g->first(e,w) ; g->valid(e); g->next(e)) {
2.1060 + Node v=g->head(e);
2.1061 + if (!M[v] && (*flow)[e] < (*capacity)[e] ) {
2.1062 + queue.push(v);
2.1063 + M.set(v, true);
2.1064 + }
2.1065 + }
2.1066 +
2.1067 + InEdgeIt f;
2.1068 + for(g->first(f,w) ; g->valid(f); g->next(f)) {
2.1069 + Node v=g->tail(f);
2.1070 + if (!M[v] && (*flow)[f] > 0 ) {
2.1071 + queue.push(v);
2.1072 + M.set(v, true);
2.1073 + }
2.1074 + }
2.1075 + }
2.1076 + }
2.1077 +
2.1078 + template<typename _CutMap>
2.1079 + void minMinCut2(_CutMap& M) const {
2.1080 + ResGW res_graph(*g, *capacity, *flow);
2.1081 + BfsIterator<ResGW, _CutMap> bfs(res_graph, M);
2.1082 + bfs.pushAndSetReached(s);
2.1083 + while (!bfs.finished()) ++bfs;
2.1084 + }
2.1085 +
2.1086 + Num flowValue() const {
2.1087 + Num a=0;
2.1088 + FOR_EACH_INC_LOC(InEdgeIt, e, *g, t) a+=(*flow)[e];
2.1089 + FOR_EACH_INC_LOC(OutEdgeIt, e, *g, t) a-=(*flow)[e];
2.1090 + return a;
2.1091 + //marci figyu: excess[t] epp ezt adja preflow 1. fazisa utan
2.1092 + }
2.1093 +
2.1094 + template<typename MapGraphWrapper>
2.1095 + class DistanceMap {
2.1096 + protected:
2.1097 + const MapGraphWrapper* g;
2.1098 + typename MapGraphWrapper::template NodeMap<int> dist;
2.1099 + public:
2.1100 + DistanceMap(MapGraphWrapper& _g) : g(&_g), dist(*g, g->nodeNum()) { }
2.1101 + void set(const typename MapGraphWrapper::Node& n, int a) {
2.1102 + dist.set(n, a);
2.1103 + }
2.1104 + int operator[](const typename MapGraphWrapper::Node& n) const {
2.1105 + return dist[n];
2.1106 + }
2.1107 + // int get(const typename MapGraphWrapper::Node& n) const {
2.1108 + // return dist[n]; }
2.1109 + // bool get(const typename MapGraphWrapper::Edge& e) const {
2.1110 + // return (dist.get(g->tail(e))<dist.get(g->head(e))); }
2.1111 + bool operator[](const typename MapGraphWrapper::Edge& e) const {
2.1112 + return (dist[g->tail(e)]<dist[g->head(e)]);
2.1113 + }
2.1114 + };
2.1115 +
2.1116 + };
2.1117 +
2.1118 +
2.1119 +
2.1120 + template <typename Graph, typename Num, typename CapMap, typename FlowMap>
2.1121 + bool AugmentingFlow<Graph, Num, CapMap, FlowMap>::augmentOnShortestPath()
2.1122 + {
2.1123 + ResGW res_graph(*g, *capacity, *flow);
2.1124 + bool _augment=false;
2.1125 +
2.1126 + //ReachedMap level(res_graph);
2.1127 + FOR_EACH_LOC(typename Graph::NodeIt, e, *g) level.set(e, 0);
2.1128 + BfsIterator<ResGW, ReachedMap> bfs(res_graph, level);
2.1129 + bfs.pushAndSetReached(s);
2.1130 +
2.1131 + typename ResGW::template NodeMap<ResGWEdge> pred(res_graph);
2.1132 + pred.set(s, INVALID);
2.1133 +
2.1134 + typename ResGW::template NodeMap<Num> free(res_graph);
2.1135 +
2.1136 + //searching for augmenting path
2.1137 + while ( !bfs.finished() ) {
2.1138 + ResGWOutEdgeIt e=bfs;
2.1139 + if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
2.1140 + Node v=res_graph.tail(e);
2.1141 + Node w=res_graph.head(e);
2.1142 + pred.set(w, e);
2.1143 + if (res_graph.valid(pred[v])) {
2.1144 + free.set(w, std::min(free[v], res_graph.resCap(e)));
2.1145 + } else {
2.1146 + free.set(w, res_graph.resCap(e));
2.1147 + }
2.1148 + if (res_graph.head(e)==t) { _augment=true; break; }
2.1149 + }
2.1150 +
2.1151 + ++bfs;
2.1152 + } //end of searching augmenting path
2.1153 +
2.1154 + if (_augment) {
2.1155 + Node n=t;
2.1156 + Num augment_value=free[t];
2.1157 + while (res_graph.valid(pred[n])) {
2.1158 + ResGWEdge e=pred[n];
2.1159 + res_graph.augment(e, augment_value);
2.1160 + n=res_graph.tail(e);
2.1161 + }
2.1162 + }
2.1163 +
2.1164 + status=AFTER_AUGMENTING;
2.1165 + return _augment;
2.1166 + }
2.1167 +
2.1168 + template <typename Graph, typename Num, typename CapMap, typename FlowMap>
2.1169 + bool AugmentingFlow<Graph, Num, CapMap, FlowMap>::augmentOnShortestPath2()
2.1170 + {
2.1171 + ResGW res_graph(*g, *capacity, *flow);
2.1172 + bool _augment=false;
2.1173 +
2.1174 + if (status!=AFTER_FAST_AUGMENTING) {
2.1175 + FOR_EACH_LOC(typename Graph::NodeIt, e, *g) level.set(e, 0);
2.1176 + number_of_augmentations=1;
2.1177 + } else {
2.1178 + ++number_of_augmentations;
2.1179 + }
2.1180 + TrickyReachedMap<ReachedMap>
2.1181 + tricky_reached_map(level, number_of_augmentations);
2.1182 + //ReachedMap level(res_graph);
2.1183 +// FOR_EACH_LOC(typename Graph::NodeIt, e, *g) level.set(e, 0);
2.1184 + BfsIterator<ResGW, TrickyReachedMap<ReachedMap> >
2.1185 + bfs(res_graph, tricky_reached_map);
2.1186 + bfs.pushAndSetReached(s);
2.1187 +
2.1188 + typename ResGW::template NodeMap<ResGWEdge> pred(res_graph);
2.1189 + pred.set(s, INVALID);
2.1190 +
2.1191 + typename ResGW::template NodeMap<Num> free(res_graph);
2.1192 +
2.1193 + //searching for augmenting path
2.1194 + while ( !bfs.finished() ) {
2.1195 + ResGWOutEdgeIt e=bfs;
2.1196 + if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
2.1197 + Node v=res_graph.tail(e);
2.1198 + Node w=res_graph.head(e);
2.1199 + pred.set(w, e);
2.1200 + if (res_graph.valid(pred[v])) {
2.1201 + free.set(w, std::min(free[v], res_graph.resCap(e)));
2.1202 + } else {
2.1203 + free.set(w, res_graph.resCap(e));
2.1204 + }
2.1205 + if (res_graph.head(e)==t) { _augment=true; break; }
2.1206 + }
2.1207 +
2.1208 + ++bfs;
2.1209 + } //end of searching augmenting path
2.1210 +
2.1211 + if (_augment) {
2.1212 + Node n=t;
2.1213 + Num augment_value=free[t];
2.1214 + while (res_graph.valid(pred[n])) {
2.1215 + ResGWEdge e=pred[n];
2.1216 + res_graph.augment(e, augment_value);
2.1217 + n=res_graph.tail(e);
2.1218 + }
2.1219 + }
2.1220 +
2.1221 + status=AFTER_FAST_AUGMENTING;
2.1222 + return _augment;
2.1223 + }
2.1224 +
2.1225 +
2.1226 + template <typename Graph, typename Num, typename CapMap, typename FlowMap>
2.1227 + template<typename MutableGraph>
2.1228 + bool AugmentingFlow<Graph, Num, CapMap, FlowMap>::augmentOnBlockingFlow()
2.1229 + {
2.1230 + typedef MutableGraph MG;
2.1231 + bool _augment=false;
2.1232 +
2.1233 + ResGW res_graph(*g, *capacity, *flow);
2.1234 +
2.1235 + //bfs for distances on the residual graph
2.1236 + //ReachedMap level(res_graph);
2.1237 + FOR_EACH_LOC(typename Graph::NodeIt, e, *g) level.set(e, 0);
2.1238 + BfsIterator<ResGW, ReachedMap> bfs(res_graph, level);
2.1239 + bfs.pushAndSetReached(s);
2.1240 + typename ResGW::template NodeMap<int>
2.1241 + dist(res_graph); //filled up with 0's
2.1242 +
2.1243 + //F will contain the physical copy of the residual graph
2.1244 + //with the set of edges which are on shortest paths
2.1245 + MG F;
2.1246 + typename ResGW::template NodeMap<typename MG::Node>
2.1247 + res_graph_to_F(res_graph);
2.1248 + {
2.1249 + typename ResGW::NodeIt n;
2.1250 + for(res_graph.first(n); res_graph.valid(n); res_graph.next(n)) {
2.1251 + res_graph_to_F.set(n, F.addNode());
2.1252 + }
2.1253 + }
2.1254 +
2.1255 + typename MG::Node sF=res_graph_to_F[s];
2.1256 + typename MG::Node tF=res_graph_to_F[t];
2.1257 + typename MG::template EdgeMap<ResGWEdge> original_edge(F);
2.1258 + typename MG::template EdgeMap<Num> residual_capacity(F);
2.1259 +
2.1260 + while ( !bfs.finished() ) {
2.1261 + ResGWOutEdgeIt e=bfs;
2.1262 + if (res_graph.valid(e)) {
2.1263 + if (bfs.isBNodeNewlyReached()) {
2.1264 + dist.set(res_graph.head(e), dist[res_graph.tail(e)]+1);
2.1265 + typename MG::Edge f=F.addEdge(res_graph_to_F[res_graph.tail(e)],
2.1266 + res_graph_to_F[res_graph.head(e)]);
2.1267 + original_edge.update();
2.1268 + original_edge.set(f, e);
2.1269 + residual_capacity.update();
2.1270 + residual_capacity.set(f, res_graph.resCap(e));
2.1271 + } else {
2.1272 + if (dist[res_graph.head(e)]==(dist[res_graph.tail(e)]+1)) {
2.1273 + typename MG::Edge f=F.addEdge(res_graph_to_F[res_graph.tail(e)],
2.1274 + res_graph_to_F[res_graph.head(e)]);
2.1275 + original_edge.update();
2.1276 + original_edge.set(f, e);
2.1277 + residual_capacity.update();
2.1278 + residual_capacity.set(f, res_graph.resCap(e));
2.1279 + }
2.1280 + }
2.1281 + }
2.1282 + ++bfs;
2.1283 + } //computing distances from s in the residual graph
2.1284 +
2.1285 + bool __augment=true;
2.1286 +
2.1287 + while (__augment) {
2.1288 + __augment=false;
2.1289 + //computing blocking flow with dfs
2.1290 + DfsIterator< MG, typename MG::template NodeMap<bool> > dfs(F);
2.1291 + typename MG::template NodeMap<typename MG::Edge> pred(F);
2.1292 + pred.set(sF, INVALID);
2.1293 + //invalid iterators for sources
2.1294 +
2.1295 + typename MG::template NodeMap<Num> free(F);
2.1296 +
2.1297 + dfs.pushAndSetReached(sF);
2.1298 + while (!dfs.finished()) {
2.1299 + ++dfs;
2.1300 + if (F.valid(/*typename MG::OutEdgeIt*/(dfs))) {
2.1301 + if (dfs.isBNodeNewlyReached()) {
2.1302 + typename MG::Node v=F.aNode(dfs);
2.1303 + typename MG::Node w=F.bNode(dfs);
2.1304 + pred.set(w, dfs);
2.1305 + if (F.valid(pred[v])) {
2.1306 + free.set(w, std::min(free[v], residual_capacity[dfs]));
2.1307 + } else {
2.1308 + free.set(w, residual_capacity[dfs]);
2.1309 + }
2.1310 + if (w==tF) {
2.1311 + __augment=true;
2.1312 + _augment=true;
2.1313 + break;
2.1314 + }
2.1315 +
2.1316 + } else {
2.1317 + F.erase(/*typename MG::OutEdgeIt*/(dfs));
2.1318 + }
2.1319 + }
2.1320 + }
2.1321 +
2.1322 + if (__augment) {
2.1323 + typename MG::Node n=tF;
2.1324 + Num augment_value=free[tF];
2.1325 + while (F.valid(pred[n])) {
2.1326 + typename MG::Edge e=pred[n];
2.1327 + res_graph.augment(original_edge[e], augment_value);
2.1328 + n=F.tail(e);
2.1329 + if (residual_capacity[e]==augment_value)
2.1330 + F.erase(e);
2.1331 + else
2.1332 + residual_capacity.set(e, residual_capacity[e]-augment_value);
2.1333 + }
2.1334 + }
2.1335 +
2.1336 + }
2.1337 +
2.1338 + status=AFTER_AUGMENTING;
2.1339 + return _augment;
2.1340 + }
2.1341 +
2.1342 +
2.1343 +
2.1344 +
2.1345 + template <typename Graph, typename Num, typename CapMap, typename FlowMap>
2.1346 + bool AugmentingFlow<Graph, Num, CapMap, FlowMap>::augmentOnBlockingFlow2()
2.1347 + {
2.1348 + bool _augment=false;
2.1349 +
2.1350 + ResGW res_graph(*g, *capacity, *flow);
2.1351 +
2.1352 + //ReachedMap level(res_graph);
2.1353 + FOR_EACH_LOC(typename Graph::NodeIt, e, *g) level.set(e, 0);
2.1354 + BfsIterator<ResGW, ReachedMap> bfs(res_graph, level);
2.1355 +
2.1356 + bfs.pushAndSetReached(s);
2.1357 + DistanceMap<ResGW> dist(res_graph);
2.1358 + while ( !bfs.finished() ) {
2.1359 + ResGWOutEdgeIt e=bfs;
2.1360 + if (res_graph.valid(e) && bfs.isBNodeNewlyReached()) {
2.1361 + dist.set(res_graph.head(e), dist[res_graph.tail(e)]+1);
2.1362 + }
2.1363 + ++bfs;
2.1364 + } //computing distances from s in the residual graph
2.1365 +
2.1366 + //Subgraph containing the edges on some shortest paths
2.1367 + ConstMap<typename ResGW::Node, bool> true_map(true);
2.1368 + typedef SubGraphWrapper<ResGW, ConstMap<typename ResGW::Node, bool>,
2.1369 + DistanceMap<ResGW> > FilterResGW;
2.1370 + FilterResGW filter_res_graph(res_graph, true_map, dist);
2.1371 +
2.1372 + //Subgraph, which is able to delete edges which are already
2.1373 + //met by the dfs
2.1374 + typename FilterResGW::template NodeMap<typename FilterResGW::OutEdgeIt>
2.1375 + first_out_edges(filter_res_graph);
2.1376 + typename FilterResGW::NodeIt v;
2.1377 + for(filter_res_graph.first(v); filter_res_graph.valid(v);
2.1378 + filter_res_graph.next(v))
2.1379 + {
2.1380 + typename FilterResGW::OutEdgeIt e;
2.1381 + filter_res_graph.first(e, v);
2.1382 + first_out_edges.set(v, e);
2.1383 + }
2.1384 + typedef ErasingFirstGraphWrapper<FilterResGW, typename FilterResGW::
2.1385 + template NodeMap<typename FilterResGW::OutEdgeIt> > ErasingResGW;
2.1386 + ErasingResGW erasing_res_graph(filter_res_graph, first_out_edges);
2.1387 +
2.1388 + bool __augment=true;
2.1389 +
2.1390 + while (__augment) {
2.1391 +
2.1392 + __augment=false;
2.1393 + //computing blocking flow with dfs
2.1394 + DfsIterator< ErasingResGW,
2.1395 + typename ErasingResGW::template NodeMap<bool> >
2.1396 + dfs(erasing_res_graph);
2.1397 + typename ErasingResGW::
2.1398 + template NodeMap<typename ErasingResGW::OutEdgeIt>
2.1399 + pred(erasing_res_graph);
2.1400 + pred.set(s, INVALID);
2.1401 + //invalid iterators for sources
2.1402 +
2.1403 + typename ErasingResGW::template NodeMap<Num>
2.1404 + free1(erasing_res_graph);
2.1405 +
2.1406 + dfs.pushAndSetReached
2.1407 + ///\bug hugo 0.2
2.1408 + (typename ErasingResGW::Node
2.1409 + (typename FilterResGW::Node
2.1410 + (typename ResGW::Node(s)
2.1411 + )
2.1412 + )
2.1413 + );
2.1414 + while (!dfs.finished()) {
2.1415 + ++dfs;
2.1416 + if (erasing_res_graph.valid(typename ErasingResGW::OutEdgeIt(dfs)))
2.1417 + {
2.1418 + if (dfs.isBNodeNewlyReached()) {
2.1419 +
2.1420 + typename ErasingResGW::Node v=erasing_res_graph.aNode(dfs);
2.1421 + typename ErasingResGW::Node w=erasing_res_graph.bNode(dfs);
2.1422 +
2.1423 + pred.set(w, /*typename ErasingResGW::OutEdgeIt*/(dfs));
2.1424 + if (erasing_res_graph.valid(pred[v])) {
2.1425 + free1.set
2.1426 + (w, std::min(free1[v], res_graph.resCap
2.1427 + (typename ErasingResGW::OutEdgeIt(dfs))));
2.1428 + } else {
2.1429 + free1.set
2.1430 + (w, res_graph.resCap
2.1431 + (typename ErasingResGW::OutEdgeIt(dfs)));
2.1432 + }
2.1433 +
2.1434 + if (w==t) {
2.1435 + __augment=true;
2.1436 + _augment=true;
2.1437 + break;
2.1438 + }
2.1439 + } else {
2.1440 + erasing_res_graph.erase(dfs);
2.1441 + }
2.1442 + }
2.1443 + }
2.1444 +
2.1445 + if (__augment) {
2.1446 + typename ErasingResGW::Node
2.1447 + n=typename FilterResGW::Node(typename ResGW::Node(t));
2.1448 + // typename ResGW::NodeMap<Num> a(res_graph);
2.1449 + // typename ResGW::Node b;
2.1450 + // Num j=a[b];
2.1451 + // typename FilterResGW::NodeMap<Num> a1(filter_res_graph);
2.1452 + // typename FilterResGW::Node b1;
2.1453 + // Num j1=a1[b1];
2.1454 + // typename ErasingResGW::NodeMap<Num> a2(erasing_res_graph);
2.1455 + // typename ErasingResGW::Node b2;
2.1456 + // Num j2=a2[b2];
2.1457 + Num augment_value=free1[n];
2.1458 + while (erasing_res_graph.valid(pred[n])) {
2.1459 + typename ErasingResGW::OutEdgeIt e=pred[n];
2.1460 + res_graph.augment(e, augment_value);
2.1461 + n=erasing_res_graph.tail(e);
2.1462 + if (res_graph.resCap(e)==0)
2.1463 + erasing_res_graph.erase(e);
2.1464 + }
2.1465 + }
2.1466 +
2.1467 + } //while (__augment)
2.1468 +
2.1469 + status=AFTER_AUGMENTING;
2.1470 + return _augment;
2.1471 + }
2.1472 +
2.1473 +
2.1474 +} //namespace hugo
2.1475 +
2.1476 +#endif //HUGO_AUGMENTING_FLOW_H
2.1477 +
2.1478 +
2.1479 +
2.1480 +
3.1 --- a/src/work/marci/bfs_dfs_misc.h Tue Aug 17 10:24:19 2004 +0000
3.2 +++ b/src/work/marci/bfs_dfs_misc.h Tue Aug 17 11:20:16 2004 +0000
3.3 @@ -11,7 +11,7 @@
3.4 // ///\author Marton Makai
3.5
3.6 #include <bfs_dfs.h>
3.7 -#include <hugo/for_each_macros.h>
3.8 +#include <for_each_macros.h>
3.9
3.10 namespace hugo {
3.11
4.1 --- a/src/work/marci/bfsit_vs_byhand.cc Tue Aug 17 10:24:19 2004 +0000
4.2 +++ b/src/work/marci/bfsit_vs_byhand.cc Tue Aug 17 11:20:16 2004 +0000
4.3 @@ -6,7 +6,7 @@
4.4 //#include <smart_graph.h>
4.5 #include <hugo/dimacs.h>
4.6 #include <hugo/time_measure.h>
4.7 -#include <hugo/for_each_macros.h>
4.8 +//#include <hugo/for_each_macros.h>
4.9 #include <bfs_dfs.h>
4.10
4.11 using namespace hugo;
4.12 @@ -21,7 +21,7 @@
4.13
4.14 Graph g;
4.15 Node s, t;
4.16 - Graph::EdgeMap<int> cap(g);
4.17 + //Graph::EdgeMap<int> cap(g);
4.18 //readDimacsMaxFlow(std::cin, g, s, t, cap);
4.19 readDimacs(std::cin, g);
4.20
5.1 --- a/src/work/marci/bipartite_graph_wrapper.h Tue Aug 17 10:24:19 2004 +0000
5.2 +++ b/src/work/marci/bipartite_graph_wrapper.h Tue Aug 17 11:20:16 2004 +0000
5.3 @@ -13,6 +13,7 @@
5.4 #include <hugo/invalid.h>
5.5 #include <iter_map.h>
5.6 #include <hugo/graph_wrapper.h>
5.7 +#include <for_each_macros.h>
5.8
5.9 namespace hugo {
5.10
6.1 --- a/src/work/marci/bipartite_graph_wrapper_test.cc Tue Aug 17 10:24:19 2004 +0000
6.2 +++ b/src/work/marci/bipartite_graph_wrapper_test.cc Tue Aug 17 11:20:16 2004 +0000
6.3 @@ -7,12 +7,13 @@
6.4 //#include <smart_graph.h>
6.5 //#include <dimacs.h>
6.6 #include <hugo/time_measure.h>
6.7 -#include <hugo/for_each_macros.h>
6.8 +#include <for_each_macros.h>
6.9 #include <bfs_dfs.h>
6.10 #include <hugo/graph_wrapper.h>
6.11 #include <bipartite_graph_wrapper.h>
6.12 #include <hugo/maps.h>
6.13 -#include <max_flow.h>
6.14 +#include <hugo/max_flow.h>
6.15 +#include <augmenting_flow.h>
6.16
6.17 using namespace hugo;
6.18
6.19 @@ -133,7 +134,7 @@
6.20 ++bfs_stgw;
6.21 }
6.22
6.23 - MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
6.24 + AugmentingFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
6.25 max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, flow);
6.26 while (max_flow_test.augmentOnShortestPath()) { }
6.27
7.1 --- a/src/work/marci/bipartite_matching_try.cc Tue Aug 17 10:24:19 2004 +0000
7.2 +++ b/src/work/marci/bipartite_matching_try.cc Tue Aug 17 11:20:16 2004 +0000
7.3 @@ -8,12 +8,13 @@
7.4 //#include <smart_graph.h>
7.5 //#include <dimacs.h>
7.6 #include <hugo/time_measure.h>
7.7 -#include <hugo/for_each_macros.h>
7.8 +#include <for_each_macros.h>
7.9 #include <bfs_dfs.h>
7.10 #include <hugo/graph_wrapper.h>
7.11 #include <bipartite_graph_wrapper.h>
7.12 #include <hugo/maps.h>
7.13 -#include <max_flow.h>
7.14 +#include <hugo/max_flow.h>
7.15 +#include <augmenting_flow.h>
7.16
7.17 /**
7.18 * Inicializalja a veletlenszamgeneratort.
7.19 @@ -163,7 +164,7 @@
7.20 Timer ts;
7.21 ts.reset();
7.22 stGW::EdgeMap<int> max_flow(stgw);
7.23 - MaxFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
7.24 + AugmentingFlow<stGW, int, ConstMap<stGW::Edge, int>, stGW::EdgeMap<int> >
7.25 max_flow_test(stgw, stgw.S_NODE, stgw.T_NODE, const1map, max_flow);
7.26 // while (max_flow_test.augmentOnShortestPath()) { }
7.27 typedef SageGraph MutableGraph;
8.1 --- a/src/work/marci/bipartite_matching_try_3.cc Tue Aug 17 10:24:19 2004 +0000
8.2 +++ b/src/work/marci/bipartite_matching_try_3.cc Tue Aug 17 11:20:16 2004 +0000
8.3 @@ -7,11 +7,11 @@
8.4 //#include <smart_graph.h>
8.5 //#include <dimacs.h>
8.6 #include <hugo/time_measure.h>
8.7 -#include <hugo/for_each_macros.h>
8.8 +#include <for_each_macros.h>
8.9 #include <bfs_dfs.h>
8.10 #include <bipartite_graph_wrapper.h>
8.11 #include <hugo/maps.h>
8.12 -#include <max_flow.h>
8.13 +#include <hugo/max_flow.h>
8.14 #include <graph_gen.h>
8.15 #include <max_bipartite_matching.h>
8.16
9.1 --- a/src/work/marci/lg_vs_sg_vs_sg.cc Tue Aug 17 10:24:19 2004 +0000
9.2 +++ b/src/work/marci/lg_vs_sg_vs_sg.cc Tue Aug 17 11:20:16 2004 +0000
9.3 @@ -7,9 +7,10 @@
9.4 #include <hugo/list_graph.h>
9.5 #include <hugo/smart_graph.h>
9.6 #include <hugo/dimacs.h>
9.7 -#include <max_flow.h>
9.8 +#include <hugo/max_flow.h>
9.9 +#include <augmenting_flow.h>
9.10 #include <hugo/time_measure.h>
9.11 -#include <hugo/for_each_macros.h>
9.12 +#include <for_each_macros.h>
9.13
9.14 using namespace hugo;
9.15
9.16 @@ -37,6 +38,8 @@
9.17 Graph::EdgeMap<int> flow(g); //0 flow
9.18 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
9.19 max_flow_test(g, s, t, cap, flow/*, true*/);
9.20 + AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
9.21 + augmenting_flow_test(g, s, t, cap, flow/*, true*/);
9.22
9.23 std::cout << "SageGraph ..." << std::endl;
9.24
9.25 @@ -53,10 +56,10 @@
9.26 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
9.27 ts.reset();
9.28 int i=0;
9.29 - while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
9.30 + while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
9.31 std::cout << "elapsed time: " << ts << std::endl;
9.32 std::cout << "number of augmentation phases: " << i << std::endl;
9.33 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
9.34 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
9.35 }
9.36
9.37 // {
9.38 @@ -75,10 +78,10 @@
9.39 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
9.40 ts.reset();
9.41 int i=0;
9.42 - while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
9.43 + while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
9.44 std::cout << "elapsed time: " << ts << std::endl;
9.45 std::cout << "number of augmentation phases: " << i << std::endl;
9.46 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
9.47 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
9.48 }
9.49
9.50 {
9.51 @@ -86,10 +89,10 @@
9.52 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
9.53 ts.reset();
9.54 int i=0;
9.55 - while (max_flow_test.augmentOnShortestPath()) { ++i; }
9.56 + while (augmenting_flow_test.augmentOnShortestPath()) { ++i; }
9.57 std::cout << "elapsed time: " << ts << std::endl;
9.58 std::cout << "number of augmentation phases: " << i << std::endl;
9.59 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
9.60 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
9.61 }
9.62 }
9.63
9.64 @@ -109,6 +112,8 @@
9.65 Graph::EdgeMap<int> flow(g); //0 flow
9.66 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
9.67 max_flow_test(g, s, t, cap, flow/*, true*/);
9.68 + AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
9.69 + augmenting_flow_test(g, s, t, cap, flow/*, true*/);
9.70 // MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
9.71 // max_flow_test(g, s, t, cap, flow);
9.72
9.73 @@ -128,10 +133,10 @@
9.74 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
9.75 ts.reset();
9.76 int i=0;
9.77 - while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
9.78 + while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
9.79 std::cout << "elapsed time: " << ts << std::endl;
9.80 std::cout << "number of augmentation phases: " << i << std::endl;
9.81 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
9.82 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
9.83 }
9.84
9.85 // {
9.86 @@ -150,10 +155,10 @@
9.87 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
9.88 ts.reset();
9.89 int i=0;
9.90 - while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
9.91 + while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
9.92 std::cout << "elapsed time: " << ts << std::endl;
9.93 std::cout << "number of augmentation phases: " << i << std::endl;
9.94 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
9.95 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
9.96 }
9.97
9.98 {
9.99 @@ -161,10 +166,10 @@
9.100 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
9.101 ts.reset();
9.102 int i=0;
9.103 - while (max_flow_test.augmentOnShortestPath()) { ++i; }
9.104 + while (augmenting_flow_test.augmentOnShortestPath()) { ++i; }
9.105 std::cout << "elapsed time: " << ts << std::endl;
9.106 std::cout << "number of augmentation phases: " << i << std::endl;
9.107 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
9.108 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
9.109 }
9.110 }
9.111
9.112 @@ -184,6 +189,8 @@
9.113 Graph::EdgeMap<int> flow(g); //0 flow
9.114 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
9.115 max_flow_test(g, s, t, cap, flow/*, true*/);
9.116 + AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
9.117 + augmenting_flow_test(g, s, t, cap, flow/*, true*/);
9.118 // MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
9.119 // max_flow_test(g, s, t, cap, flow);
9.120
9.121 @@ -203,10 +210,10 @@
9.122 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
9.123 ts.reset();
9.124 int i=0;
9.125 - while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
9.126 + while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
9.127 std::cout << "elapsed time: " << ts << std::endl;
9.128 std::cout << "number of augmentation phases: " << i << std::endl;
9.129 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
9.130 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
9.131 }
9.132
9.133 // {
9.134 @@ -225,10 +232,10 @@
9.135 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
9.136 ts.reset();
9.137 int i=0;
9.138 - while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
9.139 + while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
9.140 std::cout << "elapsed time: " << ts << std::endl;
9.141 std::cout << "number of augmentation phases: " << i << std::endl;
9.142 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
9.143 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
9.144 }
9.145
9.146 {
9.147 @@ -236,15 +243,12 @@
9.148 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
9.149 ts.reset();
9.150 int i=0;
9.151 - while (max_flow_test.augmentOnShortestPath()) { ++i; }
9.152 + while (augmenting_flow_test.augmentOnShortestPath()) { ++i; }
9.153 std::cout << "elapsed time: " << ts << std::endl;
9.154 std::cout << "number of augmentation phases: " << i << std::endl;
9.155 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
9.156 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
9.157 }
9.158 }
9.159
9.160 -
9.161 -
9.162 -
9.163 return 0;
9.164 }
10.1 --- a/src/work/marci/macro_test.cc Tue Aug 17 10:24:19 2004 +0000
10.2 +++ b/src/work/marci/macro_test.cc Tue Aug 17 11:20:16 2004 +0000
10.3 @@ -3,7 +3,7 @@
10.4 #include <fstream>
10.5
10.6 #include <sage_graph.h>
10.7 -#include <hugo/for_each_macros.h>
10.8 +#include <for_each_macros.h>
10.9
10.10 using namespace hugo;
10.11
11.1 --- a/src/work/marci/makefile Tue Aug 17 10:24:19 2004 +0000
11.2 +++ b/src/work/marci/makefile Tue Aug 17 11:20:16 2004 +0000
11.3 @@ -1,10 +1,11 @@
11.4 CXX2 = g++-2.95
11.5 CXX3=$(CXX)
11.6 BOOSTROOT ?= /home/marci/boost
11.7 -INCLUDEDIRS ?= -I../.. -I.. -I../{marci,jacint,alpar,klao,akos,athos} -I$(BOOSTROOT)
11.8 +INCLUDEDIRS ?= -I../{jacint,marci,alpar,klao,akos,athos} -I../.. -I.. -I$(BOOSTROOT)
11.9
11.10 LEDABINARIES = leda_graph_demo leda_bfs_dfs max_bipartite_matching_demo
11.11 BINARIES = max_flow_demo iterator_bfs_demo macro_test lg_vs_sg_vs_sg bfsit_vs_byhand bipartite_graph_wrapper_test bipartite_matching_try bipartite_matching_try_3 top_sort_test max_flow_1
11.12 +#BINARIES = preflow_bug
11.13 #gw_vs_not preflow_demo_boost edmonds_karp_demo_boost preflow_demo_jacint preflow_demo_athos edmonds_karp_demo_alpar preflow_demo_leda
11.14
11.15 include ../makefile
12.1 --- a/src/work/marci/max_bipartite_matching.h Tue Aug 17 10:24:19 2004 +0000
12.2 +++ b/src/work/marci/max_bipartite_matching.h Tue Aug 17 11:20:16 2004 +0000
12.3 @@ -15,7 +15,7 @@
12.4 //#include <for_each_macros.h>
12.5 #include <bipartite_graph_wrapper.h>
12.6 //#include <hugo/maps.h>
12.7 -#include <max_flow.h>
12.8 +#include <hugo/max_flow.h>
12.9
12.10 namespace hugo {
12.11
13.1 --- a/src/work/marci/max_flow_1.cc Tue Aug 17 10:24:19 2004 +0000
13.2 +++ b/src/work/marci/max_flow_1.cc Tue Aug 17 11:20:16 2004 +0000
13.3 @@ -7,9 +7,9 @@
13.4 #include <hugo/dimacs.h>
13.5 #include <hugo/time_measure.h>
13.6 //#include <graph_wrapper.h>
13.7 -#include <max_flow.h>
13.8 +#include <hugo/max_flow.h>
13.9 //#include <preflow_res.h>
13.10 -#include <hugo/for_each_macros.h>
13.11 +#include <for_each_macros.h>
13.12
13.13 using namespace hugo;
13.14
14.1 --- a/src/work/marci/max_flow_demo.cc Tue Aug 17 10:24:19 2004 +0000
14.2 +++ b/src/work/marci/max_flow_demo.cc Tue Aug 17 11:20:16 2004 +0000
14.3 @@ -7,9 +7,10 @@
14.4 #include <hugo/dimacs.h>
14.5 #include <hugo/time_measure.h>
14.6 //#include <graph_wrapper.h>
14.7 -#include <max_flow.h>
14.8 +#include <hugo/max_flow.h>
14.9 +#include <augmenting_flow.h>
14.10 //#include <preflow_res.h>
14.11 -#include <hugo/for_each_macros.h>
14.12 +#include <for_each_macros.h>
14.13 #include <graph_concept.h>
14.14
14.15 using namespace hugo;
14.16 @@ -38,8 +39,8 @@
14.17 typedef SageGraph MutableGraph;
14.18
14.19 //typedef FullFeatureGraphConcept Graph;
14.20 - typedef SmartGraph Graph;
14.21 - // typedef SageGraph Graph;
14.22 + //typedef SmartGraph Graph;
14.23 + typedef SageGraph Graph;
14.24 typedef Graph::Node Node;
14.25 typedef Graph::EdgeIt EdgeIt;
14.26
14.27 @@ -75,6 +76,9 @@
14.28 Graph::EdgeMap<int> flow(g); //0 flow
14.29 MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
14.30 max_flow_test(g, s, t, cap, flow);
14.31 + AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
14.32 + augmenting_flow_test(g, s, t, cap, flow);
14.33 +
14.34 Graph::NodeMap<bool> cut(g);
14.35
14.36 {
14.37 @@ -123,10 +127,10 @@
14.38 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
14.39 ts.reset();
14.40 int i=0;
14.41 - while (max_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
14.42 + while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
14.43 std::cout << "elapsed time: " << ts << std::endl;
14.44 std::cout << "number of augmentation phases: " << i << std::endl;
14.45 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
14.46 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
14.47
14.48 FOR_EACH_LOC(Graph::EdgeIt, e, g) {
14.49 if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e])
14.50 @@ -152,10 +156,10 @@
14.51 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
14.52 ts.reset();
14.53 int i=0;
14.54 - while (max_flow_test.augmentOnBlockingFlow2()) { ++i; }
14.55 + while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
14.56 std::cout << "elapsed time: " << ts << std::endl;
14.57 std::cout << "number of augmentation phases: " << i << std::endl;
14.58 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
14.59 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
14.60
14.61 FOR_EACH_LOC(Graph::EdgeIt, e, g) {
14.62 if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e])
14.63 @@ -170,10 +174,10 @@
14.64 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
14.65 ts.reset();
14.66 int i=0;
14.67 - while (max_flow_test.augmentOnShortestPath()) { ++i; }
14.68 + while (augmenting_flow_test.augmentOnShortestPath()) { ++i; }
14.69 std::cout << "elapsed time: " << ts << std::endl;
14.70 std::cout << "number of augmentation phases: " << i << std::endl;
14.71 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
14.72 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
14.73
14.74 FOR_EACH_LOC(Graph::EdgeIt, e, g) {
14.75 if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e])
14.76 @@ -188,10 +192,10 @@
14.77 FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
14.78 ts.reset();
14.79 int i=0;
14.80 - while (max_flow_test.augmentOnShortestPath2()) { ++i; }
14.81 + while (augmenting_flow_test.augmentOnShortestPath2()) { ++i; }
14.82 std::cout << "elapsed time: " << ts << std::endl;
14.83 std::cout << "number of augmentation phases: " << i << std::endl;
14.84 - std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
14.85 + std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
14.86
14.87 FOR_EACH_LOC(Graph::EdgeIt, e, g) {
14.88 if (cut[g.tail(e)] && !cut[g.head(e)] && !flow[e]==cap[e])
15.1 --- a/src/work/marci/top_sort_test.cc Tue Aug 17 10:24:19 2004 +0000
15.2 +++ b/src/work/marci/top_sort_test.cc Tue Aug 17 11:20:16 2004 +0000
15.3 @@ -8,7 +8,7 @@
15.4 #include <sage_graph.h>
15.5 #include <hugo/graph_wrapper.h>
15.6 #include <hugo/maps.h>
15.7 -#include <hugo/for_each_macros.h>
15.8 +#include <for_each_macros.h>
15.9
15.10 using namespace hugo;
15.11