Source code for the experiment with column scalings
import sys
import random
import argparse
import gurobipy as gp
# Use parameters for greater flexibility
parser = argparse.ArgumentParser(formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-f','--infile', help='Problem File',
default=None, required=True)
parser.add_argument('-s','--scale', help='Scaling Factor',
type=float, default=10000.0)
args = parser.parse_args()
# Load input problem
m = gp.read(args.infile)
# Scale domain of all columns randomly in the given domain
for var in m.getVars():
if var.vtype == gp.GRB.CONTINUOUS:
scale = random.uniform(args.scale/2.0, args.scale*2.0)
flip = random.randint(0,3)
if flip == 0:
scale = 1.0
elif flip == 1:
scale = 1.0/scale
col = m.getCol(var)
for i in range(col.size()):
coeff = col.getCoeff(i)
row = col.getConstr(i)
m.chgCoeff(row, var, coeff*scale)
var.obj = var.obj*scale
if var.lb > -gp.GRB.INFINITY:
var.lb = var.lb/scale
if var.ub < gp.GRB.INFINITY:
var.ub = var.ub/scale
# Optimize
m.optimize()
if m.Status == gp.GRB.OPTIMAL:
print('Kappa: %e\n' % m.KappaExact)