1.1 --- a/src/work/jacint/preflow_hl3.h Fri Feb 20 22:01:02 2004 +0000
1.2 +++ b/src/work/jacint/preflow_hl3.h Sat Feb 21 21:01:22 2004 +0000
1.3 @@ -2,35 +2,31 @@
1.4 /*
1.5 preflow_hl3.h
1.6 by jacint.
1.7 -Runs the highest label variant of the preflow push algorithm with
1.8 -running time O(n^2\sqrt(m)), with the felszippantos 'empty level'
1.9 -and with the two-phase heuristic: if there is no active node of
1.10 -level at most n, then we go into phase 1, do a bfs
1.11 -from s, and flow the excess back to s.
1.12
1.13 -In phase 1 we shift everything downwards by n.
1.14 +Heuristics:
1.15
1.16 -'A' is a parameter for the empty_level heuristic
1.17 + suck gap : if there is a gap, then we put all
1.18 + nodes reachable from the relabelled node to level n
1.19 + 2 phase
1.20 + highest label
1.21
1.22 -Member functions:
1.23 +The constructor runs the algorithm.
1.24
1.25 -void run() : runs the algorithm
1.26 +Members:
1.27
1.28 - The following functions should be used after run() was already run.
1.29 +T maxFlow() : returns the value of a maximum flow
1.30
1.31 -T maxflow() : returns the value of a maximum flow
1.32 +T flowOnEdge(EdgeIt e) : for a fixed maximum flow x it returns x(e)
1.33
1.34 -T flowonedge(EdgeIt e) : for a fixed maximum flow x it returns x(e)
1.35 +FlowMap Flow() : returns the fixed maximum flow x
1.36
1.37 -FlowMap allflow() : returns the fixed maximum flow x
1.38 -
1.39 -void mincut(CutMap& M) : sets M to the characteristic vector of a
1.40 +void minCut(CutMap& M) : sets M to the characteristic vector of a
1.41 minimum cut. M should be a map of bools initialized to false.
1.42
1.43 -void min_mincut(CutMap& M) : sets M to the characteristic vector of the
1.44 +void minMinCut(CutMap& M) : sets M to the characteristic vector of the
1.45 minimum min cut. M should be a map of bools initialized to false.
1.46
1.47 -void max_mincut(CutMap& M) : sets M to the characteristic vector of the
1.48 +void maxMinCut(CutMap& M) : sets M to the characteristic vector of the
1.49 maximum min cut. M should be a map of bools initialized to false.
1.50
1.51 */
1.52 @@ -38,17 +34,17 @@
1.53 #ifndef PREFLOW_HL3_H
1.54 #define PREFLOW_HL3_H
1.55
1.56 -#define A 1
1.57 -
1.58 #include <vector>
1.59 #include <stack>
1.60 #include <queue>
1.61
1.62 +#include <time_measure.h> //for test
1.63 +
1.64 namespace hugo {
1.65
1.66 template <typename Graph, typename T,
1.67 - typename FlowMap=typename Graph::EdgeMap<T>, typename CapMap=typename Graph::EdgeMap<T>,
1.68 - typename IntMap=typename Graph::NodeMap<int>, typename TMap=typename Graph::NodeMap<T> >
1.69 + typename FlowMap=typename Graph::EdgeMap<T>,
1.70 + typename CapMap=typename Graph::EdgeMap<T> >
1.71 class preflow_hl3 {
1.72
1.73 typedef typename Graph::NodeIt NodeIt;
1.74 @@ -66,12 +62,11 @@
1.75
1.76 public:
1.77
1.78 + double time; //for test
1.79 +
1.80 preflow_hl3(Graph& _G, NodeIt _s, NodeIt _t, CapMap& _capacity) :
1.81 - G(_G), s(_s), t(_t), flow(_G, 0), capacity(_capacity) { }
1.82 -
1.83 -
1.84 - void run() {
1.85 -
1.86 + G(_G), s(_s), t(_t), flow(_G, 0), capacity(_capacity) {
1.87 +
1.88 bool phase=0;
1.89 int n=G.nodeNum();
1.90 int b=n-2;
1.91 @@ -80,8 +75,8 @@
1.92 In the beginning it is at most n-2.
1.93 */
1.94
1.95 - IntMap level(G,n);
1.96 - TMap excess(G);
1.97 + typename Graph::NodeMap<int> level(G,n);
1.98 + typename Graph::NodeMap<T> excess(G);
1.99
1.100 std::vector<int> numb(n);
1.101 /*
1.102 @@ -148,7 +143,8 @@
1.103 if ( b == 0 ) {
1.104 if ( phase ) break;
1.105 phase=1;
1.106 -
1.107 + time=currTime();
1.108 +
1.109 level.set(s,0);
1.110
1.111 std::queue<NodeIt> bfs_queue;
1.112 @@ -187,11 +183,11 @@
1.113 if ( stack[b].empty() ) --b;
1.114 else {
1.115
1.116 - NodeIt w=stack[b].top(); //w is a highest label active node.
1.117 + NodeIt w=stack[b].top();
1.118 stack[b].pop();
1.119 int lev=level.get(w);
1.120 - int exc=excess.get(w);
1.121 - int newlevel=n; //In newlevel we bound the next level of w.
1.122 + T exc=excess.get(w);
1.123 + int newlevel=n; //bound on the next level of w.
1.124
1.125 for(OutEdgeIt e=G.template first<OutEdgeIt>(w); e.valid(); ++e) {
1.126
1.127 @@ -206,9 +202,9 @@
1.128 stack[level.get(v)].push(v);
1.129 /*v becomes active.*/
1.130
1.131 - int cap=capacity.get(e);
1.132 - int flo=flow.get(e);
1.133 - int remcap=cap-flo;
1.134 + T cap=capacity.get(e);
1.135 + T flo=flow.get(e);
1.136 + T remcap=cap-flo;
1.137
1.138 if ( remcap >= exc ) {
1.139 /*A nonsaturating push.*/
1.140 @@ -244,7 +240,7 @@
1.141 stack[level.get(v)].push(v);
1.142 /*v becomes active.*/
1.143
1.144 - int flo=flow.get(e);
1.145 + T flo=flow.get(e);
1.146
1.147 if ( flo >= exc ) {
1.148 /*A nonsaturating push.*/
1.149 @@ -349,17 +345,18 @@
1.150 Returns the maximum value of a flow.
1.151 */
1.152
1.153 - T maxflow() {
1.154 + T maxFlow() {
1.155 return value;
1.156 }
1.157
1.158
1.159
1.160 /*
1.161 - For the maximum flow x found by the algorithm, it returns the flow value on Edge e, i.e. x(e).
1.162 + For the maximum flow x found by the algorithm,
1.163 + it returns the flow value on edge e, i.e. x(e).
1.164 */
1.165
1.166 - T flowonedge(EdgeIt e) {
1.167 + T flowOnEdge(EdgeIt e) {
1.168 return flow.get(e);
1.169 }
1.170
1.171 @@ -369,7 +366,7 @@
1.172 Returns the maximum flow x found by the algorithm.
1.173 */
1.174
1.175 - FlowMap allflow() {
1.176 + FlowMap Flow() {
1.177 return flow;
1.178 }
1.179
1.180 @@ -381,7 +378,7 @@
1.181 */
1.182
1.183 template<typename CutMap>
1.184 - void mincut(CutMap& M) {
1.185 + void minCut(CutMap& M) {
1.186
1.187 std::queue<NodeIt> queue;
1.188
1.189 @@ -420,7 +417,7 @@
1.190 */
1.191
1.192 template<typename CutMap>
1.193 - void max_mincut(CutMap& M) {
1.194 + void maxMinCut(CutMap& M) {
1.195
1.196 std::queue<NodeIt> queue;
1.197
1.198 @@ -457,14 +454,14 @@
1.199
1.200
1.201 template<typename CutMap>
1.202 - void min_mincut(CutMap& M) {
1.203 - mincut(M);
1.204 + void minMinCut(CutMap& M) {
1.205 + minCut(M);
1.206 }
1.207
1.208
1.209
1.210 };
1.211 -}//namespace hugo
1.212 +}//namespace
1.213 #endif
1.214
1.215