Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/fleeteffortaggregator.cc
[mareframe] / trunk / gadget / fleeteffortaggregator.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/fleeteffortaggregator.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "fleeteffortaggregator.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 :     FleetEffortAggregator::FleetEffortAggregator(const FleetPtrVector& Fleets,
11 :     const StockPtrVector& Stocks, const IntMatrix& Areas)
12 :     : areas(Areas), doescatch(Fleets.Size(), Stocks.Size(), 0) {
13 :    
14 :     int i, j;
15 :     //JMB its simpler to just store pointers to the predators
16 :     //and preys rather than pointers to the fleets and stocks
17 :     for (i = 0; i < Stocks.Size(); i++)
18 :     preys.resize(Stocks[i]->getPrey());
19 :     for (i = 0; i < Fleets.Size(); i++)
20 :     predators.resize(Fleets[i]->getPredator());
21 :    
22 :     for (i = 0; i < predators.Size(); i++)
23 :     for (j = 0; j < preys.Size(); j++)
24 :     if (predators[i]->doesEat(preys[j]->getName()))
25 :     doescatch[i][j] = 1;
26 :    
27 :     for (i = 0; i < areas.Nrow(); i++)
28 :     total.resize(new DoubleMatrix(predators.Size(), preys.Size(), 0.0));
29 :     }
30 :    
31 :     FleetEffortAggregator::~FleetEffortAggregator() {
32 :     int i;
33 :     for (i = 0; i < total.Size(); i++)
34 :     delete total[i];
35 :     }
36 :    
37 :     void FleetEffortAggregator::Print(ofstream& outfile) const {
38 :     int i, j, k;
39 :     for (i = 0; i < total.Size(); i++) {
40 :     outfile << "\t\tInternal areas " << i << endl;
41 :     for (j = 0; j < total[i]->Nrow(); j++) {
42 :     outfile << TAB << TAB;
43 :     for (k = 0; k < total[i]->Ncol(j); k++)
44 :     outfile << setw(smallwidth) << (*total[i])[j][k] << sep;
45 :     outfile << endl;
46 :     }
47 :     }
48 :     outfile.flush();
49 :     }
50 :    
51 :     void FleetEffortAggregator::Reset() {
52 :     int i;
53 :     for (i = 0; i < total.Size(); i++)
54 :     (*total[i]).setToZero();
55 :     }
56 :    
57 :     void FleetEffortAggregator::Sum() {
58 :    
59 :     int f, g, h, i, j;
60 :     int predl = 0; //JMB there is only ever one length group ...
61 :    
62 :     this->Reset();
63 :     //Sum over the appropriate predators, preys and areas
64 :     for (f = 0; f < predators.Size(); f++)
65 :     for (h = 0; h < preys.Size(); h++)
66 :     if (doescatch[f][h])
67 :     for (i = 0; i < areas.Nrow(); i++)
68 :     for (j = 0; j < areas.Ncol(i); j++)
69 :     if ((preys[h]->isPreyArea(areas[i][j])) && (predators[f]->isInArea(areas[i][j])))
70 :     for (g = 0; g < predators[f]->numPreys(); g++)
71 :     if (strcasecmp(preys[h]->getName(), predators[f]->getPrey(g)->getName()) == 0)
72 :     (*total[i])[f][h] += predators[f]->getConsumptionRatio(areas[i][j], g, predl);
73 :     }

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge