Nemo  2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
How to add a LCE?

The LifeCycleEvent interface declares a few methods that must be defined in the implementation class. These are the execute(), clone(), requiredAgeClass(), addAgeClass(), and removeAgeClass() functions. Besides those functions, the interface declares the way to build a basic LCE with one built-in parameter, the LCE's name. That name, as specified in the LifeCycleEvent class constructor, is the character string that will be read from the parameter file (or init file, see the user manual) and which value will determine its position in the life cycle. The LifeCycleEvent class constructor has a second argument, the name of the trait to be linked with. That link is an index number used then as the argument to the traits accessors interface declared by the Individual class. The linked trait may be absent in the derived class. Please have a look at the code documentation for more details on the LifeCycleEvent interface and its implementations.

The next example is very simple and shows a basic implementation of an LCE linked with MyTrait declared above:

The mylce.h file looks like this:

#include "lifecycleevent.h"
class MyLCE: public LifeCycleEvent {
double _my_LCE_var;
public:
//this LCE is called "myLCEname" and links with the trait called "mytraitname"
//it also adds a parameter called "my_lce_option" to its ParamSet
// CONSTRUCTOR:
MyLCE( ) : LifeCycleEvent( "myLCEname", "mytraitname" ), _my_LCE_var(0)
{
//we add a new parameter to the ParamSet using the SimComponent interface
//we also add a parameter updater:
ParamUpdater< MyLCE > *updater = new ParamUpdater< MyLCE >(&MyLCE::setParameters);
SimComponent::add_parameter( "my_lce_option", DBL, true, true, 0, 1, updater);
}
virtual ~MyLCE( ) { }
virtual void setParameters ( );
virtual void execute ( );
virtual MyLCE* clone ( ) { return new MyLCE(); }
//this LCE does not remove any age-class from the metapopulation age structure:
virtual age_t removeAgeClass ( )
{
return 0;
}
//it however adds individuals into the ADULTS age-class
virtual age_t addAgeClass ( )
{
return ADULTS;
}
//it requires that individuals in the OFFSPRING age-class are present in the metapopulation
virtual age_t requiredAgeClass ( )
{
return OFFSPRG;
}
//SimComponent implementation:
virtual void loadFileServices ( FileServices* loader ) { }
virtual void loadStatServices ( StatServices* loader ) { }
};
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:52
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:73
virtual age_t requiredAgeClass()=0
Specifies what age-classes are required by the LCE to execute.
virtual void execute()=0
Execute the event on the pop.
virtual age_t removeAgeClass()=0
Removes the returned age-class flag(s) from the current Metapop age-class flags.
virtual age_t addAgeClass()=0
Adds the returned age-class flag(s) to the current Metapop age-class flags.
virtual LifeCycleEvent * clone()=0
Cloning interface.
Implementation of the ParamUpdaterBase interface.
Definition: param.h:363
virtual void loadStatServices(StatServices *loader)=0
Loads the component's StatHandler onto the StatServices.
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
virtual void loadFileServices(FileServices *loader)=0
Loads the component's FileHandler onto the FileServices.
virtual bool setParameters()=0
Default interface needed to initialize the component's variables from its input parameters value.
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
unsigned int age_t
Age class flags.
Definition: types.h:46
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
@ DBL
Definition: types.h:78
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50

mylce.cpp:

#include "metapop.h"
#include "individual.h"
#include "mylce.h"
#include "mytrait.h"
//note: the constructor is defined in the header directly, not here
//-----------------------------------------------------------------------------
// MyLCE::setParameters
//-----------------------------------------------------------------------------
void MyLCE::setParameters ( )
{
//set the variable value to the parameter's value using the SimConponent interface
_my_LCE_var = get_parameter_value( "my_lce_option" );
}
//-----------------------------------------------------------------------------
// MyLCE::execute
//-----------------------------------------------------------------------------
void MyLCE::execute ()
{
//number of patches present in the metapopulation:
unsigned int patch_nbr = _popPtr->getPatchNbr();
//note here the use of the protected member LifeCycleEvent::_popPtr
//the phenotype recorder:
double phenotype;
//pointer to a patch:
Patch *current_patch;
//pointer to an individual:
Individual *ind;
//for all individuals in the metapop, check its MyTrait's phenotype value and decide what to do with it.
for( unsigned int i = 0; i < patch_nbr; i++ ) {
current_patch = _popPtr->getPatch( i );
//iterate over all offspring females in the current patch:
for( unsigned int j = 0; j < current_patch->size( FEM, OFFSx); ++j ) {
//set the pointer to the current individual:
ind = current_patch->get( FEM, OFFSx, j);
//get its phenotype using the linked trait index as defined in the base class:
phenotype = ( double* )ind->getTraitValue( _LCELinkedTraitIndex );
//check its value
if( !( phenotype < _my_LCE_var ) ) {
//if match my var, move it from the offspring container to the adults container:
current_patch->move( FEM, OFFSx, ADLTx, j);
j--;
}
//else, do nothing with it...
}//end for females
//do the same with males...
for( unsigned int j = 0; j < current_patch-> size( MAL, OFFSx ); ++j ) {
[...]
}
}//end for all patches
}
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:49
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:271
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:496
void move(sex_t SEX, age_idx from, age_idx to, unsigned int at)
Moves an individual from an age class to an other one.
Definition: metapop.h:596
Individual * get(sex_t SEX, age_idx AGE, unsigned int at)
Returns a pointer to the individual sitting at the index passed.
Definition: metapop.h:532
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37
@ OFFSx
Definition: types.h:42
@ ADLTx
Definition: types.h:42

<<prev | –t o p– | next>>


Generated for Nemo v2.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR