# HG changeset patch # User alpar # Date 1113599730 0 # Node ID b4330c52caebcfdaf7a068727b76f96f0a053446 # Parent 04733359bac236ab243c29c4c6014264b776b7c8 - Adding new lp_demo.cc finished - Several 'unused variable' warnings fixed in 'lp_skeleton.cc' diff -r 04733359bac2 -r b4330c52caeb src/demo/Makefile.am --- a/src/demo/Makefile.am Fri Apr 15 20:46:18 2005 +0000 +++ b/src/demo/Makefile.am Fri Apr 15 21:15:30 2005 +0000 @@ -30,6 +30,6 @@ 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) +lp_maxflow_demo_SOURCES = lp_maxflow_demo.cc +lp_maxflow_demo_CXXFLAGS = $(GLPK_CFLAGS) +lp_maxflow_demo_LDFLAGS = $(GLPK_LIBS) diff -r 04733359bac2 -r b4330c52caeb src/demo/lp_demo.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/demo/lp_demo.cc Fri Apr 15 21:15:30 2005 +0000 @@ -0,0 +1,96 @@ +#include +#include +using namespace lemon; + +int main() +{ + //The following example is taken from the documentation of the GLPK library. + //See it in the GLPK reference manual and among the GLPK sample files (sample.c) + LpGlpk lp; + typedef LpGlpk::Row Row; + typedef LpGlpk::Col Col; + + lp.max(); + + Col x1 = lp.addCol(); + Col x2 = lp.addCol(); + Col x3 = lp.addCol(); + + //One solution + // Row p = lp.addRow(); + // Row q = lp.addRow(); + // Row r = lp.addRow(); + // lp.setRow(p,x1+x2+x3 <=100); + // lp.setRow(q,10*x1+4*x2+5*x3<=600); + // lp.setRow(r,2*x1+2*x2+6*x3<=300); + + //A more elegant one + //Constraints + lp.addRow(x1+x2+x3 <=100); + lp.addRow(10*x1+4*x2+5*x3<=600); + lp.addRow(2*x1+2*x2+6*x3<=300); + //Nonnegativity of the variables + lp.colLowerBound(x1, 0); + lp.colLowerBound(x2, 0); + lp.colLowerBound(x3, 0); + //Objective function + lp.setObj(10*x1+6*x2+4*x3); + + lp.solve(); + + if (lp.primalStatus()==LpSolverBase::OPTIMAL){ + printf("Z = %g; x1 = %g; x2 = %g; x3 = %g\n", + lp.primalValue(), + lp.primal(x1), lp.primal(x2), lp.primal(x3)); + } + else{ + std::cout<<"Optimal solution not found!"<