I\'m new using cplex and I try to find some information on internet but didn\'t find clear stuff to help me in my problem.
I have P[k] k will be equal to 1 to 4
You probably want to use an IloNumExpr
for(int k = 0; k < 4; k++){
IloNumExpr sum_over_i(env);
for(int i = 0; i < 5; i++){
sum_over_i += x[i][k];
}
model.add(sum_over_i >= 2 * p[k]; );
}
You also need to declare x as a 2-dimensional array.
IloArray x(env, 4);
for (int k = 0; k < 4; ++k)
x[k] = IloIntVarArray(env, 5, 0, 1);
Also, in c++, array indices are from 0 to size-1, not 1 to size. Your objective should be written
model.add(IloMaximize(env, 1000 * p[0] + 2000 * p[1] + 500 * p[2] + 1500 * p[3]));