Hi,
let's go on with the example from https://www.linkedin.com/pulse/what-optimization-how-can-help-you-do-more-less-zoo-buses-fleischer/
Many CPLEX users know that you may call CPLEX in the cloud by sending the model to the cloud through dropsolve or API and then their python code runs in the cloud.
But we can also run some docplex code locally and then the cplex model will run in the cloud and the python code locally.
Let me give an example:
from docplex.mp.model import Model
from docplex.mp.context import Context
url = "https://api-oaas.docloud.ibmcloud.com/job_manager/rest/v1"
key = "YOUR API KEY"
ctx = Context.make_default_context(url=url, key=key)
mdl = Model(name='buses',context=ctx)
mdl.nbbus40 = mdl.integer_var(name='nbBus40')
mdl.nbbus30 = mdl.integer_var(name='nbBus30')
mdl.add_constraint(mdl.nbbus40*40 + mdl.nbbus30*30 >= 300, 'kids')
mdl.minimize(mdl.nbbus40*500 + mdl.nbbus30*400)
mdl.solve()
print(mdl.nbbus40.solution_value);
print(mdl.nbbus30.solution_value);
which gives
6.0
2.0
and this does not require cplex on your machine. CPLEX ran in the cloud
regards
PS:
Many similar examples at https://www.linkedin.com/pulse/making-optimization-simple-python-alex-fleischer/
#CPLEXOptimizers#DecisionOptimization