alpar@1309
|
1 |
#include<lemon/lp_glpk.h>
|
alpar@1309
|
2 |
#include<lemon/graph_reader.h>
|
alpar@1309
|
3 |
#include<lemon/list_graph.h>
|
alpar@1309
|
4 |
|
alpar@1309
|
5 |
using namespace lemon;
|
alpar@1309
|
6 |
|
alpar@1309
|
7 |
template<class G,class C>
|
alpar@1309
|
8 |
double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t)
|
alpar@1309
|
9 |
{
|
alpar@1309
|
10 |
LpGlpk lp;
|
alpar@1309
|
11 |
|
alpar@1309
|
12 |
typedef G Graph;
|
alpar@1309
|
13 |
typedef typename G::Node Node;
|
alpar@1309
|
14 |
typedef typename G::NodeIt NodeIt;
|
alpar@1309
|
15 |
typedef typename G::Edge Edge;
|
alpar@1309
|
16 |
typedef typename G::EdgeIt EdgeIt;
|
alpar@1309
|
17 |
typedef typename G::OutEdgeIt OutEdgeIt;
|
alpar@1309
|
18 |
typedef typename G::InEdgeIt InEdgeIt;
|
alpar@1309
|
19 |
|
alpar@1309
|
20 |
typename G::template EdgeMap<LpGlpk::Col> x(g);
|
alpar@1309
|
21 |
lp.addColSet(x);
|
alpar@1309
|
22 |
|
alpar@1309
|
23 |
for(EdgeIt e(g);e!=INVALID;++e) {
|
alpar@1309
|
24 |
lp.colUpperBound(x[e],cap[e]);
|
alpar@1309
|
25 |
lp.colLowerBound(x[e],0);
|
alpar@1309
|
26 |
}
|
alpar@1309
|
27 |
|
alpar@1309
|
28 |
for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) {
|
alpar@1309
|
29 |
LpGlpk::Expr ex;
|
alpar@1309
|
30 |
for(InEdgeIt e(g,n);e!=INVALID;++e) ex+=x[e];
|
alpar@1309
|
31 |
for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e];
|
alpar@1309
|
32 |
lp.addRow(ex==0);
|
alpar@1309
|
33 |
}
|
alpar@1309
|
34 |
{
|
alpar@1309
|
35 |
LpGlpk::Expr ex;
|
alpar@1309
|
36 |
for(InEdgeIt e(g,t);e!=INVALID;++e) ex+=x[e];
|
alpar@1309
|
37 |
for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
|
alpar@1309
|
38 |
lp.setObj(ex);
|
alpar@1309
|
39 |
}
|
alpar@1309
|
40 |
|
alpar@1309
|
41 |
lp.solve();
|
alpar@1309
|
42 |
|
alpar@1309
|
43 |
return 0;
|
alpar@1309
|
44 |
}
|
alpar@1309
|
45 |
|
alpar@1309
|
46 |
int main()
|
alpar@1309
|
47 |
{
|
alpar@1309
|
48 |
LpGlpk lp_glpk;
|
alpar@1309
|
49 |
|
alpar@1309
|
50 |
ListGraph g;
|
alpar@1309
|
51 |
ListGraph::Node s=g.addNode();
|
alpar@1309
|
52 |
ListGraph::Node t=g.addNode();
|
alpar@1309
|
53 |
|
alpar@1309
|
54 |
ListGraph::EdgeMap<double> cap(g);
|
alpar@1309
|
55 |
|
alpar@1309
|
56 |
GraphReader<ListGraph> reader(std::cin,g);
|
alpar@1309
|
57 |
reader.addEdgeMap("capacity",cap).run();
|
alpar@1309
|
58 |
|
alpar@1309
|
59 |
maxFlow(g,cap,s,t);
|
alpar@1309
|
60 |
|
alpar@1309
|
61 |
}
|