Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCE_Disperse_base Class Reference

The base class of the dispersal LCEs, all events move offspring to the post-dispersal patch containers. More...

#include <LCEdisperse.h>

+ Inheritance diagram for LCE_Disperse_base:
+ Collaboration diagram for LCE_Disperse_base:

Public Member Functions

 LCE_Disperse_base ()
 
virtual ~LCE_Disperse_base ()
 Deallocates the disp matrix. More...
 
bool setBaseParameters (string prefix)
 
void setParamPrefix (string pref)
 
void addParameters (string prefix, ParamUpdaterBase *updater)
 
void setIndentityDispMatrix (TMatrix *mat)
 
unsigned int getMigrationPatchForward (sex_t SEX, unsigned int LocalPatch)
 
unsigned int getMigrationPatchBackward (sex_t SEX, unsigned int LocalPatch)
 
unsigned int getMigrationIndex (vector< double > &rates)
 
unsigned int getMigrationIndexGSLdiscrete (gsl_ran_discrete_t *rates)
 
void setPropaguleTargets ()
 
void swapPostDisp ()
 
void reset_counters ()
 
Dispersal Matrix
void set_isForward (bool val)
 
bool checkForwardDispersalMatrix (TMatrix *mat)
 
bool checkBackwardDispersalMatrix (TMatrix *mat)
 
void allocateDispMatrix (sex_t sex, unsigned int dim)
 
bool updateDispMatrix ()
 
bool setDispMatrix ()
 
bool setReducedMatricesBySex (sex_t SEX, Param &connectivity, Param &rate)
 
bool setReducedDispMatrix ()
 The reduced dispersal matrix contains the indices of the patches to which each patch is connected. More...
 
bool setIsland_MigrantPool_Matrix ()
 
bool setIsland_PropagulePool_Matrix ()
 
bool setSteppingStone1DMatrix ()
 
bool setLatticeMatrix ()
 Sets the dispersal matrices for the Lattice dispersal model. More...
 
bool setBasicLatticeMatrix (int rows, int cols, double phi_mal, double phi_fem, double disp_mal, double disp_fem)
 
bool setLatticeTorrusMatrix (int rows, int cols, double disp_mal, double disp_fem, TMatrix *grid)
 
bool setLatticeAbsorbingMatrix ()
 
bool setLatticeReflectingMatrix (int rows, int cols, TMatrix *grid)
 
Accessors
bool isForward ()
 
bool isByNumber ()
 
unsigned int getDispersalModel ()
 
double getPropaguleProb ()
 
unsigned int getPropaguleTarget (unsigned int home)
 
vector< double > getConnectedPatches (sex_t SEX, unsigned int local_patch)
 
vector< double > getConnectedRates (sex_t SEX, unsigned int local_patch)
 
double getReducedDispersalRate (sex_t SEX, unsigned int row, unsigned int col)
 
unsigned int getReducedDispersalPatchID (sex_t SEX, unsigned int row, unsigned int col)
 
Implementations
virtual void loadFileServices (FileServices *loader)
 
virtual void loadStatServices (StatServices *loader)
 
virtual bool resetParameterFromSource (std::string param, SimComponent *cmpt)
 
virtual age_t removeAgeClass ()
 
virtual age_t addAgeClass ()
 
virtual age_t requiredAgeClass ()
 
- Public Member Functions inherited from LifeCycleEvent
 LifeCycleEvent (const char *name, const char *trait_link)
 Cstor. More...
 
virtual ~LifeCycleEvent ()
 
virtual void init (Metapop *popPtr)
 Sets the pointer to the current Metapop and the trait link if applicable. More...
 
virtual bool attach_trait (string trait)
 
virtual void set_paramset (std::string name, bool required, SimComponent *owner)
 
virtual void set_event_name (std::string &name)
 Set the name of the event (name of the ParamSet) and add the corresponding parameter to the set. More...
 
virtual void set_event_name (const char *name)
 
virtual string & get_event_name ()
 Accessor to the LCE's name. More...
 
virtual int get_rank ()
 Accessor to the LCE rank in the life cycle. More...
 
virtual void set_pop_ptr (Metapop *popPtr)
 Accessors for the population pointer. More...
 
virtual Metapopget_pop_ptr ()
 
virtual void execute ()=0
 Execute the event on the pop. More...
 
virtual LifeCycleEventclone ()=0
 Cloning interface. More...
 
- Public Member Functions inherited from SimComponent
 SimComponent ()
 
virtual ~SimComponent ()
 
virtual void loadUpdaters (UpdaterServices *loader)
 Loads the parameters and component updater onto the updater manager. More...
 
virtual bool setParameters ()=0
 Default interface needed to initialize the component's variables from its input parameters value. More...
 
virtual void set_paramset (ParamSet *paramset)
 Sets the ParamSet member. More...
 
virtual void set_paramsetFromCopy (const ParamSet &PSet)
 Reset the set of parameters from a another set. More...
 
virtual ParamSetget_paramset ()
 ParamSet accessor. More...
 
virtual void add_parameter (Param *param)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd, ParamUpdaterBase *updater)
 Interface to add a parameter and its updater to the set. More...
 
virtual Paramget_parameter (std::string name)
 Param getter. More...
 
virtual double get_parameter_value (std::string name)
 Param value getter. More...
 
virtual string get_name ()
 Returnd the name of the ParamSet, i.e. More...
 
virtual bool has_parameter (std::string name)
 Param getter. More...
 

Protected Attributes

unsigned int _npatch
 Number of patches in the population. More...
 
vector< vector< double > > _reducedDispMat [2]
 Matrix containing the indexes of the patches connected to each patch. More...
 
vector< vector< double > > _reducedDispMatProba [2]
 Matrix containing the probability to migrate to/from the connected patches. More...
 
- Protected Attributes inherited from LifeCycleEvent
std::string _event_name
 The param name to be read in the init file. More...
 
Metapop_popPtr
 The ptr to the current Metapop. More...
 
std::string _LCELinkedTraitType
 The name of the linked trait. More...
 
int _LCELinkedTraitIndex
 The index in the individual's trait table of the linked trait. More...
 
- Protected Attributes inherited from SimComponent
ParamSet_paramSet
 The parameters container. More...
 

Private Attributes

int _disp_model
 
double _disp_propagule_prob
 
vector< unsigned int > _PropaguleTargets
 
double _fem_rate
 
double _mal_rate
 
bool _isForward
 
bool _isByNumber
 
TMatrix_DispMatrix [2]
 The sex-specific dispersal matrices, [0] for males, [1] for females, might be used as connectivity matrix as well. More...
 
string _prefix
 Parameter name prefix (dispersal, seed_disp, breed_disp, etc.) More...
 

Friends

class LCE_Disperse_ConstDisp
 
class LCE_Disperse_EvolDisp
 

Detailed Description

The base class of the dispersal LCEs, all events move offspring to the post-dispersal patch containers.

Stores the dispersal matrices and dispersal model parameters and interface.

Constructor & Destructor Documentation

◆ LCE_Disperse_base()

LCE_Disperse_base::LCE_Disperse_base ( )
46 , _fem_rate (-1), _mal_rate(-1), _isForward(1), _isByNumber(0), _npatch(0)
47 {
48  _DispMatrix[0] = NULL;
49  _DispMatrix[1] = NULL;
50 }
TMatrix * _DispMatrix[2]
The sex-specific dispersal matrices, [0] for males, [1] for females, might be used as connectivity ma...
Definition: LCEdisperse.h:53
double _disp_propagule_prob
Definition: LCEdisperse.h:46
bool _isByNumber
Definition: LCEdisperse.h:50
double _fem_rate
Definition: LCEdisperse.h:48
bool _isForward
Definition: LCEdisperse.h:49
int _disp_model
Definition: LCEdisperse.h:45
vector< unsigned int > _PropaguleTargets
Definition: LCEdisperse.h:47
double _mal_rate
Definition: LCEdisperse.h:48
unsigned int _npatch
Number of patches in the population.
Definition: LCEdisperse.h:63
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:97

References _DispMatrix.

◆ ~LCE_Disperse_base()

LCE_Disperse_base::~LCE_Disperse_base ( )
virtual

Deallocates the disp matrix.

53 {
54  if(NULL != _DispMatrix[0])
55  delete _DispMatrix[0];
56 
57  if(NULL != _DispMatrix[1])
58  delete _DispMatrix[1];
59 }

References _DispMatrix.

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Disperse_base::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Disperse.

132 {return NONE;}
#define NONE
No age flag.
Definition: types.h:47

References NONE.

◆ addParameters()

