HIGHLIGHT The End of Start - openmpp/openmpp.github.io GitHub Wiki

Home > Model Development Topics > Highlight Topic

Yes, that Start. Person::Start(a,b,c,d,e,f,…)

Modgen required that each entity had a single entity function named Start and a single entity function named Finish. In a complex model, that required a single Start with all possible arguments to handle the various ways to start an entity, most of which were unused in a given call. It also led to a monolithic Start function to handle all possible ways of starting an entity, in a ‘catch-all’ module. And it sometimes led to the creation of a special argument whose only purpose was to distinguish the different ways of starting an entity.

By design OpenM++ has no such requirement. An OpenM++ foundational design principle is to let the C++ language do its thing, as a powerful stand-alone language which is also fully integrated and understood by the IDE used by the model developer.

In ompp, there is nothing special about the name Start (or Finish). In fact, the ompp compiler omc contains no references whatsoever to Start or Finish. Instead, three entity member functions generated by the ompp compiler are called by model code to handle the lifecycle of an entity: initialize_attributes(), enter_simulation(), and exit_simulation().

This design freedom allows you to code a model without being limited to a single Start function, like Modgen was. One way is to declare overloaded versions of Start, each specialized to start an entity in a different way. For example, to start a Person entity using a microdata Observation, one could declare (in an entity Person {...}; syntactic island) and define (in C++ code) the member function

void Person::Start(Microdata_ptr microdata_record);

and to start a Person entity as a newborn during the simulation, declare and define the member function

void Person::Start(Person_ptr mother);

and to clone a Person entity as an immigrant

void Person::Start(Person_ptr donor, int year_of_immigration);

These examples use a C++ language feature called “function overloading”, where different versions of the same named function are distinguished by the number, order, and types of arguments (aka the 'function signature').

Alternatively, different function names can be used, either if necessary to distinguish Start variants sharing the same 'function signature' or as a coding style choice, e.g.

void Person::Start_microdata(Microdata_ptr microdata_record);
void Person::Start_newborn(Person_ptr mother);
void Person::Start_immigrant(Person_ptr donor, int year_of_immigration);

Either way, the C++ implementation code for these functions can be located in its appropriate substantive module, e.g. StartPop.mpp, Fertility.mpp, Immigration.mpp.

⚠️ **GitHub.com Fallback** ⚠️