What is the best way to model or represent an equality constraint which includes an absolute term in the expression:
$$ x = |y| $$
$x \in \mathbb{R^+}$ and $y \in \mathbb{R}$
Operations Research Stack Exchange is a question and answer site for operations research and analytics professionals, educators, and students. It only takes a minute to sign up.
Sign up to join this communityWhat is the best way to model or represent an equality constraint which includes an absolute term in the expression:
$$ x = |y| $$
$x \in \mathbb{R^+}$ and $y \in \mathbb{R}$
If the objective function and the remaining constraints are such that the solver will always prefer smaller values of $x$ over larger values, you can get by with two constraints: $x\ge y$ and $x\ge -y.$ Otherwise, assuming you know an upper bound $U$ for $\vert y\vert,$ you can introduce a binary variable $z$ and the constraints $$0\le x-y \le 2U\cdot z$$and $$0 \le x+y \le 2U\cdot (1-z).$$ When $z=0,$ the first constraint forces $x=y$ (meaning $y$ must be $\ge 0$) and the second constraint is harmless (since $x+y=2y=2\vert y\vert \le 2U$). When $z=1,$ the second constraint forces $x=-y$ (meaning $y$ must be $\le 0$) and the first constraint is harmless (since $x-y=2\vert y\vert$).