2
$\begingroup$

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 = m.addVar()
x.UB = 2
x.LB = 1
cstr0 = m.addConstr(3*x <= 3)
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
$\endgroup$
  • $\begingroup$ "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? $\endgroup$ – Marco Lübbecke May 14 at 19:21
  • 1
    $\begingroup$ 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. $\endgroup$ – user3680510 May 15 at 8:08
  • $\begingroup$ I understand, thanks for clarifying $\endgroup$ – Marco Lübbecke May 15 at 8:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.