How to round up a variable to it’s nearest tenth in gurobi?
AnsweredI am working on a code in Gurobi and I would like to round up an variable to the nearest tenth. However, I don’t know hoe to do it. I constantly get the error that it is not possible to do it with an variable/ linear expression.
0
-
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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Say you want to round up variable \(x\) to its next tenth. You could add a new variable \(y\) that represents a tenth of \(x\) and is used everywhere where you need \(x\). \(x\) needs to be integer and to enforce rounding up, you can add 5 to its value:
\[\begin{aligned}
10x &\geq y + 5\\
&\dots \\
x &\text{ integer}
\end{aligned}\]Then, \(10x\) will represent the rounded value of \(y\).
I hope that helps.
Cheers,
Matthias0
Post is closed for comments.
Comments
2 comments