我有一个类型的约束(在 zmpl 中)
S1 中的总和 (i,j):x[i,j]*c[i,j]<=100
其中,x 是二维的二进制变量,c[i,j] 是参数。我想将其更改为
S1 中的 sum (i,j) : x[i,j]*c[i,sum (i) x[i,j]]<=100
本质上,第二个索引中的参数取决于第 i 行中所选变量的数量。任何有效的方法来做到这一点?
我有一个类型的约束(在 zmpl 中)
S1 中的总和 (i,j):x[i,j]*c[i,j]<=100
其中,x 是二维的二进制变量,c[i,j] 是参数。我想将其更改为
S1 中的 sum (i,j) : x[i,j]*c[i,sum (i) x[i,j]]<=100
本质上,第二个索引中的参数取决于第 i 行中所选变量的数量。任何有效的方法来做到这一点?
第一:不可能用变量表达式来索引参数,因为这本质上也使它们成为变量。
相反,我建议使用额外的变量来模拟所需的约束,并且我尝试尽可能地简化:
set S2 := { 0..card(S1) }; # new set to model all possible outcomes of the sum operation
var y[S1] >= 0; # y models nonnegative coefficients c[i,j]
var z[S2] binary; # models the value of the x-sum
subto binlink: sum <i,j> in S1: x[i,j] - sum <s> in S2: s * z[s] == 0;
# binlink expresses the outcome of the x-sum in z
subto partition: sum <s> in S2: z[s] == 1;
# maybe redundant because of binlink, but easy to write
subto coeflink: forall <i,j> in S1: y[i,j] == sum <s> in S2: c[i,s] * z[i,s]
#links continous coefficient variable to coefficient parameter
subto yourcons: sum <i,j> in S1: x[i,j] * y[i,j] <= 100;
# finally...
请注意,这个公式是非线性的,但我认为值得一试。它的有效性在很大程度上取决于您的公式中“动态系数”的数量以及我的答案中定义的集合S2的大小。