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

Please note that this page refers to installations from the old software stack. There are two software stacks on Euler. Newer versions of software are found in the new software stack.

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.

Please note that this page refers to installations from the old software stack. There are two software stacks on Euler. Newer versions of software are found in the new software stack.

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:

[sfux@eu-login-06 ~]$ module load new gcc/4.8.2 python/2.7.12 gurobi/7.0.2
Autoloading openblas/0.2.13_seq
[sfux@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:

[sfux@eu-login-08 ~]$ module load new matlab/9.1 gurobi/7.0.2
[sfux@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:

[sfux@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
[sfux@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

sbatch [Slurm options] --wrap="gurobi_cl my_model_file.lp"

Python interface

sbatch [Slurm options] --wrap="python"

Matlab interface

sbatch [Slurm options] --wrap="matlab -nodisplay -nojvm -singleCompThread -r my_gurobi_script"

R interface

sbatch [Slurm options] --wrap="R --vanilla --slave < my_gurobi_script.R > outputfile"
Here you need to replace [Slurm options] with Slurm parameters for the resource requirements of the job. Please find a documentation about the parameters of sbatch 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 10.0.1:

[sfux@eu-login-47 test1]$ cp /cluster/apps/nss/gurobi/10.0.1/x86_64/examples/matlab/mip1.m .
[sfux@eu-login-47 test1]$ module load gurobi/10.0.1 matlab/R2022b
[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.
                                                 R2022b 64-bit (glnxa64)
                                                           September 14, 2022

To get started, type one of these: helpwin, helpdesk, or demo.
For product information, visit
>> addpath('/cluster/apps/nss/gurobi/10.0.1/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

For installing the Python interface, you can use pip. Load your preferred Python and Gurobi module and then run

pip install --user gurobipy==10.0.1

Please make sure that the version of gurobipy matches the version number of the Gurobi module that is loaded.

Alternatively, you can also install gurobipy in a virtual environment.