Solved

# Modelling question - if then constraint

• 2 replies
• 994 views

Userlevel 1 +3
• Enthusiast
• 9 replies
Dear Staff,
I would like your tips for an if-then constraint.

In particular, I have the following variables:
R, binary variable
P, continuous variable
Y, continuous variable

I have the following parameters:
A
B

The constraints I would like to write are the following:

1) if R=1 then P = A*Y
2) if R=0 then P = B*Y

I would like to know if it is possible to have a linear formulation without using indicator constraints.

Thank you,
icon

Best answer by mohansx 5 June 2019, 21:23

View original

### 2 replies

Userlevel 5 +5
Hi @Chibo ,

You can use a big M formulation as below to model your constraints. You will have 4 sets of constraints in total. Here, M is a sufficiently large number, you should select this value based on the values of A, B and maximum range of Y.

code:
`P >= A*Y + (R-1)*MP <= A*Y + (1-R)*MP >= B*Y - R*MP <= B*Y + R*M`

When R = 1, these become

code:
`P >= A*YP <= A*YP >= B*Y - MP <= B*Y + M`

1 and 2 will make P = A*Y. 3 and 4 will always be satisfied if the value of M is large enough.

Similarly, when R = 0 - 3 and 4 will make P = B*Y and 1 and 2 will be rendered redundant.
Userlevel 1 +3
Hello,
thank you very much for your help and for these precious suggestions. It is very kind of you.
I will try to implement them!