2
$\begingroup$

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>

$\endgroup$
1
  • $\begingroup$ 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. $\endgroup$
    – A.Omidi
    Apr 23 at 12:20
6
$\begingroup$

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 $$

$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.