Julia (JuMP):具有多个条件值的指标约束(布尔表达式是否可能?)

Julia (JuMP): Indicator constraints with multiple conditional values (is a boolean expression possible?)

我想根据二元决策变量 x 随“时间”的值变化来实施约束。

我正在尝试为电力系统的单元组合优化问题实施最小运行时间约束。 x 表示单元激活,其中 01 分别表示电源单元 n 在特定时间 t 关闭或已开启。

为此,indicator constraints seem to be a promising solution and with the inspiration of a similar problem 实施似乎非常简单。

所以,由于引入了布尔运算符(!¬),我过早地想用布尔方式表达变化:

@constraint(m, xx1[n=1:N,t=2:T], (!x[n,t-1] && x[n,t]) => {next(t, 1) + next(t, 2) == 2})

说:如果单位之前停用但现在打开,则要求单位在接下来的 2 次激活。

其中 next(t, i) = x[((t - 1 + i) % T) + 1].

我收到以下错误:

LoadError: MethodError: no method matching !(::VariableRef)
Closest candidates are:
  !(!Matched::Missing) at missing.jl:100
  !(!Matched::Bool) at bool.jl:33
  !(!Matched::Function) at operators.jl:896

我检查了指标约束是否仅对单个术语正常工作。

问题:这是否可能或是否有其他明显的解决方案?

故障排除和解决方法:我已经尝试了以下方法(如果我的诊断有误,请指正):

您可以从 github 获得工作代码。

诀窍是找到具有等效真值的约束-table:

# Like
(!x[1] && x[2]) => {z == 1}

# Is equivalent to:
z >= -x[1] + x[2]

# Proof
-x[1] + x[2] = sum <= z
--------------------------
 - 0  +  0   =  0  <= 0
 - 1  +  0   =  -1 <= 0 
 - 0  +  1   =  1  <= 1
 - 1  +  1   =  0  <= 0

有人推荐我 MOSEK Modeling Cookbook 帮助制定正确的约束公式。

最终请参阅线程 here,我从中获得了更多详细信息的答案。