Originally posted by: ChrisBr
Hello David,
I think some character have been eaten by the writer, so I guess you wanted to write
c[ Tasks[j][j] ]
//case 1
or
c[ Tasks[j] ][j]
//case 2
In case 1 I suppose that Task is an IloArray<IloIntVarArray> (so 2 dimensions) and c is either an IloIntArray or a IloNumArray (so 1 dimension)
Note that in this case you cannot write IloAllDiff(env, Tasks), you have to flatten the array Tasks before.
Here is an sample of code which looks like what you want:
//model.add(IloAllDiff(env, Tasks)); // cannot compile! IloIntVarArray Tasks2(env, NTasks*NTasks);
for (i=0; i<NTasks; ++i)
for (j=0; j<NTasks; ++j) Tasks2[i*NTasks+j] = Tasks[i][j]; model.add(IloAllDiff(env, Tasks2)); IloExpr Obj_Func_1(env, 0);
for (j = 0; j < NTasks; j++)
{ Obj_Func_1 += c[Tasks[j][j]];
} IloObjective objective = IloMinimize(env, Obj_Func_1); model.add(objective);
In case 2 I suppose that Task is an IloIntVarArray (so 1 dimension) and c is either an IloArray<IloIntArray> or a IloArray<IloNumArray> (so 2 dimensions)
You have to flatten the array c
Here is an sample of code which looks like what you want:
model.add(IloAllDiff(env, Tasks)); IloIntArray c2(env, NTasks*NTasks);
for (i=0; i<NTasks; ++i)
for (j=0; j<NTasks; ++j) c2[i*NTasks+j] = c[i][j]; IloExpr Obj_Func_1(env, 0);
for (j = 0; j < NTasks; j++)
{
//Obj_Func_1 += c[Tasks[j]][j]; // cannot compile! Obj_Func_1 += c2[Tasks[j]*NTasks +j];
} IloObjective objective = IloMinimize(env, Obj_Func_1); model.add(objective);
I hope this helps,
Chris
#CPOptimizer#DecisionOptimization