void LCE_Disperse_base::addParameters ( string  prefix,
ParamUpdaterBase updater 
)
62 {
63  add_parameter(prefix + "_model",INT,false,true,1,4,updater);
64  add_parameter(prefix + "_border_model",INT,false,true,1,3,updater);
65  add_parameter(prefix + "_lattice_range",INT,false,true,1,2,updater);
66  add_parameter(prefix + "_lattice_rows",INT,false,false,0,0,updater);
67  add_parameter(prefix + "_lattice_columns",INT,false,false,0,0,updater);
68  add_parameter(prefix + "_propagule_prob",DBL,false,true,0,1,updater);
69  add_parameter(prefix + "_matrix",MAT,false,false,0,0,updater);
70  add_parameter(prefix + "_matrix_fem",STR,false,false,0,0,updater);
71  add_parameter(prefix + "_matrix_mal",STR,false,false,0,0,updater);
72  add_parameter(prefix + "_rate",DBL,false,true,0,1,updater);
73  add_parameter(prefix + "_rate_fem",DBL,false,true,0,1,updater);
74  add_parameter(prefix + "_rate_mal",DBL,false,true,0,1,updater);
75  add_parameter(prefix + "_connectivity_matrix",MAT,false,false,0,0,updater);
76  add_parameter(prefix + "_reduced_matrix",MAT,false,false,0,0,updater);
77  add_parameter(prefix + "_connectivity_matrix_fem",MAT,false,false,0,0,updater);
78  add_parameter(prefix + "_connectivity_matrix_mal",MAT,false,false,0,0,updater);
79  add_parameter(prefix + "_reduced_matrix_fem",MAT,false,false,0,0,updater);
80  add_parameter(prefix + "_reduced_matrix_mal",MAT,false,false,0,0,updater);
81 
82  add_parameter(prefix + "_by_number", BOOL,false,false,0,0,0);
83 }
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:111
@ DBL
Definition: types.h:77
@ MAT
Definition: types.h:77
@ BOOL
Definition: types.h:77
@ STR
Definition: types.h:77
@ INT
Definition: types.h:77

References SimComponent::add_parameter(), BOOL, DBL, INT, MAT, and STR.

Referenced by LCE_Breed_Disperse::LCE_Breed_Disperse(), LCE_Disperse_ConstDisp::LCE_Disperse_ConstDisp(), LCE_Disperse_EvolDisp::LCE_Disperse_EvolDisp(), and LCE_SeedDisp::LCE_SeedDisp().

+ Here is the caller graph for this function:

◆ allocateDispMatrix()

void LCE_Disperse_base::allocateDispMatrix ( sex_t  sex,
unsigned int  dim 
)
405 {
406  if(_DispMatrix[sex] != NULL)
407  _DispMatrix[sex]->reset(dim,dim);
408  else
409  _DispMatrix[sex] = new TMatrix(dim,dim);
410 }
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions and all elements to 0.
Definition: tmatrix.h:160

References _DispMatrix, and TMatrix::reset().

Referenced by setIsland_MigrantPool_Matrix(), setIsland_PropagulePool_Matrix(), setLatticeMatrix(), and setSteppingStone1DMatrix().

+ Here is the caller graph for this function:

◆ checkBackwardDispersalMatrix()

bool LCE_Disperse_base::checkBackwardDispersalMatrix ( TMatrix mat)
439 {
440  double cntr;
441 
442  for(unsigned int i = 0; i < mat->getNbCols(); ++i) {
443  cntr = 0;
444  for(unsigned int j = 0; j < mat->getNbRows(); ++j) {
445 
446  if(mat->get(i,j) < 0 )
447  return error("elements of the dispersal matrix cannot be negative (row %i, column %i)!\n", i, j);
448 
449  cntr += mat->get(j,i);
450  }
451 
452  if(cntr < 0.999999 || cntr > 1.000001) {
453  error("The elements of column %i of the dispersal matrix do not sum to 1!\n",i+1);
454  error("sum of row %i is: %f\n",i+1, cntr);
455  return false;
456  }
457  }
458  return true;
459 }
unsigned int getNbRows() const
Gives the number of rows.
Definition: tmatrix.h:211
unsigned int getNbCols() const
Gives the number of columns.
Definition: tmatrix.h:214
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:192
int error(const char *str,...)
Definition: output.cc:78

References error(), TMatrix::get(), TMatrix::getNbCols(), and TMatrix::getNbRows().

Referenced by setBaseParameters(), and setDispMatrix().

+ Here is the caller graph for this function:

◆ checkForwardDispersalMatrix()

bool LCE_Disperse_base::checkForwardDispersalMatrix ( TMatrix mat)
415 {
416  double cntr;
417 
418  for(unsigned int i = 0; i < mat->getNbRows(); ++i) {
419  cntr = 0;
420  for(unsigned int j = 0; j < mat->getNbCols(); ++j) {
421 
422  if(mat->get(i,j) < 0 )
423  return error("elements of the dispersal matrix cannot be negative (row %i, column %i)!\n", i, j);
424 
425  cntr += mat->get(i,j);
426  }
427  if(cntr < 0.999999 || cntr > 1.000001) {
428  error("the elements of row %i of the dispersal matrix do not sum to 1!\n",i+1);
429  error("sum of row %i is: %f\n",i+1, cntr);
430  return false;
431  }
432  }
433  return true;
434 }

References error(), TMatrix::get(), TMatrix::getNbCols(), and TMatrix::getNbRows().

Referenced by setBaseParameters(), and setDispMatrix().

+ Here is the caller graph for this function:

◆ getConnectedPatches()

vector< double > LCE_Disperse_base::getConnectedPatches ( sex_t  SEX,
unsigned int  local_patch 
)
1301 {
1302 // vector<double> cpatches = _reducedDispMat[SEX][local_patch];
1303 //
1304 // cpatches.erase(cpatches.begin());
1305 
1306  return _reducedDispMat[SEX][local_patch];
1307 }
vector< vector< double > > _reducedDispMat[2]
Matrix containing the indexes of the patches connected to each patch.
Definition: LCEdisperse.h:66

References _reducedDispMat.

Referenced by LCE_Breed_Selection_Disperse::do_breed(), and LCE_Breed_Disperse::do_breed_disperse_in_empty_patch().

+ Here is the caller graph for this function:

◆ getConnectedRates()

vector< double > LCE_Disperse_base::getConnectedRates ( sex_t  SEX,
unsigned int  local_patch 
)
1312 {
1313 // vector<double> cpatches = _reducedDispMatProba[SEX][local_patch];
1314 
1315 // cpatches.erase(cpatches.begin());
1316 
1317  return _reducedDispMatProba[SEX][local_patch];
1318 }
vector< vector< double > > _reducedDispMatProba[2]
Matrix containing the probability to migrate to/from the connected patches.
Definition: LCEdisperse.h:68

References _reducedDispMatProba.

Referenced by LCE_Breed_Selection_Disperse::do_breed(), LCE_Breed_Disperse::do_breed_disperse_in_empty_patch(), and LCE_Breed_Disperse::do_breed_disperse_in_patch().

+ Here is the caller graph for this function:

◆ getDispersalModel()

unsigned int LCE_Disperse_base::getDispersalModel ( )
inline

◆ getMigrationIndex()

unsigned int LCE_Disperse_base::getMigrationIndex ( vector< double > &  rates)
1275 {
1276  double sum = 0, random = RAND::Uniform();
1277  unsigned int SourcePatch = 0;
1278 
1279  if(random > 0.999999) random = 0.999999;//this to avoid overflows when random == 1
1280 
1281  sum = rates[SourcePatch];
1282 
1283  while (random > sum) {
1284  SourcePatch++;
1285  sum += rates[SourcePatch];
1286  }
1287 
1288  return SourcePatch;
1289 }
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:126

References RAND::Uniform().

◆ getMigrationIndexGSLdiscrete()

unsigned int LCE_Disperse_base::getMigrationIndexGSLdiscrete ( gsl_ran_discrete_t *  rates)
1294 {
1295  return RAND::Discrete(rates);
1296 }
static size_t Discrete(const gsl_ran_discrete_t *g)
Calling the GSL ran_discrete function.
Definition: Uniform.h:813

References RAND::Discrete().

Referenced by LCE_Breed_Disperse::get_parent().

+ Here is the caller graph for this function:

◆ getMigrationPatchBackward()

unsigned int LCE_Disperse_base::getMigrationPatchBackward ( sex_t  SEX,
unsigned int  LocalPatch 
)
1256 {
1257  double sum = 0, random = RAND::Uniform();
1258  unsigned int SourcePatch = 0;
1259 
1260  if(random > 0.999999) random = 0.999999;//this to avoid overflows when random == 1
1261 
1262  sum = _reducedDispMatProba[SEX][LocalPatch][SourcePatch];
1263 
1264  while (random > sum) {
1265  SourcePatch++;
1266  sum += _reducedDispMatProba[SEX][LocalPatch][SourcePatch];
1267  }
1268 
1269  return _reducedDispMat[SEX][LocalPatch][SourcePatch];
1270 }

References _reducedDispMat, _reducedDispMatProba, and RAND::Uniform().

◆ getMigrationPatchForward()

unsigned int LCE_Disperse_base::getMigrationPatchForward ( sex_t  SEX,
unsigned int  LocalPatch 
)
1236 {
1237  double sum = 0, random = RAND::Uniform();
1238  unsigned int AimedPatch = 0;
1239 
1240  if(random > 0.999999) random = 0.999999;//this to avoid overflows when random == 1
1241 
1242  sum = _reducedDispMatProba[SEX][LocalPatch][AimedPatch];
1243 
1244  while (random > sum) {
1245  AimedPatch++;
1246  sum += _reducedDispMatProba[SEX][LocalPatch][AimedPatch];
1247  }
1248 
1249  //return the patch ID stored in the connectivity matrix:
1250  return _reducedDispMat[SEX][LocalPatch][AimedPatch];
1251 }

References _reducedDispMat, _reducedDispMatProba, and RAND::Uniform().

Referenced by LCE_Disperse_ConstDisp::MigratePatch(), and LCE_Disperse_ConstDisp::MigratePatch_AbsorbingBorder().

+ Here is the caller graph for this function:

◆ getPropaguleProb()

double LCE_Disperse_base::getPropaguleProb ( )
inline
115 {return _disp_propagule_prob;}

References _disp_propagule_prob.

Referenced by LCE_Disperse_EvolDisp::Migrate_Island_Propagule(), and setIsland_PropagulePool_Matrix().

