[英]AllDifferent Constraint in Pyomo
I am trying to run a MINLP problem on Pyomo.我正在尝试在 Pyomo 上运行 MINLP 问题。 I have formulated an objective function and one of my constraints is this:
我制定了一个目标 function ,我的限制之一是:
model.c2 = Constraint(expr = sum(model.x[i] for i in blocks) <= 4560)
I want something like this:我想要这样的东西:
x+y+z<=3 with x not equal to y not equal to z. x+y+z<=3 x 不等于 y 不等于 z。
How do I write a constraint for this?我该如何为此编写约束?
The answer depends a bit on the details (are the variables integers, are all values in the domain covered).答案在一定程度上取决于细节(变量是整数,是所涵盖域中的所有值)。 Here is a reference that may be of interest:
这是一个可能感兴趣的参考:
Williams, H. Paul and Yan, Hong (2001), Representations of the 'all_different' predicate of constraint satisfaction in integer programming, Informs Journal on Computing, 13 (2).
Williams, H. Paul 和 Yan, Hong (2001),integer 编程中约束满足的“all_different”谓词的表示,Informs Journal on Computing,13 (2)。 96-103.
96-103。
Let's define the problem more precisely.让我们更准确地定义问题。 Say we have
n
integers, x[i]
, that take unique values between 1,...,n
.假设我们有
n
整数x[i]
,它们在1,...,n
之间取唯一值。 We can implement this as:我们可以将其实现为:
We can introduce binary variables我们可以引入二进制变量
y[i,k] = 1 if x[i]=k
0 otherwise
With this, we can write:有了这个,我们可以写:
x[i] = sum(k, k*y[i,k]) (1)
sum(k, y[i,k]) = 1 ∀i (2)
sum(i, y[i,k]) = 1 ∀k (3)
y[i,k] ∈ {0,1}
where i ∈ {1,..,n}
and k ∈ {1,..,n}
.其中
i ∈ {1,..,n}
和k ∈ {1,..,n}
。
If you have fewer variables than n
, say i ∈ {1,..,m}
with m < n
, then we need to replace (3) by:如果您的变量少于
n
,例如i ∈ {1,..,m}
且m < n
,那么我们需要将 (3) 替换为:
sum(i, y[i,k]) ≤ 1 ∀k (3a)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.