Nemo  2.3.56
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)
 
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)
 
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 ( )
47, _fem_rate (-1), _mal_rate(-1), _isForward(1), _isByNumber(0), _npatch(0)
48{
49 _DispMatrix[0] = NULL;
50 _DispMatrix[1] = NULL;
51}
TMatrix * _DispMatrix[2]
The sex-specific dispersal matrices, [0] for males, [1] for females, might be used as connectivity ma...
Definition: LCEdisperse.h:50
double _disp_propagule_prob
Definition: LCEdisperse.h:43
bool _isByNumber
Definition: LCEdisperse.h:47
double _fem_rate
Definition: LCEdisperse.h:45
bool _isForward
Definition: LCEdisperse.h:46
int _disp_model
Definition: LCEdisperse.h:42
vector< unsigned int > _PropaguleTargets
Definition: LCEdisperse.h:44
double _mal_rate
Definition: LCEdisperse.h:45
unsigned int _npatch
Number of patches in the population.
Definition: LCEdisperse.h:60
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:73

References _DispMatrix.

◆ ~LCE_Disperse_base()

LCE_Disperse_base::~LCE_Disperse_base ( )
virtual

Deallocates the disp matrix.

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

References _DispMatrix.

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Disperse_base::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Disperse, and LCE_Breed_Selection_Disperse.

119{return NONE;}
#define NONE
No age flag.
Definition: types.h:48

References NONE.

◆ addParameters()

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

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 
)
403{
404 if(_DispMatrix[sex] != NULL)
405 _DispMatrix[sex]->reset(dim,dim);
406 else
407 _DispMatrix[sex] = new TMatrix(dim,dim);
408}
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.
Definition: tmatrix.h:116

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)
432{
433 double cntr;
434
435 for(unsigned int i = 0; i < mat->getNbCols(); ++i) {
436 cntr = 0;
437 for(unsigned int j = 0; j < mat->getNbRows(); ++j)
438 cntr += mat->get(j,i);
439 if(cntr < 0.999999 || cntr > 1.000001) {
440 error("The elements of column %i of the dispersal matrix do not sum to 1!\n",i+1);
441 error("sum of row %i is: %f\n",i+1, cntr);
442 return false;
443 }
444 }
445 return true;
446}
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:147
unsigned int getNbRows()
Gives the number of rows.
Definition: tmatrix.h:166
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:169
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)
413{
414 double cntr;
415
416 for(unsigned int i = 0; i < mat->getNbRows(); ++i) {
417 cntr = 0;
418 for(unsigned int j = 0; j < mat->getNbCols(); ++j)
419 cntr += mat->get(i,j);
420 if(cntr < 0.999999 || cntr > 1.000001) {
421 error("the elements of row %i of the dispersal matrix do not sum to 1!\n",i+1);
422 error("sum of row %i is: %f\n",i+1, cntr);
423 return false;
424 }
425 }
426 return true;
427}

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

Referenced by setBaseParameters(), and setDispMatrix().

+ Here is the caller graph for this function:

◆ getDispersalModel()

◆ getMigrationPatchBackward()

unsigned int LCE_Disperse_base::getMigrationPatchBackward ( sex_t  SEX,
unsigned int  LocalPatch 
)
1242{
1243 double sum = 0, random = RAND::Uniform();
1244 unsigned int SourcePatch = 0;
1245
1246 if(random > 0.999999) random = 0.999999;//this to avoid overflows when random == 1
1247
1248 sum = _reducedDispMatProba[SEX][LocalPatch][SourcePatch];
1249
1250 while (random > sum) {
1251 SourcePatch++;
1252 sum += _reducedDispMatProba[SEX][LocalPatch][SourcePatch];
1253 }
1254
1255 return _reducedDispMat[SEX][LocalPatch][SourcePatch];
1256}
vector< vector< double > > _reducedDispMatProba[2]
Matrix containing the probability to migrate to/from the connected patches.
Definition: LCEdisperse.h:65
vector< vector< double > > _reducedDispMat[2]
Matrix containing the indexes of the patches connected to each patch.
Definition: LCEdisperse.h:63
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:125

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

Referenced by LCE_Breed_Disperse::get_parent().

+ Here is the caller graph for this function:

◆ getMigrationPatchForward()

