Originally posted by: MBEUTCHA
You are absolutely right. I think the following code wil work.
range r = 1..10;
dvar int+ x[r];
dvar int+ y[r];
// The following array of values will be use to see if an initial solution could be find
float values[i in 1..2] = (i==1)? 10 : 0;
minimize
sum( i in r ) x[i] + sum( j in r ) y[j];
subject to{
ctSum:
sum( i in r ) x[i] >= 10;
forall( j in r )
ctEqual:
y[j] == j;
}
main{
thisOplModel.generate();
var def = thisOplModel.modelDefinition;
// Searching for an initial solution
writeln( Searching the initial solution");
var cplex1 = new IloCplex();
cplex1.cloktype = 1;
cplex1.tilim = 180; // we set the overall time of optimization to 3 mins
cplex1.IntSolLim = 1; // we ask Cplex to stop if it finds one integer solution
var opl1 = new IloOplModel(def, cplex1);
opl1.x[1].UB = opl1.values[1];
opl1.x[1].LB = opl1.values[1];
opl1.x[2].UB = opl1.values[2];
opl1.x[2].LB = opl1.values[2];
opl1.generate();
if( cplex1.solve()){
// if a solution has been found within the time limit, we are sure that x[1] = 10 and x[2] = 0;
// this solution will be the starting point.
writeln(opl1.printSolution());
// Setting initial solution
writeln("Setting initial solution");
var cplex2 = new IloCplex();
var opl2 = new IloOplModel(def, cplex2);
opl2.generate();
cplex2.addMIPStart(opl2.x , opl1.x.solutionValue,1,0);
cplex2.solve();
writeln(opl2.printSolution());
opl1.end();
cplex1.end();
opl2.end();
cplex2.end();
0;
}
else{
writeln(" Starting solution not found within the available time");
cpelx1.setDefaults();
...
cplex1.end();
opl1.end();
0;
}
#DecisionOptimization#OPLusingCPLEXOptimizer