#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!"<