marci@174
|
1 |
// -*- c++ -*-
|
marci@73
|
2 |
#include <iostream>
|
marci@73
|
3 |
#include <fstream>
|
marci@73
|
4 |
|
marci@174
|
5 |
#include <list_graph.h>
|
marci@415
|
6 |
#include <smart_graph.h>
|
marci@174
|
7 |
#include <dimacs.h>
|
marci@472
|
8 |
//#include <edmonds_karp.h>
|
marci@73
|
9 |
#include <time_measure.h>
|
marci@303
|
10 |
//#include <graph_wrapper.h>
|
marci@311
|
11 |
#include <preflow.h>
|
marci@472
|
12 |
//#include <preflow_res.h>
|
marci@333
|
13 |
#include <for_each_macros.h>
|
marci@266
|
14 |
|
alpar@105
|
15 |
using namespace hugo;
|
marci@73
|
16 |
|
marci@73
|
17 |
// Use a DIMACS max flow file as stdin.
|
marci@73
|
18 |
// read_dimacs_demo < dimacs_max_flow_file
|
marci@139
|
19 |
|
marci@174
|
20 |
|
marci@174
|
21 |
// struct Ize {
|
marci@174
|
22 |
// };
|
marci@139
|
23 |
|
marci@174
|
24 |
// struct Mize {
|
marci@174
|
25 |
// Ize bumm;
|
marci@174
|
26 |
// };
|
marci@139
|
27 |
|
marci@174
|
28 |
// template <typename B>
|
marci@174
|
29 |
// class Huha {
|
marci@174
|
30 |
// public:
|
marci@174
|
31 |
// int u;
|
marci@174
|
32 |
// B brr;
|
marci@174
|
33 |
// };
|
marci@174
|
34 |
|
marci@139
|
35 |
|
marci@73
|
36 |
int main(int, char **) {
|
marci@73
|
37 |
|
marci@174
|
38 |
typedef ListGraph MutableGraph;
|
marci@139
|
39 |
|
marci@415
|
40 |
typedef SmartGraph Graph;
|
marci@415
|
41 |
// typedef ListGraph Graph;
|
marci@174
|
42 |
typedef Graph::Node Node;
|
marci@174
|
43 |
typedef Graph::EdgeIt EdgeIt;
|
marci@139
|
44 |
|
marci@139
|
45 |
|
marci@174
|
46 |
// Mize mize[10];
|
marci@174
|
47 |
// Mize bize[0];
|
marci@174
|
48 |
// Mize zize;
|
marci@174
|
49 |
// typedef Mize Tize[0];
|
marci@146
|
50 |
|
marci@174
|
51 |
// std::cout << &zize << " " << sizeof(mize) << sizeof(Tize) << std::endl;
|
marci@174
|
52 |
// std::cout << sizeof(bize) << std::endl;
|
marci@146
|
53 |
|
marci@146
|
54 |
|
marci@174
|
55 |
// Huha<Tize> k;
|
marci@174
|
56 |
// std::cout << sizeof(k) << std::endl;
|
marci@139
|
57 |
|
marci@174
|
58 |
|
marci@174
|
59 |
// struct Bumm {
|
marci@174
|
60 |
// //int a;
|
marci@174
|
61 |
// bool b;
|
marci@174
|
62 |
// };
|
marci@174
|
63 |
|
marci@174
|
64 |
// std::cout << sizeof(Bumm) << std::endl;
|
marci@174
|
65 |
|
marci@174
|
66 |
|
marci@174
|
67 |
Graph G;
|
marci@174
|
68 |
Node s, t;
|
marci@174
|
69 |
Graph::EdgeMap<int> cap(G);
|
marci@73
|
70 |
readDimacsMaxFlow(std::cin, G, s, t, cap);
|
marci@333
|
71 |
Timer ts;
|
marci@333
|
72 |
Graph::EdgeMap<int> flow(G); //0 flow
|
marci@333
|
73 |
Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
|
marci@465
|
74 |
pre_flow_test(G, s, t, cap, flow/*, true*/);
|
marci@472
|
75 |
// Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
|
marci@472
|
76 |
// pre_flow_ize(G, s, t, cap, flow/*, false*/);
|
marci@465
|
77 |
// PreflowRes<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
|
marci@465
|
78 |
// pre_flow_res(G, s, t, cap, flow/*, true*/);
|
marci@472
|
79 |
//MaxFlow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >
|
marci@472
|
80 |
// max_flow_test(G, s, t, cap, flow);
|
marci@155
|
81 |
|
marci@311
|
82 |
{
|
marci@311
|
83 |
std::cout << "preflow ..." << std::endl;
|
marci@311
|
84 |
ts.reset();
|
marci@333
|
85 |
pre_flow_test.run();
|
marci@311
|
86 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@333
|
87 |
std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
|
marci@311
|
88 |
}
|
marci@73
|
89 |
|
marci@133
|
90 |
{
|
marci@418
|
91 |
std::cout << "preflow ..." << std::endl;
|
marci@418
|
92 |
FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@418
|
93 |
ts.reset();
|
marci@472
|
94 |
pre_flow_test.preflow(Preflow<Graph, int, Graph::EdgeMap<int>, Graph::EdgeMap<int> >::GEN_FLOW);
|
marci@418
|
95 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@472
|
96 |
std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
|
marci@418
|
97 |
}
|
marci@418
|
98 |
|
marci@465
|
99 |
// {
|
marci@465
|
100 |
// std::cout << "wrapped preflow ..." << std::endl;
|
marci@465
|
101 |
// FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@465
|
102 |
// ts.reset();
|
marci@465
|
103 |
// pre_flow_res.run();
|
marci@465
|
104 |
// std::cout << "elapsed time: " << ts << std::endl;
|
marci@465
|
105 |
// std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
|
marci@465
|
106 |
// }
|
marci@376
|
107 |
|
marci@376
|
108 |
{
|
marci@311
|
109 |
std::cout << "physical blocking flow augmentation ..." << std::endl;
|
marci@333
|
110 |
FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@174
|
111 |
ts.reset();
|
marci@174
|
112 |
int i=0;
|
marci@472
|
113 |
while (pre_flow_test.augmentOnBlockingFlow<MutableGraph>()) { ++i; }
|
marci@174
|
114 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@174
|
115 |
std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@472
|
116 |
std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
|
marci@168
|
117 |
}
|
marci@168
|
118 |
|
marci@472
|
119 |
// {
|
marci@472
|
120 |
// std::cout << "faster physical blocking flow augmentation ..." << std::endl;
|
marci@472
|
121 |
// FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@472
|
122 |
// ts.reset();
|
marci@472
|
123 |
// int i=0;
|
marci@472
|
124 |
// while (max_flow_test.augmentOnBlockingFlow1<MutableGraph>()) { ++i; }
|
marci@472
|
125 |
// std::cout << "elapsed time: " << ts << std::endl;
|
marci@472
|
126 |
// std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@472
|
127 |
// std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@472
|
128 |
// }
|
marci@266
|
129 |
|
marci@269
|
130 |
{
|
marci@311
|
131 |
std::cout << "on-the-fly blocking flow augmentation ..." << std::endl;
|
marci@333
|
132 |
FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@269
|
133 |
ts.reset();
|
marci@269
|
134 |
int i=0;
|
marci@472
|
135 |
while (pre_flow_test.augmentOnBlockingFlow2()) { ++i; }
|
marci@269
|
136 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@269
|
137 |
std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@472
|
138 |
std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
|
marci@269
|
139 |
}
|
marci@266
|
140 |
|
marci@168
|
141 |
{
|
marci@311
|
142 |
std::cout << "on-the-fly shortest path augmentation ..." << std::endl;
|
marci@333
|
143 |
FOR_EACH_LOC(Graph::EdgeIt, e, G) flow.set(e, 0);
|
marci@206
|
144 |
ts.reset();
|
marci@174
|
145 |
int i=0;
|
marci@472
|
146 |
while (pre_flow_test.augmentOnShortestPath()) { ++i; }
|
marci@174
|
147 |
std::cout << "elapsed time: " << ts << std::endl;
|
marci@174
|
148 |
std::cout << "number of augmentation phases: " << i << std::endl;
|
marci@472
|
149 |
std::cout << "flow value: "<< pre_flow_test.flowValue() << std::endl;
|
marci@168
|
150 |
}
|
marci@133
|
151 |
|
marci@73
|
152 |
|
marci@73
|
153 |
return 0;
|
marci@73
|
154 |
}
|