Skip to content

CPLEX

How to obtain Cplex

CPLEX Optimization Studio is available for students, in addition to teachers, researchers and university staff. In order to download it, please follow the link:

https://www.ibm.com/academic/home

on the CIRRELT/GERAD Linux computers, cplex is already available and can be accessed by loading the cplex-studio module.

module load cplex-studio

Installation

For some programming languages, like python and julia, in addition to installing cplex, you need to add the modules specific to the language.

To use cplex with python, you need to use version 22.1.2 or newer. For this version, it's possible to install the packages for python up to 3.12.

Here's an installation procedure.

Creation and activation of a virtual environment.

python3 -m venv .venv
. .venv/bin/activate

Upgrade pip and installe the cplex packages

pip3 install --upgrade pip
pip3 install cplex docplex

This will install the free version of cplex that has size limitations. To remove the restrictions, we use the script provided by ibm: https://www.ibm.com/support/pages/does-cplex-optimization-studio-2211-support-python-311

python3 /home/ibm/cplex-studio/make_full.py /home/ibm/cplex-studio/22.1.2

Here's an exemple on the installation procedure. We recommend that you use a virtual environment for your project.

import Pkg
Pkg.add("JuMP")
ENV["CPLEX_STUDIO_BINARIES"] = "/home/ibm/cplex-studio/22.1.1/cplex/bin/x86-64_linux/"
Pkg.add("CPLEX")
Pkg.build("CPLEX")

CPLEX tutorial

Here's a 2 part tutorial to learn how to implement a mathematical model with CPLEX in C++.

You can refer to this reference document that covers the most important notions (classes and methods).

You can also refer to commented examples that come with the CPLEX installation. Those examples cover the notions learned in the reference document.

Cplex parameters

Since version 11, the solver will try to use all processors on the machine to solve the problem. It is therefore really important that you specifiy a limited number of processors so your solve doesn't interfere with other programs that could be running.

You can see in these tabs the parameter to change to use 1 processor.

cplex.setParam(IloCplex::Param::Threads, 1);
CPXsetintparam(env, CPXPARAM_Threads, 1);
execute PARAMS {
  cplex.threads = 1;
}
set threads 1
  % Initialize the CPLEX object
  cplex = Cplex('lpex1');
  % set maximum number of threads
  cplex.Param.threads.Cur = 1;
option cplex_options 'threads=1';
cpx.parameters.threads.set(1)
 set_optimizer_attribute(model, "CPXPARAM_Threads", 1)