# Enforcing Order in a Linear Programming Question

I have an optimization model to fulfill the water requirements of a city's distribution network. The model includes water sources from rainfall collection, river extraction, reservoir storage, and external supply. I need the model to prioritize the order of water sources to meet the demand: first from rainfall collection, then from river extraction, then from reservoir storage, and finally from external supply.

We have modeled it as such: I am trying to solve a problem in which I have $$4$$ variables:

• $$x^1$$: rainfall collection,
• $$x^2$$: river extraction,
• $$x^3_t$$: reservoir storage drained, and
• $$x^4_t$$: external supply

($$x^1$$ and $$x^2$$ can only be chosen once across all timestamps).

I need $$x^1 + x^2 + x^3_t + x^4_t \geq demand_t$$, where $$t$$ is the current timestamp. We also have $$x^3_t \leq 100$$.

I basically want to encode: if ($$x^1 + x^2 + x^3_t \geq demand_t$$), then ($$x^4_t = 0$$).

How can I enforce that I drain the reservoir storage as much as possible, and only once its drained, do I use the external supply if there's any remaining demand?

We tried an attempt at $$BigM$$, but we were quite confused how to make it work for this problem.

• Welcome to OR.SE. For the conditional statement, you can take a look at this post. Also, if you want to force the model to use more from a specific resource, one possible way would be to assign an appropriate weight to the resource into the objective function and let the model decide which one would be selected. Commented Jun 22 at 5:22
• Also, would you elaborate more on How can I enforce that I drain the reservoir storage as much as possible, and only once its drained, do I use the external supply if there's any remaining demand? Commented Jun 22 at 5:25
• Two questions: Why is the demand constraint $\ge$ rather than $=$ (i.e., why would you want to use more water than you need) and (regarding the lack of a time subscript on the first two variables) aren't you saying that the same water from the first two sources used in period 1 can be used again in period 2 (some sort of recycling)?
– prubin
Commented Jun 22 at 16:05
• Actually, one more question: is there some reason that, absent additional constraints, the solver would want to use an external supply before the other alternatives were fully exploited? Is the external supply cheaper than some of the others?
– prubin
Commented Jun 22 at 16:07
• @A.Omidi So basically it's possible that the external supply may be cheaper than the reservoir storage per gallon of water, so my model may want to use the external supply. However, I only should be able to use the external supply once the reservoir storage is fully used.
– snek
Commented Jun 24 at 4:43

For simplicity, I will omit the $$t$$ index. You want to enforce $$x_1+x_2+x_3\ge d \implies x_4=0.$$ Equivalently, enforce the contrapositive $$x_4>0 \implies x_1+x_2+x_3< d.$$ Let $$\epsilon$$ be a small positive constant tolerance and enforce $$x_4>0 \implies x_1+x_2+x_3\le d-\epsilon.$$ Introduce binary decision variable $$y$$ and enforce \begin{align} x_4>0 &\implies y=1\\ y=1 &\implies x_1+x_2+x_3\le d-\epsilon \end{align} Rewrite as indicator constraints: \begin{align} y=0 &\implies x_4\le 0\\ y=1 &\implies x_1+x_2+x_3\le d-\epsilon \end{align} If your solver doesn’t support indicator constraints, you can linearize via big-M by imposing \begin{align} x_4 &\le M_1 y\\ x_1+x_2+x_3&\le d-\epsilon+M_2(1-y) \end{align}
Similarly, to enforce the more common rule $$z_1>0 \implies z_2=U_2$$, where $$0\le z_i\le U_i$$, introduce binary decision variable $$y$$ and impose \begin{align} y=0 &\implies z_1\le 0 \\ y=1 &\implies z_2\ge U_2 \end{align} Linearize via big-M as \begin{align} z_1&\le U_1 y \\ z_2&\ge U_2 y \end{align}