1 : |
agomez |
1 |
#include "fleetpreyaggregator.h" |
2 : |
|
|
#include "errorhandler.h" |
3 : |
|
|
#include "stock.h" |
4 : |
|
|
#include "stockprey.h" |
5 : |
|
|
#include "poppredator.h" |
6 : |
|
|
#include "fleet.h" |
7 : |
|
|
#include "gadget.h" |
8 : |
|
|
#include "global.h" |
9 : |
|
|
|
10 : |
|
|
FleetPreyAggregator::FleetPreyAggregator(const FleetPtrVector& Fleets,
|
11 : |
|
|
const StockPtrVector& Stocks, LengthGroupDivision* const Lgrpdiv,
|
12 : |
|
|
const IntMatrix& Areas, const IntMatrix& Ages, int overcons)
|
13 : |
|
|
: LgrpDiv(Lgrpdiv), areas(Areas), ages(Ages), overconsumption(overcons),
|
14 : |
|
|
doescatch(Fleets.Size(), Stocks.Size(), 0), suitptr(0), alptr(0) {
|
15 : |
|
|
|
16 : |
|
|
int i, j;
|
17 : |
|
|
//JMB its simpler to just store pointers to the predators
|
18 : |
|
|
//and preys rather than pointers to the fleets and stocks
|
19 : |
|
|
for (i = 0; i < Stocks.Size(); i++)
|
20 : |
|
|
preys.resize(Stocks[i]->getPrey());
|
21 : |
|
|
for (i = 0; i < Fleets.Size(); i++)
|
22 : |
|
|
predators.resize(Fleets[i]->getPredator());
|
23 : |
|
|
|
24 : |
|
|
for (i = 0; i < preys.Size(); i++) {
|
25 : |
|
|
CI.resize(new ConversionIndex(preys[i]->getLengthGroupDiv(), LgrpDiv));
|
26 : |
|
|
if (CI[i]->Error())
|
27 : |
|
|
handle.logMessage(LOGFAIL, "Error in fleetpreyaggregator - error when checking length structure");
|
28 : |
|
|
}
|
29 : |
|
|
|
30 : |
|
|
for (i = 0; i < predators.Size(); i++)
|
31 : |
|
|
for (j = 0; j < preys.Size(); j++)
|
32 : |
|
|
if (predators[i]->doesEat(preys[j]->getName()))
|
33 : |
|
|
doescatch[i][j] = 1;
|
34 : |
|
|
|
35 : |
|
|
//Resize total using dummy variables tmppop and popmatrix
|
36 : |
|
|
PopInfo tmppop;
|
37 : |
|
|
tmppop.N = 1.0;
|
38 : |
|
|
PopInfoMatrix popmatrix(ages.Nrow(), LgrpDiv->numLengthGroups(), tmppop);
|
39 : |
|
|
total.resize(areas.Nrow(), 0, 0, popmatrix);
|
40 : |
|
|
this->Reset();
|
41 : |
|
|
}
|
42 : |
|
|
|
43 : |
|
|
FleetPreyAggregator::~FleetPreyAggregator() {
|
44 : |
|
|
int i;
|
45 : |
|
|
for (i = 0; i < CI.Size(); i++)
|
46 : |
|
|
delete CI[i];
|
47 : |
|
|
}
|
48 : |
|
|
|
49 : |
|
|
void FleetPreyAggregator::Print(ofstream& outfile) const {
|
50 : |
|
|
int i, j;
|
51 : |
|
|
for (i = 0; i < total.Size(); i++) {
|
52 : |
|
|
outfile << "\tInternal areas";
|
53 : |
|
|
for (j = 0; j < areas.Ncol(i); j++)
|
54 : |
|
|
outfile << sep << areas[i][j];
|
55 : |
|
|
outfile << endl;
|
56 : |
|
|
total[i].printNumbers(outfile);
|
57 : |
|
|
}
|
58 : |
|
|
outfile.flush();
|
59 : |
|
|
}
|
60 : |
|
|
|
61 : |
|
|
void FleetPreyAggregator::Reset() {
|
62 : |
|
|
int i;
|
63 : |
|
|
for (i = 0; i < total.Size(); i++)
|
64 : |
|
|
total[i].setToZero();
|
65 : |
|
|
}
|
66 : |
|
|
|
67 : |
|
|
int FleetPreyAggregator::checkCatchData() {
|
68 : |
|
|
int i, j, k;
|
69 : |
|
|
double check = 0.0;
|
70 : |
|
|
|
71 : |
|
|
for (i = 0; i < total.Size(); i++)
|
72 : |
|
|
for (j = 0; j < total[i].Nrow(); j++)
|
73 : |
|
|
for (k = 0; k < total[i].maxLength(j); k++)
|
74 : |
|
|
check += total[i][j][k].N;
|
75 : |
|
|
|
76 : |
|
|
if (isZero(check))
|
77 : |
|
|
return 1;
|
78 : |
|
|
return 0;
|
79 : |
|
|
}
|
80 : |
|
|
|
81 : |
|
|
void FleetPreyAggregator::Sum() {
|
82 : |
|
|
|
83 : |
|
|
int f, g, h, i, j, k, r, z;
|
84 : |
|
|
int predl = 0; //JMB there is only ever one length group ...
|
85 : |
|
|
double ratio;
|
86 : |
|
|
|
87 : |
|
|
this->Reset();
|
88 : |
|
|
//Sum over the appropriate predators, preys, areas, ages and length groups
|
89 : |
|
|
for (f = 0; f < predators.Size(); f++) {
|
90 : |
|
|
for (h = 0; h < preys.Size(); h++) {
|
91 : |
|
|
if (doescatch[f][h]) {
|
92 : |
|
|
for (r = 0; r < areas.Nrow(); r++) {
|
93 : |
|
|
for (j = 0; j < areas.Ncol(r); j++) {
|
94 : |
|
|
if ((preys[h]->isPreyArea(areas[r][j])) && (predators[f]->isInArea(areas[r][j]))) {
|
95 : |
|
|
for (i = 0; i < predators[f]->numPreys(); i++) {
|
96 : |
|
|
if (strcasecmp(preys[h]->getName(), predators[f]->getPrey(i)->getName()) == 0) {
|
97 : |
|
|
|
98 : |
|
|
//JMB cleaned up the overconsumption stuff
|
99 : |
|
|
if (overconsumption)
|
100 : |
|
|
suitptr = &((PopPredator*)predators[f])->getUseSuitability(areas[r][j], i)[predl];
|
101 : |
|
|
else
|
102 : |
|
|
suitptr = &predators[f]->getSuitability(i)[predl];
|
103 : |
|
|
|
104 : |
|
|
alptr = &((StockPrey*)preys[h])->getConsumptionALK(areas[r][j]);
|
105 : |
|
|
ratio = predators[f]->getConsumptionRatio(areas[r][j], i, predl);
|
106 : |
|
|
for (g = 0; g < ages.Nrow(); g++)
|
107 : |
|
|
for (k = 0; k < ages.Ncol(g); k++)
|
108 : |
|
|
if ((alptr->minAge() <= ages[g][k]) && (ages[g][k] <= alptr->maxAge()))
|
109 : |
|
|
total[r][g].Add((*alptr)[ages[g][k]], *CI[h], *suitptr, ratio);
|
110 : |
|
|
|
111 : |
|
|
}
|
112 : |
|
|
}
|
113 : |
|
|
}
|
114 : |
|
|
}
|
115 : |
|
|
}
|
116 : |
|
|
}
|
117 : |
|
|
}
|
118 : |
|
|
}
|
119 : |
|
|
}
|