+ Here is the caller graph for this function:

◆ getPropaguleTarget()

unsigned int LCE_Disperse_base::getPropaguleTarget ( unsigned int  home)
inline
116 {return _PropaguleTargets[home];}

References _PropaguleTargets.

Referenced by LCE_Disperse_EvolDisp::Migrate_Island_Propagule(), and setIsland_PropagulePool_Matrix().

+ Here is the caller graph for this function:

◆ getReducedDispersalPatchID()

unsigned int LCE_Disperse_base::getReducedDispersalPatchID ( sex_t  SEX,
unsigned int  row,
unsigned int  col 
)
1333 {
1334  if(col < _reducedDispMat[SEX][row].size())
1335  return _reducedDispMat[SEX][row][col];
1336  else
1337  return -1;
1338 }

References _reducedDispMat.

Referenced by LCE_Breed_Disperse::get_parent().

+ Here is the caller graph for this function:

◆ getReducedDispersalRate()

double LCE_Disperse_base::getReducedDispersalRate ( sex_t  SEX,
unsigned int  row,
unsigned int  col 
)
1323 {
1324  if(col < _reducedDispMatProba[SEX][row].size())
1325  return _reducedDispMatProba[SEX][row][col];
1326  else
1327  return -1.0;
1328 }

References _reducedDispMatProba.

◆ isByNumber()

bool LCE_Disperse_base::isByNumber ( )
inline
113 {return _isByNumber;}

References _isByNumber.

Referenced by LCE_Disperse_ConstDisp::setParameters().

+ Here is the caller graph for this function:

◆ isForward()

bool LCE_Disperse_base::isForward ( )
inline
112 {return _isForward;}

References _isForward.

◆ loadFileServices()

virtual void LCE_Disperse_base::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Disperse.

128 {}

◆ loadStatServices()

virtual void LCE_Disperse_base::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Disperse.

129 {}

◆ removeAgeClass()

virtual age_t LCE_Disperse_base::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Disperse.

131 {return NONE;}

References NONE.

◆ requiredAgeClass()

virtual age_t LCE_Disperse_base::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Disperse.

133 {return OFFSPRG;}
#define OFFSPRG
Offspring age class flag.
Definition: types.h:49

References OFFSPRG.

◆ reset_counters()

void LCE_Disperse_base::reset_counters ( )
390 {
391  Patch *patch;
392  for(unsigned int i = 0; i < _npatch; i++) {
393 
394  patch = _popPtr->getPatch(i);
395 
396  patch->reset_counters();
397 
398  patch->flush(PDISPx, _popPtr);
399  }
400 }
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:80
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:256
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:431
void flush(sex_t SEX, age_idx AGE, Metapop *pop)
Removes all individual pointers of the appropriate sex and age class and flush them into the recyclin...
Definition: metapop.h:686
void reset_counters()
Definition: patch.cc:55
@ PDISPx
Definition: types.h:41

References _npatch, LifeCycleEvent::_popPtr, Patch::flush(), Metapop::getPatch(), PDISPx, and Patch::reset_counters().

Referenced by LCE_Breed_Disperse::execute(), LCE_Breed_Selection_Disperse::execute(), LCE_Disperse_ConstDisp::execute(), and LCE_Disperse_EvolDisp::execute().

+ Here is the caller graph for this function:

◆ resetParameterFromSource()

virtual bool LCE_Disperse_base::resetParameterFromSource ( std::string  param,
SimComponent cmpt 
)
inlinevirtual

Implements SimComponent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Disperse.

130 {return false;}

◆ set_isForward()

void LCE_Disperse_base::set_isForward ( bool  val)
inline
84 {_isForward = val;}

References _isForward.

Referenced by LCE_Breed_Disperse::setParameters().

+ Here is the caller graph for this function:

◆ setBaseParameters()

bool LCE_Disperse_base::setBaseParameters ( string  prefix)
88 {
89  _prefix = prefix;
90 
92 
93  _disp_model = (int)_paramSet->getValue(prefix + "_model");
94 
95  _disp_propagule_prob = _paramSet->getValue(prefix + "_propagule_prob");
96 
97  if(get_parameter(prefix + "_by_number")->isSet())
98  _isByNumber = true;
99  else
100  _isByNumber = false;
101 
102  // SET MATRICES FROM INPUT MODELS --------------------------------------------------------
103 
104  if(_DispMatrix[0]) delete _DispMatrix[0];
105  _DispMatrix[0] = NULL;
106 
107  if(_DispMatrix[1]) delete _DispMatrix[1];
108  _DispMatrix[1] = NULL;
109 
110  //skip this if there is only one patch
111 // if(_npatch == 1) {
112 // warning("not setting the dispersal LCE whith only one patch in the population\n");
113 // return false;
114 // }
115 
116  // connectivity matrix is specified in input --------------------------------------------
117 
118  if( (_paramSet->isSet(prefix + "_connectivity_matrix") && _paramSet->isSet(prefix + "_reduced_matrix") ) ||
119  (_paramSet->isSet(prefix + "_connectivity_matrix_mal") && _paramSet->isSet(prefix + "_reduced_matrix_mal") ) ||
120  (_paramSet->isSet(prefix + "_connectivity_matrix_fem") && _paramSet->isSet(prefix + "_reduced_matrix_fem")) )
121  {
122 
123  _disp_model=0;
124 
125  // both sex identical matrices
126  if(_paramSet->isSet(prefix + "_connectivity_matrix") && _paramSet->isSet(prefix + "_reduced_matrix")){
127  if( ! setReducedMatricesBySex(FEM, (*get_parameter(prefix + "_connectivity_matrix")), (*get_parameter(prefix + "_reduced_matrix"))) )
128  return false;
129  if( ! setReducedMatricesBySex(MAL, (*get_parameter(prefix + "_connectivity_matrix")), (*get_parameter(prefix + "_reduced_matrix"))) )
130  return false;
131  }
132 
133  // female specific matrices
134  if(_paramSet->isSet(prefix + "_connectivity_matrix_fem") && _paramSet->isSet(prefix + "_reduced_matrix_fem")){
135  if( ! setReducedMatricesBySex(FEM, (*get_parameter(prefix + "_connectivity_matrix_fem")), (*get_parameter(prefix + "_reduced_matrix_fem"))) )
136  return false;
137  }
138 
139  // male specific matrices
140  if(_paramSet->isSet(prefix + "_connectivity_matrix_mal") && _paramSet->isSet(prefix + "_reduced_matrix_mal")){
141  if( ! setReducedMatricesBySex(MAL, (*get_parameter(prefix + "_connectivity_matrix_mal")), (*get_parameter(prefix + "_reduced_matrix_mal"))) )
142  return false;
143  }
144 
145  if( (_paramSet->isSet(prefix + "_connectivity_matrix_fem") && !_paramSet->isSet(prefix + "_connectivity_matrix_mal") ) ||
146  (_paramSet->isSet(prefix + "_connectivity_matrix_mal") && !_paramSet->isSet(prefix + "_connectivity_matrix_fem") ))
147  return error("both \"%s_connectivity_matrix\" and \"%s_reduced_matrix\" must be set for each sex together\n", prefix.c_str(), prefix.c_str());
148 
149 
150 #ifdef _DEBUG_
151  cout << "=== female reduced dispersal matrix ===\n";
152  for (unsigned int i = 0; i < _npatch; ++i) {
153  cout << " [";
154  for (unsigned int k = 0; k < _reducedDispMat[FEM][i].size(); k++) {
155  cout << _reducedDispMatProba[FEM][i][k] << " [" << _reducedDispMat[FEM][i][k] <<"] ";
156  }
157  cout<<"]\n";
158  }
159 
160  cout << "=== male reduced dispersal matrix ===\n";
161  for (unsigned int i = 0; i < _npatch; ++i) {
162  cout << " [";
163  for (unsigned int k = 0; k < _reducedDispMat[MAL][i].size(); k++) {
164  cout << _reducedDispMatProba[MAL][i][k] << " [" << _reducedDispMat[MAL][i][k] <<"] ";
165  }
166  cout<<"]\n";
167 
168  }
169 #endif
170 
171  }
172  // dispersal matrix is specified in input -----------------------------------------------
173 
174  else if ( (_paramSet->isSet(prefix + "_connectivity_matrix") &&
175  !_paramSet->isSet(prefix + "_reduced_matrix")) ||
176  (!_paramSet->isSet(prefix + "_connectivity_matrix") &&
177  _paramSet->isSet(prefix + "_reduced_matrix")))
178 
179  {
180  return error("both \"%s_connectivity_matrix\" and \"%s_reduced_matrix\" must be set together\n", prefix.c_str(), prefix.c_str());
181  }
182 
183  // connectivity or reduced matrices not given in input
184  else
185 
186  {
187 
188  if(_paramSet->isSet(prefix + "_matrix")) {
189 
190  _DispMatrix[0] = new TMatrix();
191 
192  _paramSet->getMatrix(prefix + "_matrix",_DispMatrix[0]);
193 
194  //same dispersal matrix for males and females
195  _DispMatrix[1] = new TMatrix(*_DispMatrix[0]);
196 
197  } else {
198 
199  if(_paramSet->isSet(prefix + "_matrix_fem")) {
200 
201  _DispMatrix[FEM] = new TMatrix();
202 
203  _paramSet->getMatrix(prefix + "_matrix_fem",_DispMatrix[FEM]);
204 
205  }
206 
207  if(_paramSet->isSet(prefix + "_matrix_mal")) {
208 
209  _DispMatrix[MAL] = new TMatrix();
210 
211  _paramSet->getMatrix(prefix + "_matrix_mal",_DispMatrix[MAL]);
212 
213  }
214  }
215 
216  if( _paramSet->isSet(prefix + "_matrix") ||
217  ( _paramSet->isSet(prefix + "_matrix_fem") && _paramSet->isSet(prefix + "_matrix_mal") ) )
218  {
219 
220  if( ( _paramSet->isSet(prefix + "_rate") ||
221  ( _paramSet->isSet(prefix + "_rate_fem") && _paramSet->isSet(prefix + "_rate_mal")) )
222  || _paramSet->isSet(prefix + "_model") )
223  warning("parameter \"dispersal_matrix\" takes precedence over parameters \"dispersal_rate\" and \"dispersal_model\"\n");
224 
225  _disp_model = 0;
226 
227  if(_DispMatrix[FEM]) {
228 
229  //check if we want the Identity matrix
230  if(_DispMatrix[FEM]->length() == 1 && _DispMatrix[FEM]->get(0,0) == 1)
232 
233  //check dimensions
234  if(_DispMatrix[FEM]->length() != _npatch*_npatch)
235  return error("the size of the female dispersal matrix is not equal to patch_number X patch_number (%i[%i,%i] != %i)!\n",
236  _DispMatrix[FEM]->length(),_DispMatrix[FEM]->getNbRows(),_DispMatrix[FEM]->getNbCols(),_npatch*_npatch);
237 
238  //check that migration rates sum to 1 per row or column
239  if(!_isByNumber) {
240  if(_isForward) {
241  if(!checkForwardDispersalMatrix(_DispMatrix[FEM])) return false;
242  } else {
243  if(!checkBackwardDispersalMatrix(_DispMatrix[FEM])) return false;
244  }
245  }
246  }
247 
248  if(_DispMatrix[MAL]) {
249 
250  //check if we want the Identity matrix
251  if(_DispMatrix[MAL]->length() == 1 && _DispMatrix[MAL]->get(0,0) == 1)
253 
254  //check dimensions
255  if(_DispMatrix[MAL]->length() != _npatch*_npatch)
256  return error("the size of the male dispersal matrix is not equal to patch_number X patch_number (%i[%i,%i] != %i)!\n",
257  _DispMatrix[MAL]->length(),_DispMatrix[MAL]->getNbRows(),_DispMatrix[MAL]->getNbCols(),_npatch*_npatch);
258 
259 
260  //check that migration rates sum to 1 per row or column
261  if(!_isByNumber) {
262  if(_isForward) {
263  if(!checkForwardDispersalMatrix(_DispMatrix[MAL])) return false;
264  } else {
265  if(!checkBackwardDispersalMatrix(_DispMatrix[MAL])) return false;
266  }
267  }
268  }
269 
271 
272  // dispersal rate is given in input ---------------------------------------------------
273  } else {
274 
275  if(!_paramSet->isSet(prefix + "_model")) return error("Dispersal model is not set!\n");
276 
277  if(_paramSet->isSet(prefix + "_rate"))
278 
279  {
280 
281  _fem_rate = _mal_rate = _paramSet->getValue(prefix + "_rate");
282 
283  if(!setDispMatrix()) return false;
284 
285  }
286 
287  else if( _paramSet->isSet(prefix + "_rate_fem") && _paramSet->isSet(prefix + "_rate_mal") )
288 
289  {
290  _fem_rate = _paramSet->getValue(prefix + "_rate_fem");
291 
292  _mal_rate = _paramSet->getValue(prefix + "_rate_mal");
293 
294  if(!setDispMatrix()) return false;
295  }
296 
297  else {
298  return error("Dispersal rate parameters not set!\n");
299  }
300 
301  }
302 
303  }
304  return true;
305 }
bool setReducedDispMatrix()
The reduced dispersal matrix contains the indices of the patches to which each patch is connected.
Definition: LCEdisperse.cc:1108
bool setDispMatrix()
Definition: LCEdisperse.cc:515
bool checkBackwardDispersalMatrix(TMatrix *mat)
Definition: LCEdisperse.cc:438
string _prefix
Parameter name prefix (dispersal, seed_disp, breed_disp, etc.)
Definition: LCEdisperse.h:56
bool setReducedMatricesBySex(sex_t SEX, Param &connectivity, Param &rate)
Definition: LCEdisperse.cc:309
void setIndentityDispMatrix(TMatrix *mat)
Definition: LCEdisperse.cc:355
bool checkForwardDispersalMatrix(TMatrix *mat)
Definition: LCEdisperse.cc:414
unsigned int getPatchNbr()
Definition: metapop.h:275
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:303
double getValue(string name)
Accessor the parameters value.
Definition: param.h:301
bool isSet()
Accessor to the status flag.
Definition: param.h:287
bool isSet()
Definition: param.h:139
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:138
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:47
void warning(const char *str,...)
Definition: output.cc:57
@ FEM
Definition: types.h:36
@ MAL
Definition: types.h:36

