Comments Off on CPLEX


CPLEX Optimizer provides flexible and high-performance mathematical programming solvers for linear programming, mixed-integer programming, constraint programming, and quadratic constraint programming problems. These solvers include a distributed parallel algorithm for mixed-integer programming to leverage multiple computers to solve challenging problems.

Setting up the environment

ml optimizer/cplex
ml optimizer/cplex/12.8.0 
  • Available version : (limited version) and 12.8.0 (academic version)


Access to the software

  • Loading the cplex module
  • Type in cplex command line
$ ml optimizer/cplex/ 
$ cplex

Welcome to IBM(R) ILOG(R) CPLEX(R) Interactive Optimizer Community Edition
  with Simplex, Mixed Integer & Barrier Optimizers
5725-A06 5725-A29 5724-Y48 5724-Y49 5724-Y54 5724-Y55 5655-Y21
Copyright IBM Corp. 1988, 2022.  All Rights Reserved.

Type 'help' for a list of available commands.
Type 'help' followed by a command name for more
information on commands.

CPLEX> help

add             add constraints to the problem
baropt          solve using barrier algorithm
change          change the problem
display         display problem, solution, or parameter settings
enter           enter a new problem
feasopt         find relaxation to an infeasible problem
help            provide information on CPLEX commands
mipopt          solve a mixed integer program
netopt          solve the problem using network method
optimize        solve the problem
populate        get additional solutions for a mixed integer program
primopt         solve using the primal method
quit            leave CPLEX
read            read problem or advanced start information from a file
set             set parameters
tools           tools for analysis and debugging of models
tranopt         solve using the dual method
write           write problem or solution information to a file
xecute          execute a command from the operating system

Enter enough characters to uniquely identify commands & options. Commands can be
entered partially (CPLEX will prompt you for further information) or as a whole.
CPLEX> quit

Launching a job

For launching the job, we need 2 input files in addition to the launch script:

  • the file containing the problem to solve
  • a cplex command file
Description of the toy example

Minimize – x1 – 2 x2 – 3 x3 with the following constraints :

  • x1 + x2 + x3 <= 20
  • x1 – 3 x2 + x3 <= 30
  • 3 x1 + 2 x2 – x3 >= 100
  • x3 – 4 x4 <= 40
  • 0 <= x1 <= 40
  • x2 >= 10
  • 0 <= x3 <= 100
  • All other variables are >= 0.
File example.mps containing the problem
 N  obj     
 L  c1      
 L  c2      
 G  c3      
 L  c4      
    x1        obj                 -1   c1                  -1
    x1        c2                   1   c3                   3
    x2        obj                 -2   c1                   1
    x2        c2                  -3   c3                   2
    x3        obj                 -3   c1                   1
    x3        c2                   1   c3                  -1
    x3        c4                   1
    x4        c4                  -4
    rhs       c1                  20   c2                  30
    rhs       c3                 100   c4                  40
 UP bnd       x1                  40
 LO bnd       x2                  10
 UP bnd       x3                 100
cplex command file

The following commands ask to find :

  • an optimization of the problem described in the example.mps file
  • display the problem
  • display the solution for the 4 variables x1, x2, x3 and x4
  • display the quality of the solution
  • then quit cplex
read example.mps
display problem all
display solution variables 1-4
display solution quality
Script to launch a cplex job

We assume that the script is called launch_cplex.sh.

#SBATCH --job-name=test_cplex
#SBATCH --partition=normal-amd			# submission queue
#SBATCH --time=1:00:00			# 1-1 means one day and one hour
#SBATCH --mem=8G				# T-tera, G-giga, M-mega
#SBATCH --cpus-per-task=1
#SBATCH --ntasks-per-node=1
#SBATCH --nodes=1

ml optimizer/cplex
cplex -f mycplexcommands.txt
Submitting the job
sbatch launch_cplex.sh

Search for examples

Here is a command to search for other toy examples :

ml help optimizer/cplex