absolute value in objective

2,530 views
Skip to first unread message

RAA

unread,
May 10, 2017, 1:22:20 PM5/10/17
to Gurobi Optimization
Hi folks, 

Is there a way to directly have absolute value in the objective with out the need to linearize it using Gurobi/python ? Some thing like 

minimize sum_i |x_i - f_i|

Thanks



des...@gurobi.com

unread,
May 10, 2017, 7:38:29 PM5/10/17
to Gurobi Optimization

Tobias Achterberg

unread,
May 11, 2017, 3:31:04 AM5/11/17
to desilva via Gurobi Optimization
More precisely, you cannot use general constraints (like abs) directly in the
objective. You need to introduce an auxiliary variable and add a general
constraint. So, instead of writing

min |x - y|

you would write

min z
z = |x - y|

with the constraint being the ABS constraint, see the reference that Amal mentioned.


Regards,

Tobias

Tobias Achterberg

unread,
May 11, 2017, 3:33:23 AM5/11/17
to desilva via Gurobi Optimization
You cannot directly add general constraints like ABS to the objective. You need
to introduce an auxiliary variable to do so and link it to the problem variables
with a general constraint.

Thus, instead of writing

min |x - y|

you need to model it via

min z
s.t. z = |x - y|

The constraint is a general constraint of type ABS, see the reference that Amal
mentioned.


Best regards,

Tobias

Michael Winkler

unread,
May 11, 2017, 8:14:44 AM5/11/17
to Gurobi Optimization
Actually it slightly different but not reallly more complicated. You have to add two auxiliary variables and then it will look like:

min sum abs_z_i

abs_z_i = | z_i |
z_i = x_i - f_i

This is because the abs constraint can only get one variable "as input".

Best,
Michael

Taner Cokyasar

unread,
May 11, 2017, 7:43:54 PM5/11/17
to Gurobi Optimization
Sum of the abs value differences can be linearized as following:

min               sum |x_i  -  f_i|

will become

min               sum a_i+b_i
subject to
                     x_i  -  f_i  -  a_i  +  b_i  = 0

I understand your concern for finding a way to make it without this linearization procedure... However, you shall not have an abs operator in the obj. function. Even though you are introducing two more variables into your model and making it more complicated, you are getting the benefit of using linear programming rather than losing time with non-linear.

Tobias Achterberg

unread,
May 12, 2017, 2:46:03 AM5/12/17
to gur...@googlegroups.com
To avoid confusion, please note that the general constraints (like abs) in
Gurobi do not lead to non-linear models. They will be linearized (similar to
what you propose for abs) automatically during presolve.

Regards,

Tobias
Reply all
Reply to author
Forward
0 new messages