如何使用 or-tools 在我们的 MIP 问题中设置类似 y = max(x1,x2,x3) 的等式约束?

How to set an equality constraint like y = max(x1,x2,x3) in our MIP problem with or-tools?

我使用 or-tools 解决 MIP 问题,我想添加一个约束,其中变量 y 等于其他变量 Xi 中的最大值。例如:y = max(x1,x2,x3)。 or-tools 中有没有 max 函数可以做到这一点?

我可以添加 4 个约束,例如:

y >= x1
y >= x2
y >= x3
y <= MAX  # where MAX is the upper bound of y.

但可能会出现错误的情况

x3 >= y.

只需将其放入一些简单的结构中,例如:

-元组max((x1,x2,x3))

-列表max([x1,x2,x3])

-或设置max({x1,x2,x3})

最后一种情况最好,因为在检查差异之前消除了重复项。

使用 python 的 max() 运算符不起作用。 你应该看看文献

参见:https://www.leandro-coelho.com/how-to-linearize-max-min-and-abs-functions/