# Efficient way to do user rescaling of variable in Gurobi

Is there a better way than the code below to the rescaling of variable in a model after the model has been build with Gurobi? Like some build in function or a direct manipulation of the column object? I am using the python api of Gurobi.

MWE:

from gurobipy import *

m = Model()

x.UB = 2
x.LB = 1
m.update()
print "before", m.getRow(cstr0), x.LB, x.UB

scaling_factor = 1/3.0
col = m.getCol(x)
for i in xrange(col.size()):
cstr = col.getConstr(i)
coeff = col.getCoeff(i)
m.chgCoeff(cstr, x, scaling_factor*coeff)

x.UB = x.UB * 1/float(scaling_factor)
x.LB = x.LB * 1/float(scaling_factor)
m.update()
print "after", m.getRow(cstr0), x.LB, x.UB

• "better" may depend on what you are trying to achieve. gurobi is scaling your coefficients if this is good for numerical reasons, why would you do it yourself? – Marco Lübbecke May 14 at 19:21
• i have written a separation routine of valid inequalities for 0/1 polytopes, but the variables in the model have general bounds, so i need to rescale the variables in order to use the inequalities. I have talked to the Gurobi support, they said that this is the only way. – user3680510 May 15 at 8:08
• I understand, thanks for clarifying – Marco Lübbecke May 15 at 8:09