Getting started with constraint programming in DOcplex

To get started using the Constraint Programming Modeling for Python feature of IBM Decision Optimization CPLEX Modeling for Python library (docplex.cp), you first need to:

  • verify that your system meets the requirements,
  • choose which CPLEX Optimizer you want to use,
  • install Python and DOcplex.

As an alternative, you can choose to use the Data Scientist Workbench and not need to install anything on your computer.

Installation

This section contains information about installing IBM Decision Optimization CPLEX Modeling for Python.

System requirements

  • Windows, Linux or Mac OS operating systems.
  • Python with version 2.7.x, 3.4 to 3.8.
  • A local installation of IBM ILOG CPLEX Optimization Studio.

Get Python development tools

  • If you are new to Python, you might want a development studio with editors and debuggers. Both PyCharm and PyDev have free editions.
  • You can download appropriate Python version from Python.org.
  • A good alternative is to use Anaconda, which includes a Python interpreter and around 200 of the most popular Python packages for science, math, engineering, and data analysis.

Install the CPLEX modeling library

The IBM Decision Optimization CPLEX Modeling for Python (DOcplex) library can be installed via pip from PyPI.

Use pip to install the modeling library:

> pip install docplex

pip is the standard tool that is used to install Python packages and is included in Python 2.7.9 (and later) and Python 3.4 (and later). See pip for more details. Refer to the pip documentation for easy access to the upgrade, uninstall, and version checking commands.

See README.md for a detailed list of dependencies that are automatically downloaded and installed.

Solve model with a local solver

Local solve is available if you have a local installation of CPLEX Optimization Studio, with a version number higher or equal to 12.7.0.

The local solving is enabled by default.

Details are available in section Solve a model with local solver.

Test an example

A set of examples is available for download here.

  • Retrieve the examples archive docplex_examples.zip and uncompress it where you want.

  • Go to the directory where the root directory of the examples is located.

  • Open a command prompt and enter (on Windows, for example):

    > set PYTHONPATH=.
    > python examples/cp/basic/color.py