What is the CPLEX equivalent of Gurobi's .set() method?

244 views Asked by At

I am trying to translate some Gurobi code across to CPLEX and am having trouble working out how to set the starting value for a variable.

The original code looks like this:

for (int b=0; b<nB ; ++b){
    for (int t=0; t<t_max; ++t){
        Yvars[b][t].set(GRB_DoubleAttr_Start, startVals[b][t+shift]);
    }
}

what would be the equivalent CPLEX code? I cant find information anywhere of how to do this. The closest I can find is this:

http://www.ibm.com/support/knowledgecenter/en/SS9UKU_12.4.0/com.ibm.cplex.zos.help/UsrMan/topics/discr_optim/mip/para/49_mipStarts.html

However, that suggests that I have to add the start values to the model itself, like this:

 IloNumVarArray startVar(env);
 IloNumArray startVal(env);
 for (int b = 0; b < nB; ++b)
     for (int t = 0; t < t_max; ++t) {
         startVar.add(Yvars[b][t]);
         startVal.add(startVals[b][t+shift]);
     }
 cplex.addMIPStart(startVar, startVal);

And not just affect the individual variables as in the original code. Is there a way to just do it to the variables like with Gurobi? Or do I have to do everything at once?

1

There are 1 answers

0
rkersh On BEST ANSWER

The way you're adding the MIP start in CPLEX is correct (and there is no alternate syntax). I'm not sure what you mean exactly by "do I have to do everything at once", but perhaps you are asking whether you can provide the MIP start value for a subset of variables rather than all of them. If that is the case, see MIP starts and effort level (e.g., with CPX_MIPSTART_SOLVEMIP CPLEX solves a subMIP where you must specify the value of at least one discrete variable). With the C++ API, the addMIPStart method has an optional effort parameter to control this.