# modifying objective function in ilocplex model

 1 Hi I am working on a model that should be able to solve knapsack problems with different objective functions and right hand sides. The left hand side coefficients and the dimension of the knapsack problems will stay the same. My idea is to make a class called KnSolver where in the constructor the IloEnv, the IloModel, the Cplex environment, the LHS coefficients and the variables (called x) are initialized as these should be used repeatedly. Further an IloExpr is created as lhs = IloScalProd(LHS , x). The idea was to create a member function called KpSolve(double* objCoefs, int RHS) that takes as argument the obj.coefficients and the RHS. It could in pseudo code look like void KpSolve(double* objCoefs, int RHS){ IloNumArray CostCoefs(env); IloExpr Obj(env); for(j

 3 You can modify the objective function using IloObjective::setLinearCoefs See the cutstock.cpp for an example of use. More generally, if in CPLEX 12.4 documentation you search for "changing right hand side" you get to the "Modifying problems" page that lists all relevant APIs. For modification of rhs you have these : IloRange::setLB, IloRange::setUB, IloRange::setBounds answered 23 Oct '12, 09:49 jfpuget 2.5k●3●10 accept rate: 8% Thank you very much for the fast reply. (24 Oct '12, 03:20) Sune My pleasure. Can you formally accept the answer if it helped you? (24 Oct '12, 04:17) jfpuget
 0 That I can. However, I'm getting an Empty handle message when I implement it, and I don't know how to resolve it. In the constructor I do IloObjective OBJ = IloMaximize(env); for(int j=0; j
 toggle preview community wiki

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "Title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported

Tags:

×191
×30
×21