#ifdef HAVE_CONFIG_H #include #endif #include #ifdef HAVE_GLPK #include #elif HAVE_CPLEX #include #endif using namespace lemon; #ifdef HAVE_GLPK typedef LpGlpk LpDefault; #elif HAVE_CPLEX typedef LpCplex LpDefault; #endif 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) //A default solver is taken LpDefault lp; typedef LpDefault::Row Row; typedef LpDefault::Col Col; //This will be a maximization lp.max(); //We add coloumns (variables) to our problem Col x1 = lp.addCol(); Col x2 = lp.addCol(); Col x3 = lp.addCol(); //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); //Call the routine of the underlying LP solver lp.solve(); //Print results 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!"<