Does the abs_() function keep the problem a MILP?
AnsweredHi,
I am trying to model a problem as a MILP and solve it using Gurobi.
Given a variable X and a constant N, I'd like to define a variable Y which is equal to abs(X-N).
I was having trouble formulating it, and than I discovered the helper abs_() method.
I wasn't able to find any details regarding the implementation, specifically whether it may hurt the linearity of the MILP?
Thank you
0
-
Hi Carmel,
Thank you for participating in Gurobi forum and contacting us.
Using abs_() will not hurt the linearity of your MILP.
If you want to know how this may work internally, I will explain it below. Note: you do not need to add any of the constraints below to your model. You may use the 'abs(.)' construct instead.
Let z be a binary variable and M be a big constant (say, >= 2max{|x|}):
- use the following inequalities to ensure z = 1 if x >= 0, and z = 0 if x <= 0:
- zM >= x >= (z-1)M
- Create two new inequalities:
- (1-z)M >= y-x >= (z-1)M
- zM >= y+x >= -zM
Then, the above set of linear inequalities is equivalent to y = |x|. I assume you prefer to validate yourself.
0
Please sign in to leave a comment.
Comments
1 comment