ZIMPL:约束中无法识别二维变量声明

ZIMPL: 2D variable declaration not recognized in constraint

我在 Zimpl 中声明 2D 变量时遇到了真正的挑战。 (参数似乎工作正常。)

以下是我的MWE:

set I := {1 to 10};
set J := {1 to 5};

param A[I*J] := read InputFile as "n+";
var x[I] binary;
var s[J] binary; # this works but doesn't do what I need
var s2[I*J] binary; # this does what I need but doesn't work

minimize sum<i,j> in I*J with A[i,j] < 5: (s2[i,j] - x[i]) * A[i,j];

# this constraint compiles
subto constraint1:
   forall <j> in J do sum <i> in I with A[i,j] < 5: x[i] <= 1 + s[j];

# this constraint does not compile
subto constraint2:
   forall <j> in J do sum <i> in I with A[i,j] < 5: x[i] <= 1 + s2[i,j];

当尝试创建我的 lp 文件时,我得到

Error 133: Unknown symbol "i"

有没有人对我如何使第二个约束起作用有任何见解?据我所知,这与 Zimpl 用户手册中的容量设施问题(第 6.3 节)的实现相同。

提前致谢。

您在约束的左侧有 i 的总和,但在右侧也有引用 i。你期望 i 的值是多少?

可行的是

forall <j> in J do sum <i> in I with A[i,j] < 5: (x[i] - s2[i,j]) <= 1;

但我不确定这是否是您想要实现的目标。

添加 Leon 的评论以做出更完整的回答:

To add to what Gerald wrote, in ZIMPL sums always only consider the next variable, so you have to put parenthesis to make it work.

补充一下 Gerald 写的,在 ZIMPL 求和中总是只考虑下一个变量,所以你必须加上括号才能让它起作用。

在最小化时缺少名称。 它应该最小化 obj: sum ...