I am interested in solving a set of maximization problems where those problems only just differ in their objective. The objective functions are all linear and the constraints are all just affine. I was wondering what is the most efficient way to implement it using CPLEX since I would like the solver to reuse as much information across the different solves. The problems are solved sequentially one after the other (as shown in the for loop below). I tried to get this information from the CPLEX manual, but I was unsuccessful. Any help would be appreciated. Below I have provided a snippet from my code (in C++), any advice on improving its speed will be great.

IloEnv env;
IloModel model(env);        
IloNumVarArray vec_x_vars(env);

// I call a function here to populate constraints into the model

std::vector<IloNumArray> vec_obj_coeffs; //Assume this vector contains all the different linear objectives

IloExpr obj_expr(env);
for(size_t uiIndex = 0; uiIndex < vec_objectives.size(); uiIndex++)
   obj_expr.setLinearCoefs(vec_x_vars, vec_objectives[uiIndex]);
   IloObjective obj = IloMaximize(env, obj_expr);
   IloCplex cplex(model);

Is the implementation above the best possible in terms of efficiency that we can get?


1 Answer 1


The only thing I would change is to add the IloObjective object outside the loop and then set the coefficients directly in this object. That way you avoid adding and removing the objective function to/from the model. Whether it is significantly faster, I have no idea, unfortunately.

  • $\begingroup$ I agree with @Djames. You can find the documentation her: www-eio.upc.es/lceio/manuals/cplex-11/html/refcppcplex/html/… $\endgroup$
    – Sune
    Feb 9, 2021 at 7:07
  • $\begingroup$ Just a clarification, so are you suggesting I create an IloObjective obj(env, IloObjective::Maximize) before the for loop and just keep updating obj using obj.setLinearCoefs(vec_x_vars, vec_objectives[uiIndex]) within the for loop, and that would be sufficient? $\endgroup$
    – batwing
    Feb 9, 2021 at 18:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.