Originally posted by: YongjiaSong
Hi all,
I have a problem in iteratively solving the LP. In each iteration, I have to modify the objective coefficient as well as variable bounds.
How can I implement this using C++ in CPLEX?
I have done an easy version of it by only changing the objective coefficient. What I did is:
IloModel singleLP(env);
IloCplex singleLP_Cplex(singleLP);
IloNumVarArray x(env, knap.nbItems, 0, 1);
IloObjective objective(env, IloObjective::Maximize);
singleLP.add(objective);
IloExpr str(env);
for (int j = 0; j < knap.nbItems; ++j)
str += x[j]*knap.weight[i][j];
singleLP.add(str <= knap.capacity
kk);
singleLP_Cplex.setParam(IloCplex::SimDisplay, 0);
singleLP_Cplex.setParam(IloCplex::PreInd, 0);
While (iter < MaxIter)
{
IloObjective oldobjective = singleLP_Cplex.getObjective();
singleLP.remove(oldobjective);
IloExpr newobj(env);
for (int j = 0; j < knap.nbItems; ++j)
newobj += x[j]*knap.weight
iihttp://k*knap.nbItems+j;
singleLP.add(IloMaximize(env, newobj));
singleLP_Cplex.setParam(IloCplex::SimDisplay, 0);
try{
singleLP_Cplex.solve();
}
iter++;
}
Which removes the old objective and a new one. I tried to use objective.setExpr(), but it doesn't work.
Thanks!
#CPLEXOptimizers#DecisionOptimization