Filter Content By
Version
Text Search
${sidebar_list_label} - Back
Filter by Language
Python Interface
Gurobi comes with a Python extension module called “gurobipy” that
offers convenient object-oriented modeling constructs and an API to
all Gurobi features. The Gurobi distribution also includes a Python
interpreter and a basic set of Python modules (see the
interactive shell), which are
sufficient to build and run simple
optimization models. You can also install gurobipy
into an
existing Python installation or virtual environment
(https://docs.python.org/3/library/venv.html).
In this section, we will first review installation options. We then point out some useful Python tools and their installation. Finally, we introduce you to the basic usage of gurobipy by means of a few concrete examples.
Subsections
- Python Installation Options
- Python Tools
- gurobipy, the Gurobi Python Interface
- Simple Python Example
- Example mip1.py
- Example details
- Creating the model
- Adding variables to the model
- Setting the objective
- Adding constraints to the model
- Optimizing the model
- Reporting results - attributes
- Cleaning up
- Error handling
- Running the example
- Python Matrix Example
- Example matrix1.py
- Example details
- Creating the model
- Adding variables to the model
- Setting the objective
- Adding constraints to the model
- Optimizing the model
- Reporting results - attributes
- Error handling
- Running the example
- Python Dictionary Example
- Motivation
- Lists and Tuples
- Dictionaries
- List comprehension and generator expressions
- The tuplelist class
- The tupledict class
- netflow.py example
- netflow.py example details
- Building a multi-dimensional array of variables
- Arc capacity constraints
- Flow conservation constraints
- Results
- Running the examples