mip_demo.cc File Reference
Detailed Description
This example shows how can we solve an integer program with
lemon Mip interface and with default solver.
#include <lemon/lp.h>
using namespace lemon;
int main(){
Mip ilp;
typedef Mip::Row Row;
typedef Mip::Col Col;
ilp.max();
Col x1 = ilp.addCol();
Col x2 = ilp.addCol();
Col x3 = ilp.addCol();
ilp.integer(x1,true);
ilp.integer(x2,true);
ilp.integer(x3,true);
ilp.addRow(x1+x2+x3 <=100);
ilp.addRow(10*x1+4*x2+5*x3<=600);
ilp.addRow(2*x1+2*x2+6*x3<=300);
ilp.colLowerBound(x1, 0);
ilp.colLowerBound(x2, 0);
ilp.colLowerBound(x3, 0);
ilp.obj(10*x1+6*x2+4*x3);
ilp.solve();
if (ilp.primalStatus()==LpSolverBase::OPTIMAL){
std::cout<<"Optimal solution found!"<<std::endl;
printf("optimum value = %g; x1 = %g; x2 = %g; x3 = %g\n",
ilp.primalValue(),
ilp.primal(x1), ilp.primal(x2), ilp.primal(x3));
}
else{
std::cout<<"Optimal solution not found!"<<std::endl;
}
}
#include <lemon/lp.h>