Runtime parameters
A convenient means of modifying data in a Mosel model when running the model (that is, without having to modify the model itself and recompile it) is to use runtime parameters. Such parameters are declared at the beginning of the model in a parameters block where every parameter is given a default value that will be applied if no other value is specified for this parameter at the model execution.
Consider the following model rtparams.mos that may receive parameters of four different types—integer, real, string, and Boolean—and prints out their values.
model "Runtime parameters" parameters PARAM1 = 0 PARAM2 = 0.5 PARAM3 = '' PARAM4 = false end-parameters writeln_(PARAM1, " ", PARAM2, " ", PARAM3, " ", PARAM4) end-model
The master model runrtparam.mos executing this (sub)model may look as follows—all runtime parameters are given new values:
model "Run model rtparams" uses "mmjobs" declarations modPar: Model end-declarations ! Compile the model file if compile("rtparams.mos")<>0 then exit(1); end-if load(modPar, "rtparams.bim") ! Load the bim file ! Start model execution run(modPar, "PARAM1=" + 2 + ",PARAM2=" + 3.4 + ",PARAM3='a string'" + ",PARAM4=" + true) wait ! Wait for model termination dropnextevent ! Ignore termination event message end-model
An alternative formulation to the above makes use of the subroutine setmodpar to define the parameter values for the submodel (notice that we need to load the module mmsystem for the text handling functionality)—after starting the model run we delete the parameters definition; it would also be possible to remove individual parameter value settings by applying resetmodpar to the object params.
model "Run model rtparams 2" uses "mmjobs", "mmsystem" declarations modPar: Model params: text end-declarations ! Compile the model file if compile("rtparams.mos")<>0 then exit(1); end-if load(modPar, "rtparams.bim") ! Load the bim file setmodpar(params, "PARAM1", 2) ! Set values for model parameters setmodpar(params, "PARAM2", 3.4) setmodpar(params, "PARAM3", 'a string') setmodpar(params, "PARAM4", true) run(modPar, params) ! Start model execution params:= "" ! Delete the parameters definition wait ! Wait for model termination dropnextevent ! Ignore termination event message end-model
© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.