1 : |
agomez |
1 |
#ifndef popinfo_h
|
2 : |
|
|
#define popinfo_h
|
3 : |
|
|
|
4 : |
|
|
#include "gadget.h" |
5 : |
ulcessvp |
2 |
#include "mathfunc.h" |
6 : |
agomez |
1 |
|
7 : |
|
|
/**
|
8 : |
|
|
* \class PopInfo
|
9 : |
|
|
* \brief This is the class used to store information about the number, and mean weight, of a population cell of a stock
|
10 : |
|
|
*/
|
11 : |
|
|
class PopInfo {
|
12 : |
|
|
public:
|
13 : |
|
|
/**
|
14 : |
|
|
* \brief This is the PopInfo constructor
|
15 : |
|
|
*/
|
16 : |
ulcessvp |
3 |
PopInfo(double Ni = 0.0, double Wi = 0.0)
|
17 : |
|
|
: N(Ni), W(Wi)
|
18 : |
|
|
{};
|
19 : |
agomez |
1 |
/**
|
20 : |
|
|
* \brief This is the PopInfo destructor
|
21 : |
|
|
*/
|
22 : |
|
|
~PopInfo() {};
|
23 : |
|
|
/**
|
24 : |
|
|
* \brief This is the number of fish in the population cell
|
25 : |
|
|
*/
|
26 : |
|
|
double N;
|
27 : |
|
|
/**
|
28 : |
|
|
* \brief This is the mean weight of the fish in the population cell
|
29 : |
|
|
*/
|
30 : |
|
|
double W;
|
31 : |
|
|
/**
|
32 : |
|
|
* \brief This operator will subtract a number from the PopInfo
|
33 : |
|
|
* \param a is the number to subtract
|
34 : |
|
|
*/
|
35 : |
|
|
void operator -= (double a) { N -= a; };
|
36 : |
|
|
/**
|
37 : |
|
|
* \brief This operator will increase the PopInfo by a multiplicative constant
|
38 : |
|
|
* \param a is the multiplicative constant
|
39 : |
|
|
*/
|
40 : |
|
|
void operator *= (double a) { N *= a; };
|
41 : |
|
|
/**
|
42 : |
|
|
* \brief This function will set the PopInfo to zero
|
43 : |
|
|
*/
|
44 : |
|
|
void setToZero() { N = 0.0; W = 0.0; };
|
45 : |
|
|
/**
|
46 : |
|
|
* \brief This operator will set the PopInfo equal to an existing PopInfo
|
47 : |
|
|
* \param a is the PopInfo to copy
|
48 : |
|
|
*/
|
49 : |
ulcessvp |
3 |
PopInfo& operator = (const PopInfo& a) {
|
50 : |
|
|
N = a.N;
|
51 : |
|
|
W = a.W;
|
52 : |
|
|
return *this;
|
53 : |
|
|
}
|
54 : |
|
|
|
55 : |
agomez |
1 |
/**
|
56 : |
|
|
* \brief This operator will add an existing PopInfo to the current PopInfo
|
57 : |
|
|
* \param a is the PopInfo to add
|
58 : |
|
|
*/
|
59 : |
ulcessvp |
3 |
PopInfo& operator += (const PopInfo& a) {
|
60 : |
ulcessvp |
2 |
if (isZero(N + a.N)) {
|
61 : |
|
|
W = 0.0;
|
62 : |
|
|
N = 0.0;
|
63 : |
|
|
} else if (isZero(a.N)) {
|
64 : |
|
|
//adding a zero popinfo, so don't do anything
|
65 : |
|
|
} else if (isZero(N)) {
|
66 : |
|
|
W = a.W;
|
67 : |
|
|
N = a.N;
|
68 : |
|
|
} else {
|
69 : |
|
|
W = (N * W + a.N * a.W) / (N + a.N);
|
70 : |
|
|
N = N + a.N;
|
71 : |
|
|
}
|
72 : |
|
|
return *this;
|
73 : |
|
|
}
|
74 : |
|
|
|
75 : |
|
|
|
76 : |
|
|
;
|
77 : |
agomez |
1 |
/**
|
78 : |
|
|
* \brief This operator will multiply the PopInfo by a constant
|
79 : |
|
|
* \param a is the constant
|
80 : |
|
|
*/
|
81 : |
ulcessvp |
3 |
PopInfo operator * (double a) const {
|
82 : |
|
|
return PopInfo(N * a, W);
|
83 : |
|
|
}
|
84 : |
agomez |
1 |
};
|
85 : |
|
|
|
86 : |
|
|
#endif
|