Message Boards Message Boards


GurobiLink: an interface to Gurobi numerical optimization solver

Posted 1 year ago
2 Replies
12 Total Likes

GitHub repository:

Since version 12.2 Wolfram Language users can solve their optimization problems with the Gurobi Optimizer, by using the built-in Method -> "GUROBI" option. When you select this option, your optimization problem is formulated with GurobiLink into a form that the Gurobi Optimizer understands. To allow users to understand and improve this GurobiLink package we have made it available on GitHub. The following text is from its README file:

GurobiLink is a package implemented in Wolfram Language and C++ using LibraryLink that provides an interface to the Gurobi numerical optimization solver. Gurobi can be used with the same ease as the built-in solvers and has excellent performance for particularly large or complicated (e.g. mixed-integer) models. It supports continuous and mixed-integer linear programming (LP), quadratic programming (QP), quadratically-constrained programming (QCP) and other classes of problems.

The package requires a Gurobi license (free academic licenses and evaluation licenses for commercial users are available, please see the Gurobi documentation for license installation instructions). It works with Gurobi version 9.0 and later and is bundled with Wolfram Language products (such as Mathematica or Wolfram Desktop) version 12.2 and later.

GurobiLink makes the solver accessible as a plug-in through the Wolfram Language optimization method framework and is used to implement Method -> "Gurobi" in functons like NMinimize or ConvexOptimization. This allows seamless integration of the Wolfram Language modeling capabilities with the high performance of Gurobi, for example

In[1]:= ConvexOptimization[Total[x], Norm[x] <= 1, Element[x, Vectors[10, Integers]],
            Method -> "Gurobi"] // AbsoluteTiming

Out[1]= {0.004534, {x -> {0, 0, -1, 0, 0, 0, 0, 0, 0, 0}}}

How to build

The build requires CMake 3.15 or later, a C++ compiler with support for C++11, as well as installations of Wolfram Language and the Gurobi Optimizer.

The general steps for building the complete paclet are

git clone GurobiLink
cd GurobiLink
mkdir build
cd build
cmake <options> ..
cmake --build . --target install

which will place the result by default in the GurobiLink/build/install directory.

The typical CMake options required for building are

  • WOLFRAM_INSTALLATION -- Wolfram layout location, for example, /usr/local/Wolfram/Mathematica/12.3
  • GUROBI_VERSION -- version number, for example, 9.1.2
  • GUROBI_HOME -- where Gurobi is installed, for example, /opt/gurobi912/linux64

It may not always be necessary to specify all of these, since the build system provides reasonable defaults.

The built paclet can then be enabled in a particular Wolfram Language session using PacletDirectoryLoad or packed into a .paclet archive using CreatePacletArchive.

The .paclet format is suitable for distribution or permanent installation using PacletInstall.

Some platform-specific examples follow:


Create a build directory, e.g. C:\dev\git\Paclets\GurobiLink\build

cd C:\dev\git\Paclets\GurobiLink
mkdir build
cd build

Configure the build using the 64-bit Visual Studio 2017 generator (see cmake --help for other possible CMake generators)

cmake -G "Visual Studio 15 2017 Win64" ^ -DWOLFRAM_INSTALLATION="C:\Program Files\Wolfram Research\Mathematica\12.3"^ -DGUROBI_VERSION=9.1.2^ -DGUROBI_HOME="C:\gurobi912\win64"^ -DINSTALL_PDB=ON ^ ..

The generated solution can be opened in the Visual Studio IDE using

cmake --open .

To build, select the appropriate configuration (for example, Debug), right-click the desired target (for example, INSTALL) and choose 'Build' from the context menu.

Alternatively, to build the debug configuration from the command line use

cmake --build . --config Debug --target INSTALL

The development version of the paclet will be assembled in build\install and can be enabled in a Wolfram Language session by


Sanity-check the build by running the included basic test file:



Create a build directory, e.g. ~/git/Paclets/GurobiLink/build

cd ~/git/Paclets/GurobiLink
mkdir build
cd build

Configure the build using the default Unix Makefiles generator (see cmake --help for other possible CMake generators)

cmake -DWOLFRAM_INSTALLATION="/Applications/" \
      -DGUROBI_VERSION=9.1.2 \

Build the debug configuration from the command line

cmake --build . --config Debug --target install

The development version of the paclet will be assembled in build/install and can be enabled in a Wolfram Language session by


Sanity-check the build by running the included basic test file:


See also

POSTED BY: Arnoud Buzing
2 Replies

enter image description here -- you have earned Featured Contributor Badge enter image description here Your exceptional post has been selected for our editorial column Staff Picks and Your Profile is now distinguished by a Featured Contributor Badge and is displayed on the Featured Contributor Board. Thank you!

POSTED BY: Moderation Team

Note that this post came directly from the recently open sourced GurobiLink:

Since version 12.2 of the Wolfram Language, various optimization functions already support the Method->"GUROBI" without any hassle:

The open sourcing of the code is intended for people who want to study and improve this functionality.

POSTED BY: Arnoud Buzing
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract