简体   繁体   中英

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

I work with or-tools to solve an MIP problem and I would like to add a constaint where a variable y is equal to the maximum among other variables Xi. For example : y = max(x1,x2,x3). Is there any max function in or-tools to do this?

I could add 4 constraints like :

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

But there could be a wrong situation where

x3 >= y.

Using the max() operator of python does not work. You should have a look at the literature

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

Just put it into some simple structure, like:

-tuple max((x1,x2,x3))

-list max([x1,x2,x3])

-or set max({x1,x2,x3})

Last case is the best, becouse eliminate duplicates before checking difference.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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