# HG changeset patch # User alpar # Date 1113597978 0 # Node ID 04733359bac236ab243c29c4c6014264b776b7c8 # Parent 4338e4280f678e8a2f543f2adaf1fe182e4b7403 lp_demo.cc becomes lp_maxflow_demo.cc WARNING: Repo doesn't compile! diff -r 4338e4280f67 -r 04733359bac2 src/demo/Makefile.am --- a/src/demo/Makefile.am Fri Apr 15 20:26:01 2005 +0000 +++ b/src/demo/Makefile.am Fri Apr 15 20:46:18 2005 +0000 @@ -11,7 +11,7 @@ sub_graph_wrapper_demo if HAVE_GLPK -noinst_PROGRAMS += lp_demo +noinst_PROGRAMS += lp_demo lp_maxflow_demo endif dim_to_dot_SOURCES = dim_to_dot.cc @@ -29,3 +29,7 @@ lp_demo_SOURCES = lp_demo.cc lp_demo_CXXFLAGS = $(GLPK_CFLAGS) lp_demo_LDFLAGS = $(GLPK_LIBS) + +lp_demo_SOURCES = lp_maxflow_demo.cc +lp_demo_CXXFLAGS = $(GLPK_CFLAGS) +lp_demo_LDFLAGS = $(GLPK_LIBS) diff -r 4338e4280f67 -r 04733359bac2 src/demo/lp_demo.cc --- a/src/demo/lp_demo.cc Fri Apr 15 20:26:01 2005 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,68 +0,0 @@ -#include -#include -#include - -using namespace lemon; - -template -double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t) -{ - LpGlpk lp; - - typedef G Graph; - typedef typename G::Node Node; - typedef typename G::NodeIt NodeIt; - typedef typename G::Edge Edge; - typedef typename G::EdgeIt EdgeIt; - typedef typename G::OutEdgeIt OutEdgeIt; - typedef typename G::InEdgeIt InEdgeIt; - - typename G::template EdgeMap x(g); - lp.addColSet(x); - - for(EdgeIt e(g);e!=INVALID;++e) { - lp.colUpperBound(x[e],cap[e]); - lp.colLowerBound(x[e],0); - } - - for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) { - LpGlpk::Expr ex; - for(InEdgeIt e(g,n);e!=INVALID;++e) ex+=x[e]; - for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e]; - lp.addRow(ex==0); - } - { - LpGlpk::Expr ex; - for(InEdgeIt e(g,t);e!=INVALID;++e) ex+=x[e]; - for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e]; - lp.setObj(ex); - } - lp.max(); - - lp.presolver(true); - - lp.messageLevel(3); - - lp.solve(); - - return lp.primalValue(); -} - -int main() -{ - ListGraph g; - ListGraph::Node s; - ListGraph::Node t; - - ListGraph::EdgeMap cap(g); - - GraphReader reader(std::cin,g); - reader.addNode("source",s).addNode("target",t) - .addEdgeMap("capacity",cap).run(); - - // std::ifstream file("../test/preflow_"); -// readDimacs(file, g, cap, s, t); - - std::cout << "Max flow value = " << maxFlow(g,cap,s,t) << std::endl; - -} diff -r 4338e4280f67 -r 04733359bac2 src/demo/lp_maxflow_demo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/demo/lp_maxflow_demo.cc Fri Apr 15 20:46:18 2005 +0000 @@ -0,0 +1,68 @@ +#include +#include +#include + +using namespace lemon; + +template +double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t) +{ + LpGlpk lp; + + typedef G Graph; + typedef typename G::Node Node; + typedef typename G::NodeIt NodeIt; + typedef typename G::Edge Edge; + typedef typename G::EdgeIt EdgeIt; + typedef typename G::OutEdgeIt OutEdgeIt; + typedef typename G::InEdgeIt InEdgeIt; + + typename G::template EdgeMap x(g); + lp.addColSet(x); + + for(EdgeIt e(g);e!=INVALID;++e) { + lp.colUpperBound(x[e],cap[e]); + lp.colLowerBound(x[e],0); + } + + for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) { + LpGlpk::Expr ex; + for(InEdgeIt e(g,n);e!=INVALID;++e) ex+=x[e]; + for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e]; + lp.addRow(ex==0); + } + { + LpGlpk::Expr ex; + for(InEdgeIt e(g,t);e!=INVALID;++e) ex+=x[e]; + for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e]; + lp.setObj(ex); + } + lp.max(); + + lp.presolver(true); + + lp.messageLevel(3); + + lp.solve(); + + return lp.primalValue(); +} + +int main() +{ + ListGraph g; + ListGraph::Node s; + ListGraph::Node t; + + ListGraph::EdgeMap cap(g); + + GraphReader reader(std::cin,g); + reader.addNode("source",s).addNode("target",t) + .addEdgeMap("capacity",cap).run(); + + // std::ifstream file("../test/preflow_"); +// readDimacs(file, g, cap, s, t); + + std::cout << "Max flow value = " << maxFlow(g,cap,s,t) << std::endl; + +}