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/suits.cc
[mareframe] / trunk / gadget / suits.cc Repository:
ViewVC logotype

Annotation of /trunk/gadget/suits.cc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (view) (download)

1 : agomez 1 #include "prey.h"
2 :     #include "predator.h"
3 :     #include "suits.h"
4 :     #include "mathfunc.h"
5 :     #include "gadget.h"
6 :    
7 :     Suits::~Suits() {
8 :     int i;
9 :     for (i = 0; i < preynames.Size(); i++) {
10 :     delete[] preynames[i];
11 :     delete suitFunction[i];
12 :     delete preCalcSuitability[i];
13 :     }
14 :     }
15 :    
16 :     void Suits::addPrey(const char* preyname, SuitFunc* suitf) {
17 :     preCalcSuitability.resizeBlank(1);
18 :     suitFunction.resize(suitf);
19 :     preynames.resize(new char[strlen(preyname) + 1]);
20 :     strcpy(preynames[preynames.Size() - 1], preyname);
21 :     }
22 :    
23 :     void Suits::deletePrey(int i, Keeper* const keeper) {
24 :     if (preynames.Size() == 0)
25 :     return;
26 :     suitFunction.Delete(i, keeper);
27 :     preynames.Delete(i);
28 :     preCalcSuitability.Delete(i);
29 :     }
30 :    
31 :     void Suits::Initialise(const Predator* const pred) {
32 :     int p;
33 :     for (p = 0; p < preynames.Size(); p++)
34 :     preCalcSuitability[p] = new DoubleMatrix(pred->getLengthGroupDiv()->numLengthGroups(), pred->getPrey(p)->getLengthGroupDiv()->numLengthGroups(), 0.0);
35 :     }
36 :    
37 :     void Suits::Reset(const Predator* const pred, const TimeClass* const TimeInfo) {
38 :     int i, j, p;
39 :    
40 :     for (p = 0; p < preynames.Size(); p++) {
41 :     suitFunction[p]->updateConstants(TimeInfo);
42 :     if (suitFunction[p]->didChange(TimeInfo)) {
43 :     for (i = 0; i < preCalcSuitability[p]->Nrow(); i++) {
44 :     for (j = 0; j < preCalcSuitability[p]->Ncol(i); j++) {
45 :     if (suitFunction[p]->usesPreyLength())
46 :     suitFunction[p]->setPreyLength(pred->getPrey(p)->getLengthGroupDiv()->meanLength(j));
47 :    
48 :     if (suitFunction[p]->usesPredLength())
49 :     suitFunction[p]->setPredLength(pred->getLengthGroupDiv()->meanLength(i));
50 :    
51 :     (*preCalcSuitability[p])[i][j] = suitFunction[p]->calculate();
52 :     }
53 :     }
54 :     }
55 :     }
56 :    
57 :     #ifdef SUIT_SCALE
58 :     //Scaling of suitabilities, so that in each lengthgroup of each predator, the
59 :     //maximum suitability is exactly 1, if any suitability is different from 0.
60 :     double mult;
61 :     for (i = 0; i < pred->getLengthGroupDiv()->numLengthGroups(); i++) {
62 :     mult = 0.0;
63 :     for (p = 0; p < preynames.Size(); p++)
64 :     for (j = 0; j < preCalcSuitability[p]->Ncol(i); j++)
65 :     mult = max((*preCalcSuitability[p])[i][j], mult);
66 :    
67 :     if (!(isZero(mult)))
68 :     for (p = 0; p < preynames.Size(); p++)
69 :     for (j = 0; j < preCalcSuitability[p]->Ncol(i); j++)
70 :     (*preCalcSuitability[p])[i][j] /= mult;
71 :     }
72 :     #endif
73 :     }

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

Powered By FusionForge