How to use CPLEX with Octeract Engine

Start Solving

Would you like to solve a problem using CPLEX?

CPLEX on Windows

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 CPLEX. 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 CPLEX.

Step 2: Replace the Dummy File in the Engine

In order to do this, you’ll need to locate the file containing the third-party code in the CPLEX folder. Navigate to where CPLEX is downloaded on your PC. From there, locate the bin folder. Copy the file cplex12100.dll. Go to where Octeract Engine is downloaded on your PC. In the bin folder, locate the CPLEX dummy file. Replace this by pasting the file you’ve just copied. Rename this file to cplex.dll

Step 3: Set Solver Options to use CPLEX

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 CPLEX. Save the file as octeract.opt in the folder where you’ll be running a problem. In this tutorial, it is the nl folder in the examples folder.

LP_SOLVER = CPLEX
MILP_SOLVER = CPLEX

Step 4: Run a Problem

To run a problem using the Engine and CPLEX, open a PowerShell session. Using the cd command, 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 CPLEX as a third-party solver. The solution will be displayed in PowerShell.

octeract-engine .\ex6_1_1.nl -o 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.

CPLEX 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 CPLEX. 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 CPLEX.

c/Users/emmel/Downloads\$ ./cos_installer_preview-12.10.0.0.R2-Linux-CC43LML.bin

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 CPLEX folder, installed on your PC, to the lib folder in your Octeract folder. In this example, the file name copied is called libcplex12100.so and is found in the bin folder. Rename this file to libcplex.so

cp /opt/ibm/ILOG/CPLEX_Studio_Community1210/cplex/bin/x86-64_linux/libcplex12100.so ./libcplex.so

Step 3: Set Solver Options to use CPLEX

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 CPLEX. 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 CPLEX
LP_SOLVER = CPLEX
MILP_SOLVER = CPLEX

Step 4: Run a Problem

To run a problem using the Engine and CPLEX, 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 CPLEX 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).