invoke
OPL keyword for scripting statements in data files
Purpose
OPL keyword to call an IBM ILOG Script function after a data initialization.
context |
---|
Data files (.dat) |
Syntax
Invoke_opt: /* empty */ | Invoke Invoke: "invoke" Id
Description
This keyword allows you to call an IBM ILOG Script function after a data initialization. For single values, an additional step is required (see the second code example).
Example 1
In the model file:
float t[1..3]=...;
execute
{
writeln("after invoke");
writeln("t=",t);
}
In the data file:
prepare {
function transformIntoHours(t, name) {
writeln("t=",t);
for(var a=1;a<=t.size;a++) t[a]=t[a]/60;
return true;
}
}
// t is given in minutes and has to be converted into hours
t = [600,240,150] invoke transformIntoHours;
Result:
// The display is
// t= [600 240 150]
// after invoke
// t= [10 4 2.5]
Example 2 (single value)
If in the model file you have:
int t=...;
execute
{
writeln(t);
}
and in the data file you have:
prepare {
function f(t, name) {
t=6;
writeln(t);
return true;
}
}
t = 5 invoke f;
the result is
6
5
because of the properties of function
in IBM ILOG Script.
To obtain the expected result
5
6
you must replace t=6
with thisOplModel[name]=6
.
See reference information on IBM ILOG Script in Language structure.