References _disp_model, _disp_propagule_prob, _DispMatrix, _fem_rate, _isByNumber, _isForward, _mal_rate, _npatch, SimComponent::_paramSet, LifeCycleEvent::_popPtr, _prefix, _reducedDispMat, _reducedDispMatProba, checkBackwardDispersalMatrix(), checkForwardDispersalMatrix(), error(), FEM, SimComponent::get_parameter(), ParamSet::getMatrix(), Metapop::getPatchNbr(), ParamSet::getValue(), Param::isSet(), ParamSet::isSet(), MAL, setDispMatrix(), setIndentityDispMatrix(), setReducedDispMatrix(), setReducedMatricesBySex(), and warning().

Referenced by LCE_Breed_Disperse::setParameters(), and LCE_Disperse_ConstDisp::setParameters().

+ Here is the caller graph for this function:

◆ setBasicLatticeMatrix()

bool LCE_Disperse_base::setBasicLatticeMatrix ( int  rows,
int  cols,
double  phi_mal,
double  phi_fem,
double  disp_mal,
double  disp_fem 
)
786 {
787  TMatrix* mmat = _DispMatrix[MAL];
788  TMatrix* fmat = _DispMatrix[FEM];
789 
790  //init:
791  fmat->assign(0.0);
792  mmat->assign(0.0);
793 
794  TMatrix grid(rows, cols);
795 
796  int p = 0;
797  for (int i = 0; i < rows; ++i) {
798  for (int j = 0; j < cols ; ++j) {
799  grid.set(i, j, p++);
800  }
801  }
802  assert( p == rows*cols );
803 
804  //diagonal:
805  for (unsigned int i = 0; i < _npatch; ++i){
806  fmat->set(i, i, phi_fem);
807  mmat->set(i, i, phi_mal);
808  }
809 
810  int connect;
811 
812  for (int x = 0; x < rows; ++x) {
813  for (int y = 0; y < cols; ++y) {
814 
815  p = grid.get(x, y);
816 
817  connect = p + 1; //patch to the right
818 
819  if (connect < (x + 1)*cols) { //stay on the same row
820  fmat->set(p, connect, disp_fem);
821  mmat->set(p, connect, disp_mal);
822  }
823 
824  connect = p - 1; //patch to the left
825 
826  if (connect >= x*cols ) {
827  fmat->set(p, connect, disp_fem);
828  mmat->set(p, connect, disp_mal);
829  }
830 
831  connect = p + cols; //patch one row up
832 
833  if (connect < (int)_npatch ) {
834  fmat->set(p, connect, disp_fem);
835  mmat->set(p, connect, disp_mal);
836  }
837 
838  connect = p - cols; //patch one row down
839 
840  if (connect >= 0 ) {
841  fmat->set(p, connect, disp_fem);
842  mmat->set(p, connect, disp_mal);
843  }
844 
845  //diagonal steps:
846  if((unsigned int)get_parameter_value(_prefix + "_lattice_range") == 2) {
847 
848  connect = p + cols; //patches one row up
849 
850  if (connect < (int)_npatch ) { //we are not on the last row
851 
852  if (connect + 1 < (x + 2)*cols) { //do not reach past the right border
853  fmat->set(p, connect + 1, disp_fem);
854  mmat->set(p, connect + 1, disp_mal);
855  }
856 
857  if (connect - 1 >= (x + 1)*cols) { //do not reach past the left border
858  fmat->set(p, connect - 1, disp_fem);
859  mmat->set(p, connect - 1, disp_mal);
860  }
861  }
862 
863  connect = p - cols; //patches one row down
864 
865  if (connect >= 0) { //we are not on the first row
866 
867  if (connect + 1 < (x + 1)*cols) {
868  fmat->set(p, connect + 1, disp_fem);
869  mmat->set(p, connect + 1, disp_mal);
870  }
871 
872  if (connect - 1 >= (x - 1)*cols) {
873  fmat->set(p, connect - 1, disp_fem);
874  mmat->set(p, connect - 1, disp_mal);
875  }
876  }
877  } //lattice range == 2
878 
879  } //y
880  } //x
881 
882  switch((unsigned int)get_parameter_value(_prefix + "_border_model")) {
883  case 1:
884  return setLatticeTorrusMatrix(rows, cols, disp_mal, disp_fem, &grid);
885  case 2:
886  return setLatticeReflectingMatrix(rows, cols, &grid);
887  case 3:
888  return setLatticeAbsorbingMatrix();
889  default:
890  error("parameter \"%s_border_model\" accepts only three values: [1,2,3]\n", _prefix.c_str());
891  break;
892  }
893 
894  return false;
895 }
bool setLatticeTorrusMatrix(int rows, int cols, double disp_mal, double disp_fem, TMatrix *grid)
Definition: LCEdisperse.cc:899
bool setLatticeAbsorbingMatrix()
Definition: LCEdisperse.cc:1050
bool setLatticeReflectingMatrix(int rows, int cols, TMatrix *grid)
Definition: LCEdisperse.cc:1009
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:142
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:102
void assign(double val)
Assigns a value to all element of the matrix.
Definition: tmatrix.h:154

References _DispMatrix, _npatch, _prefix, TMatrix::assign(), error(), FEM, TMatrix::get(), SimComponent::get_parameter_value(), MAL, TMatrix::set(), setLatticeAbsorbingMatrix(), setLatticeReflectingMatrix(), and setLatticeTorrusMatrix().

Referenced by setLatticeMatrix().

+ Here is the caller graph for this function:

◆ setDispMatrix()

bool LCE_Disperse_base::setDispMatrix ( )
516 {
517 
518  switch ( getDispersalModel() ) {
519  case 1:
520  if( !setIsland_MigrantPool_Matrix() ) return false;
521  break;
522  case 2:
523  if( !setIsland_PropagulePool_Matrix() ) return false;
524  break;
525  case 3:
526  if( !setSteppingStone1DMatrix() ) return false;
527  break;
528  case 4:
529  if( !setLatticeMatrix() ) return false;
530  break;
531  default:
532  return error("Dispersal model '%i' not yet implemented\n",getDispersalModel());
533  }
534 
535  if(_isForward) {
536  if(!checkForwardDispersalMatrix(_DispMatrix[FEM])) return false;
537  if(!checkForwardDispersalMatrix(_DispMatrix[MAL])) return false;
538  } else {
539  if(!checkBackwardDispersalMatrix(_DispMatrix[FEM])) return false;
540  if(!checkBackwardDispersalMatrix(_DispMatrix[MAL])) return false;
541  }
542 
543  return setReducedDispMatrix();
544 }
bool setSteppingStone1DMatrix()
Definition: LCEdisperse.cc:635
bool setIsland_MigrantPool_Matrix()
Definition: LCEdisperse.cc:548
bool setIsland_PropagulePool_Matrix()
Definition: LCEdisperse.cc:580
bool setLatticeMatrix()
Sets the dispersal matrices for the Lattice dispersal model.
Definition: LCEdisperse.cc:722
unsigned int getDispersalModel()
Definition: LCEdisperse.h:114

References _DispMatrix, _isForward, checkBackwardDispersalMatrix(), checkForwardDispersalMatrix(), error(), FEM, getDispersalModel(), MAL, setIsland_MigrantPool_Matrix(), setIsland_PropagulePool_Matrix(), setLatticeMatrix(), setReducedDispMatrix(), and setSteppingStone1DMatrix().

Referenced by setBaseParameters(), and updateDispMatrix().

+ Here is the caller graph for this function:

◆ setIndentityDispMatrix()

void LCE_Disperse_base::setIndentityDispMatrix ( TMatrix mat)
356 {
357  mat->reset(_npatch, _npatch);
358  mat->assign(0);
359  for(unsigned int i = 0; i < _npatch; ++i) mat->set(i, i, 1);
360 }

References _npatch, TMatrix::assign(), TMatrix::reset(), and TMatrix::set().

Referenced by setBaseParameters().

+ Here is the caller graph for this function:

◆ setIsland_MigrantPool_Matrix()

bool LCE_Disperse_base::setIsland_MigrantPool_Matrix ( )
549 {
550 #ifdef _DEBUG_
551  cout<<"setIsland_MigrantPool_Matrix(_npatch="<<_npatch<<", _mal_rate="
552  <<_mal_rate<<", _fem_rate="<<_fem_rate<<")"<<endl;
553 #endif
556 
557  TMatrix* mmat = _DispMatrix[MAL];
558  TMatrix* fmat = _DispMatrix[FEM];
559  double pmal = 1 - _mal_rate;
560  double pfem = 1 - _fem_rate;
561  double mmal = _mal_rate/(_npatch-1);
562  double mfem = _fem_rate/(_npatch-1);
563 
564  for (unsigned int i=0; i<_npatch; ++i){
565  for (unsigned int j=0; j<_npatch; ++j){
566  mmat->set(i,j, mmal);
567  fmat->set(i,j, mfem);
568  }
569  }
570 
571  for (unsigned int i=0; i<_npatch; ++i){
572  mmat->set(i,i, pmal);
573  fmat->set(i,i, pfem);
574  }
575  return true;
576 }
void allocateDispMatrix(sex_t sex, unsigned int dim)
Definition: LCEdisperse.cc:404

References _DispMatrix, _fem_rate, _mal_rate, _npatch, allocateDispMatrix(), FEM, MAL, and TMatrix::set().

Referenced by setDispMatrix().

+ Here is the caller graph for this function:

◆ setIsland_PropagulePool_Matrix()

bool LCE_Disperse_base::setIsland_PropagulePool_Matrix ( )
581 {
582 #ifdef _DEBUG_
583  cout<<"setIsland_PropagulePool_Matrix(_npatch="<<_npatch<<", _mal_rate="
584  <<_mal_rate<<", _fem_rate="<<_fem_rate<<")"<<endl;
585 #endif
586 
589 
590  if( !_paramSet->isSet(_prefix + "_propagule_prob") ) {
591  error("Missing parameter \"dispersal_propagule_prob\" with dispersal model 2!\n");
592  return false;
593  }
594 
596 
597  double propagulePHI = getPropaguleProb();
598  double c1 = (1 - _fem_rate), c2 = (_fem_rate*propagulePHI),
599  c3 = (_fem_rate*(1.0 - propagulePHI)/(_npatch-2));
600 
601  TMatrix* mmat = _DispMatrix[MAL];
602  TMatrix* fmat = _DispMatrix[FEM];
603 
604  for (unsigned int i=0; i < _npatch; ++i){
605 
606  fmat->set(i, i, c1);
607 
608  for (unsigned int j=i+1; j < _npatch; ++j){
609  fmat->set(i, j, c3);
610  fmat->set(j, i, c3);
611  }
612  fmat->set(i, getPropaguleTarget(i), c2);
613  }
614 
615  c1 = (1 - _mal_rate);
616  c2 = (_mal_rate*propagulePHI);
617  c3 = (_mal_rate*(1.0 - propagulePHI)/(_npatch-2));
618 
619  for (unsigned int i=0; i < _npatch; ++i){
620 
621  mmat->set(i, i, c1);
622 
623  for (unsigned int j=i+1; j< _npatch; ++j) {
624  mmat->set(i, j, c3);
625  mmat->set(j, i, c3);
626  }
627  mmat->set(i, getPropaguleTarget(i), c2);
628  }
629 
630  return true;
631 }
unsigned int getPropaguleTarget(unsigned int home)
Definition: LCEdisperse.h:116
double getPropaguleProb()
Definition: LCEdisperse.h:115
void setPropaguleTargets()
Definition: LCEdisperse.cc:463

References _DispMatrix, _fem_rate, _mal_rate, _npatch, SimComponent::_paramSet, _prefix, allocateDispMatrix(), error(), FEM, getPropaguleProb(), getPropaguleTarget(), ParamSet::isSet(), MAL, TMatrix::set(), and setPropaguleTargets().

Referenced by LCE_Breed_Selection_Disperse::breed_selection_disperse_propagule(), LCE_Breed_Disperse::do_breed_disperse_propagule(), LCE_Disperse_ConstDisp::Migrate_propagule(), and setDispMatrix().

+ Here is the caller graph for this function:

◆ setLatticeAbsorbingMatrix()

bool LCE_Disperse_base::setLatticeAbsorbingMatrix ( )
1051 {
1052  TMatrix* mmat = _DispMatrix[MAL];
1053  TMatrix* fmat = _DispMatrix[FEM];
1054 
1055  fmat->set(_npatch, _npatch, 1.0);
1056  mmat->set(_npatch, _npatch, 1.0);
1057 
1058  double sum;
1059 
1060  if(_isForward) {
1061  //set the absorbing patch probs to 1 - sum(row)
1062  for(unsigned int i = 0; i < _npatch; ++i) {
1063  sum = 0;
1064  for (unsigned int j = 0; j < _npatch; ++j) {
1065  sum += fmat->get(i, j);
1066  }
1067  fmat->set(i, _npatch, 1.0 - sum);
1068  }
1069 
1070  for(unsigned int i = 0; i < _npatch; ++i) {
1071  sum = 0;
1072  for (unsigned int j = 0; j < _npatch; ++j) {
1073  sum += mmat->get(i, j);
1074  }
1075  mmat->set(i, _npatch, 1.0 - sum);
1076  }
1077  //backward migration:
1078  }else {
1079  //the missing immigrant rate from non-existing patches must be added to the "philopatric" rate
1080  for(unsigned int i = 0; i < _npatch; ++i) {
1081  sum = 0;
1082  for (unsigned int j = 0; j < _npatch; ++j) {
1083  sum += fmat->get(j, i);
1084  }
1085  fmat->plus(i, i, 1.0 - sum);
1086  }
1087 
1088  for(unsigned int i = 0; i < _npatch; ++i) {
1089  sum = 0;
1090  for (unsigned int j = 0; j < _npatch; ++j) {
1091  sum += mmat->get(j, i);
1092  }
1093  mmat->plus(i, i, 1.0 - sum);
1094  }
1095  }
1096 
1097  return true;
1098 }
void plus(unsigned int i, unsigned int j, double value)
Adds a value to an element of the matrix.
Definition: tmatrix.h:255

