There are two real variables $x$ and $y$. The conditions are such that:
- if $y\le 0$, then $x=0$
- if $y>0$, then $x=y$
How to write linear equations or inequalities to satisfy both the conditions?
There are two real variables $x$ and $y$. The conditions are such that:
How to write linear equations or inequalities to satisfy both the conditions?
Let $L_x,U_x$ denote a lower and upper bound for $x$, and $L_y,U_y$ denote a lower and upper bound for $y$.
Define an additional binary variable $\delta \in \{0,1\}$ and enforce the following:
$$ y \le 0 \implies \delta = 1 \implies x=0 \tag{1} $$
$$ y> 0 \implies \delta = 0 \implies x=y \tag{2} $$
Or equivalently via contrapositive:
$$ \delta = 0 \implies x=y \quad \text{and} \quad y> 0 \tag{3} $$
$$ \delta = 1 \implies x=0 \quad \text{and} \quad y\le 0 \tag{4} $$
$(3)$ can be modeled as follows: \begin{align} y+L_x\cdot\delta&\le x\le y+U_x\cdot\delta \tag{5}\\ \epsilon+L_y\cdot \delta &\le y \tag{6} \end{align}
$\epsilon$ is a small positive constant (tolerance).
And $(4)$ as follows: \begin{align} 0+L_x\cdot(1-\delta)\le x&\le 0+ U_x\cdot(1-\delta) \tag{7}\\ y&\le 0+U_y \cdot(1-\delta) \tag{8} \end{align}
As per RobPratt's comments:
These simplifications yield:
\begin{align} L\cdot \delta &\le y \\ y&\le x \\ x&\le y+U\cdot\delta \\ x&\le U\cdot(1-\delta) \\ x&\ge 0 \end{align}
It is worth noting that the desired relationship can be expressed as $x=\max(y,0)$. You want to model a disjunction of two rays from the origin. Impose finite bounds \begin{align} 0 \le x \le U \tag1\\ L \le y \le U \tag2 \end{align} and model a disjunction of two line segments (from $(0,0)$ to $(U,U)$ and from $(0,0)$ to $(0,L)$). For both, we must have $$y \le x \tag3$$ Now introduce a binary decision variable $\delta$ and enforce \begin{align} \delta = 0 &\implies y \ge x\\ \delta = 1 &\implies x \le 0 \end{align} either by using indicator constraints or by explicitly imposing big-M constraints \begin{align} x - y &\le -L\delta \tag4\\ x &\le U(1-\delta) \tag5 \end{align}