Changeset 109:fc5982b39e10 in lemon-0.x for src/work/jacint/preflow_hl3.h
- Timestamp:
- 02/21/04 22:01:22 (20 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@144
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
src/work/jacint/preflow_hl3.h
r105 r109 3 3 preflow_hl3.h 4 4 by jacint. 5 Runs the highest label variant of the preflow push algorithm with 6 running time O(n^2\sqrt(m)), with the felszippantos 'empty level' 7 and with the two-phase heuristic: if there is no active node of 8 level at most n, then we go into phase 1, do a bfs 9 from s, and flow the excess back to s. 10 11 In phase 1 we shift everything downwards by n. 12 13 'A' is a parameter for the empty_level heuristic 14 15 Member functions: 16 17 void run() : runs the algorithm 18 19 The following functions should be used after run() was already run. 20 21 T maxflow() : returns the value of a maximum flow 22 23 T flowonedge(EdgeIt e) : for a fixed maximum flow x it returns x(e) 24 25 FlowMap allflow() : returns the fixed maximum flow x 26 27 void mincut(CutMap& M) : sets M to the characteristic vector of a 5 6 Heuristics: 7 8 suck gap : if there is a gap, then we put all 9 nodes reachable from the relabelled node to level n 10 2 phase 11 highest label 12 13 The constructor runs the algorithm. 14 15 Members: 16 17 T maxFlow() : returns the value of a maximum flow 18 19 T flowOnEdge(EdgeIt e) : for a fixed maximum flow x it returns x(e) 20 21 FlowMap Flow() : returns the fixed maximum flow x 22 23 void minCut(CutMap& M) : sets M to the characteristic vector of a 28 24 minimum cut. M should be a map of bools initialized to false. 29 25 30 void min _mincut(CutMap& M) : sets M to the characteristic vector of the26 void minMinCut(CutMap& M) : sets M to the characteristic vector of the 31 27 minimum min cut. M should be a map of bools initialized to false. 32 28 33 void max _mincut(CutMap& M) : sets M to the characteristic vector of the29 void maxMinCut(CutMap& M) : sets M to the characteristic vector of the 34 30 maximum min cut. M should be a map of bools initialized to false. 35 31 … … 38 34 #ifndef PREFLOW_HL3_H 39 35 #define PREFLOW_HL3_H 40 41 #define A 142 36 43 37 #include <vector> … … 45 39 #include <queue> 46 40 41 #include <time_measure.h> //for test 42 47 43 namespace hugo { 48 44 49 45 template <typename Graph, typename T, 50 typename FlowMap=typename Graph::EdgeMap<T>, typename CapMap=typename Graph::EdgeMap<T>,51 typename IntMap=typename Graph::NodeMap<int>, typename TMap=typename Graph::NodeMap<T> >46 typename FlowMap=typename Graph::EdgeMap<T>, 47 typename CapMap=typename Graph::EdgeMap<T> > 52 48 class preflow_hl3 { 53 49 … … 67 63 public: 68 64 65 double time; //for test 66 69 67 preflow_hl3(Graph& _G, NodeIt _s, NodeIt _t, CapMap& _capacity) : 70 G(_G), s(_s), t(_t), flow(_G, 0), capacity(_capacity) { } 71 72 73 void run() { 74 68 G(_G), s(_s), t(_t), flow(_G, 0), capacity(_capacity) { 69 75 70 bool phase=0; 76 71 int n=G.nodeNum(); … … 81 76 */ 82 77 83 IntMaplevel(G,n);84 TMapexcess(G);78 typename Graph::NodeMap<int> level(G,n); 79 typename Graph::NodeMap<T> excess(G); 85 80 86 81 std::vector<int> numb(n); … … 149 144 if ( phase ) break; 150 145 phase=1; 151 146 time=currTime(); 147 152 148 level.set(s,0); 153 149 … … 188 184 else { 189 185 190 NodeIt w=stack[b].top(); //w is a highest label active node.186 NodeIt w=stack[b].top(); 191 187 stack[b].pop(); 192 188 int lev=level.get(w); 193 intexc=excess.get(w);194 int newlevel=n; //In newlevel we boundthe next level of w.189 T exc=excess.get(w); 190 int newlevel=n; //bound on the next level of w. 195 191 196 192 for(OutEdgeIt e=G.template first<OutEdgeIt>(w); e.valid(); ++e) { … … 207 203 /*v becomes active.*/ 208 204 209 intcap=capacity.get(e);210 intflo=flow.get(e);211 intremcap=cap-flo;205 T cap=capacity.get(e); 206 T flo=flow.get(e); 207 T remcap=cap-flo; 212 208 213 209 if ( remcap >= exc ) { … … 245 241 /*v becomes active.*/ 246 242 247 intflo=flow.get(e);243 T flo=flow.get(e); 248 244 249 245 if ( flo >= exc ) { … … 350 346 */ 351 347 352 T max flow() {348 T maxFlow() { 353 349 return value; 354 350 } … … 357 353 358 354 /* 359 For the maximum flow x found by the algorithm, it returns the flow value on Edge e, i.e. x(e). 355 For the maximum flow x found by the algorithm, 356 it returns the flow value on edge e, i.e. x(e). 360 357 */ 361 358 362 T flow onedge(EdgeIt e) {359 T flowOnEdge(EdgeIt e) { 363 360 return flow.get(e); 364 361 } … … 370 367 */ 371 368 372 FlowMap allflow() {369 FlowMap Flow() { 373 370 return flow; 374 371 } … … 382 379 383 380 template<typename CutMap> 384 void min cut(CutMap& M) {381 void minCut(CutMap& M) { 385 382 386 383 std::queue<NodeIt> queue; … … 421 418 422 419 template<typename CutMap> 423 void max _mincut(CutMap& M) {420 void maxMinCut(CutMap& M) { 424 421 425 422 std::queue<NodeIt> queue; … … 458 455 459 456 template<typename CutMap> 460 void min _mincut(CutMap& M) {461 min cut(M);457 void minMinCut(CutMap& M) { 458 minCut(M); 462 459 } 463 460 … … 465 462 466 463 }; 467 }//namespace hugo464 }//namespace 468 465 #endif 469 466
Note: See TracChangeset
for help on using the changeset viewer.