I really have no idea about what to write here now.
1 #include<lemon/lp_glpk.h>
2 #include<lemon/graph_reader.h>
3 #include<lemon/list_graph.h>
7 template<class G,class C>
8 double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t)
13 typedef typename G::Node Node;
14 typedef typename G::NodeIt NodeIt;
15 typedef typename G::Edge Edge;
16 typedef typename G::EdgeIt EdgeIt;
17 typedef typename G::OutEdgeIt OutEdgeIt;
18 typedef typename G::InEdgeIt InEdgeIt;
20 typename G::template EdgeMap<LpGlpk::Col> x(g);
23 for(EdgeIt e(g);e!=INVALID;++e) {
24 lp.colUpperBound(x[e],cap[e]);
25 lp.colLowerBound(x[e],0);
28 for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) {
30 for(InEdgeIt e(g,n);e!=INVALID;++e) ex+=x[e];
31 for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e];
36 for(InEdgeIt e(g,t);e!=INVALID;++e) ex+=x[e];
37 for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
48 return lp.primalValue();
57 ListGraph::EdgeMap<double> cap(g);
59 GraphReader<ListGraph> reader(std::cin,g);
60 reader.addNode("source",s).addNode("target",t)
61 .addEdgeMap("capacity",cap).run();
63 // std::ifstream file("../test/preflow_");
64 // readDimacs(file, g, cap, s, t);
66 std::cout << "Max flow value = " << maxFlow(g,cap,s,t) << std::endl;