# How to write the following constraint? [duplicate]

I would like to write the following constraint, where $$varBuyWater$$ and $$varSellWater$$ are decision variables on how much water to buy and to sell. However, I do not want the solver to buy and sell water at the same time, because that makes no sense.

How do I force to solver to have either one of them, i.e. if $$varBuyWater > 0$$ then $$varSellWater = 0$$ and the other way around. Is there a way to do this>

• If you want to buy and then selling the water, the constraint something like $sellwater \leq buywater$ might be helpful, otherwise, you should use a big-m formulation based on your needs. One example mentioned by @Kuifje. Apr 23, 2021 at 12:20

You need to introduce a binary variable for buying, $$b$$, and one for selling, $$s$$.
Make sure $$b$$ and $$s$$ are active when $$varBuyWater$$ and $$varSellWater$$ are positive, respectively: $$varBuyWater \le M_1 b \\ varSellWater \le M_2 s \\$$
$$M_1$$ and $$M_2$$ are upper bounds on variables $$varBuyWater$$ and $$varSellWater$$.
And impose that both binaries cannot take value $$1$$ simultaneously: $$b+s \le 1$$