Gurobi Optimizer

Gurobi Optimizer is a commercial optimizing library.


Aalto University has a site-wide floating license for Gurobi.

Important notes

As of writing of this Guide, Aalto only has a valid license for Gurobi 9.X and older. Therefore Gurobi 10 cannot be run on triton unless you bring your own license.

Gurobi with Python

Package names

Unfortunately the python gurobi packages installed via pip and via conda come with two distinct package names gurobi for the anaconda package and gurobipy for the pip package. Normally, we install the guobi package in the anaconda environment, but there are some anaconda modules which have the gurobipy package. So you might need to select the correct package.

License Files for older Anaconda modules

Older anaconda modules on Triton might not have the GRB_LICENSE_FILE environment variable set properly, so you might need to point to it manually. To do so, you need to create a gurobi.lic file in your home folder. The file should contain the following single line:

You can create this license file with the following command on the login node:

echo "" > ~/gurobi.lic

The license is an Educational Institution Site License:

Free Academic License Requirements, Gurobi Academic Licenses: Can only be used by faculty, students, or staff of a recognized degree-granting academic institution. Can be used for: Research or educational purposes. Consulting projects with industry – provided that approval from Gurobi has been granted.

After setting the license, one can run, for example:

module load anaconda

And then run the following script

import gurobipy as gp
# Depending on your anaconda version you
# might need gurobi instead of gurobipy

# Create a new model
m = gp.Model()

# Create variables
x = m.addVar(vtype='B', name="x")
y = m.addVar(vtype='B', name="y")
z = m.addVar(vtype='B', name="z")

# Set objective function
m.setObjective(x + y + 2 * z, gp.GRB.MAXIMIZE)

# Add constraints
m.addConstr(x + 2 * y + 3 * z <= 4)
m.addConstr(x + y >= 1)

# Solve it!

print(f"Optimal objective value: {m.objVal}")
print(f"Solution values: x={x.X}, y={y.X}, z={z.X}")

Gurobi with Julia

For Julia there exists a package called Gurobi.jl that provides an interface to Gurobi. This package needs Gurobi C libraries so that it can run. The easiest way of obtaining these libraries is to load the anaconda-module and use the same libraries that the Python API uses.

To install Gurobi.jl, one can use the following commands:

module load gurobi/9.5.2
module load julia

After this, in the julia-shell, install Gurobi.jl with:

using Pkg

# Test installation
using Gurobi

Before using the package do note the recommendations from Gurobi.jl’ GitHub-page regarding the use of JuMP.jl and the reuse of environments.

Gurobi with any other language supported by gurobi

For other languages supported by gurobi (like MATLAB, R or C/C++) use

module load gurobi/9.5.2

to load gurobi version 9.5.2 and then follow the instructions from the gurobi web-page. All global variables necessary for gurobi are already set, so you don’t need any further configuration