marci@73
|
1 |
#include <iostream>
|
marci@73
|
2 |
#include <fstream>
|
marci@73
|
3 |
|
marci@73
|
4 |
#include <list_graph.hh>
|
marci@73
|
5 |
#include <dimacs.hh>
|
marci@73
|
6 |
#include <edmonds_karp.hh>
|
marci@73
|
7 |
#include <time_measure.h>
|
marci@73
|
8 |
|
alpar@105
|
9 |
using namespace hugo;
|
marci@73
|
10 |
|
marci@73
|
11 |
// Use a DIMACS max flow file as stdin.
|
marci@73
|
12 |
// read_dimacs_demo < dimacs_max_flow_file
|
marci@73
|
13 |
int main(int, char **) {
|
marci@73
|
14 |
typedef ListGraph::NodeIt NodeIt;
|
marci@73
|
15 |
typedef ListGraph::EachEdgeIt EachEdgeIt;
|
marci@73
|
16 |
|
marci@73
|
17 |
ListGraph G;
|
marci@73
|
18 |
NodeIt s, t;
|
marci@73
|
19 |
ListGraph::EdgeMap<int> cap(G);
|
marci@73
|
20 |
readDimacsMaxFlow(std::cin, G, s, t, cap);
|
marci@73
|
21 |
|
marci@100
|
22 |
/*
|
marci@100
|
23 |
double pre_time_copy=currTime();
|
marci@100
|
24 |
ListGraph F;
|
marci@100
|
25 |
ListGraph::NodeMap<NodeIt> G_to_F(G);
|
marci@100
|
26 |
typedef ListGraph::EachNodeIt EachNodeIt;
|
marci@100
|
27 |
for(EachNodeIt n=G.first<EachNodeIt>(); n.valid(); ++n) {
|
marci@100
|
28 |
G_to_F.set(n, F.addNode());
|
marci@100
|
29 |
}
|
marci@100
|
30 |
for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
|
marci@100
|
31 |
F.addEdge(G_to_F.get(G.tail(e)), G_to_F.get(G.head(e)));
|
marci@100
|
32 |
}
|
marci@100
|
33 |
double post_time_copy=currTime();
|
marci@100
|
34 |
std::cout << "copy time: " << post_time_copy-pre_time_copy << " sec"<< std::endl;
|
marci@100
|
35 |
*/
|
marci@100
|
36 |
|
marci@73
|
37 |
std::cout << "edmonds karp demo..." << std::endl;
|
marci@73
|
38 |
ListGraph::EdgeMap<int> flow(G); //0 flow
|
marci@73
|
39 |
|
marci@73
|
40 |
double pre_time=currTime();
|
marci@73
|
41 |
MaxFlow<ListGraph, int, ListGraph::EdgeMap<int>, ListGraph::EdgeMap<int> > max_flow_test(G, s, t, flow, cap);
|
marci@100
|
42 |
max_flow_test.augmentWithBlockingFlow();
|
marci@73
|
43 |
max_flow_test.run();
|
marci@73
|
44 |
double post_time=currTime();
|
marci@73
|
45 |
//std::cout << "maximum flow: "<< std::endl;
|
marci@73
|
46 |
//for(EachEdgeIt e=G.first<EachEdgeIt>(); e.valid(); ++e) {
|
marci@73
|
47 |
// std::cout<<"("<<G.tail(e)<< "-"<<flow.get(e)<<"->"<<G.head(e)<<") ";
|
marci@73
|
48 |
//}
|
marci@73
|
49 |
//std::cout<<std::endl;
|
marci@73
|
50 |
std::cout << "elapsed time: " << post_time-pre_time << " sec"<< std::endl;
|
marci@73
|
51 |
std::cout << "flow value: "<< max_flow_test.flowValue() << std::endl;
|
marci@73
|
52 |
|
marci@73
|
53 |
return 0;
|
marci@73
|
54 |
}
|