References _DispMatrix, _isForward, _npatch, FEM, TMatrix::get(), MAL, TMatrix::plus(), and TMatrix::set().

Referenced by setBasicLatticeMatrix().

+ Here is the caller graph for this function:

◆ setLatticeMatrix()

bool LCE_Disperse_base::setLatticeMatrix ( )

Sets the dispersal matrices for the Lattice dispersal model.

Each matrix has 'patch number' x 'patch number' cells unless the lattice model is the absorbing boundaries model where we add the sink patch.

The "dispersal_lattice_range" parameter defines the number of neighbouring patches to disperse into. Option 1 sets this number to 4 (left and right, up and down patches) whereas option 2 allows to disperse to the 8 neighbouring patches, including the patches on the diagonals.

723 {
724 #ifdef _DEBUG_
725  message("setLatticeMatrix()\n");
726 #endif
727  if(!_paramSet->isSet(_prefix + "_border_model"))
728  return error("Missing parameter \"dispersal_border_model\" with dispersal model 4!\n");
729 
730  if(!_paramSet->isSet(_prefix + "_lattice_range") )
731  return error("Missing parameter \"dispersal_lattice_range\" with dispersal model 4!\n");
732 
733  int rows, cols;
734 
735  if( !_paramSet->isSet(_prefix + "_lattice_rows") && !_paramSet->isSet(_prefix + "_lattice_columns") ) {
736 
737  rows = cols = (int) sqrt((double)_npatch);
738 
739  if( rows*cols != (int)_npatch )
740  return error("The number of patches is not a square number in the lattice dispersal model\n");
741 
742  } else {
743 
744  rows = _paramSet->getValue(_prefix + "_lattice_rows");
745 
746  cols = _paramSet->getValue(_prefix + "_lattice_columns");
747 
748  if(rows == -1) return error("number of rows of the dispersal lattice is not specified\n");
749  if(cols == -1) return error("number of columns of the dispersal lattice is not specified\n");
750 
751  if( rows*cols != (int)_npatch ){
752  error("The size of the dispersal matrix in the lattice model is not equal to the number of patches,\n");
753  return error("parameters %s_lattice_rows and %s_lattice_columns must be set.\n", _prefix.c_str(), _prefix.c_str());
754  }
755  }
756 
759  if((unsigned int)get_parameter_value(_prefix + "_border_model") == 3) {
762  } else {
765  }
766 
770  unsigned int range = (unsigned int)get_parameter_value(_prefix + "_lattice_range");
771  //philopatry:
772  double pmal = 1 - _mal_rate, pfem = 1 - _fem_rate;
773  //migration:
774  double mmal = _mal_rate/(range == 1 ? 4 : 8), mfem = _fem_rate/(range == 1 ? 4 : 8);
775 
776  setBasicLatticeMatrix(rows, cols, pmal, pfem, mmal, mfem);
777 
778 
779  return true;
780 }
bool setBasicLatticeMatrix(int rows, int cols, double phi_mal, double phi_fem, double disp_mal, double disp_fem)
Definition: LCEdisperse.cc:784
void message(const char *message,...)
Definition: output.cc:39

References _fem_rate, _mal_rate, _npatch, SimComponent::_paramSet, _prefix, allocateDispMatrix(), error(), FEM, SimComponent::get_parameter_value(), ParamSet::getValue(), ParamSet::isSet(), MAL, message(), and setBasicLatticeMatrix().

Referenced by setDispMatrix(), and LCE_Disperse_EvolDisp::setParameters().

+ Here is the caller graph for this function:

◆ setLatticeReflectingMatrix()

bool LCE_Disperse_base::setLatticeReflectingMatrix ( int  rows,
int  cols,
TMatrix grid 
)
1010 {
1011  TMatrix* mmat = _DispMatrix[MAL];
1012  TMatrix* fmat = _DispMatrix[FEM];
1013 
1014  vector<unsigned int> border_cells;
1015 
1016  for (unsigned int i = 0; i < _npatch; ++i) {
1017 
1018  for (int j = 0; j < cols; ++j)
1019  border_cells.push_back( j ); //first row
1020 
1021  for (int j = 1; j < rows - 1; ++j) { //intermediate rows, only the two border cells
1022  border_cells.push_back( j*cols );
1023  border_cells.push_back( (j + 1)*cols - 1 );
1024  }
1025 
1026  for (unsigned int j = cols*(rows-1); j < _npatch; ++j)
1027  border_cells.push_back( j ); //last row
1028 
1029  }
1030 
1031  double sum;
1032  // individuals who can't disperse past the border stay in place:
1033  for (unsigned int i = 0; i < border_cells.size(); ++i) {
1034  //sum of dispersal rates:
1035  sum = fmat->rowSum( border_cells[i] ) - fmat->get(border_cells[i], border_cells[i]);
1036  //difference gives 1 - m:
1037  fmat->set(border_cells[i], border_cells[i], 1 - sum);
1038 
1039  sum = mmat->rowSum( border_cells[i] ) - mmat->get(border_cells[i], border_cells[i]);
1040  mmat->set(border_cells[i], border_cells[i], 1 - sum);
1041  }
1042 
1043  if(!_isForward) { fmat->transpose(); mmat->transpose(); }
1044 
1045  return true;
1046 }
void transpose()
Transpose the matrix, swaps columns for rows.
Definition: tmatrix.h:332
double rowSum(unsigned int row)
Sum all elements in a row.
Definition: tmatrix.h:353

References _DispMatrix, _isForward, _npatch, FEM, TMatrix::get(), MAL, TMatrix::rowSum(), TMatrix::set(), and TMatrix::transpose().

Referenced by setBasicLatticeMatrix().

+ Here is the caller graph for this function:

◆ setLatticeTorrusMatrix()

bool LCE_Disperse_base::setLatticeTorrusMatrix ( int  rows,
int  cols,
double  disp_mal,
double  disp_fem,
TMatrix grid 
)
900 {
901  TMatrix* mmat = _DispMatrix[MAL];
902  TMatrix* fmat = _DispMatrix[FEM];
903 
904  int x, y;
905 
906  x = 0; //first row, connect with upper row
907  for (y = 0; y < cols; ++y) {
908  fmat->set( grid->get(x, y), grid->get( rows-1, y ), disp_fem);
909  mmat->set( grid->get(x, y), grid->get( rows-1, y ), disp_mal);
910  }
911 
912  x = rows - 1; //last row, connect with bottom row
913  for (y = 0; y < cols; ++y) {
914  fmat->set( grid->get(x, y), grid->get( 0, y ), disp_fem);
915  mmat->set( grid->get(x, y), grid->get( 0, y ), disp_mal);
916  }
917 
918  y = 0; //left column, connect with right-most column
919  for (x = 0; x < rows; ++x) {
920  fmat->set( grid->get(x, y), grid->get( x, cols - 1 ), disp_fem);
921  mmat->set( grid->get(x, y), grid->get( x, cols - 1 ), disp_mal);
922  }
923 
924  y = cols - 1; //right-most column, connect with left-most column
925  for (x = 0; x < rows; ++x) {
926  fmat->set( grid->get(x, y), grid->get( x, 0 ), disp_fem);
927  mmat->set( grid->get(x, y), grid->get( x, 0 ), disp_mal);
928  }
929 
930  //connect along diagonals
931 
932  if((int)get_parameter_value(_prefix + "_lattice_range") == 2) {
933 
934 
935  //CORNERS:
936 
937  //first patch on first row, wrap around to top right border (last patch)
938  fmat->set( grid->get(0, 0), grid->get( rows - 1, cols - 1 ), disp_fem);
939  mmat->set( grid->get(0, 0), grid->get( rows - 1, cols - 1 ), disp_mal);
940  //last patch to first patch
941  fmat->set( grid->get( rows - 1, cols - 1 ), grid->get(0, 0), disp_fem);
942  mmat->set( grid->get( rows - 1, cols - 1 ), grid->get(0, 0), disp_mal);
943 
944  //last patch on first row, wrap around to top left border
945  fmat->set( grid->get(0, cols - 1), grid->get( rows - 1, 0 ), disp_fem);
946  mmat->set( grid->get(0, cols - 1), grid->get( rows - 1, 0 ), disp_mal);
947  //third corner to second corner
948  fmat->set( grid->get( rows - 1, 0 ), grid->get(0, cols - 1), disp_fem);
949  mmat->set( grid->get( rows - 1, 0 ), grid->get(0, cols - 1), disp_mal);
950 
951 
952  //BORDERS:
953 
954  x = 0;//we are on the first row
955 
956  for (y = 0; y < cols - 1; ++y) {
957  //diagonal step to the right, move to the other side of the grid
958  fmat->set( grid->get(x, y), grid->get( rows-1, y + 1 ), disp_fem);
959  mmat->set( grid->get(x, y), grid->get( rows-1, y + 1 ), disp_mal);
960  }
961  for (y = 1; y < cols; ++y) {
962  //diagonal step to the left, move to the other side of the grid
963  fmat->set( grid->get(x, y), grid->get( rows-1, y - 1 ), disp_fem);
964  mmat->set( grid->get(x, y), grid->get( rows-1, y - 1 ), disp_mal);
965  }
966 
967  x = rows - 1; //last row
968 
969  for (y = 0; y < cols - 1; ++y) {
970  //diagonal step to the right, move to the first row
971  fmat->set( grid->get(x, y), grid->get( 0, y + 1 ), disp_fem);
972  mmat->set( grid->get(x, y), grid->get( 0, y + 1 ), disp_mal);
973  }
974  for (y = 1; y < cols; ++y) {
975  //diagonal step to the left, move to the first row
976  fmat->set( grid->get(x, y), grid->get( 0, y - 1 ), disp_fem);
977  mmat->set( grid->get(x, y), grid->get( 0, y - 1 ), disp_mal);
978  }
979 
980  //in-between rows, connect first and last columns
981  for (x = 0; x < rows; ++x) {
982 
983  if(x > 0) {
984  //diagonal step down, to previous row
985  y = 0; //first column
986  fmat->set( grid->get(x, y), grid->get( x - 1, cols - 1 ), disp_fem);
987  mmat->set( grid->get(x, y), grid->get( x - 1, cols - 1 ), disp_mal);
988  y = cols - 1; //last column
989  fmat->set( grid->get(x, y), grid->get( x - 1, 0 ), disp_fem);
990  mmat->set( grid->get(x, y), grid->get( x - 1, 0 ), disp_mal);
991  }
992  if(x < rows - 1){
993  //diagonal step up, to next row
994  y = 0;
995  fmat->set( grid->get(x, y), grid->get( x + 1, cols - 1 ), disp_fem);
996  mmat->set( grid->get(x, y), grid->get( x + 1, cols - 1 ), disp_mal);
997  y = cols - 1;
998  fmat->set( grid->get(x, y), grid->get( x + 1, 0 ), disp_fem);
999  mmat->set( grid->get(x, y), grid->get( x + 1, 0 ), disp_mal);
1000  }
1001  }
1002  }
1003  //the matrix is symmetrical no need to transpose for backward migration
1004  return true;
1005 }

