Rounding up and rounding down bounds for the solution (LP)?
AnsweredHello everybody,
may i ask if it is possible to get the rounding up and round down bounds for the solution x* after solving an LP?
Currenly, the solver returns floating-point values.
thank you very much!
best
-
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,
I am not sure if I understand correctly so I assume that, e.g., for a given 1 dimensional solution \(x^*=1.1\), you would like to get \(x^*=1\) instead. Is this correct?
This is not directly possible in Gurobi but can be achieved with some extra work using the below code after a problem has been solved successfully
roundedSolution = []
for v in m.getVars():
roundedSolution.append(round(v.X)) # round each solution variable value
print('%s %g rounded value: %g' % (v.varName, v.x, roundedSolution[-1]))The rounded values can be found in the \(\texttt{roundedSolution}\) list.
Best regards,
Jaromił0 -
Hi,
Thank you very much for the answer. However, this is not the question that I was trying to ask. Please let me rephrase the question.
For instance, for a given problem, Gurobi returns a solution x*=0.3333. But in practice, we know this solution is an approximation to the real solution, right? Let's assume that the real solution is 1/3. Due to the floating-point representation, we can only get 0.3333.
In this toy example, we can clearly see that 0.3333 is derived in the rounding-down mode, indicating that this value is a lower bound of the true solution. If we can set the rounding mode to be round-up, then Gurobi should return something like 0.3334, and this corresponds to the upper bound of the true solution.
So in general, my question is: is it possible for us to get the bounds directly? Or can we set the rounding mode?
Thank you very much!
best regards,
Huimin
0 -
Hi Huimin,
Thank you for the clarification.
It is currently not possible to obtain the bounds you mention or set a rounding mode, meaning that your solution will always suffer from floating point arithmetic in the last decimals. You could try setting the NumericFocus parameter to 3 to perform more accurate computations and reduce the impact of round-off erros and may get you a few more decimals of precision. However, this will not achieve the specific rounding you are asking for.
Best regards,
Jaromił0 -
Ah! I see. Thank you very much!
0
Post is closed for comments.
Comments
5 comments