Better handling of the input files of the tests.
2 #include "test_tools.h"
3 #include <hugo/smart_graph.h>
4 #include <hugo/dimacs.h>
5 #include <hugo/preflow.h>
6 #include <hugo/skeletons/graph.h>
7 #include <hugo/skeletons/maps.h>
16 typedef skeleton::StaticGraphSkeleton Graph;
18 typedef Graph::Node Node;
19 typedef Graph::Edge Edge;
20 typedef skeleton::ReadMap<Edge,VType> CapMap;
21 typedef skeleton::ReadWriteMap<Edge,VType> FlowMap;
22 typedef skeleton::ReadWriteMap<Node,bool> CutMap;
24 typedef Preflow<Graph, int, CapMap, FlowMap> PType;
32 PType preflow_test(G,n,n,cap,flow);
35 preflow_test.flowValue();
36 preflow_test.setSource(n);
37 preflow_test.setFlow(flow);
39 preflow_test.phase1(PType::NO_FLOW);
40 preflow_test.minCut(cut);
42 preflow_test.phase2();
43 preflow_test.setTarget(n);
44 preflow_test.setCap(cap);
45 preflow_test.minMinCut(cut);
46 preflow_test.maxMinCut(cut);
49 int cut_value ( SmartGraph& G, SmartGraph::NodeMap<bool>& cut,
50 SmartGraph::EdgeMap<int>& cap) {
53 for(SmartGraph::EdgeIt e(G); e!=INVALID; ++e) {
54 if (cut[G.tail(e)] && !cut[G.head(e)]) c+=cap[e];
61 typedef SmartGraph Graph;
63 typedef Graph::Node Node;
64 typedef Graph::NodeIt NodeIt;
65 typedef Graph::EdgeIt EdgeIt;
66 typedef Graph::EdgeMap<int> CapMap;
67 typedef Graph::EdgeMap<int> FlowMap;
68 typedef Graph::NodeMap<bool> CutMap;
70 typedef Preflow<Graph, int> PType;
74 f_name=new char[strlen(getenv("srcdir"))+50];
75 strcpy(f_name,getenv("srcdir"));
76 strcat(f_name,"/preflow_graph.inp");
78 std::ifstream file(f_name);
80 check(file,"Input file '" << f_name << "' not found.");
87 readDimacs(file, G, cap, s, t);
91 PType preflow_test(G, s, t, cap, flow);
92 preflow_test.run(PType::ZERO_FLOW);
95 CutMap mincut(G,false);
96 preflow_test.minCut(mincut);
97 int min_cut_value=cut_value(G,mincut,cap);
99 CutMap minmincut(G,false);
100 preflow_test.minMinCut(minmincut);
101 int min_min_cut_value=cut_value(G,minmincut,cap);
103 CutMap maxmincut(G,false);
104 preflow_test.maxMinCut(maxmincut);
105 int max_min_cut_value=cut_value(G,maxmincut,cap);
107 check(preflow_test.flowValue() == min_cut_value &&
108 min_cut_value == min_min_cut_value &&
109 min_min_cut_value == max_min_cut_value,
110 "The max flow value is not equal to the three min cut values.");
112 int flow_value=preflow_test.flowValue();
115 for(EdgeIt e(G); e!=INVALID; ++e) cap[e]=2*cap[e];
116 preflow_test.setCap(cap);
118 NodeIt tmp_node(G,t);
122 preflow_test.setTarget(t); //the max flow value remains 2*flow_value
123 //warning: ++t must be a valid node. In preflow_graph, it is.
125 preflow_test.phase1(PType::PRE_FLOW);
127 CutMap mincut1(G,false);
128 preflow_test.minCut(mincut1);
129 min_cut_value=cut_value(G,mincut1,cap);
131 check(preflow_test.flowValue() == min_cut_value &&
132 min_cut_value == 2*flow_value,
133 "The max flow value or the min cut value is wrong.");
135 preflow_test.phase2();
137 CutMap mincut2(G,false);
138 preflow_test.minCut(mincut2);
139 min_cut_value=cut_value(G,mincut2,cap);
141 CutMap minmincut2(G,false);
142 preflow_test.minMinCut(minmincut2);
143 min_min_cut_value=cut_value(G,minmincut2,cap);
146 preflow_test.maxMinCut(maxmincut);
148 max_min_cut_value=cut_value(G,maxmincut,cap);
150 check(preflow_test.flowValue() == min_cut_value &&
151 min_cut_value == min_min_cut_value &&
152 min_min_cut_value == max_min_cut_value &&
153 min_cut_value == 2*flow_value,
154 "The max flow value or the three min cut values were not doubled");
157 for( int i=1; i==1000; ++i ) {
162 preflow_test.setFlow(flow);
163 preflow_test.setSource(s);
167 CutMap mincut3(G,false);
168 preflow_test.minCut(mincut3);
169 min_cut_value=cut_value(G,mincut3,cap);
171 CutMap minmincut3(G,false);
172 preflow_test.minMinCut(minmincut3);
173 min_min_cut_value=cut_value(G,minmincut3,cap);
175 preflow_test.maxMinCut(maxmincut);
176 max_min_cut_value=cut_value(G,maxmincut,cap);
178 check(preflow_test.flowValue() == min_cut_value &&
179 min_cut_value == min_min_cut_value &&
180 min_min_cut_value == max_min_cut_value,
181 "The max flow value or the three min cut values are incorrect.");