简体   繁体   English

ILP - “变量是否等于另一个变量”

[英]ILP - "Is variable equal to another variable"

In an ILP, given two variables x and y, is it possible to define a variable z where在 ILP 中,给定两个变量 x 和 y,是否可以定义变量 z 其中

z = (x==y)? z = (x==y)?

Meaning, if x equals y then z = 1. Else, z = 0.意思是,如果 x 等于 y,则 z = 1。否则,z = 0。

x and y are integer variables bounded between (1, M). x 和 y 是介于 (1, M) 之间的 integer 个变量。

If you know that x <= y , then you can use z in {0,1}, x+Mz >= y, x+z <= y .如果您知道x <= y ,那么您可以z in {0,1}, x+Mz >= y, x+z <= y

If you don't know which of x and y is minimum, you can do it with more work, by adding a variable minxy which takes the value of the minimum.如果您不知道xy中的哪一个是最小值,您可以通过添加一个取最小值的变量minxy来做更多的工作。 You need to introduce another new variable (which I call a ) to do this.您需要引入另一个新变量(我称之为a )来执行此操作。

Introduce a variable a that's 0 if x<=y, 1 if y<=x (it could be either 0 or 1 if x==y):引入一个变量a如果 x<=y 则为 0,如果 y<=x 则为 1(如果 x==y 则它可以是 0 或 1):

a in {0,1}, x-y <= Ma, y-x <= M(1-a)

Introduce a variable minxy that's the minimum of x and y :引入一个变量minxy ,它是xy的最小值:

minxy <= x
minxy <= y
minxy >= x - Ma
minxy >= y - M(1-a)

Then you can define your z :然后你可以定义你的z

minxy + Mz >= x + y - minxy
minxy + z <= x + y - minxy

(Noting that max(x,y) is x + y - minxy ). (注意max(x,y)x + y - minxy )。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ILP:变量的独占范围 - ILP: Exclusive range for variable 排序python变量以匹配另一个变量 - sort python variable to match another variable 如何在AMPL中写“不等于”或设置变量参数的条件? - How to write “not equal to” in AMPL or set such as a condition for a variable's parameter? 如何检查 C++ 中的双变量是否几乎等于零? - how to check if double variable is almost equal to zero in C++? 因为一个变量增加另一个变量 - as one variable increases another decreases 为什么我们必须定义变量 dp = [0] * (n+1) 只是为了将其变量设置为等于 0(在动态规划中) - Why we have to define variable dp = [0] * (n+1) just to set its variable equal to 0( In Dynamic Programming) 随时间变化的变量Y应该接近另一个变量X - A variable Y that should approach another variable X over time 如何将许多可变大小的工作单元分成大小相等的桶? - How do I split many variable-sized units of work into equal sized buckets? 不使用ILP的关系数据挖掘 - Relational Data Mining without ILP 在与Javascript中的另一个变量的值匹配之前,增加变量的值的最快方法是什么? - What is the fastest way to increase the value of a variable until it matches the value of another variable in Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM