Gurobi

From ScientificComputing
Jump to: navigation, search

Category

Mathematics, Development

Description

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

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

Environment modules

Version Module load command Additional modules loaded automatically
6.0.2 module load gurobi/6.0.2 (python/2.7.6) (r/3.1.2) (matlab/8.2)
6.5.1 module load gurobi/6.5.1 (python/3.4.3) (r/3.3.0) (matlab/8.4)
7.0.2 module load gurobi/7.0.2 (python/2.7.12) (r/3.4.0) (matlab/9.1)
8.0.0 module load new gurobi/8.0.0 (python/2.7.14) (matlab/R2018a)
c6.0.2 module load new 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

gurobi>

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 (9.1.0.441655) 64-bit (glnxa64)
                                                  September 7, 2016

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

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 my_guroby_script.py"

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.

Example

We are using the example from the gurobi website
http://www.gurobi.com/documentation/7.0/quickstart_linux/solving_a_simple_model_the.html

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 
Maximize
  .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
Bounds
  Cu <= 1000
  Ni <= 50
  Zi <= 50
  Mn <= 50
Integers
  Pennies Nickels Dimes Quarters Dollars
End
[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
JOBID      USER        STAT  QUEUE      FROM_HOST   EXEC_HOST   JOB_NAME   SUBMIT_TIME
60506881   Leonhard    PEND  normal.4h  eu-login-10             * coins.lp Apr  4 13:21
[leonhard@eu-login-10 ~]$ bjobs
JOBID      USER        STAT  QUEUE      FROM_HOST   EXEC_HOST   JOB_NAME   SUBMIT_TIME
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.

Links

http://www.gurobi.com

http://www.gurobi.com/resources/getting-started/starting-with-gurobi
https://en.wikipedia.org/wiki/Gurobi