Setting the initial solution

Shows how to use a value array.

The class that enables you to pass an initial solution to the CPLEX MIP algorithm is IloOplCplexVectors. You can control the part of the model to be set with an initial solution by attaching a pair of elements made up of a constraint array and a value array. The value array is defined in the model.

// The following array of values (defined as data) will be used as 
// a starting solution to warm-start the CPLEX search.
float values[i in r] = (i==5)? 10 : 0;

The second part of the main block illustrates how to use it.

  // Setting initial solution
  writeln("Setting initial solution");
  var cplex2 = new IloCplex();
  var opl2 = new IloOplModel(def, cplex2);
  opl2.generate();
  var vectors = new IloOplCplexVectors();
  // We attach the values (defined as data) as starting solution
  // for the variables x.
  vectors.attach(opl2.x,opl2.values);
  vectors.setVectors(cplex2);   
  cplex2.solve();   
  writeln(opl2.printSolution());

The solution is then:


Setting an initial solution
x = [0 0 0 0 10 0 0 0 0 0];
y = [1 2 3 4 5 6 7 8 9 10];

The CPLEX log reports:

MIP start values provide initial solution with objective 65.0000