Specialized ConstMap for defining constant maps at compile time, by klao.
Time comparision of the generic and specialized maps.
4 #include "test_tools.h"
5 #include <hugo/smart_graph.h>
6 #include <hugo/dimacs.h>
7 #include <hugo/preflow.h>
8 #include <hugo/skeletons/graph.h>
9 #include <hugo/skeletons/maps.h>
16 typedef skeleton::StaticGraph 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;
73 if( getenv("srcdir") ) {
74 f_name = std::string(getenv("srcdir")) + "/preflow_graph.dim";
77 f_name = "preflow_graph.dim";
80 std::ifstream file(f_name.c_str());
82 check(file, "Input file '" << f_name << "' not found.");
87 readDimacs(file, G, cap, s, t);
93 PType preflow_test(G, s, t, cap, flow);
94 preflow_test.run(PType::ZERO_FLOW);
96 CutMap mincut(G,false);
97 preflow_test.minCut(mincut);
98 int min_cut_value=cut_value(G,mincut,cap);
100 CutMap minmincut(G,false);
101 preflow_test.minMinCut(minmincut);
102 int min_min_cut_value=cut_value(G,minmincut,cap);
104 CutMap maxmincut(G,false);
105 preflow_test.maxMinCut(maxmincut);
106 int max_min_cut_value=cut_value(G,maxmincut,cap);
108 check(preflow_test.flowValue() == min_cut_value &&
109 min_cut_value == min_min_cut_value &&
110 min_min_cut_value == max_min_cut_value,
111 "The max flow value is not equal to the three min cut values.");
113 int flow_value=preflow_test.flowValue();
117 for(EdgeIt e(G); e!=INVALID; ++e) cap[e]=2*cap[e];
118 preflow_test.setCap(cap);
120 preflow_test.phase1(PType::PRE_FLOW);
122 CutMap mincut1(G,false);
123 preflow_test.minCut(mincut1);
124 min_cut_value=cut_value(G,mincut1,cap);
126 check(preflow_test.flowValue() == min_cut_value &&
127 min_cut_value == 2*flow_value,
128 "The max flow value or the min cut value is wrong.");
130 preflow_test.phase2();
132 CutMap mincut2(G,false);
133 preflow_test.minCut(mincut2);
134 min_cut_value=cut_value(G,mincut2,cap);
136 CutMap minmincut2(G,false);
137 preflow_test.minMinCut(minmincut2);
138 min_min_cut_value=cut_value(G,minmincut2,cap);
140 preflow_test.maxMinCut(maxmincut);
141 max_min_cut_value=cut_value(G,maxmincut,cap);
143 check(preflow_test.flowValue() == min_cut_value &&
144 min_cut_value == min_min_cut_value &&
145 min_min_cut_value == max_min_cut_value &&
146 min_cut_value == 2*flow_value,
147 "The max flow value or the three min cut values were not doubled");
152 for( int i=1; i==10; ++i ) {
157 preflow_test.setFlow(flow);
161 if ( tmp1 != INVALID ) s=tmp1;
165 if ( tmp2 != INVALID ) t=tmp2;
167 preflow_test.setSource(s);
168 preflow_test.setTarget(t);
172 CutMap mincut3(G,false);
173 preflow_test.minCut(mincut3);
174 min_cut_value=cut_value(G,mincut3,cap);
176 CutMap minmincut3(G,false);
177 preflow_test.minMinCut(minmincut3);
178 min_min_cut_value=cut_value(G,minmincut3,cap);
180 preflow_test.maxMinCut(maxmincut);
181 max_min_cut_value=cut_value(G,maxmincut,cap);
183 check(preflow_test.flowValue() == min_cut_value &&
184 min_cut_value == min_min_cut_value &&
185 min_min_cut_value == max_min_cut_value,
186 "The max flow value or the three min cut values are incorrect.");