Skip to content

Instantly share code, notes, and snippets.

@abelsiqueira
Last active April 25, 2018 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save abelsiqueira/569b3bf8de7e7976d3656a8ee960891c to your computer and use it in GitHub Desktop.
Save abelsiqueira/569b3bf8de7e7976d3656a8ee960891c to your computer and use it in GitHub Desktop.
Academic license - for non-commercial use only
Optimize a model with 2 rows, 2 columns and 2 nonzeros
Model has 1 quadratic constraint
Coefficient statistics:
Matrix range [1e+00, 1e+00]
QMatrix range [1e+00, 1e+00]
Objective range [0e+00, 0e+00]
Bounds range [0e+00, 0e+00]
RHS range [1e+00, 2e+00]
Presolve removed 2 rows and 2 columns
Presolve time: 0.00s
Presolve: All rows and columns removed
Barrier solved model in 0 iterations and 0.00 seconds
Optimal objective 0.00000000e+00
13
Freed default Gurobi environment
#!/usr/bin/python
from gurobipy import *
# Create a new model
m = Model("soc3")
# Create variables
x = m.addVar(name="x") # x >= 0 by default
y = m.addVar(name="y")
# Set objective: x
obj = 0.0*x
m.setObjective(obj, GRB.MINIMIZE)
# Add constraint: y >= 2
m.addConstr(y >= 2, "c0")
# Add constraint: x <= 1
m.addConstr(x <= 1, "c1")
# Add constraint: y^2 <= x^2 # x >= 0 implicitly
m.addQConstr(y*y <= x*x, "c2")
m.optimize()
print(m.status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment