(!******************************************************
Xpress Executor Example Model
=============================
file blendexecutor.mos
``````````````````````
Demonstrates executing the 'blend3c' model using Xpress Executor
with the supplied input data & displaying the results.
Uses the 'executor' package included in Xpress to talk to Xpress
Executor.
Assumes that you have an Xpress Executor component already configured
with the blend3c model.
(c) 2017-2017 Fair Isaac Corporation
author: J. Farmer, Oct. 2017
*******************************************************!)
model "Blend Executor"
uses "mmsystem", "mmssl", "executor"
parameters
! You should set the DMP_EXECUTOR_URL, DMP_SOLUTION_CLIENT_ID and DMP_SOLUTION_SECRET parameters
! to point to the component you want to test.
! The root URL of the Xpress Executor DMP component
! Obtain this by clicking "View Links" for the Xpress Executor component on the DMP UI, then remove the
! part of the URL after the domain name, e.g.: https://vm65j75lqh-vm65j75lqh.dms.usw2.ficoanalyticcloud.com
DMP_EXECUTOR_URL=""
! The client ID of solution containing the Xpress Executor DMP component
! Obtain this through the DMP UI
DMP_SOLUTION_CLIENT_ID=""
! The secret of the solution containing the Xpress Executor DMP component
! Obtain this through the DMP UI
DMP_SOLUTION_SECRET=""
! The root DMP manager URL. This will be different depending on which instance of DMP you are using.
DMP_MANAGER_URL="https://manager.dms.usw2.ficoanalyticcloud.com/"
! The input file for the remote model
INPUTFILE="../data/blend.csv"
! File into which to save the results
RESULTFILE="blendresults.csv"
end-parameters
declarations
! Entity representing our Xpress Executor component instance
executor: Executor
! Record representing our remote execution and its current status
modelExecution: ModelExecution
! Array of parameters
modelParameterNames: set of string
modelParameters: dynamic array(modelParameterNames) of text
end-declarations
public declarations
public inputText: text
public runLog: text
end-declarations
! Declare array used to hold result data
declarations
ORES=1..2
use: array(ORES) of real
end-declarations
! Configure Mosel to use TLS1.2 ciphers with HTTPS to allow us to talk to DMP
setparam("https_ciphers","TLSv1.2+HIGH:\!SSLv2:\!aNULL:\!eNULL:\!3DES:@STRENGTH")
! Log into DMP
writeln("Initializing executor entity")
executor.componenturl := DMP_EXECUTOR_URL
executor.dmpmanagerurl := DMP_MANAGER_URL
executor.clientid := DMP_SOLUTION_CLIENT_ID
executor.secret := DMP_SOLUTION_SECRET
! Execute our model
writeln("Submitting model execution")
modelParameters("INPUTFILE"):="input" ! In Xpress Executor, the inputs we provide will be provided to the model in a file called "input"
modelParameters("RESULTFILE"):="result" ! In Xpress Executor, we can only access model results from a file called "result"
modelExecution := executorexecute( executor, INPUTFILE, modelParameters )
if executor.status<>EXECUTOR_OK then
writeln("Error starting execution: ",executor.lasterror)
exit(1)
end-if
! Model will be executing asynchronously; wait up to 10 minutes for it to complete.
writeln("Waiting for completion of execution")
executorwaitfor( executor, modelExecution, 10*60 )
if executor.status<>EXECUTOR_OK then
writeln("Error waiting for execution: ",executor.lasterror)
! executor.status OK means we had no errors querying the status and either the model has completed or
! the model is still running after our timeout
elif not modelExecution.iscompleted then
writeln("Execution failed to complete after 10 minutes")
! Check if the model status isn't OK or the exit code isn't zero
! Depending on what your model does, you may not need to check the exit code or a non-zero value may not indicate
! an error, but an status other than OK always means an error.
elif modelExecution.status<>EXECUTION_STATUS_OK or modelExecution.exitcode<>0 then
writeln("Execution failed, status=",modelExecution.status," and exit code=", modelExecution.exitcode)
! In event of failure, output the run log so we can diagnose the problem
executorfetchrunlog( executor, modelExecution, "text:runLog" )
if executor.status<>EXECUTOR_OK then
writeln("Error fetching run log: ",executor.lasterror)
else
writeln("Execution run log follows:")
writeln(runLog)
end-if
! If model execution status is OK and exitCode is 0, execution was successful so download and display results
else
writeln("Fetching execution results")
executorfetchresult( executor, modelExecution, RESULTFILE )
if executor.status<>EXECUTOR_OK then
writeln("Error fetching result file: ",executor.lasterror)
else
! Parse results and display to user
initializations from "mmsheet.csv:"+RESULTFILE
use as "[A1:B2]"
end-initializations
writeln
writeln("Solution:")
forall(o in ORES) writeln(" use(" + o + "): ", use(o))
end-if
end-if
! Whether we were successful or not, delete execution from component
executordelete( executor, modelExecution )
if executor.status<>EXECUTOR_OK then
writeln("Failed to delete execution due to error: ", executor.lasterror)
exit(1)
end-if
end-model
|
(!******************************************************
Mosel User Guide Example Problems
=================================
file blend3c.mos
````````````````
Reading data from an Excel spreadsheet
- using the CSV driver -
(c) 2013 Fair Isaac Corporation
author: S. Heipcke, Jan. 2013
*******************************************************!)
model "Blend 3"
uses "mmxprs", "mmsheet"
parameters
INPUTFILE="../data/blend.csv"
RESULTFILE="result.csv"
end-parameters
declarations
REV = 125 ! Unit revenue of product
MINGRADE = 4 ! Minimum permitted grade of product
MAXGRADE = 5 ! Maximum permitted grade of product
ORES = 1..2 ! Range of ores
COST: array(ORES) of real ! Unit cost of ores
AVAIL: array(ORES) of real ! Availability of ores
GRADE: array(ORES) of real ! Grade of ores (measured per unit of mass)
use: array(ORES) of mpvar ! Quantities of ores used
end-declarations
!*** Read data from spreadsheet blend.csv ***
! Spreadsheet range contains data only (no header line):
initializations from "mmsheet.csv:"+INPUTFILE
[COST,AVAIL,GRADE] as "[B3:E4]" ! or: "[R3C2:R4C5]"
end-initializations
(! Or (spreadsheet range includes a header line as with ODBC):
initializations from "mmsheet.csv:"+INPUTFILE
[COST,AVAIL,GRADE] as "skiph;[B2:E4]"
end-initializations
!)
! Objective: maximize total profit
Profit:= sum(o in ORES) (REV-COST(o))* use(o)
! Lower and upper bounds on ore quality
sum(o in ORES) (GRADE(o)-MINGRADE)*use(o) >= 0
sum(o in ORES) (MAXGRADE-GRADE(o))*use(o) >= 0
! Set upper bounds on variables
forall(o in ORES) use(o) <= AVAIL(o)
maximize(Profit) ! Solve the LP-problem
! Print out the solution
writeln("Solution:\n Objective: ", getobjval)
forall(o in ORES) writeln(" use(" + o + "): ", getsol(use(o)))
! Write solution to CSV file
declarations
solvalues: array(ORES) of real
end-declarations
forall (o in ORES) solvalues(o) := getsol(use(o))
initializations to "mmsheet.csv:"+RESULTFILE
solvalues as "grow;[A1:B1]"
end-initializations
end-model
|