0

I have tried this problem for weeks but still could not do it. Please give me some advice, thanks in advance!

for example, I know how to add condition of each index in the "forall", but how to add condition for combination of index in the "forall", for example, (I, j) != (r, s), such as (2, 3) != (2, 4).

range i = 0..5; 
range j = 0..3;
range r = 0..5;
range s = 0..3;

forall(ci in i, cr in r, cj in j:cj!=0 && cj!=ci, cs in s:cs!=0, ck in k)
EliminateSubtour2:
W[cj][cs][ck] >= W[ci][cr][ck] + 1 - (N*H*(1 - X[ci][cr][cj][cs][ck]));

The final goal is to add this constraint, 
W[cj][cs][ck] >= W[ci][cr][ck] + 1 - (N*H*(1 - X[ci][cr][cj][cs][ck])); when (I,r) != (j,s)

I tried using tuple but the system says tuple could not be used for indexing. Thanks in advance!

liu chao
  • 1
  • 2

1 Answers1

0

you could use the or operator ||

range i = 0..5; 
range j = 0..3;
range r = 0..5;
range s = 0..3;

dvar boolean X[i][j][r][s];

maximize sum(I in i,J in j,R in r,S in s) X[I,J,R,S];
subject to
{
  forall(I in i,J in j,R in r,S in s:(I!=J) || (R!=S)) X[I,J,R,S]==0;
}

plus in CPLEX_Studio1210\opl\examples\opl\models\TravelingSalesmanProblem there is a subtour elimination example

Alex Fleischer
  • 9,276
  • 2
  • 12
  • 15