|
Nemo
2.2.0
|
Randomly removes individuals from the patches according to the extinction rate parameter. More...
#include <LCEmisc.h>
Inheritance diagram for LCE_Patch_Extinction:
Collaboration diagram for LCE_Patch_Extinction:Public Member Functions | |
| LCE_Patch_Extinction () | |
| virtual | ~LCE_Patch_Extinction () |
| bool | set_matrix_param (TMatrix *mat, string name) |
| void | do_flush (Patch *patch) |
| void | do_remove (age_idx AGE, Patch *patch) |
| unsigned int | get_harvest_size (age_idx AGE, Patch *patch) |
| virtual bool | setParameters () |
| Default interface needed to initialize the component's variables from its input parameters value. | |
| virtual void | execute () |
| Execute the event on the pop. | |
| virtual LifeCycleEvent * | clone () |
| Cloning interface. | |
| virtual void | loadFileServices (FileServices *loader) |
| Loads the component's FileHandler onto the FileServices. | |
| virtual void | loadStatServices (StatServices *loader) |
| Loads the component's StatHandler onto the StatServices. | |
| virtual age_t | removeAgeClass () |
| Removes the returned age-class flag(s) from the current Metapop age-class flags. | |
| virtual age_t | addAgeClass () |
| Adds the returned age-class flag(s) to the current Metapop age-class flags. | |
| virtual age_t | requiredAgeClass () |
| Specifies what age-classes are required by the LCE to execute. | |
Private Member Functions | |
| unsigned int | rand_uniform (double max) |
| unsigned int | rand_poisson (double mean) |
| unsigned int | rand_gaussian (double mean) |
| unsigned int | rand_exp (double mean) |
| unsigned int | rand_lognormal (double mean) |
Private Attributes | |
| TMatrix * | _Xtion_rate |
| Patch extinction probability. | |
| TMatrix * | _harvest_size |
| Number of individual to remove per patch. | |
| TMatrix * | _harvest_proportion |
| Proportion of the patch size to remove. | |
| string | _harvest_distribution |
| Name of the distribution to use. | |
| bool | _harvest_size_varies |
| Flags. | |
| bool | _by_size |
| bool | _by_proportion |
| double | _harvest_dist_stdev |
| Standard deviate to use with the Gaussian dist. | |
| double | _harvest_dist_shape |
| shape variable to use with the gamma dist. | |
| double | _extinction_threshold |
| Patch extinction threshold in % of total size of the patch. | |
| unsigned int(LCE_Patch_Extinction::* | _rand_size_fct )(double) |
Randomly removes individuals from the patches according to the extinction rate parameter.
Sets the patches extinction flag accordingly.
| LCE_Patch_Extinction::LCE_Patch_Extinction | ( | ) |
Definition at line 133 of file LCEmisc.cc.
Referenced by clone().
: LifeCycleEvent("extinction",""), _Xtion_rate(0), _harvest_size(0), _harvest_proportion(0), _harvest_size_varies(0), _by_size(0), _by_proportion(0), _harvest_dist_stdev(0), _extinction_threshold(0), _rand_size_fct(0) { ParamUpdater< LCE_Patch_Extinction > * updater = new ParamUpdater< LCE_Patch_Extinction > (&LCE_Patch_Extinction::setParameters); add_parameter("extinction_rate", DBL, 0, 1, 0, 1, updater); add_parameter("extinction_threshold", DBL, 0, 1, 0, 1, updater); add_parameter("extinction_size", INT, 0, 0, 0, 0, updater); add_parameter("extinction_proportion", DBL, 0, 1, 0, 1, updater); add_parameter("extinction_size_distribution", STR, 0, 0, 0, 0, updater); add_parameter("extinction_size_dist_stdev", DBL, 0, 0, 0, 0, updater); add_parameter("extinction_size_dist_shape", DBL, 0, 0, 0, 0, updater); }
| virtual LCE_Patch_Extinction::~LCE_Patch_Extinction | ( | ) | [inline, virtual] |
Definition at line 131 of file LCEmisc.h.
References _harvest_proportion, _harvest_size, and _Xtion_rate.
{
if(_Xtion_rate) delete _Xtion_rate;
if(_harvest_size) delete _harvest_size;
if(_harvest_proportion) delete _harvest_proportion;
}
| virtual age_t LCE_Patch_Extinction::addAgeClass | ( | ) | [inline, virtual] |
Adds the returned age-class flag(s) to the current Metapop age-class flags.
Implements LifeCycleEvent.
Definition at line 153 of file LCEmisc.h.
{return 0;}
| virtual LifeCycleEvent* LCE_Patch_Extinction::clone | ( | ) | [inline, virtual] |
Cloning interface.
Implements LifeCycleEvent.
Definition at line 147 of file LCEmisc.h.
References LCE_Patch_Extinction().
{return new LCE_Patch_Extinction();}
| void LCE_Patch_Extinction::do_flush | ( | Patch * | patch | ) |
Definition at line 316 of file LCEmisc.cc.
{
patch->flush(_popPtr);
patch->set_isExtinct(true);
patch->set_age(0);
}
Definition at line 325 of file LCEmisc.cc.
{
unsigned int remove_size;
sex_t sex;
//check if probability of event is set, and if removal will happen
if(_Xtion_rate) if( RAND::Uniform() > _Xtion_rate->get(0, patch->getID()) ) return;
if(patch->size(AGE) != 0) {
remove_size = get_harvest_size(AGE, patch);
for(unsigned int i = 0; i < remove_size; ++i) {
sex = (sex_t)RAND::RandBool();
if(patch->size(sex, AGE) != 0)
_popPtr->recycle( patch->remove( sex, AGE, (unsigned int)RAND::Uniform(patch->size(sex, AGE)) ) );
else
_popPtr->recycle( patch->remove( (sex_t)!sex, AGE, (unsigned int)RAND::Uniform(patch->size( (sex_t)!sex, AGE) ) ) );
if(patch->size(AGE) == 0) break;
}
// cout<<"--removed "<<remove_size<<" individuals in age class "<<AGE<<", patch "<< patch->getID()<<" size = "<<patch->size(AGE)<<endl;
}
}
| void LCE_Patch_Extinction::execute | ( | ) | [virtual] |
Execute the event on the pop.
Implements LifeCycleEvent.
Definition at line 281 of file LCEmisc.cc.
{
#ifdef _DEBUG_
message("LCE_Patch_Extinction::execute ");
unsigned int cnt = 0;
#endif
Patch *patch;
for(unsigned int i = 0; i < _popPtr->getPatchNbr(); i++) {
patch = _popPtr->getPatch(i);
if(_by_size || _by_proportion) {
do_remove(OFFSx, patch);
do_remove(ADLTx, patch);
} else if(_Xtion_rate)
if( RAND::Uniform() < _Xtion_rate->get(0, i) )
do_flush(patch);
if(_extinction_threshold != -1) {
if( _extinction_threshold < 1 && (double)patch->size(ALL)/patch->get_K() < _extinction_threshold )
do_flush(patch);
else if( patch->size(ALL) < _extinction_threshold )
do_flush(patch);
}
#ifdef _DEBUG_
cnt += (patch->get_isExtinct());
#endif
}
#ifdef _DEBUG_
message("(%i extinct patches)\n",cnt);
#endif
}
Definition at line 351 of file LCEmisc.cc.
{
if( _by_size ) {
if(_harvest_size_varies)
return (this->*_rand_size_fct) (_harvest_size->get(0, patch->getID()));
else return (unsigned int)_harvest_size->get(0, patch->getID());
} else if( _by_proportion ) {
return (unsigned int)(_harvest_proportion->get(0, patch->getID()) * patch->size(AGE));
}
return 0;
}
| virtual void LCE_Patch_Extinction::loadFileServices | ( | FileServices * | loader | ) | [inline, virtual] |
Loads the component's FileHandler onto the FileServices.
| loader | the file service |
Implements SimComponent.
Definition at line 150 of file LCEmisc.h.
{}
| virtual void LCE_Patch_Extinction::loadStatServices | ( | StatServices * | loader | ) | [inline, virtual] |
Loads the component's StatHandler onto the StatServices.
| loader | the stat service |
Implements SimComponent.
Definition at line 151 of file LCEmisc.h.
{}
| unsigned int LCE_Patch_Extinction::rand_exp | ( | double | mean | ) | [inline, private] |
Definition at line 125 of file LCEmisc.h.
References RAND::Uniform().
{return (unsigned int)(-1.0 * mean * log(1.0-RAND::Uniform()));}
| unsigned int LCE_Patch_Extinction::rand_gaussian | ( | double | mean | ) | [inline, private] |
Definition at line 124 of file LCEmisc.h.
References _harvest_dist_stdev, and RAND::Gaussian().
{return (unsigned int)abs(mean + RAND::Gaussian(_harvest_dist_stdev));}
| unsigned int LCE_Patch_Extinction::rand_lognormal | ( | double | mean | ) | [inline, private] |
Definition at line 126 of file LCEmisc.h.
References _harvest_dist_stdev, and RAND::LogNormal().
{return (unsigned int)RAND::LogNormal(mean, _harvest_dist_stdev);}
| unsigned int LCE_Patch_Extinction::rand_poisson | ( | double | mean | ) | [inline, private] |
Definition at line 123 of file LCEmisc.h.
References RAND::Poisson().
{return (unsigned int)RAND::Poisson(mean);}
| unsigned int LCE_Patch_Extinction::rand_uniform | ( | double | max | ) | [inline, private] |
Definition at line 122 of file LCEmisc.h.
References RAND::Uniform().
{return RAND::Uniform((unsigned int)max);}
| virtual age_t LCE_Patch_Extinction::removeAgeClass | ( | ) | [inline, virtual] |
Removes the returned age-class flag(s) from the current Metapop age-class flags.
Implements LifeCycleEvent.
Definition at line 152 of file LCEmisc.h.
{return 0;}
| virtual age_t LCE_Patch_Extinction::requiredAgeClass | ( | ) | [inline, virtual] |
Specifies what age-classes are required by the LCE to execute.
Implements LifeCycleEvent.
Definition at line 154 of file LCEmisc.h.
{return 0;}
| bool LCE_Patch_Extinction::set_matrix_param | ( | TMatrix * | mat, |
| string | name | ||
| ) |
Definition at line 252 of file LCEmisc.cc.
{
double value;
Param* param = get_parameter(name);
if(param->isMatrix()) {
param->getMatrix(mat);
if(mat->getNbRows() > 1) {
error("The \"%s\" matrix must be a one-dimensional array.\n", name.c_str());
return false;
}
if(mat->getNbCols() != _popPtr->getPatchNbr()) {
error("The length of the \"%s\" array must be equal to the number of patches.\n", name.c_str());
return false;
}
} else {
value = param->getValue();
mat->reset(1, _popPtr->getPatchNbr());
mat->assign(value);
}
return true;
}
| bool LCE_Patch_Extinction::setParameters | ( | ) | [virtual] |
Default interface needed to initialize the component's variables from its input parameters value.
Formerly called 'init'.
Implements SimComponent.
Definition at line 151 of file LCEmisc.cc.
{
if(get_parameter("extinction_rate")->isSet()) {
if(!_Xtion_rate) _Xtion_rate = new TMatrix();
if(!set_matrix_param(_Xtion_rate, "extinction_rate")) return false;
} else {
if(_Xtion_rate) delete _Xtion_rate; _Xtion_rate = 0;
}
if(get_parameter("extinction_size")->isSet()) {
if(!_harvest_size) _harvest_size = new TMatrix();
if(!set_matrix_param(_harvest_size, "extinction_size")) return false;
_by_size = true;
} else {
if(_harvest_size) delete _harvest_size; _harvest_size = 0;
_by_size = false;
}
if(get_parameter("extinction_proportion")->isSet()) {
if(!_harvest_proportion) _harvest_proportion = new TMatrix();
if(!set_matrix_param(_harvest_proportion, "extinction_proportion")) return false;
_by_proportion = true;
} else {
if(_harvest_proportion) delete _harvest_proportion; _harvest_proportion = 0;
_by_proportion = false;
}
_extinction_threshold = get_parameter_value("extinction_threshold");
if( !_Xtion_rate && !_by_size && !_by_proportion) {
error("Please give one of the following parameter: \"extinction_rate\", \"extinction_size\", or \"extinction_proportion\".\n");
return false;
}
else if(_by_size && _by_proportion) {
warning("Both \"extinction_size\" and \"extinction_proportion\" are set, using sizes only.\n");
_by_proportion = false;
}
if(get_parameter("extinction_size_distribution")->isSet()) {
if(!_by_size) {
error("\"extinction_size_distribution\" is set but the \"extinction_size\" parameter is not!\n");
return false;
}
_harvest_distribution = _paramSet->getArg("extinction_size_distribution");
_harvest_size_varies = true;
_harvest_dist_stdev = get_parameter_value("extinction_size_dist_stdev");
if(_harvest_distribution.compare("poisson") == 0)
_rand_size_fct = &LCE_Patch_Extinction::rand_poisson;
else if(_harvest_distribution.compare("uniform") == 0)
_rand_size_fct = &LCE_Patch_Extinction::rand_uniform;
else if(_harvest_distribution.compare("normal") == 0) {
_rand_size_fct = &LCE_Patch_Extinction::rand_gaussian;
if(_harvest_dist_stdev == -1) {
error("Standard deviation of the normal distribution for the harvesting size distribution is missing!\n");
return false;
}
} else if(_harvest_distribution.compare("lognormal") == 0) {
_rand_size_fct = &LCE_Patch_Extinction::rand_lognormal;
if(_harvest_dist_stdev == -1) {
error("Standard deviation of the lognormal distribution for the harvesting size distribution is missing!\n");
return false;
}
} else if(_harvest_distribution.compare("exponential") == 0)
_rand_size_fct = &LCE_Patch_Extinction::rand_exp;
else {
error("Distribution \"%s\" is not a valid option for \"harvest_size_distribution\"\n",
_harvest_distribution.c_str());
return false;
}
}
return true;
}
bool LCE_Patch_Extinction::_by_proportion [private] |
bool LCE_Patch_Extinction::_by_size [private] |
double LCE_Patch_Extinction::_extinction_threshold [private] |
double LCE_Patch_Extinction::_harvest_dist_shape [private] |
double LCE_Patch_Extinction::_harvest_dist_stdev [private] |
Standard deviate to use with the Gaussian dist.
Definition at line 114 of file LCEmisc.h.
Referenced by rand_gaussian(), and rand_lognormal().
string LCE_Patch_Extinction::_harvest_distribution [private] |
TMatrix* LCE_Patch_Extinction::_harvest_proportion [private] |
Proportion of the patch size to remove.
Definition at line 108 of file LCEmisc.h.
Referenced by ~LCE_Patch_Extinction().
TMatrix* LCE_Patch_Extinction::_harvest_size [private] |
Number of individual to remove per patch.
Definition at line 106 of file LCEmisc.h.
Referenced by ~LCE_Patch_Extinction().
bool LCE_Patch_Extinction::_harvest_size_varies [private] |
unsigned int(LCE_Patch_Extinction:: * LCE_Patch_Extinction::_rand_size_fct)(double) [private] |
TMatrix* LCE_Patch_Extinction::_Xtion_rate [private] |
Patch extinction probability.
Definition at line 104 of file LCEmisc.h.
Referenced by ~LCE_Patch_Extinction().
1.7.5.1 -- Nemo is hosted by