From ScientificComputing
Jump to: navigation, search


Mathematics, Development


The Gurobi Optimizer is a state-of-the-art solver for mathematical programming. It includes the following solvers:
  • linear programming solver (LP)
  • mixed-integer linear programming solver (MILP)
  • mixed-integer quadratic programming solver (MIQP)
  • quadratic programming solver (QP)
  • quadratically constrained programming solver (QCP)
  • mixed-integer quadratically constrained programming solver (MIQCP)
The solvers in the Gurobi Optimizer were designed from the ground up to exploit modern architectures and multi-core processors, using the most advanced implementations of the latest algorithms.

Available versions (Euler, old software stack)

Legacy versions Supported versions New versions
6.0.2, 6.5.1, 7.0.2 8.0.0, 8.1.1, 9.0.0, c6.0.2

Environment modules (Euler, old software stack)

Version Module load command Additional modules loaded automatically
6.0.2 module load gcc/4.8.2 gurobi/6.0.2 (python/2.7.6) (r/3.1.2) (matlab/8.2)
6.5.1 module load gcc/4.8.2 gurobi/6.5.1 (python/3.4.3) (r/3.3.0) (matlab/8.4)
7.0.2 module load new gurobi/7.0.2 (python/2.7.12) (r/3.4.0) (matlab/9.1)
8.0.0 module load new gcc/4.8.2 gurobi/8.0.0 (python/2.7.14)
8.1.1 module load new gcc/4.8.2 gurobi/8.1.1 (python/3.7.1)
9.0.0 module load new gcc/4.8.2 gurobi/9.0.0
c6.0.2 module load python/3.4.3 netcdf/4.3.1 gurobi/c6.0.2 openblas/0.2.13_seq legacy centos_cruft/6 szip/2.1 hdf5/1.8.12

The modules listed in parenthesis are only required if you would like to use the corresponding interface.

Interactive session

You can start an interactive session of the different Gurobi interfaces, by loading the corresponding modules and then starting their interpreter.

Python interface:

[leonhard@eu-login-06 ~]$ module load new gcc/4.8.2 python/2.7.12 gurobi/7.0.2
Autoloading openblas/0.2.13_seq
[leonhard@eu-login-06 ~]$ python
Python 2.7.12 (default, Nov  2 2016, 13:46:00) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.

Gurobi Interactive Shell (linux64), Version 7.0.2
Copyright (c) 2017, Gurobi Optimization, Inc.
Type "help()" for help


Matlab interface:

