Installing CPLEX

Quick notes on the process of installing the CPLEX optimiser.

Download

Go to the AMPL Portal. From there you can follow a link to find out more about the Community Edition. Back in the portal you should login with GitHub profile. The download the command line bundle.

Unpack the archive.

sudo tar -C /opt -zxvf ampl.linux64.tgz 
export PATH=/opt/ampl.linux-intel64/:$PATH

The download page should include a unique license UUID, which will look something like this:

0d3207a2-bf5b-4cec-9269-ac06b73eda2a

📢 The UUID above is not valid.

Activate the license.

amplkey activate --uuid 0d3207a2-bf5b-4cec-9269-ac06b73eda2a

Check that you can run CPLEX.

cplex -v
AMPL/CPLEX Optimizer [22.1.1] (Linux x86_64), driver(20241206), MP(20240724)

Demo license with maintenance expiring 20250205.
Using license file "/opt/ampl.linux-intel64/ampl.lic".

Python Modules

Install the relevant Python modules.

pip install amplpy --upgrade
python -m amplpy.modules install cplex

While you’re about it you may want to install some other Python modules that are available.

python -m amplpy.modules install coin

This will give you access to, for example, the Couenne solver.

Test

To test I ran it on a simple problem. The problem is specified in linaer.mod using AMPL format. Use the ampl executable to solve the problem.

ampl

In the interactive interpreter give these instructions:

option solver cplex;
model linear.mod;
solve;
display x1, x2;
display obj;
quit;

That will produce the following results:

CPLEX 22.1.1: optimal solution; objective 720
2 simplex iterations
x1 = 6
x2 = 16

obj = 720