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.
Setting up an optimization engine
Check the operation
MacOS: 10.14.6 CPLEX Optimization Studio: 12.9
It was done in the environment of.
As for COS, all installations are done by default in the usual way.
The test was done with Jupyter Notebook. As for anaconda, which is the premise, everything is done by default in the usual way.
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 with the following command.
$ python -V
In my environment, I got the following results:
Python 3.7.3
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.
Install the DO Python API library with the following pip command.
$ pip install docplex
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.
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