Several changes in the docs.
5 #include <lemon/smart_graph.h>
6 #include <lemon/list_graph.h>
7 #include <lemon/dimacs.h>
8 #include <lemon/time_measure.h>
9 //#include <graph_wrapper.h>
10 #include <lemon/preflow.h>
11 #include <augmenting_flow.h>
12 //#include <preflow_res.h>
13 //#include <lp_solver_wrapper_2.h>
14 #include <min_cost_gen_flow.h>
16 // Use a DIMACS max flow file as stdin.
17 // max_flow_demo < dimacs_max_flow_file
19 using namespace lemon;
21 int main(int, char **) {
23 typedef ListGraph MutableGraph;
24 typedef ListGraph Graph;
25 typedef Graph::Node Node;
26 typedef Graph::Edge Edge;
27 typedef Graph::EdgeIt EdgeIt;
32 Graph::EdgeMap<int> cap(g);
33 //readDimacsMaxFlow(std::cin, g, s, t, cap);
34 readDimacs(std::cin, g, cap, s, t);
36 Graph::EdgeMap<int> flow(g); //0 flow
37 Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
38 max_flow_test(g, s, t, cap, flow);
39 AugmentingFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
40 augmenting_flow_test(g, s, t, cap, flow);
42 Graph::NodeMap<bool> cut(g);
45 std::cout << "preflow ..." << std::endl;
48 std::cout << "elapsed time: " << ts << std::endl;
49 std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
50 max_flow_test.minCut(cut);
52 for (EdgeIt e(g); e!=INVALID; ++e) {
53 if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e])
54 std::cout << "Slackness does not hold!" << std::endl;
55 if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0)
56 std::cout << "Slackness does not hold!" << std::endl;
61 // std::cout << "preflow ..." << std::endl;
62 // FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
64 // max_flow_test.preflow(Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >::GEN_FLOW);
65 // std::cout << "elapsed time: " << ts << std::endl;
66 // std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
68 // FOR_EACH_LOC(Graph::EdgeIt, e, g) {
69 // if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e])
70 // std::cout << "Slackness does not hold!" << std::endl;
71 // if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0)
72 // std::cout << "Slackness does not hold!" << std::endl;
77 // std::cout << "wrapped preflow ..." << std::endl;
78 // FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
80 // pre_flow_res.run();
81 // std::cout << "elapsed time: " << ts << std::endl;
82 // std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
86 std::cout << "physical blocking flow augmentation ..." << std::endl;
87 for (EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
90 while (augmenting_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
91 std::cout << "elapsed time: " << ts << std::endl;
92 std::cout << "number of augmentation phases: " << i << std::endl;
93 std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
95 for (EdgeIt e(g); e!=INVALID; ++e) {
96 if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e])
97 std::cout << "Slackness does not hold!" << std::endl;
98 if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0)
99 std::cout << "Slackness does not hold!" << std::endl;
104 // std::cout << "faster physical blocking flow augmentation ..." << std::endl;
105 // FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
108 // while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
109 // std::cout << "elapsed time: " << ts << std::endl;
110 // std::cout << "number of augmentation phases: " << i << std::endl;
111 // std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
115 std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
116 for (EdgeIt e(g); e!=INVALID; ++e) flow.set(e, 0);
119 while (augmenting_flow_test.augmentOnBlockingFlow2()) { ++i; }
120 std::cout << "elapsed time: " << ts << std::endl;
121 std::cout << "number of augmentation phases: " << i << std::endl;
122 std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
124 for (EdgeIt e(g); e!=INVALID; ++e) {
125 if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e])
126 std::cout << "Slackness does not hold!" << std::endl;
127 if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0)
128 std::cout << "Slackness does not hold!" << std::endl;
133 // std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
134 // FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
137 // while (augmenting_flow_test.augmentOnShortestPath()) { ++i; }
138 // std::cout << "elapsed time: " << ts << std::endl;
139 // std::cout << "number of augmentation phases: " << i << std::endl;
140 // std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
142 // FOR_EACH_LOC(Graph::EdgeIt, e, g) {
143 // if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e])
144 // std::cout << "Slackness does not hold!" << std::endl;
145 // if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0)
146 // std::cout << "Slackness does not hold!" << std::endl;
151 // std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
152 // FOR_EACH_LOC(Graph::EdgeIt, e, g) flow.set(e, 0);
155 // while (augmenting_flow_test.augmentOnShortestPath2()) { ++i; }
156 // std::cout << "elapsed time: " << ts << std::endl;
157 // std::cout << "number of augmentation phases: " << i << std::endl;
158 // std::cout << "flow value: "<< augmenting_flow_test.flowValue() << std::endl;
160 // FOR_EACH_LOC(Graph::EdgeIt, e, g) {
161 // if (cut[g.source(e)] && !cut[g.target(e)] && !flow[e]==cap[e])
162 // std::cout << "Slackness does not hold!" << std::endl;
163 // if (!cut[g.source(e)] && cut[g.target(e)] && flow[e]>0)
164 // std::cout << "Slackness does not hold!" << std::endl;
170 Edge e=g.addEdge(t, s);
171 Graph::EdgeMap<int> cost(g, 0);
174 typedef ConstMap<Node, int> Excess;
176 typedef ConstMap<Edge, int> LCap;
179 MinCostGenFlow<Graph, int, Excess, LCap>
180 min_cost(g, excess, lcap, cap, flow, cost);
184 std::cout << "elapsed time: " << ts << std::endl;
185 std::cout << "flow value: "<< flow[e] << std::endl;