work: solving a DOcplex model on the cloud
As mentioned in solving a DOcplex model using a local solver, there are restrictions on the Community Edition of IBM ILOG CPLEX Optimization Studio which make it difficult to solve a problem of any real consequence. If you would like to test out some larger optimization problems, you can register for a thirty day free trial of IBM Decision Optimization on Cloud (DOcplexcloud).
With the free trial, you will receive an APIkey to include in your DOcplex Python code to solve the problem on DOcplexcloud.
Using DOcplexcloud.
1. Sign into IBM Decision Optimization on Cloud using the IBMid you created in solving a DOcplex model using a local solver and click on “Register for a Free Trial”.
2. Once you’ve registered for the free trial, you can test out DropSolve which allows you to drag and drop problems to be solved on the cloud. Feel free to explore this option more in the DropSolve Demo and via the FAQs and Samples.
3. To use the DOcplexcloud service to solve problems modeled in DOcplex, select “Get API key & base URL”. On this page, you can generate your API key. Copy these two strings.
4. 7. To test the key, copy DOcplex/Tests/diet.py to diet-cloud.py. Edit diet-cloud.py to include the API key & base URL that you generated.
"""DOcplexcloud credentials can be specified with url and api_key in the code block below.
Alternatively, Context.make_default_context() searches the PYTHONPATH for
the following files:* cplex_config.py
* cplex_config_.py
* docloud_config.py (must only contain context.solver.docloud configuration)These files contain the credentials and other properties. For example,
something similar to::context.solver.docloud.url = "https://docloud.service.com/job_manager/rest/v1"
context.solver.docloud.key = "example api_key"
"""
url = None
key = None
Change:
url = None
key = None
to use your personal URL and API key:
url = "http://yourURLhere"
key = "Your API Key here"
From the command line, run the new diet model to solve on the cloud.
The output is:
~Tests$ python diet-cloud.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