work: solving a DOcplex model using a local solver
Once you have DOcplex installed, it is possible to model your optimization problem.
But now, how do you solve your problem? In this post, I will describe one of two choices for solving models, using a local installation of IBM ILOG CPLEX Optimization Studio. I will describe the other, using the cloud, in a future post.
Installing a local solver.
The IBM ILOG CPLEX Optimization Studio Community Edition (COS CE) is available for free; however, problem size is limited to 1000 variables and 1000 constraints.
1. Go to IBM ILOG CPLEX Optimization Studio Community Edition and click “Download”. You may be prompted to sign in using your IBMid. If you don’t have one, it is easy to create one.
2. Complete the license agreement form.
3. For the Mac, I usually select the “Download using http” tab and choose to download:
IBM ILOG CPLEX Optimization Studio Community Edition V12.7 for Mac OSX Multilingual
COSCE127MACOS.bin (159 MB)
4. Once COSCE127MACOS.bin has completed downloading, you need to install COS CE. At first, I had trouble installing, but finally managed to install by opening a shell, changing permissions on the file, and executing the file from there. I select the defaults. On my computer, CPLEX Optimization Studio is installed in ~gwyneth/Applications/IBM/ILOG/CPLEX_Studio_Community127/
.
5. As described in the DOcplex documentation topic, “Setting up an optimization engine”, the solver needs to be added to your PYTHONPATH.
I edit my shell file .bash_profile to add the solver to my PYTHONPATH:
PYTHONPATH="/Volumes/ButeraData/Users/gwyneth/Applications/IBM/ILOG/CPLEX_Studio_Community127/cplex/python/3.5/x86-64_osx"
export PYTHONPATH
6. For the updated path to take effect, you may have to quit the Terminal application and re-launch it.
7. To test the installation, I created a folder Tests in my user DOcplex directory and copied the diet.py from the examples directory there.
cd DOcplex/Tests
cp ../docplex-examples-master/examples/mp/modeling/diet.py .
python diet.py
The output is:
~Tests$ python 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
"Lowfat Milk"=1.831
"Chocolate Chip Cookies"=10.000
"Spaghetti W/ Sauce"=2.155
"Hotdog"=0.930
* 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
GBK Gwyneth
Leave a Reply