Try our new documentation site (beta).
Filter Content By
Version
Text Search
${sidebar_list_label} - Back
Filter by Language
qcp.py
#!/usr/bin/python # Copyright 2016, Gurobi Optimization, Inc. # This example formulates and solves the following simple QCP model: # maximize x # subject to x + y + z = 1 # x^2 + y^2 <= z^2 (second-order cone) # x^2 <= yz (rotated second-order cone) from gurobipy import * # Create a new model m = Model("qcp") # Create variables x = m.addVar(name="x") y = m.addVar(name="y") z = m.addVar(name="z") # Set objective: x obj = 1.0*x m.setObjective(obj, GRB.MAXIMIZE) # Add constraint: x + y + z = 1 m.addConstr(x + y + z == 1, "c0") # Add second-order cone: x^2 + y^2 <= z^2 m.addQConstr(x*x + y*y <= z*z, "qc0") # Add rotated cone: x^2 <= yz m.addQConstr(x*x <= y*z, "qc1") m.optimize() for v in m.getVars(): print('%s %g' % (v.varName, v.x)) print('Obj: %g' % obj.getValue())
![](/wp-content/plugins/hd_documentations/content/images/documentation-ampl-guide.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/documentation-cloud.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/documentation-example-tour.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/documentation-quick-start.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/documentation-reference-manuals.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/documentation-remote-services.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/quickstart-os-linux.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/quickstart-os-mac-osx.webp?x70725)
![](/wp-content/plugins/hd_documentations/content/images/quickstart-os-windows.webp?x70725)