Runtime functions with arguments¶
On the one hand AIMMS functions and procedures use local identifiers to hold the values of the arguments.
On the other hand the model editor functions that form the basis of runtime libraries operate on elements of
these function create, modify, and delete corresponding global identifiers in the model.
In other words, these functions do not operate on local identifiers.
This short how-to presents a way to add local identifiers to AIMMS procedures and functions that are created at runtime. To create local identifiers, including procedure and function arguments, first create a global declaration section, and, when finished, move the declaration section below the procedure or function being created.
To show what happens:¶
For instance, to create a variant of Sqrt, do the following steps:
Create the function, including specifications for the attributes
Create a declaration section with a parameter
a. The parameter
agets property input.
The model explorer for the runtime library now looks as follows.
A call to
me::moveto move the declaration section below the function looks as follows:
1 ! Now the trick: move the declaration section local to the function. 2 if not me::Move( 3 runtimeId : ep_sqrtDeclLocalFunction, 4 parentId : ep_sqrtFunction, 5 pos : 0) then 6 raise error "Unable to move declaration section local to function: " + CurrentErrorMessage ; 7 endif ;
The runtime library in the model explorer then looks as follows:
The elements in
AllIdentifiersthat used to reference the declaration section and the arguments, are no longer valid and should not be used after this statement.
Finish the creation by calling the AIMMS compiler using
me::compile, the runtime library in model explorer looks as follows:
Note that the model explorer now shows the argument of the function.
Subsequently, we can use the
APPLYoperator to call the function created.
p_res := apply( ep_sqrtFunction, p_inp );
You can download AIMMS 4.79 example project