1 : |
agomez |
1 |
#include "preyoveraggregator.h" |
2 : |
|
|
#include "prey.h" |
3 : |
|
|
#include "errorhandler.h" |
4 : |
|
|
#include "gadget.h" |
5 : |
|
|
#include "global.h" |
6 : |
|
|
|
7 : |
|
|
PreyOverAggregator::PreyOverAggregator(const PreyPtrVector& Preys,
|
8 : |
|
|
const IntMatrix& Areas, const LengthGroupDivision* const LgrpDiv)
|
9 : |
|
|
: preys(Preys), areas(Areas) {
|
10 : |
|
|
|
11 : |
|
|
int i, j;
|
12 : |
|
|
for (i = 0; i < preys.Size(); i++) {
|
13 : |
|
|
if (!checkLengthGroupStructure(preys[i]->getLengthGroupDiv(), LgrpDiv))
|
14 : |
|
|
handle.logMessage(LOGFAIL, "Error in preyoveraggregator - invalid length group structure");
|
15 : |
|
|
preyConv.AddRows(1, preys[i]->getLengthGroupDiv()->numLengthGroups(), -1);
|
16 : |
|
|
for (j = 0; j < preyConv.Ncol(i); j++)
|
17 : |
|
|
preyConv[i][j] = LgrpDiv->numLengthGroup(preys[i]->getLengthGroupDiv()->meanLength(j));
|
18 : |
|
|
}
|
19 : |
|
|
total.AddRows(areas.Nrow(), LgrpDiv->numLengthGroups(), 0.0);
|
20 : |
|
|
}
|
21 : |
|
|
|
22 : |
|
|
void PreyOverAggregator::Reset() {
|
23 : |
|
|
total.setToZero();
|
24 : |
|
|
}
|
25 : |
|
|
|
26 : |
|
|
void PreyOverAggregator::Sum() {
|
27 : |
|
|
int i, j, k, l;
|
28 : |
|
|
|
29 : |
|
|
this->Reset();
|
30 : |
|
|
//Sum over the appropriate preys, areas, and lengths.
|
31 : |
|
|
for (k = 0; k < preys.Size(); k++)
|
32 : |
|
|
for (i = 0; i < areas.Nrow(); i++)
|
33 : |
|
|
for (j = 0; j < areas.Ncol(i); j++)
|
34 : |
|
|
if (preys[k]->isOverConsumption(areas[i][j]))
|
35 : |
|
|
for (l = 0; l < preyConv.Ncol(k); l++)
|
36 : |
|
|
if (preyConv[k][l] >= 0)
|
37 : |
|
|
total[i][preyConv[k][l]] += (preys[k]->getOverConsumption(areas[i][j]))[l];
|
38 : |
|
|
|
39 : |
|
|
}
|