xy.h went to src/include.
2 The only difference between preflow.h and preflow_res.h is that the latter
3 uses the ResGraphWrapper, while the first does not. (Bfs is implemented by
4 hand in both.) This test program runs Preflow and PreflowRes on the same
5 graph, tests the result of these implementations and writes the running time
9 #include <smart_graph.h>
12 #include <preflow_res.h>
13 #include <time_measure.h>
17 int main(int, char **) {
19 typedef SmartGraph Graph;
21 typedef Graph::Node Node;
22 typedef Graph::EdgeIt EdgeIt;
26 Graph::EdgeMap<int> cap(G);
27 readDimacsMaxFlow(std::cin, G, s, t, cap);
31 "\n In which way are we faster: using ResGraphWrapper or not?"
34 "\n Running preflow.h on a graph with " <<
35 G.nodeNum() << " nodes and " << G.edgeNum() << " edges..."
36 << std::endl<<std::endl;
40 Graph::EdgeMap<int> flow(G,0);
41 Preflow<Graph, int> max_flow_test(G, s, t, cap, flow, 1);
44 std::cout << "Elapsed time NOT using the ResGraphWrapper: " << std::endl
47 Graph::NodeMap<bool> mincut(G);
48 max_flow_test.minMinCut(mincut);
49 int min_min_cut_value=0;
51 for(G.first(e); G.valid(e); G.next(e)) {
52 if (mincut[G.tail(e)] && !mincut[G.head(e)]) min_min_cut_value+=cap[e];
55 Graph::NodeMap<bool> cut(G);
56 max_flow_test.minCut(cut);
58 for(G.first(e); G.valid(e); G.next(e)) {
59 if (cut[G.tail(e)] && !cut[G.head(e)])
60 min_cut_value+=cap[e];
63 Graph::NodeMap<bool> maxcut(G);
64 max_flow_test.maxMinCut(maxcut);
65 int max_min_cut_value=0;
66 for(G.first(e); G.valid(e); G.next(e)) {
67 if (maxcut[G.tail(e)] && !maxcut[G.head(e)])
68 max_min_cut_value+=cap[e];
71 std::cout << "\n Checking the result: " <<std::endl;
72 std::cout << "Flow value: "<< max_flow_test.flowValue() << std::endl;
73 std::cout << "Min cut value: "<< min_cut_value << std::endl;
74 std::cout << "Min min cut value: "<< min_min_cut_value << std::endl;
75 std::cout << "Max min cut value: "<< max_min_cut_value <<
78 if ( max_flow_test.flowValue() == min_cut_value &&
79 min_cut_value == min_min_cut_value &&
80 min_min_cut_value == max_min_cut_value )
81 std::cout << "They are equal! " <<std::endl<< std::endl<<"\n";
83 Graph::EdgeMap<int> flow2(G,0);
84 PreflowRes<Graph, int> max_flow_test2(G, s, t, cap, flow2, 1);
87 std::cout << "Elapsed time using the ResGraphWrapper: " << std::endl
90 Graph::NodeMap<bool> mincut2(G);
91 max_flow_test2.minMinCut(mincut2);
92 int min_min_cut_value2=0;
93 for(G.first(e); G.valid(e); G.next(e)) {
94 if (mincut2[G.tail(e)] && !mincut2[G.head(e)]) min_min_cut_value2+=cap[e];
97 Graph::NodeMap<bool> cut2(G);
98 max_flow_test2.minCut(cut2);
100 for(G.first(e); G.valid(e); G.next(e)) {
101 if (cut2[G.tail(e)] && !cut2[G.head(e)])
102 min_cut_value2+=cap[e];
105 Graph::NodeMap<bool> maxcut2(G);
106 max_flow_test2.maxMinCut(maxcut2);
107 int max_min_cut_value2=0;
108 for(G.first(e); G.valid(e); G.next(e)) {
109 if (maxcut2[G.tail(e)] && !maxcut2[G.head(e)])
110 max_min_cut_value2+=cap[e];
113 std::cout << "\n Checking the result: " <<std::endl;
114 std::cout << "Flow value: "<< max_flow_test2.flowValue() << std::endl;
115 std::cout << "Min cut value: "<< min_cut_value2 << std::endl;
116 std::cout << "Min min cut value: "<< min_min_cut_value2 << std::endl;
117 std::cout << "Max min cut value: "<< max_min_cut_value2 <<
119 if ( max_flow_test.flowValue() == min_cut_value &&
120 min_cut_value == min_min_cut_value &&
121 min_min_cut_value == max_min_cut_value )
122 std::cout << "They are equal! " <<std::endl<<"/n";