Changes in the interface and new test program added.
3 #include <smart_graph.h>
6 #include <time_measure.h>
10 int main(int, char **) {
12 typedef SmartGraph Graph;
14 typedef Graph::Node Node;
15 typedef Graph::EdgeIt EdgeIt;
19 Graph::EdgeMap<int> cap(G);
20 readDimacsMaxFlow(std::cin, G, s, t, cap);
24 "\n Testing preflow.h on a graph with " <<
25 G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
29 Graph::EdgeMap<int> flow(G,0);
30 Preflow<Graph, int> preflow_test(G, s, t, cap, flow);
31 std::cout << "\nCalling run() (flow must be constant zero)..."<<std::endl;
34 std::cout << "Elapsed time: " << ts << std::endl;
36 Graph::NodeMap<bool> mincut(G);
37 preflow_test.minMinCut(mincut);
38 int min_min_cut_value=0;
39 Graph::NodeMap<bool> cut(G);
40 preflow_test.minCut(cut);
42 Graph::NodeMap<bool> maxcut(G);
43 preflow_test.maxMinCut(maxcut);
44 int max_min_cut_value=0;
46 for(G.first(e); G.valid(e); G.next(e)) {
48 if (mincut[G.tail(e)] && !mincut[G.head(e)]) min_min_cut_value+=c;
49 if (cut[G.tail(e)] && !cut[G.head(e)]) min_cut_value+=c;
50 if (maxcut[G.tail(e)] && !maxcut[G.head(e)]) max_min_cut_value+=c;
53 std::cout << "\nChecking the result: " <<std::endl;
54 std::cout << "Flow value: "<< preflow_test.flowValue() << std::endl;
55 std::cout << "Min cut value: "<< min_cut_value << std::endl;
56 std::cout << "Min min cut value: "<< min_min_cut_value << std::endl;
57 std::cout << "Max min cut value: "<< max_min_cut_value <<
60 if ( preflow_test.flowValue() == min_cut_value &&
61 min_cut_value == min_min_cut_value &&
62 min_min_cut_value == max_min_cut_value )
63 std::cout << "They are equal. " <<std::endl;
69 Preflow<Graph, int> preflow_test2(G, s, t, cap, flow);
70 std::cout << "\n\nCalling preflow(GEN_FLOW) with the given maximum flow..."<<std::endl;
72 preflow_test2.preflow(preflow_test2.GEN_FLOW);
73 std::cout << "Elapsed time: " << ts << std::endl;
75 Graph::NodeMap<bool> mincut2(G);
76 preflow_test.minMinCut(mincut2);
77 int min_min_cut2_value=0;
78 Graph::NodeMap<bool> cut2(G);
79 preflow_test.minCut(cut2);
81 Graph::NodeMap<bool> maxcut2(G);
82 preflow_test.maxMinCut(maxcut2);
83 int max_min_cut2_value=0;
84 for(G.first(e); G.valid(e); G.next(e)) {
86 if (mincut2[G.tail(e)] && !mincut2[G.head(e)]) min_min_cut2_value+=c;
87 if (cut2[G.tail(e)] && !cut2[G.head(e)]) min_cut2_value+=c;
88 if (maxcut2[G.tail(e)] && !maxcut2[G.head(e)]) max_min_cut2_value+=c;
91 std::cout << "\nThe given flow value is "
92 << preflow_test2.flowValue();
94 if ( preflow_test2.flowValue() == min_cut2_value &&
95 min_cut2_value == min_min_cut2_value &&
96 min_min_cut2_value == max_min_cut2_value )
97 std::cout <<", which is equal to all three min cut values."
104 Graph::EdgeMap<int> flow3(G,0);
105 Preflow<Graph, int> preflow_test3(G, s, t, cap, flow3);
106 std::cout << "\n\nCalling preflowPhase0(PREFLOW) on the constant zero flow..."<<std::endl;
108 preflow_test3.preflowPhase0(preflow_test3.PREFLOW);
109 std::cout << "Elapsed time: " << ts << std::endl;
110 Graph::NodeMap<bool> actcut3(G);
111 std::cout << "\nCalling actMinCut()..."<<std::endl;
112 preflow_test3.actMinCut(actcut3);
113 std::cout << "Calling preflowPhase1() on the given flow..."<<std::endl;
115 preflow_test3.preflowPhase1();
116 std::cout << "Elapsed time: " << ts << std::endl;
118 int act_min_cut3_value=0;
120 Graph::NodeMap<bool> mincut3(G);
121 preflow_test.minMinCut(mincut3);
122 int min_min_cut3_value=0;
124 Graph::NodeMap<bool> cut3(G);
125 preflow_test.minCut(cut3);
126 int min_cut3_value=0;
128 Graph::NodeMap<bool> maxcut3(G);
129 preflow_test.maxMinCut(maxcut3);
130 int max_min_cut3_value=0;
132 for(G.first(e); G.valid(e); G.next(e)) {
134 if (mincut3[G.tail(e)] && !mincut3[G.head(e)]) min_min_cut3_value+=c;
135 if (cut3[G.tail(e)] && !cut3[G.head(e)]) min_cut3_value+=c;
136 if (maxcut3[G.tail(e)] && !maxcut3[G.head(e)]) max_min_cut3_value+=c;
137 if (actcut3[G.tail(e)] && !actcut3[G.head(e)]) act_min_cut3_value+=c;
140 std::cout << "\nThe min cut value given by actMinCut() after phase 0 is "<<
143 if ( preflow_test3.flowValue() == min_cut3_value &&
144 min_cut3_value == min_min_cut3_value &&
145 min_min_cut3_value == max_min_cut3_value &&
146 max_min_cut3_value == act_min_cut3_value ) {
148 ", which is equal to the given flow value and to all three min cut values after phase 1."
156 Graph::EdgeMap<int> flow4(G,0);
157 Preflow<Graph, int> preflow_test4(G, s, t, cap, flow4);
159 "\n\nCalling preflow(PREFLOW) with the constant 0 flow, the result is f..."
161 preflow_test4.preflow(preflow_test4.PREFLOW);
163 std::cout << "Swapping the source and the target, "<<std::endl;
164 std::cout << "by calling resetSource(t) and resetTarget(s)..."
166 preflow_test4.resetSource(t);
167 preflow_test4.resetTarget(s);
170 "Calling preflow(PREFLOW) to find a maximum t-s flow starting with flow f..."
172 preflow_test4.preflow(preflow_test4.PREFLOW);
174 Graph::NodeMap<bool> mincut4(G);
175 preflow_test4.minMinCut(mincut4);
176 int min_min_cut4_value=0;
177 Graph::NodeMap<bool> cut4(G);
178 preflow_test4.minCut(cut4);
179 int min_cut4_value=0;
180 Graph::NodeMap<bool> maxcut4(G);
181 preflow_test4.maxMinCut(maxcut4);
182 int max_min_cut4_value=0;
183 for(G.first(e); G.valid(e); G.next(e)) {
185 if (mincut4[G.tail(e)] && !mincut4[G.head(e)]) min_min_cut4_value+=c;
186 if (cut4[G.tail(e)] && !cut4[G.head(e)]) min_cut4_value+=c;
187 if (maxcut4[G.tail(e)] && !maxcut4[G.head(e)]) max_min_cut4_value+=c;
190 std::cout << "\nThe given flow value is "
191 << preflow_test4.flowValue();
193 if ( preflow_test4.flowValue() == min_cut4_value &&
194 min_cut4_value == min_min_cut4_value &&
195 min_min_cut4_value == max_min_cut4_value )
196 std::cout <<", which is equal to all three min cut values."
202 Graph::EdgeMap<int> flow5(G,0);
203 std::cout << "Resetting the stored flow to constant zero, by calling resetFlow..."
205 preflow_test4.resetFlow(flow5);
207 "Calling preflow(GEN_FLOW) to find a maximum t-s flow "<<std::endl;
209 "starting with this constant zero flow..." <<std::endl;
210 preflow_test4.preflow(preflow_test4.GEN_FLOW);
212 Graph::NodeMap<bool> mincut5(G);
213 preflow_test4.minMinCut(mincut5);
214 int min_min_cut5_value=0;
215 Graph::NodeMap<bool> cut5(G);
216 preflow_test4.minCut(cut5);
217 int min_cut5_value=0;
218 Graph::NodeMap<bool> maxcut5(G);
219 preflow_test4.maxMinCut(maxcut5);
220 int max_min_cut5_value=0;
221 for(G.first(e); G.valid(e); G.next(e)) {
223 if (mincut5[G.tail(e)] && !mincut5[G.head(e)]) min_min_cut5_value+=c;
224 if (cut5[G.tail(e)] && !cut5[G.head(e)]) min_cut5_value+=c;
225 if (maxcut5[G.tail(e)] && !maxcut5[G.head(e)]) max_min_cut5_value+=c;
228 std::cout << "\nThe given flow value is "
229 << preflow_test4.flowValue();
231 if ( preflow_test4.flowValue() == min_cut5_value &&
232 min_cut5_value == min_min_cut5_value &&
233 min_min_cut5_value == max_min_cut5_value )
234 std::cout <<", which is equal to all three min cut values."
235 <<std::endl<<std::endl;