-1

I am working on mathematical modeling using Gurobi as a solver and python as an interface. In my model, I would like to create a binary variable but the variable is allowed to take a value of 1 if a>=1 else 0 where a is another decision variable in the model.

the binary variable should look like this as follows in the picture:-

enter image description here

1 Answers1

2

To summarize, you want to model the implications:

  x>=1 => y=1
  x=0  => y=0
  x >= 0 (non-negative variable)
  y ∈ {0,1}  (binary variable)      

There are different ways to do this.

Note that we can invert the implications:

  y=0 => x=0
  y=1 => x>=1

indicator constraints

  y=0 => x=0
  y=1 => x>=1
 

can be directly implemented as indicator constraints. See https://www.gurobi.com/documentation/9.1/refman/py_model_agc_indicator.html.

Big-M approach

  x <= M*y   (this will do y=0 => x=0)
  x >= y     (this will do y=1 => x>=1) 

Here the constant M is an upper bound on x. If M is very large, it is better to use indicator constraints.

Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39