Try our new documentation site (beta).

Source code for the experiment on a thin feasible region

from gurobipy import *
import random
import sys

# Test the effect of small perturbations on the optimal solutions
# for a problem with a thin feasible region
rhs = 1e3
m   = Model('Thin line Optimization')
x   = m.addVar(obj=1)
y   = m.addVar(obj=0, lb=-GRB.INFINITY, ub=GRB.INFINITY)
c1  = m.addConstr(  1e-5 * y + 1e-0 * x <= rhs)
c2  = m.addConstr(- 1e-5 * y + 1e-0 * x <= rhs)
m.Params.OutputFlag = 0
m.Params.Presolve   = 0
xval    = x.X
yval    = y.X
maxdiff = 0
for i in range(1024*1024):
  c1.Rhs = rhs + 2e-6 * random.random()
  c2.Rhs = rhs + 2e-6 * random.random()
  x.Obj  = 1   + 2e-6 * random.random()
  y.Obj  = 0   + 2e-6 * random.random()
  x2val = x.X
  y2val = y.X
  error = (xval-x2val)*(xval-x2val) + (yval-y2val)*(yval-y2val)
  if error > 1e-5 + maxdiff:
    print('New maxdiff %g Iter %d Kappa %g Violations: %g %g %g' %
          (error, i, m.KappaExact, m.BoundVio, m.ConstrVio,
    maxdiff = error

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.