stop function
stop(n)
Input: is a number (real or integer) of your choice
Result: None (see text)
When executed, this function halts execution of the model, and produces the following error message:
Simile ran into a problem trying to run this model.
While it was trying to calculate the value of variable
var (node x) during execution of the model at
time t, there was a user-defined interruption: n.
It is useful to define error conditions where you (the model designer) know that the model should not be used or is not applicable for some reason. Trivially, it can be used to guard against mathematical errors, for example:
if (time()-50) != 0 then 1/(time()-50) else stop(5)
This form has some merit when running in C++, but generally, to track down mathematical errors, it is easier to debug in Tcl. If execution in Tcl would take too long, then this is a useful alternative. Its primary use however, is to enable you to catch out-of-range conditions in the specific circumstances of your model.
The use of an error code in the user-defined interruption (e.g. stop(13) ) enables you to see which stop( ) function caused the model to stop running, if there is more than one in your model.
Result is undefined, because simulation stops at the point at which the function is called, but has integer type (this is important because if it is called in a conditional, the other branch of the conditional must also have a numerical type).
Examples:
if population>50 then stop(1) else 0
if (time()-50) != 0 then 1/(time()-50) else stop(5)
In: Contents >> Working with equations >> Functions >> Built-in functions