[CLPEX memo] Run DO Python API in COS installed environment

At the beginning

The standard development environment for IBM's optimization solution CPLEX is ** IBM ILOG CPLEX Optimization Studio ** (abbreviated as ** COS **). On a PC with COS installed, model development is usually done in an optimization-specific language called OPL using an Eclipse plug-in, but development using the Python API is also possible. I will write a memo of the procedure.

Reference link

Setting up an optimization engine

Premise

Check the operation

MacOS: 10.14.6 CPLEX Optimization Studio: 12.9

It was done in the environment of.

Setup steps

Introduction of COS

As for COS, all installations are done by default in the usual way.

Introduction of anaconda

The test was done with Jupyter Notebook. As for anaconda, which is the premise, everything is done by default in the usual way.

Confirmation of COS / cplex installation path

Check the COS installation path with the following command.

$ ls -l /Applications | grep CPLEX

In the environment at hand

drwxrwxr-x  11 [email protected]  admin  352  9 13 10:19 CPLEX_Optimizer129

It was the result.

Check Python version

Check with the following command.

$ python -V

In my environment, I got the following results:

Python 3.7.3

Setting the environment variable PYTHONPATH

Based on the results so far, add a line like the following to ~ / .bash_profile.

export PYTHONPATH=/Applications/CPLEX_Optimizer129/cplex/python/3.7/x86-64_osx

Please modify the part of 3.7 / x86-64_osx according to the Python version and platform.

Introducing the library

Install the DO Python API library with the following pip command.

$ pip install docplex

Operation check

This completes the necessary preparations. With the environment variable PYTHONPATH set

$ jupyter notebook

Then, start Jupyter Notebook.

Solving the traveling salesman problem with Watson Download and load the Jupyter Notebook file introduced in.

After that, Shift + Enter to execute the cells in order, and CPLEX should find the best route as shown in the figure below.

スクリーンショット 2019-12-02 15.28.01.png

Relationship between functional constraints and licenses

COS also has an evaluation version that is available for free. If you use the evaluation version, make the above settings, and try to solve the traveling sales problem, you will see a message like the one below.

CPLEX Error  1016: Community Edition. Problem size limits exceeded. Purchase at https://ibm.co/2s0wqSa.

This is literally an error caused by the functional restrictions of the evaluation version (up to 1000 rules). In the case of the evaluation version, if you correct the number of points (N) = 5 in the traveling sales problem and execute it, the functional constraint will not be hit and it will end normally.

Recommended Posts

[CLPEX memo] Run DO Python API in COS installed environment
Run Google Analytics API (core v3) in python
Use jupyter-lab installed in python virtual environment (venv)
Run Qiita API v2 Python wrapper in Python3 environment (Mac OS X 10.11 (El Capitan))
My python environment memo
virtual environment in python
C API in Python 3
OpenVINO using Inference Engine Python API in PC environment
Hit Mastodon's API in Python
Run automatic jobs in python
Run shell commands in python
Handle environment variables in Python
How to develop in a virtual environment of Python [Memo]
[SAP CP] Web API created with python in CF environment
After enabling the python virtual environment in the batch file, run the python file
[MEMO] [Development environment construction] Python
Blender Python API in Houdini (Python 3)
Jupyter Notebook 6.0.2 cannot be installed in the Python 2.7 environment created in Anaconda
[Python] How to do PCA in Python
Getting the arXiv API in Python
Run eclipse in Docker environment (noVNC)
Let's run "python -m antigravity" in python
Hit the Sesami API in Python
Run shell command / python in R
[Personal memo] Python virtual environment command memo
Run Rotrics DexArm with python API
Web application development memo in python
Install scrapy in python anaconda environment
Python environment construction memo on Mac
Python colorama Color memo (Cmder environment)
Create Gmail in Python without API
Get, post communication memo in Python
Hit the web API in Python
Vim + Python development environment setting memo
Quickly implement REST API in Python
Run unittests in Python (for beginners)
Emacs Python development environment construction memo
Run Ansible from Python using API
Access the Twitter API in Python
Get a list of packages installed in your current environment with python
[AWS] Problem avoidance memo when installing awscli and boto3 in Python 2.7 environment
Python & Machine Learning Study Memo: Environment Preparation
Mouse operation using Windows API in Python
How to access environment variables in Python
Method to build Python environment in Xcode 6
Do a non-recursive Euler Tour in Python
Try using the Kraken API in Python
Using venv in Windows + Docker environment [Python]
How to do R chartr () in Python
Tweet using the Twitter API in Python
Get Google Fit API data in Python
Run AzureKinect in Python on Christmas Eve.
Run the Python interpreter in a script
To reference environment variables in Python in Blender
Quickly try Microsoft's Face API in Python
Image sending / receiving memo in Python (Flask)
Make cron-like jobs run regularly in Python
CG image quality evaluation memo in Python
Python garbled in Windows + Git Bash environment
Run Python in C ++ on Visual Studio 2017
Introduced sip-4.14 in python3.2.2 environment with MacOS 10.7.4