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

• Thanks. Do i define w as an integer? – Sophie Jan 2 '16 at 19:51
• No need to. If $a$ and $b$ are integers so will $\omega$. – Kuifje Jan 2 '16 at 20:54
• Ok. But when i run it, i still get zero as the solution.. – Sophie Jan 2 '16 at 22:43
• 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
• Yes, they are as follows: a,b >= 0; fixed percentage constraints(decimals) for the decision variables U,V which are arrays of multiple variables. Even though, i've fixed U and V to be binary, on running the model, the resulting arrays contains decimals in some places instead of 0 or 1. – Sophie Jan 3 '16 at 0:07