References _DispMatrix, _prefix, FEM, TMatrix::get(), SimComponent::get_parameter_value(), MAL, and TMatrix::set().

Referenced by setBasicLatticeMatrix().

+ Here is the caller graph for this function:

◆ setParamPrefix()

void LCE_Disperse_base::setParamPrefix ( string  pref)
inline
78 {_prefix = pref;}

References _prefix.

◆ setPropaguleTargets()

void LCE_Disperse_base::setPropaguleTargets ( )
464 {
465  unsigned int nb_patch = _popPtr->getPatchNbr();
466  unsigned int tmp_array[nb_patch];
467  unsigned int table_index, target_patch;
468  unsigned int size, last;
469 
470  //shuffling algorithm:
471  do {
472  for(unsigned int i = 0; i < nb_patch; ++i)
473  tmp_array[i] = i;
474 
475  size = nb_patch;
476 
477  for(unsigned int orig_patch = 0; orig_patch < nb_patch-1; ++orig_patch) {
478 
479  do{
480 
481  table_index = RAND::Uniform( size );
482 
483  target_patch = tmp_array[ table_index ];
484 
485  }while(target_patch == orig_patch);
486 
487  size--;
488 
489  last = tmp_array[size];
490 
491  tmp_array[table_index] = last;
492 
493  tmp_array[size] = target_patch;
494  }
495  //do this until the last element left is not the last patch:
496  }while (tmp_array[0] == nb_patch-1);
497 
498  _PropaguleTargets.assign(nb_patch,0);
499 
500  unsigned int reverse_i = nb_patch;
501 
502  //we read the shuffled array in reverse order:
503  for(unsigned int i=0; i < _PropaguleTargets.size(); i++) {
504  _PropaguleTargets[i] = tmp_array[--reverse_i];
505 
506 #ifdef _DEBUG_
507  cout<<" -- Patch "<<i<<" : assigned Patch "<<_PropaguleTargets[i]<<endl;
508 #endif
509 
510  }
511 }

References LifeCycleEvent::_popPtr, _PropaguleTargets, Metapop::getPatchNbr(), and RAND::Uniform().

Referenced by LCE_Disperse_EvolDisp::execute(), and setIsland_PropagulePool_Matrix().

+ Here is the caller graph for this function:

◆ setReducedDispMatrix()

bool LCE_Disperse_base::setReducedDispMatrix ( )

The reduced dispersal matrix contains the indices of the patches to which each patch is connected.

The connected patches are further ordered in descending order of the migration rates. The migration rates are stored in a reduced dispersal matrix. The original dispersal matrices are cleared (de-allocated). This offers a double speed-up compared to the classical method.

1109 {
1110  unsigned int border_model = (unsigned int)get_parameter_value(_prefix + "_border_model");
1111  unsigned int num_patch = (border_model == 3 ? _npatch + 1 : _npatch);
1112 
1113  //multimap automatically orders the key values in ascending order
1114  multimap<double, unsigned int> ordered_rates_fem, ordered_rates_mal;
1115 
1116  typedef multimap<double, unsigned int>::const_iterator CI;
1117 
1118 #ifdef _DEBUG_
1119  message("== Dispersal matrices ==\n");
1120  _DispMatrix[FEM]->show_up();
1121  _DispMatrix[MAL]->show_up();
1122  message("== setting reduced dispersal matrices ==\n");
1123 #endif
1124 
1125  // purge the connectivity and reduced dipsersal matrices
1126  for (unsigned int sex = 0; sex < 2; sex++) {
1127  _reducedDispMat[sex].clear();
1128  _reducedDispMatProba[sex].clear();
1129  }
1130  // build them from full dispersal matrices given in input
1131  for (unsigned int i = 0; i < num_patch; ++i) {
1132 
1133  _reducedDispMat[0].push_back(vector<double>());
1134  _reducedDispMat[1].push_back(vector<double>());
1135 
1136  _reducedDispMatProba[0].push_back(vector<double>());
1137  _reducedDispMatProba[1].push_back(vector<double>());
1138 
1139  ordered_rates_fem.clear();
1140  ordered_rates_mal.clear();
1141 
1142  if(_isForward) {
1143  //make pairs: {disp proba, patch connected}, will be ordered by dispersal probabilities:
1144  for (unsigned int j = 0; j < num_patch; ++j)
1145  if(_DispMatrix[MAL]->get(i, j) != 0) ordered_rates_mal.insert(make_pair(_DispMatrix[MAL]->get(i, j), j));
1146 
1147 
1148  for (unsigned int j = 0; j < num_patch; ++j)
1149  if(_DispMatrix[FEM]->get(i, j) != 0) ordered_rates_fem.insert(make_pair(_DispMatrix[FEM]->get(i, j),j));
1150 
1151 
1152  } else {
1153  //backward migration matrices are read column-wise
1154  for (unsigned int j = 0; j < num_patch; ++j)
1155  if(_DispMatrix[MAL]->get(j, i) != 0) ordered_rates_mal.insert(make_pair(_DispMatrix[MAL]->get(j, i),j));
1156 
1157  for (unsigned int j = 0; j < num_patch; ++j)
1158  if(_DispMatrix[FEM]->get(j, i) != 0) ordered_rates_fem.insert(make_pair(_DispMatrix[FEM]->get(j, i),j));
1159  }
1160 
1161  if(ordered_rates_fem.size() == 1) {
1162 
1163  _reducedDispMat[FEM][i].push_back(ordered_rates_fem.begin()->second);
1164 
1165  _reducedDispMatProba[FEM][i].push_back(ordered_rates_fem.begin()->first);
1166 
1167  } else {
1168 
1169  //store the patch indices in reverse order of the migration rates:
1170  //store the dispersal rates as well in a separate reduced matrix
1171  CI p;
1172 
1173  for (p = --ordered_rates_fem.end(); p != ordered_rates_fem.begin(); --p) {
1174  _reducedDispMat[FEM][i].push_back(p->second);
1175  _reducedDispMatProba[FEM][i].push_back(p->first);
1176  }
1177  _reducedDispMat[FEM][i].push_back(ordered_rates_fem.begin()->second);
1178  _reducedDispMatProba[FEM][i].push_back(ordered_rates_fem.begin()->first);
1179 
1180  }
1181 
1182  //same for the male dispersal matrices
1183  if(ordered_rates_mal.size() == 1) {
1184 
1185  _reducedDispMat[MAL][i].push_back(ordered_rates_mal.begin()->second);
1186 
1187  _reducedDispMatProba[MAL][i].push_back(ordered_rates_mal.begin()->first);
1188 
1189  } else {
1190 
1191  CI p;
1192 
1193  for (p = --ordered_rates_mal.end(); p != ordered_rates_mal.begin(); --p) {
1194  _reducedDispMat[MAL][i].push_back(p->second);
1195  _reducedDispMatProba[MAL][i].push_back(p->first);
1196  }
1197  _reducedDispMat[MAL][i].push_back(ordered_rates_mal.begin()->second);
1198  _reducedDispMatProba[MAL][i].push_back(ordered_rates_mal.begin()->first);
1199 
1200  }
1201  }
1202 
1203  //we can now get rid of the dispersal matrices...
1204  for (unsigned int sex = 0; sex < 2; sex++) {
1205  delete _DispMatrix[sex];
1206  _DispMatrix[sex] = NULL;
1207  }
1208 
1209 #ifdef _DEBUG_
1210  cout << "=== female reduced dispersal matrix ===\n";
1211  for (unsigned int i = 0; i < num_patch; ++i) {
1212  cout << " ["<<i<<": ";
1213  for (unsigned int k = 0; k < _reducedDispMat[FEM][i].size(); k++) {
1214  cout <<"m="<< _reducedDispMatProba[FEM][i][k] << " -> " << _reducedDispMat[FEM][i][k]<<", ";
1215  }
1216  cout<<"]\n";
1217  }
1218 
1219  cout << "=== male reduced dispersal matrix ===\n";
1220  for (unsigned int i = 0; i < num_patch; ++i) {
1221  cout << " ["<<i<<": ";
1222  for (unsigned int k = 0; k < _reducedDispMat[MAL][i].size(); k++) {
1223  cout <<"m="<< _reducedDispMatProba[MAL][i][k] << " -> " << _reducedDispMat[MAL][i][k]<<", ";
1224  }
1225  cout<<"]\n";
1226 
1227  }
1228 #endif
1229 
1230  return true;
1231 }
void show_up()
Definition: tmatrix.h:363

