Hi,
you could use a new array with only the indexes you need:
range r = 1..10;
dvar int+ x[r];
dvar int+ y[r];
dvar int x3[1..1];
int values3[1..1]=[10];
// 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;
float values2[i in r] = i;
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;
x3[1]==x[3];
}
main{
thisOplModel.generate();
var def = thisOplModel.modelDefinition;
// Default behaviour
writeln("Default Behaviour");
var cplex1 = new IloCplex();
var opl1 = new IloOplModel(def, cplex1);
opl1.generate();
cplex1.solve();
writeln(opl1.printSolution());
// 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.x3,opl2.values3);
vectors.attach(opl2.y,opl2.values2);
vectors.setStart(cplex2);
//cplex2.addMIPStart(opl2.x,opl2.values);
cplex2.solve();
writeln(opl2.printSolution());
opl1.end();
cplex1.end();
opl2.end();
cplex2.end();
0;
}
which gives
x = [0
0 10 0 0 0 0 0 0 0];
y = [1 2 3 4 5 6 7 8 9 10];
x3 = [10];
In
https://www.linkedin.com/pulse/making-decision-optimization-simple-alex-fleischer/
------------------------------
[Alex] [Fleischer]
[EMEA CPLEX Optimization Technical Sales]
[IBM]
------------------------------