lp_demo.cc becomes lp_maxflow_demo.cc
authoralpar
Fri, 15 Apr 2005 20:46:18 +0000
changeset 136104733359bac2
parent 1360 4338e4280f67
child 1362 b4330c52caeb
lp_demo.cc becomes lp_maxflow_demo.cc
WARNING: Repo doesn't compile!
src/demo/Makefile.am
src/demo/lp_demo.cc
src/demo/lp_maxflow_demo.cc
     1.1 --- a/src/demo/Makefile.am	Fri Apr 15 20:26:01 2005 +0000
     1.2 +++ b/src/demo/Makefile.am	Fri Apr 15 20:46:18 2005 +0000
     1.3 @@ -11,7 +11,7 @@
     1.4  	sub_graph_wrapper_demo
     1.5  
     1.6  if HAVE_GLPK
     1.7 -noinst_PROGRAMS += lp_demo
     1.8 +noinst_PROGRAMS += lp_demo lp_maxflow_demo
     1.9  endif
    1.10  
    1.11  dim_to_dot_SOURCES = dim_to_dot.cc
    1.12 @@ -29,3 +29,7 @@
    1.13  lp_demo_SOURCES = lp_demo.cc
    1.14  lp_demo_CXXFLAGS = $(GLPK_CFLAGS)
    1.15  lp_demo_LDFLAGS = $(GLPK_LIBS)
    1.16 +
    1.17 +lp_demo_SOURCES = lp_maxflow_demo.cc
    1.18 +lp_demo_CXXFLAGS = $(GLPK_CFLAGS)
    1.19 +lp_demo_LDFLAGS = $(GLPK_LIBS)
     2.1 --- a/src/demo/lp_demo.cc	Fri Apr 15 20:26:01 2005 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,68 +0,0 @@
     2.4 -#include<lemon/lp_glpk.h>
     2.5 -#include<lemon/graph_reader.h>
     2.6 -#include<lemon/list_graph.h>
     2.7 -
     2.8 -using namespace lemon;
     2.9 -
    2.10 -template<class G,class C>
    2.11 -double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t)
    2.12 -{
    2.13 -  LpGlpk lp;
    2.14 -  
    2.15 -  typedef G Graph;
    2.16 -  typedef typename G::Node Node;
    2.17 -  typedef typename G::NodeIt NodeIt;
    2.18 -  typedef typename G::Edge Edge;
    2.19 -  typedef typename G::EdgeIt EdgeIt;
    2.20 -  typedef typename G::OutEdgeIt OutEdgeIt;
    2.21 -  typedef typename G::InEdgeIt InEdgeIt;
    2.22 -  
    2.23 -  typename G::template EdgeMap<LpGlpk::Col> x(g);
    2.24 -  lp.addColSet(x);
    2.25 -  
    2.26 -  for(EdgeIt e(g);e!=INVALID;++e) {
    2.27 -    lp.colUpperBound(x[e],cap[e]);
    2.28 -    lp.colLowerBound(x[e],0);
    2.29 -  }
    2.30 -
    2.31 -  for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) {
    2.32 -    LpGlpk::Expr ex;
    2.33 -    for(InEdgeIt  e(g,n);e!=INVALID;++e) ex+=x[e];
    2.34 -    for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e];
    2.35 -    lp.addRow(ex==0);
    2.36 -  }
    2.37 -  {
    2.38 -    LpGlpk::Expr ex;
    2.39 -    for(InEdgeIt  e(g,t);e!=INVALID;++e) ex+=x[e];
    2.40 -    for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
    2.41 -    lp.setObj(ex);
    2.42 -  }
    2.43 -  lp.max();
    2.44 -
    2.45 -  lp.presolver(true);
    2.46 -  
    2.47 -  lp.messageLevel(3);
    2.48 -
    2.49 -  lp.solve();
    2.50 -
    2.51 -  return lp.primalValue();
    2.52 -}
    2.53 -
    2.54 -int main() 
    2.55 -{
    2.56 -  ListGraph g;
    2.57 -  ListGraph::Node s;
    2.58 -  ListGraph::Node t;
    2.59 -  
    2.60 -  ListGraph::EdgeMap<double> cap(g);
    2.61 -  
    2.62 -  GraphReader<ListGraph> reader(std::cin,g);
    2.63 -  reader.addNode("source",s).addNode("target",t)
    2.64 -    .addEdgeMap("capacity",cap).run();
    2.65 -  
    2.66 -  // std::ifstream file("../test/preflow_");
    2.67 -//   readDimacs(file, g, cap, s, t);
    2.68 -
    2.69 -  std::cout << "Max flow value = " << maxFlow(g,cap,s,t) << std::endl;
    2.70 -
    2.71 -}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/demo/lp_maxflow_demo.cc	Fri Apr 15 20:46:18 2005 +0000
     3.3 @@ -0,0 +1,68 @@
     3.4 +#include<lemon/lp_glpk.h>
     3.5 +#include<lemon/graph_reader.h>
     3.6 +#include<lemon/list_graph.h>
     3.7 +
     3.8 +using namespace lemon;
     3.9 +
    3.10 +template<class G,class C>
    3.11 +double maxFlow(const G &g,const C &cap,typename G::Node s,typename G::Node t)
    3.12 +{
    3.13 +  LpGlpk lp;
    3.14 +  
    3.15 +  typedef G Graph;
    3.16 +  typedef typename G::Node Node;
    3.17 +  typedef typename G::NodeIt NodeIt;
    3.18 +  typedef typename G::Edge Edge;
    3.19 +  typedef typename G::EdgeIt EdgeIt;
    3.20 +  typedef typename G::OutEdgeIt OutEdgeIt;
    3.21 +  typedef typename G::InEdgeIt InEdgeIt;
    3.22 +  
    3.23 +  typename G::template EdgeMap<LpGlpk::Col> x(g);
    3.24 +  lp.addColSet(x);
    3.25 +  
    3.26 +  for(EdgeIt e(g);e!=INVALID;++e) {
    3.27 +    lp.colUpperBound(x[e],cap[e]);
    3.28 +    lp.colLowerBound(x[e],0);
    3.29 +  }
    3.30 +
    3.31 +  for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) {
    3.32 +    LpGlpk::Expr ex;
    3.33 +    for(InEdgeIt  e(g,n);e!=INVALID;++e) ex+=x[e];
    3.34 +    for(OutEdgeIt e(g,n);e!=INVALID;++e) ex-=x[e];
    3.35 +    lp.addRow(ex==0);
    3.36 +  }
    3.37 +  {
    3.38 +    LpGlpk::Expr ex;
    3.39 +    for(InEdgeIt  e(g,t);e!=INVALID;++e) ex+=x[e];
    3.40 +    for(OutEdgeIt e(g,t);e!=INVALID;++e) ex-=x[e];
    3.41 +    lp.setObj(ex);
    3.42 +  }
    3.43 +  lp.max();
    3.44 +
    3.45 +  lp.presolver(true);
    3.46 +  
    3.47 +  lp.messageLevel(3);
    3.48 +
    3.49 +  lp.solve();
    3.50 +
    3.51 +  return lp.primalValue();
    3.52 +}
    3.53 +
    3.54 +int main() 
    3.55 +{
    3.56 +  ListGraph g;
    3.57 +  ListGraph::Node s;
    3.58 +  ListGraph::Node t;
    3.59 +  
    3.60 +  ListGraph::EdgeMap<double> cap(g);
    3.61 +  
    3.62 +  GraphReader<ListGraph> reader(std::cin,g);
    3.63 +  reader.addNode("source",s).addNode("target",t)
    3.64 +    .addEdgeMap("capacity",cap).run();
    3.65 +  
    3.66 +  // std::ifstream file("../test/preflow_");
    3.67 +//   readDimacs(file, g, cap, s, t);
    3.68 +
    3.69 +  std::cout << "Max flow value = " << maxFlow(g,cap,s,t) << std::endl;
    3.70 +
    3.71 +}