How to model an special constraint in MILP

110 views
Skip to first unread message

s. sadeghi

unread,
Mar 18, 2019, 7:52:52 AM3/18/19
to Gurobi Optimization
  
  Hi all,

   I want to use Gurobi to solve the below describe. In the below example, all variables are boolean variables.

  if  " x1 + x2 + x3 = 0 or 3"  then " t=0 " ;
  else if " x1 + x2 + x3 = 1 or 2 "  then " t=1 " ;

  May I know is it possible to encode those constraints into integer constraints required by Gurobi?


   Best regards,

     Sadegh


Michael Winkler

unread,
Mar 19, 2019, 9:21:46 PM3/19/19
to Gurobi Optimization
You could add a quadratic constraint  "x1 + x2 + x3 - 3 h1 - [ t * h2 ] = 0", xi, h1 and t binary, h2 integer in [1,2].

If x1+x2+x3 = 0 it follows h1 = t = 0,
If x1+x2+x3 = 3 it follows h1 = 1, t = 0,
If x1+x2+x3 = 1 it follows h1 = 0, t = 1, h2 = 1
If x1+x2+x3 = 2 it follows h1 = 0, t = 1, h2 = 2

Best,
Michael

Yaarit Cohen

unread,
Mar 19, 2019, 10:22:27 PM3/19/19
to gur...@googlegroups.com
Have you tried writing it with Big-M?

Best, 
Yaarit Cohen
--

---
You received this message because you are subscribed to the Google Groups "Gurobi Optimization" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Winkler

unread,
Mar 19, 2019, 10:25:10 PM3/19/19
to Gurobi Optimization
There is a Big-M, the coefficient in front of h1.

Michael

s. sadeghi

unread,
Mar 20, 2019, 5:16:57 AM3/20/19
to Gurobi Optimization
Hi,
At first thank you for your answer.
Actually it is important to me to have a small number of variables and the constraint be linear. Do you think it can be possible?


Best regards,
Sadegh

Silke Horn

unread,
Mar 22, 2019, 5:20:33 AM3/22/19
to gur...@googlegroups.com
Hi,

You will need some auxiliary variables. How about this:

x1 + x2 + x3 - 3 h1 - t - h3 = 0
- t + h3 <= 0
- h2 + h3 <= -1
t + h2 - h3 <= 2

with h3 binary and the rest as in Michael’s answer, i.e., xi, h1, t binary, h2 in {1,2}.

This is linear and does what you asked for. (I got it by putting Michael’s answer through Gurobi’s presolve. So you could just as well use the quadratic one.)

- Silke
Reply all
Reply to author
Forward
0 new messages