| ... |
... |
@@ -34,49 +34,49 @@
|
| 34 |
34 |
typedef concepts::Digraph Digraph;
|
| 35 |
35 |
|
| 36 |
36 |
typedef Digraph::Node Node;
|
| 37 |
37 |
typedef Digraph::Arc Arc;
|
| 38 |
38 |
typedef concepts::ReadMap<Arc,VType> CapMap;
|
| 39 |
39 |
typedef concepts::ReadWriteMap<Arc,VType> FlowMap;
|
| 40 |
40 |
typedef concepts::WriteMap<Node,bool> CutMap;
|
| 41 |
41 |
|
| 42 |
42 |
Digraph g;
|
| 43 |
43 |
Node n;
|
| 44 |
44 |
Arc e;
|
| 45 |
45 |
CapMap cap;
|
| 46 |
46 |
FlowMap flow;
|
| 47 |
47 |
CutMap cut;
|
| 48 |
48 |
|
| 49 |
49 |
Preflow<Digraph, CapMap>::SetFlowMap<FlowMap>::Create preflow_test(g,cap,n,n);
|
| 50 |
50 |
|
| 51 |
51 |
preflow_test.capacityMap(cap);
|
| 52 |
52 |
flow = preflow_test.flowMap();
|
| 53 |
53 |
preflow_test.flowMap(flow);
|
| 54 |
54 |
preflow_test.source(n);
|
| 55 |
55 |
preflow_test.target(n);
|
| 56 |
56 |
|
| 57 |
57 |
preflow_test.init();
|
| 58 |
|
preflow_test.flowInit(cap);
|
|
58 |
preflow_test.init(cap);
|
| 59 |
59 |
preflow_test.startFirstPhase();
|
| 60 |
60 |
preflow_test.startSecondPhase();
|
| 61 |
61 |
preflow_test.run();
|
| 62 |
62 |
preflow_test.runMinCut();
|
| 63 |
63 |
|
| 64 |
64 |
preflow_test.flowValue();
|
| 65 |
65 |
preflow_test.minCut(n);
|
| 66 |
66 |
preflow_test.minCutMap(cut);
|
| 67 |
67 |
preflow_test.flow(e);
|
| 68 |
68 |
|
| 69 |
69 |
}
|
| 70 |
70 |
|
| 71 |
71 |
int cutValue (const SmartDigraph& g,
|
| 72 |
72 |
const SmartDigraph::NodeMap<bool>& cut,
|
| 73 |
73 |
const SmartDigraph::ArcMap<int>& cap) {
|
| 74 |
74 |
|
| 75 |
75 |
int c=0;
|
| 76 |
76 |
for(SmartDigraph::ArcIt e(g); e!=INVALID; ++e) {
|
| 77 |
77 |
if (cut[g.source(e)] && !cut[g.target(e)]) c+=cap[e];
|
| 78 |
78 |
}
|
| 79 |
79 |
return c;
|
| 80 |
80 |
}
|
| 81 |
81 |
|
| 82 |
82 |
bool checkFlow(const SmartDigraph& g,
|
| ... |
... |
@@ -132,49 +132,49 @@
|
| 132 |
132 |
arcMap("capacity", cap).
|
| 133 |
133 |
node("source",s).
|
| 134 |
134 |
node("target",t).
|
| 135 |
135 |
run();
|
| 136 |
136 |
|
| 137 |
137 |
PType preflow_test(g, cap, s, t);
|
| 138 |
138 |
preflow_test.run();
|
| 139 |
139 |
|
| 140 |
140 |
check(checkFlow(g, preflow_test.flowMap(), cap, s, t),
|
| 141 |
141 |
"The flow is not feasible.");
|
| 142 |
142 |
|
| 143 |
143 |
CutMap min_cut(g);
|
| 144 |
144 |
preflow_test.minCutMap(min_cut);
|
| 145 |
145 |
int min_cut_value=cutValue(g,min_cut,cap);
|
| 146 |
146 |
|
| 147 |
147 |
check(preflow_test.flowValue() == min_cut_value,
|
| 148 |
148 |
"The max flow value is not equal to the three min cut values.");
|
| 149 |
149 |
|
| 150 |
150 |
FlowMap flow(g);
|
| 151 |
151 |
for(ArcIt e(g); e!=INVALID; ++e) flow[e] = preflow_test.flowMap()[e];
|
| 152 |
152 |
|
| 153 |
153 |
int flow_value=preflow_test.flowValue();
|
| 154 |
154 |
|
| 155 |
155 |
for(ArcIt e(g); e!=INVALID; ++e) cap[e]=2*cap[e];
|
| 156 |
|
preflow_test.flowInit(flow);
|
|
156 |
preflow_test.init(flow);
|
| 157 |
157 |
preflow_test.startFirstPhase();
|
| 158 |
158 |
|
| 159 |
159 |
CutMap min_cut1(g);
|
| 160 |
160 |
preflow_test.minCutMap(min_cut1);
|
| 161 |
161 |
min_cut_value=cutValue(g,min_cut1,cap);
|
| 162 |
162 |
|
| 163 |
163 |
check(preflow_test.flowValue() == min_cut_value &&
|
| 164 |
164 |
min_cut_value == 2*flow_value,
|
| 165 |
165 |
"The max flow value or the min cut value is wrong.");
|
| 166 |
166 |
|
| 167 |
167 |
preflow_test.startSecondPhase();
|
| 168 |
168 |
|
| 169 |
169 |
check(checkFlow(g, preflow_test.flowMap(), cap, s, t),
|
| 170 |
170 |
"The flow is not feasible.");
|
| 171 |
171 |
|
| 172 |
172 |
CutMap min_cut2(g);
|
| 173 |
173 |
preflow_test.minCutMap(min_cut2);
|
| 174 |
174 |
min_cut_value=cutValue(g,min_cut2,cap);
|
| 175 |
175 |
|
| 176 |
176 |
check(preflow_test.flowValue() == min_cut_value &&
|
| 177 |
177 |
min_cut_value == 2*flow_value,
|
| 178 |
178 |
"The max flow value or the three min cut values were not doubled");
|
| 179 |
179 |
|
| 180 |
180 |
|