Gurobi Optimization was founded in 2008 by some of the most experienced and respected members of the optimization community. The Gurobi solver quickly became an industry performance leader in linear, quadratic, and mixed-integer programming. Gurobi is a fantastic solver for use with CVX, particularly with the integer and binary variable capability added in CVX 2.0.
Using Gurobi with CVX requires a valid license:
Academic users: information about obtaining a license can be found on the Gurobi Academic Program page.
Commercial users must purchase one of our CVX Professional licenses:
Please contact CVX Sales for more information about either option, and Gurobi Sales for pricing information for standalone Gurobi licenses.
Download the the appropriate CVX bundle from the CVX download page and following the regular installation instructions at Installation. The standard bundles include a CVX-specific version of the Gurobi version 9.0.
Obtain the licenses for Gurobi and/or CVX, as needed:
If you need a full installation of Gurobi—because you wish to use a different version than is bundled with CVX, or because you wish to use Gurobi outside of CVX—obtain an appropriate installer from the Gurobi Download Center and follow their instructions. Confirm that it can be successfully run from the MATLAB command line before proceeding with Step 2.
Next, retrieve your Gurobi license key by running the command cvx_grbgetkey {code}, where {code} is the 32-digit Gurobi key. This is a convenience wrapper around Gurobi’s own grbgetkey script. The command will look something like this:
cvx_grbgetkey xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
Important note for academic users: this step must be run from a computer connected to your university network (a VPN is usually sufficient). Please consult the Gurobi documentation for more details.
Re-run cvx_setup so that the new Gurobi and/or CVX licenses can be detected. If a CVX Professional license was obtained, supply the path to this file as the argument to the cvx_setup command, as discussed in Installing a CVX Professional license.
If successful, the output of step 4 should show that Gurobi is among the list of available solvers. If you installed both a standalone Gurobi bundled version of Gurobi, they should both be available after setup.
Even if Gurobi is successfully added to your solver list, it will not automatically be selected as your default solver. To change this, type the following two commands on the MATLAB command line:
cvx_solver gurobi
cvx_save_prefs
The first command changes the active solver to Gurobi, but only for the current session. The second line saves that change to CVX’s preference file, so that Gurobi will be selected as the active solver every time you start MATLAB.
If multiple versions of Gurobi were found on the MATLAB path, then CVX will append a numeral to the end of the solver name, allowing you to switch between them; e.g.,
cvx_solver gurobi
cvx_solver gurobi_2
cvx_solver gurobi_3
and so forth.
If you encounter problems using CVX and Gurobi, please contact CVX Support first instead of Gurobi. If we can reproduce your problem, we will determine whether or not it is an issue that is unique to CVX or needs to be forwarded to Gurobi for further analysis.