Write a forall constraint in CPLEX, indexing over a union of variables

440 views Asked by At

I'm modelling a routing problem in CPLEX opl. I am struggling to implement a certain constraint in CPLEX, which sums a decision variable X over a set of indexes j, and this ∀i ∈ V, where V = C ⋃ S.

The constraint is the following: sum(j ∈ (1..10)) Xij < 1 ∀i ∈ V I implemented this in CPLEX as follows:

forall(i in customers, i in stations) { sum(j in reach) X[i][j] < 1; }

Customers refers to C, stations refers to S, and reach refers to the range of 1..10. However, it seems impossible to use the same index (i) twice in the forall statement.

Could anyone help me to solve this problem. Thanks a lot!

1

There are 1 answers

2
Alex Fleischer On

Instead of

forall(i in customers, i in stations) { sum(j in reach) X[i][j] <= 0; }

you could write

forall(i in customers union stations) { sum(j in reach) X[i][j] <= 0; }

I tried

{int} customers={1,2};
{int} stations={2,3};

{int} reach={5};

dvar boolean X[customers union stations][reach];

subject to
{

forall(i in customers union stations) { sum(j in reach) X[i][j] <= 0; }

}

and that works