athos@1315: #include athos@1315: #include athos@1315: using namespace lemon; athos@1315: athos@1315: int main() athos@1315: { athos@1318: //The following example is taken from the documentation of the GLPK library. athos@1318: //See it in the GLPK reference manual and among the GLPK sample files (sample.c) athos@1315: LpGlpk lp; athos@1315: typedef LpGlpk::Row Row; athos@1315: typedef LpGlpk::Col Col; athos@1318: athos@1318: lp.max(); athos@1318: athos@1318: Col x1 = lp.addCol(); athos@1318: Col x2 = lp.addCol(); athos@1318: Col x3 = lp.addCol(); athos@1318: athos@1318: //One solution athos@1318: // Row p = lp.addRow(); athos@1318: // Row q = lp.addRow(); athos@1318: // Row r = lp.addRow(); athos@1318: // lp.setRow(p,x1+x2+x3 <=100); athos@1318: // lp.setRow(q,10*x1+4*x2+5*x3<=600); athos@1318: // lp.setRow(r,2*x1+2*x2+6*x3<=300); athos@1318: athos@1318: //A more elegant one athos@1318: //Constraints athos@1318: lp.addRow(x1+x2+x3 <=100); athos@1318: lp.addRow(10*x1+4*x2+5*x3<=600); athos@1318: lp.addRow(2*x1+2*x2+6*x3<=300); athos@1318: //Nonnegativity of the variables athos@1318: lp.colLowerBound(x1, 0); athos@1318: lp.colLowerBound(x2, 0); athos@1318: lp.colLowerBound(x3, 0); athos@1318: //Objective function athos@1318: lp.setObj(10*x1+6*x2+4*x3); athos@1318: athos@1318: lp.solve(); athos@1338: athos@1338: if (lp.primalStatus()==LpSolverBase::OPTIMAL){ athos@1338: printf("Z = %g; x1 = %g; x2 = %g; x3 = %g\n", athos@1338: lp.primalValue(), athos@1338: lp.primal(x1), lp.primal(x2), lp.primal(x3)); athos@1338: } athos@1338: else{ athos@1338: std::cout<<"Optimal solution not found!"<