Try our new documentation site (beta).
Gurobi Optimizer Example Tour
Version 9.0, Copyright © 2020, 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
- batchmode_c.c
- bilinear_c.c
- callback_c.c
- dense_c.c
- diet_c.c
- facility_c.c
- feasopt_c.c
- fixanddive_c.c
- gc_pwl_c.c
- gc_pwl_func_c.c
- genconstr_c.c
- lp_c.c
- lpmethod_c.c
- lpmod_c.c
- mip1_c.c
- mip2_c.c
- multiobj_c.c
- multiscenario_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
- batchmode_c++.cpp
- bilinear_c++.cpp
- callback_c++.cpp
- dense_c++.cpp
- diet_c++.cpp
- facility_c++.cpp
- feasopt_c++.cpp
- fixanddive_c++.cpp
- gc_pwl_c++.cpp
- gc_pwl_func_c++.cpp
- genconstr_c++.cpp
- lp_c++.cpp
- lpmethod_c++.cpp
- lpmod_c++.cpp
- mip1_c++.cpp
- mip2_c++.cpp
- multiobj_c++.cpp
- multiscenario_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
- Batchmode.java
- Bilinear.java
- Callback.java
- Dense.java
- Diet.java
- Facility.java
- Feasopt.java
- Fixanddive.java
- GCPWL.java
- GCPWLFunc.java
- Genconstr.java
- Lp.java
- Lpmethod.java
- Lpmod.java
- Mip1.java
- Mip2.java
- Multiobj.java
- Multiscenario.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
- batchmode_cs.cs
- bilinear_cs.cs
- callback_cs.cs
- dense_cs.cs
- diet_cs.cs
- facility_cs.cs
- feasopt_cs.cs
- fixanddive_cs.cs
- gc_pwl_cs.cs
- gc_pwl_func_cs.cs
- genconstr_cs.cs
- lp_cs.cs
- lpmethod_cs.cs
- lpmod_cs.cs
- mip1_cs.cs
- mip2_cs.cs
- multiobj_cs.cs
- multiscenario_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
- batchmode_vb.vb
- bilinear_vb.vb
- callback_vb.vb
- dense_vb.vb
- diet_vb.vb
- facility_vb.vb
- feasopt_vb.vb
- fixanddive_vb.vb
- gc_pwl_vb.vb
- gc_pwl_func_vb.vb
- genconstr_vb.vb
- lp_vb.vb
- lpmethod_vb.vb
- lpmod_vb.vb
- mip1_vb.vb
- mip2_vb.vb
- multiobj_vb.vb
- multiscenario_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
- batchmode.py
- bilinear.py
- callback.py
- custom.py
- dense.py
- diet.py
- diet2.py
- diet3.py
- diet4.py
- dietmodel.py
- facility.py
- feasopt.py
- fixanddive.py
- gc_pwl.py
- gc_pwl_func.py
- genconstr.py
- lp.py
- lpmethod.py
- lpmod.py
- matrix1.py
- matrix2.py
- mip1.py
- mip2.py
- multiobj.py
- multiscenario.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
- workforce_batchmode.py
- workforce1.py
- workforce2.py
- workforce3.py
- workforce4.py
- workforce5.py
- MATLAB Examples
- bilinear.m
- diet.m
- facility.m
- feasopt.m
- fixanddive.m
- gc_pwl.m
- gc_pwl_func.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