unsigned int LCE_Disperse_base::getMigrationPatchForward ( sex_t  SEX,
unsigned int  LocalPatch 
)
1223{
1224 double sum = 0, random = RAND::Uniform();
1225 unsigned int AimedPatch = 0;
1226
1227 if(random > 0.999999) random = 0.999999;//this to avoid overflows when random == 1
1228
1229 sum = _reducedDispMatProba[SEX][LocalPatch][AimedPatch];
1230
1231 while (random > sum) {
1232 AimedPatch++;
1233 sum += _reducedDispMatProba[SEX][LocalPatch][AimedPatch];
1234 }
1235 //return the patch ID stored in the connectivity matrix:
1236 return _reducedDispMat[SEX][LocalPatch][AimedPatch];
1237}

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
108{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
109{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:

◆ isByNumber()

bool LCE_Disperse_base::isByNumber ( )
inline
106{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
105{return _isForward;}

References _isForward.

◆ loadFileServices()

virtual void LCE_Disperse_base::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

Reimplemented in LCE_Breed_Disperse, and LCE_Breed_Selection_Disperse.

115{}

◆ loadStatServices()

virtual void LCE_Disperse_base::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

Reimplemented in LCE_Breed_Disperse, and LCE_Breed_Selection_Disperse.

116{}

◆ removeAgeClass()

virtual age_t LCE_Disperse_base::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Disperse, and LCE_Breed_Selection_Disperse.

118{return NONE;}

References NONE.

◆ requiredAgeClass()

virtual age_t LCE_Disperse_base::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Disperse, and LCE_Breed_Selection_Disperse.

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

References OFFSPRG.

◆ reset_counters()

void LCE_Disperse_base::reset_counters ( )
388{
389 Patch *patch;
390 for(unsigned int i = 0; i < _npatch; i++) {
391
392 patch = _popPtr->getPatch(i);
393
394 patch->reset_counters();
395
396 patch->flush(PDISPx, _popPtr);
397 }
398}
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
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:643
void reset_counters()
Definition: patch.cc:56
@ PDISPx
Definition: types.h:42

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_Disperse, and LCE_Breed_Selection_Disperse.

117{return false;}

◆ set_isForward()

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

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

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 ( )
503{
504
505 switch ( getDispersalModel() ) {
506 case 1:
507 if( !setIsland_MigrantPool_Matrix() ) return false;
508 break;
509 case 2:
510 if( !setIsland_PropagulePool_Matrix() ) return false;
511 break;
512 case 3:
513 if( !setSteppingStone1DMatrix() ) return false;
514 break;
515 case 4:
516 if( !setLatticeMatrix() ) return false;
517 break;
518 default:
519 return error("Dispersal model '%i' not yet implemented\n",getDispersalModel());
520 }
521
522 if(_isForward) {
523 if(!checkForwardDispersalMatrix(_DispMatrix[FEM])) return false;
524 if(!checkForwardDispersalMatrix(_DispMatrix[MAL])) return false;
525 } else {
526 if(!checkBackwardDispersalMatrix(_DispMatrix[FEM])) return false;
527 if(!checkBackwardDispersalMatrix(_DispMatrix[MAL])) return false;
528 }
529
530 return setReducedDispMatrix();
531}
bool setSteppingStone1DMatrix()
Definition: LCEdisperse.cc:622
bool setIsland_MigrantPool_Matrix()
Definition: LCEdisperse.cc:535
bool setIsland_PropagulePool_Matrix()
Definition: LCEdisperse.cc:567
bool setLatticeMatrix()
Sets the dispersal matrices for the Lattice dispersal model.
Definition: LCEdisperse.cc:709
unsigned int getDispersalModel()
Definition: LCEdisperse.h:107

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

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 ( )
536{
537#ifdef _DEBUG_
538 cout<<"setIsland_MigrantPool_Matrix(_npatch="<<_npatch<<", _mal_rate="
539 <<_mal_rate<<", _fem_rate="<<_fem_rate<<")"<<endl;
540#endif
543
544 TMatrix* mmat = _DispMatrix[MAL];
545 TMatrix* fmat = _DispMatrix[FEM];
546 double pmal = 1 - _mal_rate;
547 double pfem = 1 - _fem_rate;
548 double mmal = _mal_rate/(_npatch-1);
549 double mfem = _fem_rate/(_npatch-1);
550
551 for (unsigned int i=0; i<_npatch; ++i){
552 for (unsigned int j=0; j<_npatch; ++j){
553 mmat->set(i,j, mmal);
554 fmat->set(i,j, mfem);
555 }
556 }
557
558 for (unsigned int i=0; i<_npatch; ++i){
559 mmat->set(i,i, pmal);
560 fmat->set(i,i, pfem);
561 }
562 return true;
563}
void allocateDispMatrix(sex_t sex, unsigned int dim)
Definition: LCEdisperse.cc:402

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 ( )
568{
569#ifdef _DEBUG_
570 cout<<"setIsland_PropagulePool_Matrix(_npatch="<<_npatch<<", _mal_rate="
571 <<_mal_rate<<", _fem_rate="<<_fem_rate<<")"<<endl;
572#endif
573
576
577 if( !_paramSet->isSet(_prefix + "_propagule_prob") ) {
578 error("Missing parameter \"dispersal_propagule_prob\" with dispersal model 2!\n");
579 return false;
580 }
581
583
584 double propagulePHI = getPropaguleProb();
585 double c1 = (1 - _fem_rate), c2 = (_fem_rate*propagulePHI),
586 c3 = (_fem_rate*(1.0 - propagulePHI)/(_npatch-2));
587
588 TMatrix* mmat = _DispMatrix[MAL];
589 TMatrix* fmat = _DispMatrix[FEM];
590
591 for (unsigned int i=0; i < _npatch; ++i){
592
593 fmat->set(i, i, c1);
594
595 for (unsigned int j=i+1; j < _npatch; ++j){
596 fmat->set(i, j, c3);
597 fmat->set(j, i, c3);
598 }
599 fmat->set(i, getPropaguleTarget(i), c2);
600 }
601
602 c1 = (1 - _mal_rate);
603 c2 = (_mal_rate*propagulePHI);
604 c3 = (_mal_rate*(1.0 - propagulePHI)/(_npatch-2));
605
606 for (unsigned int i=0; i < _npatch; ++i){
607
608 mmat->set(i, i, c1);
609
610 for (unsigned int j=i+1; j< _npatch; ++j) {
611 mmat->set(i, j, c3);
612 mmat->set(j, i, c3);
613 }
614 mmat->set(i, getPropaguleTarget(i), c2);
615 }
616
617 return true;
618}
unsigned int getPropaguleTarget(unsigned int home)
Definition: LCEdisperse.h:109
double getPropaguleProb()
Definition: LCEdisperse.h:108
void setPropaguleTargets()
Definition: LCEdisperse.cc:450

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

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.

710{
711#ifdef _DEBUG_
712 message("setLatticeMatrix()\n");
713#endif
714 if(!_paramSet->isSet(_prefix + "_border_model"))
715 return error("Missing parameter \"dispersal_border_model\" with dispersal model 4!\n");
716
717 if(!_paramSet->isSet(_prefix + "_lattice_range") )
718 return error("Missing parameter \"dispersal_lattice_range\" with dispersal model 4!\n");
719
720 int rows, cols;
721
722 if( !_paramSet->isSet(_prefix + "_lattice_rows") && !_paramSet->isSet(_prefix + "_lattice_columns") ) {
723
724 rows = cols = (int) sqrt((double)_npatch);
725
726 if( rows*cols != (int)_npatch )
727 return error("The number of patches is not a square number in the lattice dispersal model\n");
728
729 } else {
730
731 rows = _paramSet->getValue(_prefix + "_lattice_rows");
732
733 cols = _paramSet->getValue(_prefix + "_lattice_columns");
734
735 if(rows == -1) return error("number of rows of the dispersal lattice is not specified\n");
736 if(cols == -1) return error("number of columns of the dispersal lattice is not specified\n");
737
738 if( rows*cols != (int)_npatch ){
739 error("The size of the dispersal matrix in the lattice model is not equal to the number of patches,\n");
740 return error("parameters %s_lattice_rows and %s_lattice_columns must be set.\n", _prefix.c_str(), _prefix.c_str());
741 }
742 }
743
746 if((unsigned int)get_parameter_value(_prefix + "_border_model") == 3) {
749 } else {
752 }
753
757 unsigned int range = (unsigned int)get_parameter_value(_prefix + "_lattice_range");
758 //philopatry:
759 double pmal = 1 - _mal_rate, pfem = 1 - _fem_rate;
760 //migration:
761 double mmal = _mal_rate/(range == 1 ? 4 : 8), mfem = _fem_rate/(range == 1 ? 4 : 8);
762
763 setBasicLatticeMatrix(rows, cols, pmal, pfem, mmal, mfem);
764
765
766 return true;
767}
bool setBasicLatticeMatrix(int rows, int cols, double phi_mal, double phi_fem, double disp_mal, double disp_fem)
Definition: LCEdisperse.cc:771
void message(const char *message,...)
Definition: output.cc:40

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

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

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

References _prefix.

◆ setPropaguleTargets()

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

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.

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

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

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

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 ( )
375{
376 Patch *patch;
377
378 for(unsigned int i = 0; i < _npatch; i++) {
379 patch = _popPtr->getPatch(i);
380 patch->swap(FEM, PDISPx, OFFSx);
381 patch->swap(MAL, PDISPx, OFFSx);
382 }
383}
void swap(sex_t SEX, age_idx from, age_idx to)
Copies all elements in the 'from' age-class container to the 'to' age-class container of the same sex...
Definition: metapop.h:609
@ OFFSx
Definition: types.h:42

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

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

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

Matrix containing the probability to migrate to/from the connected patches.

Mirror the _reducedDispMat.

Referenced by getMigrationPatchBackward(), getMigrationPatchForward(), LCE_Disperse_ConstDisp::MigratePatchByNumber(), setBaseParameters(), setReducedDispMatrix(), and setReducedMatricesBySex().


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

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

Locations of visitors to this page
Catalogued on GSR