在 AMPL 中对二元约束建模 - CPLEX

Modeling a binary constraint in AMPL - CPLEX

我有以下约束

我尝试使用以下代码在 AMPL 中对其建模:

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;

我是这个主题的新手,似乎遗漏了上面代码中的某些内容。有什么建议吗?

根据约束,y 有两个索引,i 和 j,但您的代码只给它一个索引。

应该是这样的:

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;

目前 i = j 时的行为未定义。您可能想要添加一个约束来定义这种情况下的行为,或者在声明 y 时将其从索引 space 中排除,例如:

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