Try our new documentation site (beta).
Gurobi Optimizer Example Tour
Version 8.1, Copyright © 2019, Gurobi Optimization, LLC
The GurobiTM distribution includes an extensive set of examples that illustrate commonly used features of the Gurobi libraries. Most examples have versions for C, C++, C#, Java, Visual Basic, and Python. A few, however, illustrate features that are specific to the Python interface.
The distribution also includes examples for our MATLAB® and R interfaces. Note, however, that our interfaces to these languages are built around the assumption that you will use the rich matrix-oriented capabilities of the underlying languages to build your optimization models. Thus, our examples for these languages don't attempt to show you how to build models. We have instead chosen to provide a few simple examples that demonstrate how to pass matrices into our interface.
This document provides a brief tour of these examples. We won't go
through each example in detail. Instead, we'll start with an
Overview of the set of tasks that you
are likely to want to perform with the Gurobi Optimizer. Later
sections will then describe how specific examples accomplish each of
these tasks. Alternatively, we provide a Structured
List of all of our examples, which you
can use to dive directly into an example of interest to you. In
either case, we suggest that you browse the example source code (in a
text editor, or in another browser window) while reading this
document. This document includes Source
Code for all of the examples, in all available
languages. Source files are also available in the examples
directory of the Gurobi distribution.
If you would like further details on any of the Gurobi routines used in these examples, please consult the Gurobi Reference Manual.
- Example tour
- A list of the Gurobi examples
- Load and solve a model from a file
- Build a model
- Additional modeling elements
- Modify a model
- Change parameters
- Automated parameter tuning
- Diagnose and cope with infeasibility
- MIP starts
- Model-data separation in Python
- Callbacks
- Example Source Code
- C Examples
- callback_c.c
- dense_c.c
- diet_c.c
- facility_c.c
- feasopt_c.c
- fixanddive_c.c
- genconstr_c.c
- lp_c.c
- lpmethod_c.c
- lpmod_c.c
- mip1_c.c
- mip2_c.c
- multiobj_c.c
- params_c.c
- piecewise_c.c
- poolsearch_c.c
- qcp_c.c
- qp_c.c
- sensitivity_c.c
- sos_c.c
- sudoku_c.c
- tsp_c.c
- tune_c.c
- workforce1_c.c
- workforce2_c.c
- workforce3_c.c
- workforce4_c.c
- workforce5_c.c
- C++ Examples
- callback_c++.cpp
- dense_c++.cpp
- diet_c++.cpp
- facility_c++.cpp
- feasopt_c++.cpp
- fixanddive_c++.cpp
- genconstr_c++.cpp
- lp_c++.cpp
- lpmethod_c++.cpp
- lpmod_c++.cpp
- mip1_c++.cpp
- mip2_c++.cpp
- multiobj_c++.cpp
- params_c++.cpp
- piecewise_c++.cpp
- poolsearch_c++.cpp
- sensitivity_c++.cpp
- qcp_c++.cpp
- qp_c++.cpp
- sos_c++.cpp
- sudoku_c++.cpp
- tsp_c++.cpp
- tune_c++.cpp
- workforce1_c++.cpp
- workforce2_c++.cpp
- workforce3_c++.cpp
- workforce4_c++.cpp
- workforce5_c++.cpp
- Java Examples
- Callback.java
- Dense.java
- Diet.java
- Facility.java
- Feasopt.java
- Fixanddive.java
- Genconstr.java
- Lp.java
- Lpmethod.java
- Lpmod.java
- Mip1.java
- Mip2.java
- Multiobj.java
- Params.java
- Piecewise.java
- Poolsearch.java
- Qcp.java
- Qp.java
- Sensitivity.java
- Sos.java
- Sudoku.java
- Tsp.java
- Tune.java
- Workforce1.java
- Workforce2.java
- Workforce3.java
- Workforce4.java
- Workforce5.java
- C# Examples
- callback_cs.cs
- dense_cs.cs
- diet_cs.cs
- facility_cs.cs
- feasopt_cs.cs
- fixanddive_cs.cs
- genconstr_cs.cs
- lp_cs.cs
- lpmethod_cs.cs
- lpmod_cs.cs
- mip1_cs.cs
- mip2_cs.cs
- multiobj_cs.cs
- params_cs.cs
- piecewise_cs.cs
- poolsearch_cs.cs
- qcp_cs.cs
- qp_cs.cs
- sensitivity_cs.cs
- sos_cs.cs
- sudoku_cs.cs
- tsp_cs.cs
- tune_cs.cs
- workforce1_cs.cs
- workforce2_cs.cs
- workforce3_cs.cs
- workforce4_cs.cs
- workforce5_cs.cs
- Visual Basic Examples
- callback_vb.vb
- dense_vb.vb
- diet_vb.vb
- facility_vb.vb
- feasopt_vb.vb
- fixanddive_vb.vb
- genconstr_vb.vb
- lp_vb.vb
- lpmethod_vb.vb
- lpmod_vb.vb
- mip1_vb.vb
- mip2_vb.vb
- multiobj_vb.vb
- params_vb.vb
- piecewise_vb.vb
- poolsearch_vb.vb
- qcp_vb.vb
- qp_vb.vb
- sensitivity_vb.vb
- sos_vb.vb
- sudoku_vb.vb
- tsp_vb.vb
- tune_vb.vb
- workforce1_vb.vb
- workforce2_vb.vb
- workforce3_vb.vb
- workforce4_vb.vb
- workforce5_vb.vb
- Python Examples
- callback.py
- custom.py
- dense.py
- diet.py
- diet2.py
- diet3.py
- diet4.py
- dietmodel.py
- facility.py
- feasopt.py
- fixanddive.py
- genconstr.py
- lp.py
- lpmethod.py
- lpmod.py
- mip1.py
- mip2.py
- multiobj.py
- netflow.py
- params.py
- piecewise.py
- poolsearch.py
- portfolio.py
- qcp.py
- qp.py
- sensitivity.py
- sos.py
- sudoku.py
- tsp.py
- tune.py
- workforce1.py
- workforce2.py
- workforce3.py
- workforce4.py
- workforce5.py
- MATLAB Examples
- diet.m
- facility.m
- feasopt.m
- fixanddive.m
- genconstr.m
- intlinprog.m
- linprog.m
- lp.m
- lp2.m
- lpmethod.m
- lpmod.m
- mip1.m
- mip2.m
- multiobj.m
- opttoolbox_lp.m
- opttoolbox_mip1.m
- params.m
- piecewise.m
- poolsearch.m
- qcp.m
- qp.m
- sensitivity.m
- sos.m
- sudoku.m
- workforce1.m
- workforce2.m
- workforce3.m
- workforce4.m
- workforce5.m
- R Examples
- C Examples