Nemo  2.3.46
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 ) { }
};

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
}

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


Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR