在AMPL中建模二进制约束-CPLEX

问题描述 投票:0回答:1

我有以下限制条件

enter image description here

我尝试使用以下代码在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;

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

linear-programming cplex ampl
1个回答
0
投票

根据约束,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时将其从索引空间中排除,例如:]

var y {i in 1..njobs,j in 1..njobs: i <> j} binary;
© www.soinside.com 2019 - 2024. All rights reserved.