[leonhard@eu-login-08 ~]$ module load new matlab/9.1 gurobi/7.0.2
[leonhard@eu-login-08 ~]$ matlab
MATLAB is selecting SOFTWARE OPENGL rendering.

                                                 < M A T L A B (R) >
                                       Copyright 1984-2016 The MathWorks, Inc.
                                        R2016b ( 64-bit (glnxa64)
                                                  September 7, 2016

To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit

R interface:

[leonhard@eu-login-05 ~]$ module load new gcc/4.8.2 r/3.4.0 gurobi/7.0.2
Using OpenBLAS build of R-3.4.0
[leonhard@eu-login-05 ~]$ R

R version 3.4.0 (2017-04-21) -- "You Stupid Darkness"
Copyright (C) 2017 The R Foundation for Statistical Computing
Platform: x86_64-slackware-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library('gurobi')
Loading required package: slam
Please note that interactive sessions on the login node must only be used for very small test cases. All resource-demanding computation need to be submitted as a batch job.

How to submit a job

Depending on the interface that is used, job submission is slightly different. You can submit a job in batch mode with the following command:

Gurobi command line interface

bsub [LSF options] "gurobi_cl my_model_file.lp"

Python interface

bsub [LSF options] "python"

Matlab interface

bsub [LSF options] "matlab -nodisplay -nojvm -singleCompThread -r my_gurobi_script"

R interface

bsub [LSF options] "R --vanilla --slave < my_gurobi_script.R > outputfile"
Here you need to replace [LSF options] with LSF parameters for the resource requirements of the job. Please find a documentation about the parameters of bsub on the wiki page about the batch system.

Parallel jobs

Gurobi supports running in parallel using shared memory parallelization (threads).

You can specify the number of threads to be used by a model parameter

model.Params.Threads = #cores

If you for instance set it to 8

model.Params.Threads = 8

then you would also have to request 8 cores from the batch system

bsub -n 8 ....
Please make sure that the number of cores requested from the batch system and the Gurobi model parameter have the same value.


We are using the example from the gurobi website

to demonstrate how to solve a simple model.

Imagine that it is the end of the calendar year at the United States Mint. The Mint keeps an inventory of the various minerals used to produce the coins that are put into circulation, and it wants to use up the minerals on hand before retooling for next year's coins.

The Mint produces several different types of coins, each with a different composition. The table below shows the make-up of each coin type (as reported in the US Mint coin specifications).

 	        Penny	Nickel	Dime	Quarter	Dollar
Copper (Cu)	0.06g	3.8g	2.1g	5.2g	7.2g
Nickel (Ni)	 	1.2g	0.2g	0.5g	0.2g
Zinc (Zi)	2.4g	 	 	 	0.5g
Manganese (Mn)	 	 	 	 	0.3g

For our example, we'll assume we have 1000 grams of copper and 50 grams of the other minerals. Suppose the Mint wants to use the available materials to produce coins with the maximum total dollar value. Which coins should they produce?

The corresponding gurobi input file looks like

[leonhard@eu-login-10 ~]$ cat coins.lp 
  .01 Pennies + .05 Nickels + .1 Dimes + .25 Quarters + 1 Dollars
Subject To
  Copper: .06 Pennies + 3.8 Nickels + 2.1 Dimes + 5.2 Quarters + 7.2 Dollars -
     Cu = 0
  Nickel: 1.2 Nickels + .2 Dimes + .5 Quarters + .2 Dollars -
     Ni = 0
  Zinc: 2.4 Pennies + .5 Dollars - Zi = 0
  Manganese: .3 Dollars - Mn = 0
  Cu <= 1000
  Ni <= 50
  Zi <= 50
  Mn <= 50
  Pennies Nickels Dimes Quarters Dollars
[leonhard@eu-login-10 ~]$

The job is then submitted using the gurobi command line interface:

[leonhard@eu-login-10 ~]$ bsub -n 1 -W 0:10 -R "rusage[mem=512]" "gurobi_cl ResultFile=coins.sol coins.lp"
Generic job.
Job <60506881> is submitted to queue <normal.4h>.
[leonhard@eu-login-10 ~]$ bjobs
60506881   Leonhard    PEND  normal.4h  eu-login-10             * coins.lp Apr  4 13:21
[leonhard@eu-login-10 ~]$ bjobs
60506881   Leonhard    RUN  normal.4h   eu-login-10 eu-ms-013-0 * coins.lp Apr  4 13:21
[leonhard@eu-login-10 ~]$ bjobs
No unfinished job found

The solution is then written to the file coins.sol:

[leonhard@eu-login-10 ~]$ cat coins.sol 
# Objective value = 113.45
Pennies 0
Nickels 0
Dimes 2
Quarters 53
Dollars 100
Cu 999.8
Ni 46.9
Zi 50
Mn 30
[leonhard@eu-login-10 ~]$
The LSF logs are written to the corresponding log file lsf.o60506881

License information

ETH was granted an academic Gurobi license with 4096 license tokens that can be used by all users of our HPC clusters.


Gurobi provides different interfaces (Python, Matlab, R) that can be used. Please find below instructions on how to install the interfaces locally for any version of Python, Matlab or R.

Matlab interface

For using the Matlab interface, you would need to load your favorite Matlab and Gurobi module and then add the path to the Gurobi Matlab package, using the Matlab command addpath:


where __VERSION__ needs to be replace with the Gurobi version for which you loaded the corresponding module. For Gurobi installations (9.0.2, 9.1.1) in the new software stack, the path that needs to be added is


Please find below an example to use the Matlab interface with Gurobi 9.0.0:

[sfux@eu-login-47 test1]$ cp /cluster/apps/gurobi/9.0.0/x86_64/examples/matlab/mip1.m .
[sfux@eu-login-47 test1]$ module load new gcc/4.8.2 gurobi/9.0.0 matlab/R2017b
[sfux@eu-login-47 test1]$ matlab -nodisplay -nojvm -singleCompThread
MATLAB is selecting SOFTWARE OPENGL rendering.

                                                           < M A T L A B (R) >
                                                 Copyright 1984-2017 The MathWorks, Inc.
                                                 R2017b ( 64-bit (glnxa64)
                                                           September 14, 2017

To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit
>> addpath('/cluster/apps/gurobi/9.0.0/x86_64/matlab')
>> mip1
          status: 'OPTIMAL'
     versioninfo: [1x1 struct]
         runtime: 0.0014
          objval: 3
               x: [3x1 double]
           slack: [2x1 double]
    poolobjbound: 3
            pool: [1x2 struct]
          mipgap: 0
        objbound: 3
       objboundc: 3
       itercount: 0
    baritercount: 0
       nodecount: 0 

x 1
y 0
z 1
Obj: 3.000000e+00

If you would like to install the Gurobi Matlab interface permanently, then it is sufficient to create a file


that contains the addpath command. Matlab will on startup automatically check the startup.m file.

R interface

For using the R interface, you would need to load your favorite R and Gurobi module, start an interactive R session and then use the following R command to install the interface:

install.packages('__TARBALL__', repos=NULL)

where __TARBALL__ needs to be replace with the corresponding path for the Gurobi R package. Please find below the list of options for __TARBALL__:


The interface only needs to be installed locally once and should afterwards automatically be found by R.

Python interface

The local installation of the Python interface requires an initial setup, since it uses distutils instead of pip. In a first step, you need to create a directory structure in your $HOME. The installation requires the path


with X.Y being the first two digits of the Python version. In the following example, we use Python 2.7.14

[sfux@eu-login-39 ~]$ mkdir $HOME/python
[sfux@eu-login-39 ~]$ cd $HOME/python
[sfux@eu-login-39 python]$ mkdir -p lib64/python2.7/site-packages
[sfux@eu-login-39 python]$ export PYTHONPATH=$HOME/python/lib64/python2.7/site-packages:$PYTHONPATH
[sfux@eu-login-39 python]$ module load new gcc/4.8.2 gurobi/9.0.0 python/2.7.14
Autoloading openblas/0.2.13_seq
[sfux@eu-login-39 python]$ cd /cluster/apps/gurobi/9.0.0/x86_64/

After this, you can install the package:

[sfux@eu-login-39 x86_64]$ python build -b $SCRATCH install --prefix=$HOME/python
running build
running build_py
running install
running install_lib
creating /cluster/home/sfux/python/lib64/python2.7/site-packages/gurobipy
copying /cluster/scratch/sfux/lib/gurobipy/ -> /cluster/home/sfux/python/lib64/python2.7/site-packages/gurobipy
copying /cluster/scratch/sfux/lib/gurobipy/ -> /cluster/home/sfux/python/lib64/python2.7/site-packages/gurobipy
byte-compiling /cluster/home/sfux/python/lib64/python2.7/site-packages/gurobipy/ to __init__.pyc
running install_egg_info
Writing /cluster/home/sfux/python/lib64/python2.7/site-packages/gurobipy-9.0.0-py2.7.egg-info
[sfux@eu-login-39 x86_64]$

Then the package is installed in $HOME/python. To use the package, you would need to load the modules and set the $PYTHONPATH:

[sfux@eu-login-37 ~]$ module load new gcc/4.8.2 gurobi/9.0.0 python/2.7.14
Autoloading openblas/0.2.13_seq
[sfux@eu-login-37 ~]$ export PYTHONPATH=$HOME/python/lib64/python2.7/site-packages:$PYTHONPATH
[sfux@eu-login-37 ~]$ python
Python 2.7.14 (default, Oct  4 2017, 08:15:29)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Using license file /cluster/apps/gurobi/9.0.0/x86_64/gurobi.lic
Set parameter TokenServer to value
Set parameter LogFile to value gurobi.log

Gurobi Interactive Shell (linux64), Version 9.0.0
Copyright (c) 2019, Gurobi Optimization, LLC
Type "help()" for help

To automatically set the $PYTHONPATH on login, you can add the line with the export statement into your .bashrc or .bash_profile file.