Originally posted by: SystemAdmin
[ph mooraa said:]
Hi Paul,
I really appreciate your reply. Thanks.
I think what you mean by these constraints are sort of understandable to me in 1 dimension. But I am not able to clarify it in more dimensions. It will be great if you please see the following code snippet -
IloModel mymodel(env1);
IloCplex mycplex(mymodel);
typedef IloArray<IloNumVarArray> NumVarMatrix;
typedef IloArray<NumVarMatrix> NumVar3Matrix;
NumVar3Matrix sched(env1,4);
[b]IloInt T=100;[/b]
IloNumVar t(env1,0,1000,ILOINT);
/*(part 1) 3D array initialization*/
for(int i=0;i<4;i++) {<br /> sched[ i] = NumVarMatrix(env1,4);
for(int j=0;j<4;j++) {<br /> sched[ i][j] = IloNumVarArray[b](env1,T)[/b];
for(int k=0;k<[b]T[/b];k++) {
sched[ i][j][k] = IloNumVar(env1,0,1,ILOINT);
}
}
}
...
// file read in DO[26][4]
// file read in A[4][4]
...
mymodel.add(IloMinimize(env1,t)); /*obective*/
for(IloInt m=0;m<4;m++) { /*constraint - 1*/
for (IloInt n=0;n<4;n++) {<br /> IloExpr r(env1);
for(IloInt o=0;[b]o<mycplex.getValue(t);[/b]o++) {
r+=sched[m][n][ o];
}
mymodel.add(r==A[m][n]); /*meeting the total requirements over all slots*/
}
}
for(IloInt x=0;[b]x<mycplex.getValue(t)[/b];x++) { /*constraint - 2*/
for(IloInt y=0;y<26;y++) { /*there are 26 conflicts*/
mymodel.add(sched[DO[y][0]][DO[y][1]][ x] + sched[DO[y][2]][DO[y][3]][ x] <= 1); /*only one or none is scheduled*/<br /> }
}
mycplex.solve();
the achieved job schedule is represented as 3D array. Basically it is an array of matrices where each matrix represent every time slot. Every time slot (matrix) is J x J where J (currently 4 as above) is total number of workers. Each job requires 2 workers ij and when it is scheduled that ij element of t th slot is set to 1, otherwise 0. This way 4 x 4 x t cube is all binary and objective is to minimize t.
Total job requirement to met in t slots are mentioned as constraint 1 in A[4][4] matrix. There are conflict between workers and only one out of certain pairs of workers can be scheduled in the same slot. This is mentioned in DO matrix in constraint 2 as (W1,W2)(W3,W4). This shows that either W1,W2 or W3,W4 pair can be scheduled in the same time slot.
Issue 1- Both the constraints require use of 3rd dimension (t) while mentioning the constraints. Currently I am doing this with mycplex.getValue(t) which I think might also be causing problems.
Issue 2- The first constraint you explained is sort of implicit as upper bound in this 3D array is 1 only. But I am not sure how to add the "shrinking" constraint where t scheduled time slots will be at the start.
Current output of the program (after adding T) says no solution exists.
Any pointers would be really helpful. I am not sure what I am doing wrong.
Thanks once again.
#CPLEXOptimizers#DecisionOptimization