Axel
Axel

Reputation: 2715

MIP/LP - Modelling "if b=1 then x=y" constraint

I have a Mixed Integer Programming (MIP) problem, currently modelled in Python's PuLP library. My issue is however very generic, syntax doesn't play a role here.

I want to add a constraint to my model that works like this:

if b=1 then x=y

The variable b is a binary variable taking values 0 or 1. x and y are variables that represent the current stock level. x as a continuous variable, y as an integer variable.

I know constraints can only be modelled in the following format:

a*x+c <= y    # a, c are constants, x, y variables

I hope there is some workaround how I can model the above described if b then x equals y constraint.

Here are my approaches so far:

b*y <= x
y >= x*b   # works in theory, but multiplication of 2 variables is not allowed

For 2 binary variables x and y the following is true:

M*y > x    # represents: if x then y (M is a sufficient large constant)

I guess the solution involves a large M constant, maybe even further helper variables.

A little background: I want to model an inventory problem, with continuous stock levels. However, order decisions should only be possible in integer numbers. I therefore need the stock level to be modelled with float numbers. At the point of order (b==1) however in integer.

I hope someone can help here, even if this is rather theoretic than directly coding related. Hints to further resources that might help are also highly appreciated.

Upvotes: 0

Views: 1606

Answers (1)

Erwin Kalvelagen
Erwin Kalvelagen

Reputation: 16724

b=1 => x=y

can be modeled as:

y-M(1-b) <= x <= y+M(1-b) 

Upvotes: 1

Related Questions