-
Notifications
You must be signed in to change notification settings - Fork 1
/
Specie.cpp
executable file
·160 lines (124 loc) · 3.3 KB
/
Specie.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
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
//
// Created by Malysheva, Nadezhda on 2019-07-28.
//
#include "Specie.h"
#include <limits>
#include <iostream>
#include <cmath>
#include <stdexcept>
Specie::Specie()
{
maxNumberOfContacts = 0;
numberOfContacts = 0;
deathRate = 0;
newContactRate = 0;
looseContactRate = 0;
state = S;
stateChangeTime = 0;
}
Specie::Specie(/*unsigned char age,*/ size_t maxNumberOfContacts,
size_t numberOfContacts, double deathRate,
double newContactRate, double looseContactRate, State st)
{
//setAge(age);
setMaxNumberOfContacts(maxNumberOfContacts);
setNumberOfContacts(numberOfContacts);
setDeathRate(deathRate);
setNewContactRate(newContactRate);
setLooseContactRate(looseContactRate);
state = st;
stateChangeTime = 0;
}
size_t Specie::getMaxNumberOfContacts() const
{
return maxNumberOfContacts;
}
size_t Specie::getNumberOfContacts() const
{
return numberOfContacts;
}
double Specie::getNewContactRate() const
{
double result = newContactRate;
return result;
}
double Specie::getLooseContactRate() const
{
double result = looseContactRate;
return result;
}
double Specie::getDeathRate() const
{
return deathRate;
}
Specie::State Specie::getState() const
{
return state;
}
void Specie::setMaxNumberOfContacts(unsigned int maxNumOfCont)
{
maxNumberOfContacts = maxNumOfCont;
}
void Specie::setNumberOfContacts(size_t nOfCont)
{
numberOfContacts = nOfCont;
}
void Specie::incNumberOfContacts()
{
numberOfContacts++;
}
void Specie::decNumberOfContacts()
{
numberOfContacts--;
}
void Specie::setNewContactRate (double newContRate)
{
newContactRate = newContRate;
}
void Specie::setLooseContactRate(double looseContRate)
{
looseContactRate = looseContRate;
}
void Specie::setDeathRate(double dRate)
{
deathRate = dRate;
}
void Specie::changeState (State st, double time)
{
state = st;
stateChangeTime = time;
}
double Specie::getLastStateChangeTime() const
{
return stateChangeTime;
}
bool Specie::operator== (const Specie &sp) const
{
bool result = (
maxNumberOfContacts == sp.getMaxNumberOfContacts() &&
numberOfContacts == sp.getNumberOfContacts() &&
deathRate == sp.getDeathRate() &&
newContactRate == sp.getNewContactRate() &&
looseContactRate == sp.getLooseContactRate() &&
stateChangeTime == sp.getLastStateChangeTime() &&
state == sp.getState());
return result;
}
double Specie::getNumberOfContactsLimit(double t) const
{
double a = newContactRate * maxNumberOfContacts;
double b = newContactRate + looseContactRate;
double numConStart = numberOfContacts;
double numConEnd = ExpectationOfContacts(a, b, t) + 2 * sqrt(VarianceOfContacts(a, b, t));
numConEnd = std::min(numConEnd, static_cast<double>(maxNumberOfContacts));
double result = std::max(numConStart, numConEnd);
return result;
}
double Specie::ExpectationOfContacts(double a, double b, double t)const
{
return (a / b - (a / b - numberOfContacts) * exp(-b * t));
}
double Specie::VarianceOfContacts(double a, double b, double t)const
{
return (ExpectationOfContacts(a, b, t) - numberOfContacts * exp(-2 * b * t));
}