# HG changeset patch # User athos # Date 1119885933 0 # Node ID f8efed98d6a34420902a23c4b8e1fd22ab57428f # Parent b303c1741c9a6a7b29a9c257651b392872c7d58e Only added comments. diff -r b303c1741c9a -r f8efed98d6a3 demo/lp_maxflow_demo.cc --- a/demo/lp_maxflow_demo.cc Mon Jun 27 15:22:34 2005 +0000 +++ b/demo/lp_maxflow_demo.cc Mon Jun 27 15:25:33 2005 +0000 @@ -34,26 +34,34 @@ typedef typename G::OutEdgeIt OutEdgeIt; typedef typename G::InEdgeIt InEdgeIt; + //Define a map on the edges for the variables of the LP problem typename G::template EdgeMap x(g); lp.addColSet(x); + //Nonnegativity and capacity constraints for(EdgeIt e(g);e!=INVALID;++e) { lp.colUpperBound(x[e],cap[e]); lp.colLowerBound(x[e],0); } + + //Flow conservation constraints for the nodes (except for 's' and 't') for(NodeIt n(g);n!=INVALID;++n) if(n!=s&&n!=t) { LpDefault::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); } + + //Objective function: the flow value entering 't' { LpDefault::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); } + + //Maximization lp.max(); #ifdef HAVE_GLPK @@ -61,6 +69,7 @@ lp.messageLevel(3); #endif + //Solve with the underlying solver lp.solve(); return lp.primalValue();