Enumerations - openmpp/openmpp.github.io GitHub Wiki
Home > Model Development Topics > Enumerations
This topic is under construction and/or revision.
Topic summary, two sentences max.
Content to follow.
Each dimension of a multi-dimensional parameter,
derived table or entity array is declared using an enumeration.
In RiskPaths
, for example,
parameters
{
//EN Age baseline for first pregnancy
double AgeBaselinePreg1[AGEINT_STATE];
...
};
declares the 1-dimensional array parameter AgeBaselinePreg1
using the enumeration AGEINT_STATE
,
which is a partition whose declaration is
partition AGEINT_STATE //EN 2.5 year age intervals
{
15, 17.5, 20, 22.5, 25, 27.5, 30, 32.5, 35, 37.5, 40
};
In C++ model code, an element of an array can be referenced using an index. For example, in the following code fragment
TIME Person::timeFirstPregEvent()
{
...
dHazard = AgeBaselinePreg1[age_status]
...
AgeBaselinePreg1
is indexed by the attribute age_status
to obtain an age-specific hazard.
Index errors are a common source of errors in C++ programs. Such errors are typically not detected by the C++ compiler and often manifest only indirectly when the program is executed. They can be hard to detect and resolve, because they manifest outside of a program's logic, by reading or modifying unrelated locations in memory.
In model code,
an index is invalid if it falls outside the lower and upper integer limits of an enumeration dimension.
For example, the parameter ProbMort
parameters
{
...
double ProbMort[LIFE]; //EN Death probabilities
};
is declared using the range LIFE
:
range LIFE //EN Simulated age range
{
0,100
};
The model code fragment
TIME Person::timeDeathEvent()
{
...
if (ProbMort[integer_age] >= 1)
...
}
would be invalid if integer_age
was less than 0
or greater than 100
.
The option
options index_errors = on;
causes the OpenM++ compiler to generate code which verifies that all indices are valid during a model run.