Help setting up an absolute value for expressions
AnsweredHello!
I have an absolute value that I need to set to be an absolute value.
https://stackoverflow.com/questions/58612670/how-to-handle-absolute-value-in-gurobi-constraints
I followed the advice found here but when I run my model I find that the variables in my code below both are negative. The code sample and values can be seen below in screenshots below.
freq, price_down and price_up are all read from a pandas dataframe while tot_e_del_quart is a list containing different expressions.
I've been quite stumped at this issue as I don't see what I'm doing wrong compared to other examples. Like usual any help would be greatly appreciated!
-
Official comment
This post is more than three 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 why not try our AI Gurobot?. -
Hi Bill,
The solution values of z and z1 are numerically 0, i.e., with regards to floating-point tolerances. Please consult our guide on numerics for more details on this.
Cheers,
Matthias1 -
So what you're saying is that the optimizer has made the values so small that they effectivly become 0 and the absolute value of -0 is 0?
On a more hypothetical note. Would the way the code is currently structured work in your opinion or is there some flaw in it?
If we were to say that z = -2, would z1 then be equal to 2?0 -
Any value close enough to 0 is interpreted as 0. When taking the absolute value of a variable, more things happen behind the scenes of the solver than just taking the absolute value of the value in the solution.
You should maybe relax the z variable to allow negative values in the first place. By default, all variables are non-negative and you need to specify a specific negative lower bound to change that:
z = m.addVar(lb=-GRB.INFINITY)
See also the documentation about variables.
Cheers,
Matthias1 -
Thank you so so so much Matthias.
You've helped clear this up something immensly.
Have a wonderful day!
Cheers,
Bill0
Post is closed for comments.
Comments
5 comments