rounding decimals in gurobi python

598 views
Skip to first unread message

sina.fa...@gmail.com

unread,
Feb 2, 2017, 11:42:35 AM2/2/17
to Gurobi Optimization
Hi,

I am solving a mixed-integer programming problem in which I have some allocation percentages as variables. In the optimal solution, some of these percentages have long decimal points. Could you please tell me how can I round these variables to get the objective value in 2 or 3 decimal points?

Best,

Tobias Achterberg

unread,
Feb 9, 2017, 11:06:54 AM2/9/17
to gur...@googlegroups.com
Just rounding the solution values to some precision should be easy in any
programming language. For example, if you want to keep only 3 digits, just
multiply by 1000, then round to the nearest integer, then divide by 1000.

Or do you want that Gurobi produces solution values directly that are multiples
of, say, 0.001? Then you need to introduce general integer variables y and link
them to your continuous variables like this x:

xj - 0.001 * y = 0

But this makes the problem much more difficult to solve. Why do you need this
somewhat strange restriction?

Regards,

Tobias
Reply all
Reply to author
Forward
0 new messages