# Convert an IF statement in Mixed Integer Programming

I want to convert an IF statement for my optimization problem. I want to minimize the total price. I want 800 tones of salt and 3 suppliers offer me their prices.

Supplier $$1$$ offers me $$100$$ tones at $$\\\150$$ a tone.

Supplier $$2$$ offers me $$400$$ tones at $$\\\170$$ a tone, if I take $$300$$ tones (or more)the price drops to $$\\\150$$.

Supplier $$3$$ offers me $$1600$$ tones at $$\\\170$$ a tone.

Here is my model without the if statement :

$$x_i$$ is an integer variable representing the quantity bought to the supplier $$i$$, $$p_i$$ is the price of the supplier $$i$$, $$c_i$$ is the maximal capacity offered by the supplier $$i$$.

$$Min( p_1\times x_1 + p_2\times x_2 + p_3\times x_3)$$

$$s.t. x_1 + x_2 + x_3 = 800$$

$$x_1 \leq 100$$

$$x_2 \leq 400$$

$$x_3 \leq 1600$$

Now I want to use the Big M method the convert my if statement but I don't know how to do it. I tried this method : Express a "complex" IF-Statement to Linear Programming to find the constraints but I don't know how to modify my prices. I tried this :

If $$x_2 \geq 300$$, Then $$p_2 = 150$$, Else $$p_2 = 170$$.

i.e.

If $$x_2 \geq 300$$, Then $$b = 1$$, Else $$b = 0$$ and $$p_2 = 150b + 170(1-b)$$

In addition to this I code in python the the mip library, do you know a better library to do this?

Thanks a lot !

Let $$x_i$$ represents the quantity bought from the $$i$$-th supplier, and consider the following scenario: the price of the 2nd supplier is 170\$per tonne but, if you buy at least 300 tonnes, then you get to choose a non-negative quantity $$d \le x_2 - 300$$ and you get a 20\$/tonne discount on $$d$$ tonnes, otherwise $$d=0$$ (i.e., you get no discount). Clearly this is equivalent to your original problem since, given $$x_1, \dots, x_3$$, it is always convenient to maximize $$d$$.

You can model this as follows:

\min 150x_1 + 170 x_2 + 170x_3 - 20d \quad \mbox{s.t.}\\[6pt] \begin{align*} x_1 &\le 100 \\ x_2 &\le 400 \\ x_3 &\le 1600 \\ x_1 + x_2 + x_3 &= 800 \\[6pt] 100 y &> x_2 - 300 & (1)\\ 300 y &\le x_2 &(2)\\[6pt] d &\le x_2 - 300y &(3)\\ d &\le 100y &(4)\\[6pt] x_1, x_2, x_3,d &\ge 0 \\ y &\in \{0,1\} \end{align*}

Notice that $$y$$ is a binary variable that equals $$1$$ if and only if $$x_2 \ge 300$$. Indeed, if $$x_2 \ge 300$$ the constraint $$(1)$$ is satisfied only when $$y=1$$ (recall that $$x_2 - 300$$ is at most $$100$$), and the constraint $$(2)$$ simplifies to $$300 \le x_2$$, which is true. If $$x < 300$$ then the constraint $$(2)$$ forces $$y=0$$ and the constraint $$(1)$$ simplifies to $$0 \ge x_2 - 300$$, which is true.

If $$y=0$$, then $$d$$ must be $$0$$, and this is enforced by constraint $$(4)$$ which becomes $$d \le 0$$ (recall that $$d$$ is non-negative), while $$(3)$$ is always satisfied. If $$y=1$$, then constraint $$(3)$$ enforces $$d \le x_2 - 300$$, which also implies constraint $$(4)$$ since $$d \le x_2 - 300 \le 100 = 100y$$.

• Thanks a lot, that's what I needed ! :) Jan 12, 2021 at 17:55