简体   繁体   English

ILP:变量的独占范围

[英]ILP: Exclusive range for variable

In an ILP, How can I write a constraint "X is not in the interval [Y, Y+10]"?在 ILP 中,如何编写约束“X不在[Y,Y+10] 区间内”?

Is it even possible?有可能吗?

You didn't say, but I'm assuming x and y are non-negative integers and that the range you indicate to avoid is inclusive of endpoints...您没有说,但我假设xy是非负整数,并且您指示要避免的范围包括端点...

You have an "or" condition there, so you will need to introduce a helper or "indicator" variable to handle the or condition , call it z , and a (constant) parameter for a reasonable upper bound on y , call it M :你在那里有一个“或”条件,所以你需要引入一个帮助器或“指示器”变量来处理或条件,称之为z ,以及一个(常量)参数用于y的合理上限,称之为M

z ∈ {0, 1}  # 0 if below y, 1 if above y+10
M > reasonable_upper_bound(y)

Then 2 constraints based on that info to either constrain x to the lower set of values or the upper, excluding the interval (of disinterest):然后基于该信息的 2 个约束x 约束到较低的一组值或较高的值,不包括间隔(不感兴趣):

x <= (y - 1) + z * M
x >= (y + 10 + 1) * z    

Truth Table:真值表:

       z=0      z=1
x <=   y-1      ~M
x >=   0        y + 11

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM