-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTLandscape.h
104 lines (82 loc) · 2.64 KB
/
TLandscape.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/* File: TLandscape.h
* ------------------
*/
#ifndef _TLandscape_h_
#define _TLandscape_h_
#include "TPlant.h"
#include "dws_math.h"
#include "dws_stats.h"
#include <iostream>
#include <set>
#include <map>
typedef DWS::TPos<int> Pos;
class TLandscape {
public:
TLandscape(unsigned gridsize);
TLandscape(const TLandscape& copy);
TLandscape operator=(const TLandscape& source);
~TLandscape();
//
void GetNeighbors(Pos p, int neighborhood, std::set<Pos>& outSet) const;
void BurnNeighbors(Pos p);
Pos RandomNeighbor(Pos p, int neighborhood) const;
int AddTorches(double p);
int GridSize() const {return _gSize;}
int Age() const {return _age;}
void Setr(double r) {_r=r;}
void SetChangePeriod(int n) {_envChangePeriod = n;}
void SetChangeLoci(int n) {_nEnvChangeLoci = n;}
void SetMortalityRate(double m) {this->_mortalityRate = m;}
void SetMutationRate(double mu) {this->_mutationRate = mu;}
void SetPollenNeighborhood(int n) {this->_pollenNeighborhood = n;}
void SetSeedNeighborhood(int s) {this->_seedNeighborhood = s;}
void SetBurnNeighborhood(int b) {this->_burnNeighborhood=b;}
void RunForCycles(int n);
void Print();
TPlant& PlantAt(Pos p) {return (_grid[p._x][p._y]);}
double FitnessAt(Pos p) const {return (_fitnessMap.find(p))->second;}
int PlantAgeAt(Pos p) {return (this->Age() - _grid[p._x][p._y].GetBirthTime());}
double MeanFitness() {return _meanFit;}
double TorchProp() {return _torchProp;}
double SampleSimilarity(int nSamples) const;
void SampleAgeStructure(DWS::TSample& outS) const;
void Get1DSnapshot(DWS::TBivSample& FitFlamOutS) const;
void TorchDampFitness(DWS::TSample& tfit, DWS::TSample& dfit) const;
std::ostream& WriteFitnessGrid(std::ostream& os) const;
std::ostream& WriteFlamGrid(std::ostream& os) const;
friend std::ostream& operator<<(std::ostream& os, const TLandscape& la);
// friend std::istream& operator>>(std::istream& is, TLandscape& la);
private:
void BurnFromLightning();
void BurnNormal();
protected:
void Burn();
void Recruit();
void ChangeEnvironment();
void FillGrid(int newsize);
private:
bool _gridFull;
int _gSize;
TPlant** _grid; // array of plants
std::set<Pos> _deadSet;
std::map<Pos, double> _fitnessMap;
TGenotype _optimalGenotype;
protected:
int _nSeeds;
int _nAlleles;
bool _lightningBurn;
int _burnNeighborhood;
int _seedNeighborhood;
int _pollenNeighborhood;
double _meanFit;
double _torchProp;
double _mortalityRate;
double _mutationRate;
double _r; // recomb rate between fit loci
double _R;
double _lightningFreq;
int _envChangePeriod;
int _nEnvChangeLoci; // number of loci to change each change period
int _age;
}; // class TLandscape
#endif // TLandscape.h