Originally posted by: SystemAdmin
Hi everybody,
I have an integer progamming model and I want to solve it by a local approach. Since I need to modify the model at each iteration, I need to pass a new model to Cplex. The modifications concern only the objective function, i.e., (at each iteration of the algorithm) I just need to replace the objective function with a new one. The new objective function is constructed by using the solution of the current (sub)problem. I tried the
model.remove(objective); but I got some errors! I modified the program until I got a program without error, but I discovered that no changes are present in the new objective function! And the algorithm solves the same problem at each iteration! I don't understand why no change is present in the new objective function. Below you find the Cplex codes that I used in my program.
Any suggestion is highly appreciated.
Thank you in advance.
void main()
{
// Here I define the variables and the vectors, etc. IloEnv env; IloModel model(env);
// Here I define the IloNumVarArray's
//////////////////////////////////////////
// Here I read the data
// Here I define the constraints of the model IloExpr objectif(env);
// Here I give the expression of the objective function (a "linear" function)
//////////////////////////////////////////// model.add(IloMinimize(env,objectif)); objectif.end();
// when I add this part (I mean "objectif.end();"), Cplex produces some errors! but when I delete this part there is no error!
////////////////////////////////////////////
// Solving the model by Cplex: IloCplex cplex(model);
int res = cplex.solve();
if (res)
{ NewOptimalValue = cplex.getObjValue();
}
else
{ cout<<
"The model is infeasible "<<endl;
}
////////////////////////////////////////////
// :::::::::::::::::::::::::: Starting point of the algorithm ::::::::::::::::::::::::::
do
{
//////////////////////////////////////////
// I keep a backup of the current solution in order to use it in the futur
// I need to calculate some auxiliary vectors that are used algorithm, the backup version of the solutions is used for this aim
// Now, I need to remove the current objective function in order to construct a new one (a "quadratic" function)
// This operation is done at each iteration of the algorithm model.remove(objectif);
// Now, I want to define the new objective function IloExpr objectif(env);
// Here I give the expresstion of the new objective function! model.add(IloMinimize(env,objectif)); objectif.end();
// This expression produces no error!
////////////////////////////////////////////
// Solving the model by Cplex. IloCplex cplex(model);
////////////////////////////////////////////
int res = cplex.solve();
if (res)
{ NewOptimalValue = cplex.getObjValue(); NumberOfIterations++;
}
else
{ cout<<
"There was a problem in solving the subproblem :( "<<endl; NumberOfIterations = MaxIterations;
// In order to terminate the program
}
}
while(NumberOfIterations < MaxIterations);
// :::::::::::::::::::::::::: End point of the algorithm :::::::::::::::::::::::::: env.end();
}
#CPLEXOptimizers#DecisionOptimization