# How to deal with a decision variable in the objective function that depends on if-else conditions involving other decision variables?

I'm modeling an optimization problem in which a decision variable $$x_1$$ in the objective function depends on if-else conditions involving decision variables $$x_2$$ and $$x_3$$, as the following equation, where $$a$$, $$b$$, $$c$$, and $$d$$ are constants. I know a possibility would be using binary variables, but I'm not sure how to do it. Could someone help me? $$$$x_1 = \begin{cases} a, & \text{if } x_2 \geq c \ \text{and} \ x_3 \geq d\\ b \cdot x_3, & \text{if } x_2 \geq c \ \text{and} \ 0 \leq x_3 \leq d\\ 0, & \text{otherwise} \end{cases}$$$$

• What are the bounds on $x_2$ and $x_3$? Apr 26 at 19:25
• By any chance does $a=b\cdot d$? Otherwise the value of $x_1$ when $x_2 \ge c$ and $x_3 = d$ is ambiguous. Apr 26 at 20:04
• No, $a$ is not equal to $b \cdot d$. I will work on this ambiguity. Thanks! Apr 26 at 20:17
• $x_2$ and $x_3$ are bounded by a max value from both sides, e.g., $-p_{max} \leq x_2 \leq p_{max}$ and $-e_{max} \leq x_3 \leq e_{max}$. Apr 26 at 20:21

Introduce four binary variables indicating which region you are in and the function value.

\begin{align} \delta_1 &\rightarrow x_2\geq c, ~x_3\geq d, ~x_1 = a\\ \delta_2 &\rightarrow x_2\geq c, ~0\leq x_3 \leq d, ~x_1 = bx_3\\ \delta_3 &\rightarrow x_2\leq c, ~x_1 = 0\\ \delta_4 &\rightarrow x_3\leq 0, ~x_1 = 0 \end{align}

You are in one of the regions so $$\delta_1+\delta_2 +\delta_3+\delta_4=1$$, and all the implications are standard big-M representable such as $$x_2-c\geq -M(1-\delta_1), -M(1-\delta_1) \leq x_1-a\leq M(1-\delta_1)$$ etc. By exloiting structure and linearity in some terms this can be reduced and simplified, but this is the basic model.

Is the following model correct?

Consider $$\delta_i$$ as binary variables, whereas $$x_i$$ and $$y_1$$ are continuous.

$$$$x_1 = a \delta_1 + y_1$$$$

For the first if statement: $$$$\begin{matrix} c - M(1 - \delta_2) \leq x_2 \leq c + M\delta_2\\ d - M(1 - \delta_3) \leq x_3 \leq d + M\delta_3\\ \delta_2 + \delta_3 \geq2\delta_1 \end{matrix}$$$$

For the second if statement: $$$$\begin{matrix} - M(1 - \delta_4) \leq x_3 \leq M\delta_4\\ d - M\delta_5 \leq x_3 \leq d + M(1 - \delta_5)\\ \delta_2 + \delta_4 + \delta_5 \geq 3\delta_6\\ bx_3 - M(1 - \delta_6) \leq y_1 \leq bx_3 + M(1 - \delta_6)\\ -M\delta_6 \leq y_1 \leq M\delta_6\\ \end{matrix}$$$$

• If this is meant to be an implementation of my answer, no I don't see why you would need to add two additional binary variables. if you move the $x_1$ model to a linearization of $x_1 = a\delta_1 + b\delta_2x_3$ you do not need any new binary variables as it is simply $-M(1-\delta_2) \leq y_1-x_3 \leq M(1-\delta_2)$ Apr 28 at 7:05
• if it is your own attempt, well it looks correct(-ish), but the model is less clear to untangle, and more complex combinatorially. A start is to write the logical conditions and structure first to understand how the indicators relate to the initial model, and then write the MILP interpretations, instead of just listing the final MILP model. Apr 28 at 7:16