2 |
#define popinfo_h |
#define popinfo_h |
3 |
|
|
4 |
#include "gadget.h" |
#include "gadget.h" |
5 |
|
#include "mathfunc.h" |
6 |
|
|
7 |
/** |
/** |
8 |
* \class PopInfo |
* \class PopInfo |
13 |
/** |
/** |
14 |
* \brief This is the PopInfo constructor |
* \brief This is the PopInfo constructor |
15 |
*/ |
*/ |
16 |
PopInfo() { N = 0.0; W = 0.0; }; |
PopInfo(double Ni = 0.0, double Wi = 0.0) |
17 |
|
: N(Ni), W(Wi) |
18 |
|
{}; |
19 |
/** |
/** |
20 |
* \brief This is the PopInfo destructor |
* \brief This is the PopInfo destructor |
21 |
*/ |
*/ |
46 |
* \brief This operator will set the PopInfo equal to an existing PopInfo |
* \brief This operator will set the PopInfo equal to an existing PopInfo |
47 |
* \param a is the PopInfo to copy |
* \param a is the PopInfo to copy |
48 |
*/ |
*/ |
49 |
PopInfo& operator = (const PopInfo& a); |
PopInfo& operator = (const PopInfo& a) { |
50 |
|
N = a.N; |
51 |
|
W = a.W; |
52 |
|
return *this; |
53 |
|
} |
54 |
|
|
55 |
/** |
/** |
56 |
* \brief This operator will add an existing PopInfo to the current PopInfo |
* \brief This operator will add an existing PopInfo to the current PopInfo |
57 |
* \param a is the PopInfo to add |
* \param a is the PopInfo to add |
58 |
*/ |
*/ |
59 |
PopInfo& operator += (const PopInfo& a); |
PopInfo& operator += (const PopInfo& a) { |
60 |
|
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 |
/** |
/** |
78 |
* \brief This operator will multiply the PopInfo by a constant |
* \brief This operator will multiply the PopInfo by a constant |
79 |
* \param a is the constant |
* \param a is the constant |
80 |
*/ |
*/ |
81 |
PopInfo operator * (double a); |
PopInfo operator * (double a) const { |
82 |
|
return PopInfo(N * a, W); |
83 |
|
} |
84 |
}; |
}; |
85 |
|
|
86 |
#endif |
#endif |