0

I am trying to use decision variables Y to update index of decision variable X in constraint. However, it does not seem to work in Cplex. Any help is appreciated, thanks a lot in advance. Here is my code:

// Parameters
int Tmax = ...;
int u[i][r][m] = ...;
int b[i][r][m][a] = ...;
float t[i][r][j][s] = ...;

// Variables
dvar boolean X[i][r][m][j][s][n][k];
dvar boolean Y[i][r][m][k]; 

// Objective Function
dexpr float TotalDuration =  sum(ci in i, cr in r, cm in m, cj in j, cs in s, cn in n, ck in k) t[ci][cr][cj][cs]*X[ci][cr][cm][cj][cs][cn][ck] + sum(ci in i, cr in r, cm in m, ck in k) u[ci][cr][cm]*Y[ci][cr][cm][ck];
minimize TotalDuration;

subject to {
    forall(ci in i, cr in r, cm in m, cj in j, cs in s, cn in n, ck in k)
    TimeConservative:
    X[ci][cr][cm][cj][cs][cn][ck] == X[ci][cr][cm][cj][cs][cm+u[ci][cr][cm]*Y[ci][cr][cm][ck] + t[ci][cr][cj][cs]][ck];
}
liu chao
  • 1
  • 2

1 Answers1

1

With CPLEX you cannot use a decision variable as index. With CP this is possible. Since you have only boolean decision variables, you could try using CP to solve your problem. To do this you have to add using CP; at the top of your .mod file.

If you need/want to stick with CPLEX a common way to work around this limitation is to explicitly spell out the two cases for Y by using the logical "implies" constraint:

(Y[ci][cr][cm][ck] == 0) => (/* here comes the constraint that must be satisfied if Y==0);
(Y[ci][cr][cm][ck] == 1) => (/* here comes the constraint that must be satisfied if Y==1);

This is of course only useful if Y is boolean or integer with a relative small domain.

Daniel Junglas
  • 5,830
  • 1
  • 5
  • 22
  • Thanks very much for your help but after changing some part of the codes, it still does not seem to work. – liu chao Dec 12 '19 at 09:13
  • this is the new codes: forall(ci in i, cr in r, cm in m, ck in k) linkXandY: if (Y[ci][cr][cm][ck] == 0) { sum(cj in j, cs in s, cn in n : cn == cm + t[ci][cr][cj][cs]) X[ci][cr][cm][cj][cs][cn][ck] == Y[ci][cr][cm][ck]; } else { sum(cj in j, cs in s, cn in n : cn == cm+u[ci][cr][cm] + t[ci][cr][cj][cs]) X[ci][cr][cm][cj][cs][cn][ck] == Y[ci][cr][cm][ck]; } – liu chao Dec 12 '19 at 09:14
  • You have to elaborate on what exactly does not work. Also note that what you wrote is different from what I suggested. You use `if` and `else` which is not supported for condition variables. I used the logical "implies" constraint instead. – Daniel Junglas Dec 12 '19 at 10:09
  • I found the error, which was with the if and else. I should have used the logical "implies" constraint like what you have suggested. Thanks a lot! – liu chao Dec 22 '19 at 07:21