Try our new documentation site (beta).


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)

Try Gurobi for Free

Choose the evaluation license that fits you best, and start working with our Expert Team for technical guidance and support.

Evaluation License
Get a free, full-featured license of the Gurobi Optimizer to experience the performance, support, benchmarking and tuning services we provide as part of our product offering.
Academic License
Gurobi supports the teaching and use of optimization within academic institutions. We offer free, full-featured copies of Gurobi for use in class, and for research.
Cloud Trial

Request free trial hours, so you can see how quickly and easily a model can be solved on the cloud.

Search

Gurobi Optimization