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
-
Official comment
This post is more than two years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum, or try Gurobot, our chatbot interface offering instant, expert-level support. -
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
Post is closed for comments.
Comments
2 comments