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

References _DispMatrix.

◆ ~LCE_Disperse_base()

LCE_Disperse_base::~LCE_Disperse_base ( )
virtual

Deallocates the disp matrix.

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

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.

131 {return NONE;}
#define NONE
No age flag.
Definition: types.h:46

References NONE.

◆ addParameters()

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

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 
)
404 {
405  if(_DispMatrix[sex] != NULL)
406  _DispMatrix[sex]->reset(dim,dim);
407  else
408  _DispMatrix[sex] = new TMatrix(dim,dim);
409 }
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:48
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:159

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

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

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 
)
1300 {
1301 // vector<double> cpatches = _reducedDispMat[SEX][local_patch];
1302 //
1303 // cpatches.erase(cpatches.begin());
1304 
1305  return _reducedDispMat[SEX][local_patch];
1306 }
vector< vector< double > > _reducedDispMat[2]
Matrix containing the indexes of the patches connected to each patch.
Definition: LCEdisperse.h:65

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 
)
1311 {
1312 // vector<double> cpatches = _reducedDispMatProba[SEX][local_patch];
1313 
1314 // cpatches.erase(cpatches.begin());
1315 
1316  return _reducedDispMatProba[SEX][local_patch];
1317 }
vector< vector< double > > _reducedDispMatProba[2]
Matrix containing the probability to migrate to/from the connected patches.
Definition: LCEdisperse.h:67

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

References RAND::Uniform().

◆ getMigrationIndexGSLdiscrete()

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

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

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

◆ getMigrationPatchForward()

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

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
114 {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
115 {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 
)
1332 {
1333  if(col < _reducedDispMat[SEX][row].size())
1334  return _reducedDispMat[SEX][row][col];
1335  else
1336  return -1;
1337 }

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 
)
1322 {
1323  if(col < _reducedDispMatProba[SEX][row].size())
1324  return _reducedDispMatProba[SEX][row][col];
1325  else
1326  return -1.0;
1327 }

References _reducedDispMatProba.

◆ isByNumber()

bool LCE_Disperse_base::isByNumber ( )
inline
112 {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
111 {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.

127 {}

◆ loadStatServices()

virtual void LCE_Disperse_base::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Disperse.

128 {}

◆ removeAgeClass()

virtual age_t LCE_Disperse_base::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Disperse.

130 {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.

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

References OFFSPRG.

◆ reset_counters()

void LCE_Disperse_base::reset_counters ( )
389 {
390  Patch *patch;
391  for(unsigned int i = 0; i < _npatch; i++) {
392 
393  patch = _popPtr->getPatch(i);
394 
395  patch->reset_counters();
396 
397  patch->flush(PDISPx, _popPtr);
398  }
399 }
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:79
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:255
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
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:685
void reset_counters()
Definition: patch.cc:54
@ PDISPx
Definition: types.h:40

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.

129 {return false;}

◆ set_isForward()

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

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

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

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)
355 {
356  mat->reset(_npatch, _npatch);
357  mat->assign(0);
358  for(unsigned int i = 0; i < _npatch; ++i) mat->set(i, i, 1);
359 }

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

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

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

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.

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

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

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

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
77 {_prefix = pref;}

References _prefix.

◆ setPropaguleTargets()

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

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.

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

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

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

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

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 ( )
364 {
365  //called by the 'execute' function when a change in patch number is detected
366 
367  if ( getDispersalModel() == 0 )
368  return error("cannot update the dispersal matrix provided in input when the number of population changes.\n");
369 
370  return setDispMatrix();
371 }

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.2 by  doxygen 1.9.1

Catalogued on GSR