Don't set {GLPK,CPLEX}_{CFLAGS,LIBS} if the check fails.
1 #include<lemon/graph_reader.h>
2 #include<lemon/list_graph.h>
6 #include <lemon/lp_glpk.h>
8 #include <lemon/lp_cplex.h>
11 using namespace lemon;
14 typedef LpGlpk LpDefault;
16 typedef LpCplex LpDefault;
20 template<class G,class C>
21 double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t)
26 typedef typename G::Node Node;
27 typedef typename G::NodeIt NodeIt;
28 typedef typename G::Edge Edge;
29 typedef typename G::EdgeIt EdgeIt;
30 typedef typename G::OutEdgeIt OutEdgeIt;
31 typedef typename G::InEdgeIt InEdgeIt;
33 typename G::template EdgeMap<LpDefault::Col> x(g);
36 for(EdgeIt e(g);e!=INVALID;++e) {
37 lp.colUpperBound(x[e],cap[e]);
38 lp.colLowerBound(x[e],0);
41 for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) {
43 for(InEdgeIt e(g,n);e!=INVALID;++e) ex+=x[e];
44 for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e];
49 for(InEdgeIt e(g,t);e!=INVALID;++e) ex+=x[e];
50 for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
62 return lp.primalValue();
71 ListGraph::EdgeMap<double> cap(g);
73 GraphReader<ListGraph> reader(std::cin,g);
74 reader.addNode("source",s).addNode("target",t)
75 .addEdgeMap("capacity",cap).run();
77 // std::ifstream file("../test/preflow_");
78 // readDimacs(file, g, cap, s, t);
80 std::cout << "Max flow value = " << maxFlow(g,cap,s,t) << std::endl;