References _DispMatrix, _isForward, _npatch, _prefix, _reducedDispMat, _reducedDispMatProba, FEM, SimComponent::get_parameter_value(), MAL, message(), and TMatrix::show_up().

Referenced by setBaseParameters(), setDispMatrix(), and LCE_Disperse_EvolDisp::setParameters().

+ Here is the caller graph for this function:

◆ setReducedMatricesBySex()

bool LCE_Disperse_base::setReducedMatricesBySex ( sex_t  SEX,
Param connectivity,
Param rate 
)
310 {
311  string sex = (SEX == FEM ? "female" : "male");
312 
313  connectivity.getVariableMatrix(&_reducedDispMat[SEX]);
314 
316 
317  if(_reducedDispMat[SEX].size() != _npatch)
318  return error("The %s connectivity dispersal matrix must have as many rows (%i) as the number of patches in the population (%i)\n", sex.c_str(), _reducedDispMat[SEX].size(), _npatch);
319 
320  if(_reducedDispMatProba[SEX].size() != _npatch)
321  return error("The %s reduced dispersal rate matrix must have as many rows (%i) as the number of patches in the population (%i)\n", sex.c_str(), _reducedDispMatProba[SEX].size(), _npatch);
322 
323  if (_reducedDispMat[SEX].size() != _reducedDispMatProba[SEX].size())
324  return error("The %s connectivity and reduced dispersal matrices don't have same number of rows\n", sex.c_str());
325 
326  // check match between the two matrices
327  for (unsigned int i = 0; i < _reducedDispMat[SEX].size(); ++i) {
328 
329  if (_reducedDispMat[SEX][i].size() != _reducedDispMatProba[SEX][i].size())
330  return error("Row %i of the %s connectivity and reduced dispersal matrices are not of same size\n", i+1, sex.c_str());
331 
332  double row_sum = 0;
333 
334  // we here deduce 1 from the patch ID in the connectivity matrix
335  // this is because IDs are given in range [1 - num patch] in input (in principle)
336  for (unsigned int j = 0; j < _reducedDispMat[SEX][i].size(); ++j) {
337 
338  _reducedDispMat[SEX][i][j]--; //remove 1 to make sure that the indexes start with 0, not 1!!!!
339 
340  if(_reducedDispMatProba[SEX][i][j] < 0 )
341  return error("elements of the reduced dispersal matrix for the %s cannot be negative (row %i, column %i)!\n", (SEX==FEM?"females":"males"), i,j);
342 
343  row_sum += _reducedDispMatProba[SEX][i][j];
344  }
345 
346  if(!_isByNumber && (row_sum < 0.999999 || row_sum > 1.000001))
347  return error("the elements of row %i of the %s reduced dispersal matrix do not sum to 1!\n",i+1, sex.c_str());
348 
349  }
350  return true;
351 }
void getVariableMatrix(vector< vector< double > > *mat)
Definition: param.cc:461

References _isByNumber, _npatch, _reducedDispMat, _reducedDispMatProba, error(), FEM, and Param::getVariableMatrix().

Referenced by setBaseParameters().

+ Here is the caller graph for this function:

◆ setSteppingStone1DMatrix()

bool LCE_Disperse_base::setSteppingStone1DMatrix ( )
636 {
637 #ifdef _DEBUG_
638  message("setSteppingStone1DMatrix()\n");
639 #endif
640  int border_model = (unsigned int)get_parameter_value(_prefix + "_border_model");
641 
642  //check for the border model, the extra patch is the absorbing patch
643  if(border_model == 3) {
646  } else {
649  }
650 
651  TMatrix* mmat = _DispMatrix[MAL];
652  TMatrix* fmat = _DispMatrix[FEM];
653 
654  //philopatry:
655  double pmal = 1 - _mal_rate, pfem = 1 - _fem_rate;
656  //migration:
657  double mmal = _mal_rate/2, mfem = _fem_rate/2;
658 
659  fmat->assign(0);
660  mmat->assign(0);
661 
662  //diagonal:
663  for (unsigned int i = 0; i < _npatch; ++i){
664  fmat->set(i, i, pfem);
665  mmat->set(i, i, pmal);
666  }
667  //around the diagonal
668  for (unsigned int i = 0; i < _npatch-1; ++i){
669  fmat->set(i, i+1, mfem);
670  fmat->set(i+1, i, mfem);
671  mmat->set(i, i+1, mmal);
672  mmat->set(i+1, i, mmal);
673  }
674 
675  if(border_model == 3) {
676  //absorbing boders
677  //emigrants who leave the population are put in the sink patch
678  fmat->set(0, _npatch, mfem);
679  mmat->set(0, _npatch, mmal);
680  fmat->set(_npatch -1, _npatch, mfem);
681  mmat->set(_npatch -1, _npatch, mmal);
682  fmat->set(_npatch, _npatch, 1);
683  mmat->set(_npatch, _npatch, 1);
684 
685  if(!_isForward) {
686  fmat->transpose(); mmat->transpose(); //this creates artificial immigration from sink
687  //need to reset border patches as immigration from sink not allowed:
688  fmat->set(0, 0, pfem + mfem); //the proportion not comming from the sink must be added
689  fmat->set(_npatch, 0, 0); //no immigration from sink
690  fmat->set(_npatch-1, _npatch-1, pfem + mfem);
691  fmat->set(_npatch, _npatch-1, 0);
692 
693  mmat->set(0, 0, pmal + mmal);
694  mmat->set(_npatch, 0, 0);
695  mmat->set(_npatch-1, _npatch-1, pmal + mmal);
696  mmat->set(_npatch, _npatch-1, 0);
697  }
698 
699  } else if (border_model == 2) {
700  //reflective borders,
701  //emigrants that cannot leave stay in place
702  fmat->set(0, 0, pfem+mfem);
703  mmat->set(0, 0, pmal+mmal);
704  fmat->set(_npatch -1, _npatch -1, pfem+mfem);
705  mmat->set(_npatch -1, _npatch -1, pmal+mmal);
706 
707  //no need to transpose for backward migration as the matrix is symmetrical
708 
709  } else { //is a torus by default
710  //the 2 last elements, this is a ring population!
711  fmat->set(0, _npatch -1, mfem);
712  mmat->set(0, _npatch -1, mmal);
713  fmat->set(_npatch -1, 0, mfem);
714  mmat->set(_npatch -1, 0, mmal);
715  }
716  return true;
717 }

References _DispMatrix, _fem_rate, _isForward, _mal_rate, _npatch, _prefix, allocateDispMatrix(), TMatrix::assign(), FEM, SimComponent::get_parameter_value(), MAL, message(), TMatrix::set(), and TMatrix::transpose().

Referenced by setDispMatrix().

+ Here is the caller graph for this function:

◆ swapPostDisp()

void LCE_Disperse_base::swapPostDisp ( )
377 {
378  Patch *patch;
379 
380  for(unsigned int i = 0; i < _npatch; i++) {
381  patch = _popPtr->getPatch(i);
382  patch->move(FEM, PDISPx, OFFSx);
383  patch->move(MAL, PDISPx, OFFSx);
384  }
385 }
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:610
@ OFFSx
Definition: types.h:41

References _npatch, LifeCycleEvent::_popPtr, FEM, Metapop::getPatch(), MAL, Patch::move(), OFFSx, and PDISPx.

Referenced by LCE_Disperse_EvolDisp::execute(), and LCE_Disperse_ConstDisp::Migrate().

+ Here is the caller graph for this function:

◆ updateDispMatrix()

bool LCE_Disperse_base::updateDispMatrix ( )
365 {
366  //called by the 'execute' function when a change in patch number is detected
367 
368  if ( getDispersalModel() == 0 )
369  return error("cannot update the dispersal matrix provided in input when the number of population changes.\n");
370 
371  return setDispMatrix();
372 }

References error(), getDispersalModel(), and setDispMatrix().

Referenced by LCE_Breed_Disperse::execute(), LCE_Breed_Selection_Disperse::execute(), and LCE_Disperse_ConstDisp::execute().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ LCE_Disperse_ConstDisp

friend class LCE_Disperse_ConstDisp
friend

◆ LCE_Disperse_EvolDisp

friend class LCE_Disperse_EvolDisp
friend

Member Data Documentation

◆ _disp_model

int LCE_Disperse_base::_disp_model
private

◆ _disp_propagule_prob

double LCE_Disperse_base::_disp_propagule_prob
private

◆ _DispMatrix

◆ _fem_rate

◆ _isByNumber

bool LCE_Disperse_base::_isByNumber
private

◆ _isForward

◆ _mal_rate

◆ _npatch

◆ _prefix

◆ _PropaguleTargets

vector<unsigned int> LCE_Disperse_base::_PropaguleTargets
private

◆ _reducedDispMat

vector< vector<double> > LCE_Disperse_base::_reducedDispMat[2]
protected

◆ _reducedDispMatProba

vector< vector<double> > LCE_Disperse_base::_reducedDispMatProba[2]
protected

The documentation for this class was generated from the following files:

Generated for Nemo v2.4.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR