Hi,
when you want to run OPL, you may use the IDE but you may also use oplrun (command line)
when you want to run OPL model in the cloud, you may use the IDE
Now after this long introduction, what if you want to run an OPL model with command line like oplrun but in the cloud ?
Let me tell you.
First, let us copy warehouse.mod and warehouse.dat that are in C:\ILOG\CPLEX_Studio127\opl\examples\opl\warehouse to C:/
C:\>oplrun warehouse.mod warehouse.dat
gives
OBJECTIVE: 383
Open= [1 1 1 0 1]
Storesof= [{ {3}1 5 6 8} {7 9} {} {0 2 4}]
and CPLEX ran on my machine
Now if I use oplruncloud.py
import sys
print ('Number of arguments:', len(sys.argv), 'arguments.')
print ('Argument List:', str(sys.argv))
modelName=sys.argv[1]
datName=sys.argv[2]
resFile=sys.argv[3]
logFile=sys.argv[4]
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 key"
from docplex.mp.environment import Environment
from docloud.job import JobClient
client = JobClient(url, key)
with open(modelName, "rb") as modFile:
resp = client.execute(input=[{"name":"modelOplRunCloud.mod",
"file":modFile},
datName],
output = {"solution.txt": resFile} ,
log=logFile,
gzip=True,
waittime=300,
parameters={'oaas.resultsFormat' : 'TEXT'},
delete_on_completion=True)
with open(resFile, 'r') as fin:
print (fin.read())
and then
python oplruncloud.py c:/warehouse.mod c:/warehouse.dat c:/resultsoplruncloud.txt c:/engine.log
I get
Number of arguments: 5 arguments.
Argument List: ['C:\\Python34\\alex\\oplruncloud.py', 'c:/warehouse.mod', 'c:/wa
rehouse.dat', 'c:/resultsoplruncloud.txt', 'c:/engine.log']
// solution (optimal) with objective 383
// Quality Incumbent solution:
// MILP objective 3.8300000000e+02
// MILP solution norm |x| (Total, Max) 1.40000e+01 1.00000e+00
// MILP solution error (Ax=b) (Total, Max) 0.00000e+00 0.00000e+00
// MILP x bound error (Total, Max) 0.00000e+00 0.00000e+00
// MILP x integrality error (Total, Max) 0.00000e+00 0.00000e+00
// MILP slack bound error (Total, Max) 0.00000e+00 0.00000e+00
//
Open = [1
1 1 0 1];
Supply = [[0 0 0 0 1]
[0 1 0 0 0]
[0 0 0 0 1]
[1 0 0 0 0]
[0 0 0 0 1]
[0 1 0 0 0]
[0 1 0 0 0]
[0 0 1 0 0]
[0 1 0 0 0]
[0 0 1 0 0]];
and in c:/engine.log I get the log and in resultsoplruncloud.txt I get the same.
This ran in the cloud. So to do that you even do not need to have cplex in your machine.
regards
#DecisionOptimization#OPLusingCPLEXOptimizer