-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathTPlant.cpp
77 lines (60 loc) · 1.99 KB
/
TPlant.cpp
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
/* File: TPlant.cpp
*-----------------
*/
#include "TPlant.h"
#include "dws_random.h"
// Constructors
TPlant::TPlant()
{}
TPlant::TPlant(const TPlant& copy)
: _flammability(copy._flammability),
_fitness(copy._fitness)
{}
TPlant::TPlant(double fp /*torch prob*/, int n, double p)
: _fitness(n,p)
{
_flammability=DWS::random_chance(fp)?TORCH:DAMP;
}
TPlant::TPlant(const TPlant& f, const TPlant& m, double R /*flam-fit recomb rate*/, double r /*per locus recomb rate*/)
{
TGenotype::CreateOffspring(f._fitness,m._fitness,r,this->_fitness);
if(this->_fitness.BitAt(0)==f._fitness.BitAt(0)) { // started with father
this->_flammability=DWS::random_chance(R)?m._flammability:f._flammability;
} else { // started with mother
this->_flammability=DWS::random_chance(R)?f._flammability:m._flammability;
}
}
TPlant::~TPlant()
{}
TPlant& TPlant::operator=(const TPlant& other)
{
if(&other == this) return *this;
_fitness = other._fitness;
_flammability=other._flammability;
return (*this);
}
double TPlant::TestFitness(const TGenotype compare) const
{
return (this->_fitness.Compare(compare) / (double)this->_fitness.NAlleles());
}
double TPlant::TestFitness(const TPlant compare) const
{
return (this->_fitness.Compare(compare._fitness) / (double)this->_fitness.NAlleles());
}
// static functions
void TPlant::Mate(const TPlant& f, const TPlant& m, double R /*flam-fit recomb rate*/,
double r /*per locus recomb rate*/, TPlant& offspring)
{
TGenotype::CreateOffspring(f._fitness,m._fitness,r,offspring._fitness);
if(offspring._fitness.BitAt(0)==f._fitness.BitAt(0)) { // started with father
offspring._flammability=DWS::random_chance(R)?m._flammability:f._flammability;
} else { // started with mother
offspring._flammability=DWS::random_chance(R)?f._flammability:m._flammability;
}
}
// Friend functions
std::ostream& operator<<(std::ostream& os, const TPlant& g)
{
os << "FLAMMABILITY=" << (g._flammability==TORCH?"TORCH":"DAMP") << " GENOTYPE=" << g._fitness << std::endl;
return os;
}