Repository navigation
Replies: 0 comments 2 replies
|
That's quite interesting, thanks so much for sharing this. When i look at the Start function in Demosim, I notice that the first statement is So when i want to create a new entity (Observation in my example), I just need to create it ( Also, obviously there are a few things that will be common to all Start functions (we'd have 4!). I assume this can be put in a Lastly, this might not be the best place to ask but I never really took the time to understand what you meant when you talked about syntactic islands. Can you point me to a short but comprehensive document that would explain this concept, what it is, when and how to use it, etc. many thanks in advance |
Uh oh!
There was an error while loading. Please reload this page.
Yes, that Start.
Person::Start(a,b,c,d,e,f,…)Modgen required that each entity had a single entity function named
Startand a single entity function namedFinish. In a complex model, that required a singleStartwith 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 monolithicStartfunction 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(orFinish). In fact, the ompp compileromccontains no references whatsoever toStartorFinish. 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(), andexit_simulation().This design freedom allows you to code a model without being limited to a single
Startfunction, 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 anentity Person {...};syntactic island) and define (in C++ code) the member functionand to start a Person entity as a newborn during the simulation, declare and define the member function
and to clone a Person entity as an immigrant
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.
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.All reactions