# How to use GUROBI with Octeract Engine

### Get Started

Would you like to solve a problem using Gurobi?

### Gurobi on Windows

Before we kick off the tutorial, it’s important to note that our getting started section has all the installation instructions you need to get started with Octeract Engine. After going through the guide, you’ll have:

The Engine now has an interface for Gurobi. Whether this is a solver that you’re used to or not, using the Engine’s interface for Gurobi is unfamiliar territory. Here’s a quick guide on how to use the interface for Gurobi.

### Step 2: Replace the Dummy File in the Engine

To do this, you’ll need to locate the file containing the third-party code in the Gurobi folder. Navigate to where Gurobi was downloaded on your PC. From there, locate the bin folder. Copy the .dll file – in this tutorial, it is called gurobi90.dll Go to where Octeract is installed on your PC and locate the bin folder. In there, you’ll find the Gurobi dummy file. Replace it with the .dll file you’ve just copied. Rename the file to gurobi.dll.

### Step 3: Set Solver Options to use Gurobi

To do this, you’ll need to create an options file. Open text editor on your PC – for example, Notepad, Notepad++, etc. Copy and paste the snippets below into text editor to set the third-party solver to Gurobi. Save the file as octeract.opt in the folder where you’ll be running a problem. In this tutorial, it is the nl folder inside the examples folder.

LP_SOLVER = GUROBI
MILP_SOLVER = GUROBI

### Step 4: Run a Problem

To run a problem using the Engine and Gurobi, open a PowerShell session. Using the cd command to navigate to where the nl examples folder is located on your PC. Copy and paste the snippet below to run a problem using the Engine and the options file. This will allow you to run the problem with Gurobi as a third-party solver. The solution will be displayed in PowerShell.

 octeract-engine .\ex2_1_1.nl octeract.opt
========================================
Octeract Engine v1.07.29
========================================

Preprocessing problem... 100% complete
Presolve time : 0.10s

-----------------------------------------------------------------------------------------
Iteration            GAP               LLB          BUB            Pool      Time     Mem
-----------------------------------------------------------------------------------------
90    4.246e-02 ( 67.79%)   -6.262e-02   -2.017e-02           89      1.0s    30.0MB
171    1.933e-02 ( 48.90%)   -3.953e-02   -2.020e-02          149      2.0s    32.0MB
252    1.050e-02 ( 34.20%)   -3.070e-02   -2.020e-02          209      3.0s    32.0MB
327    6.784e-03 ( 25.14%)   -2.698e-02   -2.020e-02          249      4.0s
Objective value at best solution found: -2.020e-02
3.200e+01MB
Timeout_With_Feasible_Solution
Solution file written to: C:\Users\emmel\AppData\Local\Temp\\ex6_1_1.octsol

A more detailed version of the solution is written and stored in a file on your PC. To access this, use the entire path in the line “Solution file written to:”. In this example, the path is: C:\Users\emmel\AppData\Local\Temp
From there, you’ll be able to view the solution file (.octsol) in text editor.

### Gurobi on Linux

First things first, in our getting started section, you’ll find all the installation instructions you need to get started with Octeract Engine. After going through the guide, you’ll have:

The Engine now has an interface for Gurobi. Whether this is a solver that you’re used to or not, we have the steps you need to help solve any optimsation problem. Here’s how to use the interface for Gurobi.

c/Users/emmel/Downloads\$ 'tar xvfz gurobi9.0.3_linux64.tar.gz'

### Step 2: Replace the Dummy File in the Engine

In order to do this, you’ll need to copy the third-party code from the Gurobi folder, installed on your PC, to the lib folder in your Octeract folder. In this example, the file name copied is called libgurobi90.so and is found in the lib folder. Rename this file to libgurobi.so

cp ./gurobi903/linux64/lib/libgurobi90.so ./libgurobi.so

### Step 3: Set Solver Options to use Gurobi

Create an options file and save it to the bin folder in your Octeract folder. In this tutorial, we’ll be using Vim. Use the cd command to navigate to the bin folder. Insert the snippet below to create the file called octeract.opt then set the third-party solver to GUROBI. Save the file in the current folder i.e. the bin folder.

#Create an options file
touch octeract.opt

#Open the options file
vim octeract.opt

#Set solver options to use GUROBI
LP_SOLVER = GUROBI
MILP_SOLVER = GUROBI

### Step 4: Run a Problem

To run a problem using the Engine and Gurobi, ensure you’re in the bin folder where the options file is saved. Run the Engine on a problem from the examples folder. Use the snippet below to do this. This will allow you to run the problem with Gurobi as a third-party solver. The solution will be displayed in Shell.

./octeract-engine ../examples/nl/ex6_1_1.nl
========================================
Octeract Engine v1.07.29
========================================

Preprocessing problem... 100% complete
Presolve time : 0.17s

-----------------------------------------------------------------------------------------
Iteration            GAP               LLB          BUB            Pool      Time     Mem
-----------------------------------------------------------------------------------------
80    4.923e-02 ( 70.91%)   -6.943e-02   -2.020e-02           80      1.0s    23.0MB
156    2.144e-02 ( 51.50%)   -4.164e-02   -2.020e-02          146      2.0s    24.0MB
224    1.229e-02 ( 37.83%)   -3.249e-02   -2.020e-02          184      3.0s    24.0MB
289    8.910e-03 ( 30.61%)   -2.911e-02   -2.020e-02          222      4.0s    24.0MB
352    5.790e-03 ( 22.28%)   -2.599e-02   -2.020e-02          250      5.0s    25.0MB
414    4.211e-03 ( 17.25%)   -2.441e-02   -2.020e-02          269      6.0s    25.0MB
476    3.237e-03 ( 13.81%)   -2.344e-02   -2.020e-02          272      7.0s    25.0MB
537    2.385e-03 ( 10.56%)   -2.258e-02   -2.020e-02          271      8.0s    25.0MB
597    1.745e-03 (  7.95%)   -2.194e-02   -2.020e-02          251      9.0s    25.0MB
656    1.235e-03 (  5.76%)   -2.143e-02   -2.020e-02          230     10.0s    26.0MB
684    9.997e-04 (  4.72%)   -2.120e-02   -2.020e-02          215     10.4s    26.0MB

Objective value at global solution: -2.020e-02
Solved_To_Global_Optimality
Solution file written to: /tmp/ex6_1_1.octsol

A more detailed version of the solution is written and stored in a file on your PC. To access this, use the path in the line “Solution file written to:”. From there, you’ll be able to view the solution file (.octsol).