Python API Reference#
This section documents the Gurobi Python interface. It begins with an overview of the global functions, which can be called without referencing any Python objects. It then discusses the different types of objects that are available in the interface, and the most important methods on those objects. Finally, it gives a comprehensive presentation of all of the available classes and methods.
If you are new to the Gurobi Optimizer, we suggest that you start with the Getting Started Knowledge Base article for general information. This also includes Tutorials for the different Gurobi APIs. Additionally, our Example Tour provides concrete examples of how to use the classes and methods described here. We will point to sections or examples of this tour whenever it fits in this overview.
In the Python examples in this documentation, we assume that your code starts
with an import statement import gurobipy as gp
so that global functions and
types can be accessed through the gp.
prefix. We also assume that the import
statement from gurobipy import GRB
is used so that all constants in the
GRB
class are directly accessible (e.g. as GRB.MINIMIZE
).
The Gurobi Python interface is delivered in its own packages and is installed separately from the rest of the solver. You will find instructions on how to install it in the Gurobi Python API installation guide.
Contents
- Overview
- Global Functions
- Models
- Environments
- Solving a Model
- Multiple Solutions, Objectives, and Scenarios
- Infeasible Models
- Querying and Modifying Attributes
- Additional Model Modification Information
- Lazy Updates
- Managing Parameters
- Monitoring Progress - Logging
- Monitoring Progress - Callbacks
- Modifying Solver Behavior - Callbacks
- Batch Optimization
- Error Handling
- Global Functions
- Model
Model
Model.Model
Model.addConstr
Model.addConstrs
Model.addGenConstrMax
Model.addGenConstrMin
Model.addGenConstrAbs
Model.addGenConstrAnd
Model.addGenConstrOr
Model.addGenConstrNorm
Model.addGenConstrIndicator
Model.addGenConstrPWL
Model.addGenConstrPoly
Model.addGenConstrExp
Model.addGenConstrExpA
Model.addGenConstrLog
Model.addGenConstrLogA
Model.addGenConstrLogistic
Model.addGenConstrPow
Model.addGenConstrSin
Model.addGenConstrCos
Model.addGenConstrTan
Model.addGenConstrNL
Model.addGenConstrNLAdv
Model.addLConstr
Model.addMConstr
Model.addMQConstr
Model.addMVar
Model.addQConstr
Model.addRange
Model.addSOS
Model.addVar
Model.addVars
Model.cbCut
Model.cbGet
Model.cbGetNodeRel
Model.cbGetSolution
Model.cbLazy
Model.cbProceed
Model.cbSetParam
Model.cbSetSolution
Model.cbStopOneMultiObj
Model.cbUseSolution
Model.chgCoeff
Model.close
Model.computeIIS
Model.copy
Model.discardConcurrentEnvs
Model.discardMultiobjEnvs
Model.dispose
Model.feasRelaxS
Model.feasRelax
Model.fixed
Model.convertToFixed
Model.getA
Model.getAttr
Model.getCoeff
Model.getCol
Model.getConcurrentEnv
Model.getConstrByName
Model.getConstrs
Model.getGenConstrMax
Model.getGenConstrMin
Model.getGenConstrAbs
Model.getGenConstrAnd
Model.getGenConstrOr
Model.getGenConstrNorm
Model.getGenConstrIndicator
Model.getGenConstrPWL
Model.getGenConstrPoly
Model.getGenConstrExp
Model.getGenConstrExpA
Model.getGenConstrLog
Model.getGenConstrLogA
Model.getGenConstrLogistic
Model.getGenConstrPow
Model.getGenConstrSin
Model.getGenConstrCos
Model.getGenConstrTan
Model.getGenConstrNL
Model.getGenConstrNLAdv
Model.getGenConstrs
Model.getJSONSolution
Model.getMultiobjEnv
Model.getObjective
Model.getParamInfo
Model.getPWLObj
Model.getQConstrs
Model.getQCRow
Model.getRow
Model.getSOS
Model.getSOSs
Model.getTuneResult
Model.getVarByName
Model.getVars
Model.message
Model.optimize
Model.optimizeAsync
Model.optimizeBatch
Model.Params
Model.presolve
Model.printAttr
Model.printQuality
Model.printStats
Model.read
Model.relax
Model.remove
Model.reset
Model.resetParams
Model.setAttr
Model.setMObjective
Model.setObjective
Model.setObjectiveN
Model.setPWLObj
Model.setParam
Model.singleScenarioModel
Model.sync
Model.terminate
Model.tune
Model.update
Model.write
- Var
- MVar
- Constr
- MConstr
- MQConstr
- QConstr
- SOS
- GenConstr
- MGenConstr
- LinExpr
- QuadExpr
- GenExpr
- NLExpr
- MLinExpr
- MQuadExpr
- MNLExpr
- TempConstr
- Column
- Callbacks
- GurobiError
- Env
- Batch
- GRB
- tuplelist
- tupledict
- General Constraint Helper Functions
- Matrix-Friendly API Functions
- Nonlinear Expression Helpers