jacint@109
|
1 |
#include <iostream>
|
jacint@109
|
2 |
|
jacint@220
|
3 |
#include <smart_graph.h>
|
jacint@211
|
4 |
#include <list_graph.h>
|
jacint@211
|
5 |
#include <dimacs.h>
|
jacint@372
|
6 |
#include <preflowproba.h>
|
jacint@109
|
7 |
#include <time_measure.h>
|
jacint@109
|
8 |
|
jacint@109
|
9 |
using namespace hugo;
|
jacint@109
|
10 |
|
jacint@109
|
11 |
int main(int, char **) {
|
jacint@372
|
12 |
|
jacint@372
|
13 |
typedef SmartGraph Graph;
|
jacint@372
|
14 |
|
jacint@372
|
15 |
typedef Graph::Node Node;
|
jacint@372
|
16 |
typedef Graph::EdgeIt EdgeIt;
|
jacint@109
|
17 |
|
jacint@372
|
18 |
Graph G;
|
jacint@211
|
19 |
Node s, t;
|
jacint@372
|
20 |
Graph::EdgeMap<int> cap(G);
|
jacint@109
|
21 |
readDimacsMaxFlow(std::cin, G, s, t, cap);
|
jacint@372
|
22 |
Timer ts;
|
jacint@372
|
23 |
|
jacint@109
|
24 |
std::cout << "preflow demo ..." << std::endl;
|
jacint@109
|
25 |
|
jacint@372
|
26 |
Graph::EdgeMap<int> flow(G);
|
jacint@374
|
27 |
Preflow<Graph, int> max_flow_test(G, s, t, cap, flow, 1,1);
|
jacint@372
|
28 |
ts.reset();
|
jacint@211
|
29 |
max_flow_test.run();
|
jacint@374
|
30 |
std::cout << "elapsed time with res: " << ts << std::endl;
|
jacint@374
|
31 |
|
jacint@374
|
32 |
std::cout << "preflow demo ..." << std::endl;
|
jacint@374
|
33 |
|
jacint@374
|
34 |
Graph::EdgeMap<int> flow2(G);
|
jacint@374
|
35 |
Preflow<Graph, int> max_flow_test2(G, s, t, cap, flow, 1,0);
|
jacint@374
|
36 |
ts.reset();
|
jacint@374
|
37 |
max_flow_test2.run();
|
jacint@372
|
38 |
std::cout << "elapsed time: " << ts << std::endl;
|
jacint@211
|
39 |
|
jacint@372
|
40 |
Graph::NodeMap<bool> cut(G);
|
jacint@109
|
41 |
max_flow_test.minCut(cut);
|
jacint@109
|
42 |
int min_cut_value=0;
|
jacint@211
|
43 |
EdgeIt e;
|
jacint@211
|
44 |
for(G.first(e); G.valid(e); G.next(e)) {
|
jacint@220
|
45 |
if (cut[G.tail(e)] && !cut[G.head(e)]) min_cut_value+=cap[e];
|
jacint@109
|
46 |
}
|
jacint@109
|
47 |
|
jacint@372
|
48 |
Graph::NodeMap<bool> cut1(G);
|
jacint@109
|
49 |
max_flow_test.minMinCut(cut1);
|
jacint@109
|
50 |
int min_min_cut_value=0;
|
jacint@211
|
51 |
for(G.first(e); G.valid(e); G.next(e)) {
|
jacint@220
|
52 |
if (cut[G.tail(e)] && !cut[G.head(e)])
|
jacint@220
|
53 |
min_min_cut_value+=cap[e];
|
jacint@109
|
54 |
}
|
jacint@109
|
55 |
|
jacint@372
|
56 |
Graph::NodeMap<bool> cut2(G);
|
jacint@109
|
57 |
max_flow_test.maxMinCut(cut2);
|
jacint@109
|
58 |
int max_min_cut_value=0;
|
jacint@211
|
59 |
for(G.first(e); G.valid(e); G.next(e)) {
|
jacint@220
|
60 |
if (cut2[G.tail(e)] && !cut2[G.head(e)])
|
jacint@220
|
61 |
max_min_cut_value+=cap[e];
|
jacint@109
|
62 |
}
|
jacint@109
|
63 |
|
jacint@211
|
64 |
std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
jacint@109
|
65 |
std::cout << "min cut value: "<< min_cut_value << std::endl;
|
jacint@109
|
66 |
std::cout << "min min cut value: "<< min_min_cut_value << std::endl;
|
jacint@109
|
67 |
std::cout << "max min cut value: "<< max_min_cut_value <<
|
jacint@109
|
68 |
std::endl<< std::endl;
|
jacint@109
|
69 |
|
jacint@109
|
70 |
return 0;
|
jacint@109
|
71 |
}
|