# maximizing absolute value in linear programming

I know that similar questions have been answered several times, and based on the answers, I attempted a solution to my problem. But I simply do not get the right results. The problem is as follows. I wish to solve the following optimization:

$$max(ax_1)$$ subject to $$x_1 = |x_2-x_3|$$

where $$a$$ can be both positive and negative.

I tried to set up the a "Big-M" method based Binary LP (The bounds are well known and reasonably small.) by using the following constraints:

$$x_1+(x_2-x_3)\leq M*p$$

$$x_1-(x_2-x_3)\leq M*(1-p)$$

$$x_1+(x_2-x_3)\geq -M*p$$

$$x_1-(x_2-x_3)\geq -M*(1-p)$$

where p is binary.

The bounds are $$0 \leq x_1 \leq U$$, where $$U << M$$; $$-\infty \leq x_2 \leq \infty$$; $$-\infty \leq x_3 \leq \infty$$

But this did not work. Is my above approach correct? Am I doing something wrong because of non-convexity and because of lack of closed-form solutions (as explained in Linear programming with absolute values)?

If yes, are there any alternatives? I am stuck!

This is the theoretical part.

In practice, I am having an issue with the following problem. $$max(x_1(1)+x_1(2)+x_1(3))$$

such that

$$x_1(1) = |x_2(2)-x_2(1))|$$

$$x_1(2) = |x_2(3)-x_2(2))|$$

$$x_1(3) = |x_2(4)-x_2(3))|$$

the bounds are $$0\leq x_1(1) \leq 4$$, $$0 \leq x_1(2) \leq 12$$, $$0\leq x_1(3) \leq 11$$. for $$x_2(1,...,4)$$, the bounds are [-inf inf].

I expect the fval to be 27 so that I get x_1(1,...,3) = 4, 12, 11. but I get fval to be 4 and x_1(1,...,3) = 4, 0, 0.

I suppose I am making a big blooper somewhere, but I cant figure out where...!