ahmad noori
ahmad noori

Reputation: 127

Modeling a binary constraint in AMPL - CPLEX

i have the following constraints

enter image description here

i tried to model it in AMPL using the following code:

var y {1..njobs} binary;

subject to overlap 
    {i in 1..njobs, j in i+1..njobs: i<>j}:
        xi[i] + si[i] <= xi[j]+m*y[i];

 subject to order
    {i in 1..njobs, j in i+1..njobs: i<j}:
        y[i] + y[j] = 1;

i'm new to this topic and seem to miss something in the code above. any suggestions?

Upvotes: 0

Views: 299

Answers (1)

G_B
G_B

Reputation: 1573

According to the constraints, y has two indices, i and j, but your code only gives it a single index.

Should be something like:

var y {1..njobs,1..njobs} binary;
subject to overlap 
    {i in 1..njobs, j in i+1..njobs: i<>j}:
        xi[i] + si[i] <= xi[j]+m*y[i,j];

 subject to order
    {i in 1..njobs, j in i+1..njobs: i<j}:
        y[i,j] + y[j,i] = 1;

Currently the behaviour for when i = j is undefined. You may want to either add a constraint that defines the behaviour in that case, or exclude it from the index space when you declare y, e.g.:

var y {i in 1..njobs,j in 1..njobs: i <> j} binary;

Upvotes: 1

Related Questions