Setting up an optimization engine

Get IBM® optimizers

  • Mathematical programming (MP) and Constraint programming (CP) models can be solved either with CPLEX® on the Cloud (DOcplexcloud) or with a local CPLEX installation (CPLEX Optimization Studio V12.8.0 or V12.9.0). Additionnaly, you can use docplex in `IBM Watson Studio Cloud<https://www.ibm.com/cloud/watson-studio/>`__.
  • You have different options to get the solving capability you need:
    • IBM Watson Studio Cloud is an IBM service that provides a hosted notebook service in the cloud. Sign up for a free IBM Cloud account and you’ll find many Decision Optimization Notebooks already available in Watson Studio Cloud.
    • IBM ILOG® CPLEX Optimization Studio Development or Deployment edition for solving with no engine limit or the Community Edition with engine limits. You can download the full CPLEX Community Edition here or you can download and install it from AnacondaCloud here.
    • IBM Academic Initiative for faculty members, research professionals: IBM Academic Initiative (AI) is a global program that faculty members, research professionals at accredited institutions, and qualifying members of standards organizations can join. Members can get full versions of a large selection of IBM software, including CPLEX at no charge. More information about IBM ILOG Optimization products in the IBM Academic Initiative can be found here.
    • An IBM Decision Optimization on Cloud Service account and API key. You can register for a 30-day free trial or buy a subscription here.

Engine setup

Before you run the examples, you need to set up an optimization engine. The examples are written so that they use the IBM ILOG CPLEX Optimization Studio on your computer if the product is installed.

If you do not have CPLEX Studio on your computer, you can install IBM ILOG CPLEX Community edition library for free.

Ultimately, you can use the IBM Decision Optimization on Cloud service to solve your models.

Using IBM ILOG CPLEX Optimization Studio on your computer

If you have IBM ILOG CPLEX Optimization Studio V12.8.0 or V12.9.0 installed, you need to add <cosdir>/<cplexdir>/python/<python_version>/<platform> to your PYTHONPATH.

  • <cosdir> is your CPLEX Optimization Studio installation directory.

  • <cplexdir> is your CPLEX installation directory.

  • <python_version> is:

    • 2.7 if your Python version is 2.7
    • 3.6 if your Python version is 3.6
  • <platform> is:

    • x64_win64 if your operating system is Windows
    • x86-64_linux if your operating system is Linux
    • x86-64_osx if your operating system is OS X
    • ppc64le_linux if your operating system is Power Linux
    • power7-64_aix if your operating system is AIX
    • s390x_linux if your operating system is Linux on Z

Note that if CPLEX is in the PYTHONPATH, then it overrides the DOcplexcloud credentials and solves locally, unless you use docloud as a solver agent. You change the solver agent by passing the agent parameter to the solve method of a model, or setting the context.solver.agent property.

To enable local solving with constraint programming, create a Python file cpo_config.py somewhere that is visible from the PYTHONPATH, and add the following line:

set_default(LOCAL_CONTEXT)

Details for setting up the local solver for Constraint Programming are available in section Constraint programming: Cloud or Local Solving.

Installing IBM ILOG CPLEX Optimization CE

IBM ILOG CPLEX Optimization is available as a free Community Edition. You can install the python runtimes using pip or with conda.

Installing IBM ILOG CPLEX Optimization library with pip

The IBM ILOG CPLEX Optimization library can be installed via pip from PyPI.

Use pip to install the library:

> pip install cplex

pip is the standard tool that is used to install Python packages and is included in Python 2.7.9 (and later), Python 3.5 (and later), and Python 3.6 (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.

  • The Pypi distribution of CPLEX CE is available on the following platforms:

    • Windows
    • Linux (x86-64)
    • OSX

Installing the IBM ILOG CPLEX Optimization library with conda install packager

The IBM ILOG CPLEX Optimization library can be installed via conda from the CPLEX conda home.

First install Anaconda, then use conda to install the modeling library:

> conda install -c ibmdecisionoptimization cplex

conda is the package installer that is used to install Python packages and is included in Continuum Anaconda distributions. Refer to the anaconda documentation for easy access to the upgrade, uninstall, and version checking commands.

When using conda commands, you need to specify the ibmdecisionoptimization channel. For instance, to update your already existing installation of docplex using conda:

> conda update -c ibmdecisionoptimization cplex
  • The conda distribution of CPLEX CE available on the following the platforms:

    • Windows
    • Linux (x86-64)
    • OSX
    • Linux (linux-ppc64le)

Using the IBM Decision Optimization on Cloud service

To use the CPLEX or CP Optimizer algorithms on the cloud (DOcplexcloud), you will need to get 2 things:

  • the URL of the service to be called
  • the API key that corresponds to your personal account on this web service.

The API key will identify you on the IBM cloud and will also determine your computation rights. For example, a trial key will enable you to run 1 model at a time and queue a maximum of 5 jobs for a duration of 1 month. A paid subscription with bare metal will enable you to run multiple jobs in parallel. This key will also determine the type of CPU and RAM you can access, for example. You can generate multiple keys.

You can submit a python program to the solve service either using the DOcplexcloud client API, or using docplex integrated command line interface.

In a terminal window (or command prompt window on windows), the following command submits the diet.py program to the cloud (replace your url and key with the appropriate values):

$ python -m docplex.cli -url https://your_service_url.ibm.com/ --key your_api_key execute diet.py
Model: diet
 - number of variables: 9
   - binary=0, integer=0, continuous=9
 - number of constraints: 7
   - linear=7
 - parameters: defaults
* model solved as function:
objective: 2.690
  "q_Hotdog"=0.930
  "q_Spaghetti W/ Sauce"=2.155
  "q_Chocolate Chip Cookies"=10.000
  "q_Lowfat Milk"=1.831
*  KPI: Total Calories      = 2000.000
*  KPI: Total Calcium       = 800.000
*  KPI: Total Iron          = 11.278
*  KPI: Total Vit_A         = 8518.433
*  KPI: Total Dietary_Fiber = 25.000
*  KPI: Total Carbohydrates = 256.806
*  KPI: Total Protein       = 51.174

Or you can use the API to submit your own programs.

You can read more about IBM Decision Optimization on Cloud (DOcplexcloud) and its free trial version trial version.

You can read more about IBM ILOG CPLEX Optimization Studio and its free Community Edition.