# How to write an absolute value expression in linear programming?

My objective function for the Xpress-IVE (Mosel lang) model is

minimize |a-b|

where a and b the number of elements in the decision variables which are arrays.

Since there is no function to calculate the absolute value, i want to get something of the form

objective = max(a,b) - min(a,b)

and then minimize the objective

What I have tried: introduced two variables x and y with the following constraints: x >= a x >= b y => a y => b and re-written the objective as x-y

But this gives me zero as the solution.

Could I please get a hint on what i am doing wrong?

Minimizing $$Z=|a-b|$$ is equivalent to minimizing $$Z=\omega,$$ subject to the constraints $$a-b\le \omega\\ b-a \le \omega$$
• No need to. If $a$ and $b$ are integers so will $\omega$. – Kuifje Jan 2 '16 at 20:54
• If you are just minimizing $|a-b|$, it is normal: the minimum value of an absolute value is 0. Do you have any other constraints? – Kuifje Jan 2 '16 at 23:39