Using Gurobi with Matlab

Gurobi for MATLAB is a high-performance engine swap for your optimization workflow. It replaces MATLAB’s native solvers with Gurobi’s industry-leading mathematical algorithms, allowing you to tackle massive, industrial-scale problems that would otherwise stall or time out.

Getting Started

You will need first to open an instance of Open OnDemand: https://nova-ondemand.its.iastate.edu/pun/sys/dashboard  From the "Interactive Apps" menu select "Nova Desktop".  Set your needed resources to allocate and then select "Launch".  You'll be put in a queue and once your instance is ready select "Launch Nova Desktop".

Configuring Matlab

We'll be using Matlab from a terminal rather than starting it from the desktop menu.  

  • First go to "Applications" in the top left corner and select "Terminal Emulator"
  • Next you'll need to change to the work directory you plan to use Gurobi with.  If you don't have one you can use mkdir to create a new directory.
  • Now we need to load the matlab and gurobi modules.  Type the following commands in the terminal:
    • module load matlab/R2025a gurobi/12.0.3
    • matlab
  • From the Home tab select "Set Path"


     

  • After selecting "Set Path" you'll have an option to "Add Folder" and then select "Add Folder To Path"

 

  • Under Directory add the following path: /shared/hpc/gurobi/12.0.3/linux64/matlab then click Apply and Okay
  • Next you'll need to save the path to your work directory
    •  >> savepath /work/myworkdir/pathdef.m
  • To test it is working open a second Terminal Emulator and switch to your work directory and copy the test file
    • cp /shared/hpc/gurobi/12.0.3/linux64/examples/matlab/mip1.m .
  • From the matlab command line type:
    • >> mip1
  • You should see output similar to the following:
    • >> mip1
               status: 'OPTIMAL'
          versioninfo: [1×1 struct]
              runtime: 0.0096
                 work: 1.3061e-05
              memused: 3.9280e-06
           maxmemused: 3.2866e-04
               objval: 3
                    x: [3×1 double]
                slack: [2×1 double]
         poolobjbound: 3
                 pool: [1×2 struct]
               mipgap: 0
             objbound: 3
            objboundc: 3
            itercount: 0
         baritercount: 0
            nodecount: 0
               maxvio: 0
    • x 1
      y 0
      z 1
      Obj: 3.000000e+00
      >> 

If any assistance is needed please contact researchit@iastate.edu.  For additional Matlab resources please see https://research.it.iastate.edu/using-matlab-parallel-server and https://research.it.iastate.edu/faqs#How%20can%20I