ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
Hare_THare.cpp
Go to the documentation of this file.
1 /*
2 *******************************************************************************************************
3 Copyright (c) 2011, Christopher John Topping, University of Aarhus
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without modification, are permitted provided
7 that the following conditions are met:
8 
9 Redistributions of source code must retain the above copyright notice, this list of conditions and the
10 following disclaimer.
11 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
12 the following disclaimer in the documentation and/or other materials provided with the distribution.
13 
14 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
15 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
16 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
17 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
18 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
19 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
21 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22 ********************************************************************************************************
23 */
24 //---------------------------------------------------------------------------
25 
26 #include <cmath>
27 #include <iostream>
28 #include <fstream>
29 #ifdef __UNIX
30 #undef max
31 #endif
32 #include "../Landscape/ls.h"
33 #include "../BatchALMaSS/PopulationManager.h"
34 #include "../Hare/hare_all.h"
35 
36 
37 #include "../BatchALMaSS/BoostRandomGenerators.h"
38 extern boost::variate_generator<base_generator_type&, boost::uniform_real<> > g_rand_uni;
39 
40 
41 //---------------------------------------------------------------------------
42 
43 extern CfgInt cfg_Hare_Recovery_Time;
44 // Physiological life-span
45 extern CfgInt cfg_hare_max_age;
46 extern CfgInt cfg_hare_max_age_var;
47 // extern CfgFloat cfg_Hare_StdKJWalking;
48 // extern CfgFloat cfg_Hare_StdKJForaging;
49 extern CfgInt cfg_hare_escape_dist;
50 extern CfgFloat cfg_Hare_StdSpeedWalking;
51 extern CfgFloat cfg_Hare_StdSpeedRunning;
52 extern CfgFloat cfg_ForageRestingRatio;
53 extern CfgFloat cfg_hare_ExtEff;
54 extern CfgInt cfg_hare_adult_predation;
56 static CfgFloat cfg_hare_lowfatextramort("HARE_LOWFATEXTRAMORT", CFG_CUSTOM, 10.0);
57 static CfgFloat cfg_hare_pesticidedegradationrate("HARE_PESTICIDEDEGRADATIONRATE", CFG_CUSTOM, 0.0);
58 
59 
60 //---------------------------------------------------------------------------
61 // THARE CODE
62 //---------------------------------------------------------------------------
66 THare::THare(int p_x, int p_y,
67  Landscape* p_L, THare_Population_Manager* p_PPM) : TAnimal(p_x, p_y, p_L)
68 {
69  THareInit(p_x, p_y, p_PPM);
70 }
71 //---------------------------------------------------------------------------
72 void THare::THareInit(int p_x, int p_y, THare_Population_Manager* p_PPM)
73 {
74  // The THare constructor - only needs to know about the Hare Population
75  // Manager
78  // Set the lifespan
79  m_Lifespan=cfg_hare_max_age.value()+(random(cfg_hare_max_age_var.value()*2)-cfg_hare_max_age_var.value());
80  // Energetic values - these can be overwritten by the constructor of
81  // descendent classes
82  m_KJRunning=0;
83  m_KJWalking=0;
84  m_KJForaging=0;
87  m_fatReserve=0;
90  //m_in_dispersal = false;
91  //m_TimePerForageSquare= 13 * 13; // 24 squares
92  m_ActivityTime=1440; // In the case of object creation, this cannot be set in the begin step
93  m_foragingenergy=0.001; // a bit more than 0
94  m_peg_x=p_x;
95  m_peg_y=p_y;
98  for (int i=0; i<365; i++) m_expDensity[i]=0;
99  m_DensitySum=0;
100  m_ddindex=0;
101  m_RefNum=p_PPM->GetHareRefNum();
102  m_pesticideInfluenced1 = false;
103  m_pesticide_burden = 0.0;
104  m_pesticidedegradationrate = cfg_hare_pesticidedegradationrate.value(); // default of 0.0 will remove all body burden pesticide at the end of each day
105 }
106 //---------------------------------------------------------------------------
107 
112 {
113 }
114 //---------------------------------------------------------------------------
115 
117 {
118  m_vegPalatability = new double[ tov_Undefined ];
119  // First fill in default value
120  for (int i = 0; i < tov_Undefined; i++) m_vegPalatability[ i ] = 1.0;
121  // Now set any special values
126  m_vegPalatability[ tov_None ] = 0.0;
130  /*
131  m_vegPalatability[tov_FodderBeet] = 1.25;
132  m_vegPalatability[tov_SugarBeet] = 1.25;
133  m_vegPalatability[tov_OFodderBeet] = 1.25;
134  */
135 }
136 //---------------------------------------------------------------------------
137 
139 {
144  return tohs_InitialState;
145 }
146 //---------------------------------------------------------------------------
152 void THare::Running(int a_max_dist)
153 {
154  int dist;
155  bool b;
156  // The length of this loop can cause problems, hence in very small landscapes max_dist has to be small. A minimum distance was not used because this invites infinite looping.
157  do {
158  // Choose a distance......
159  dist=random(a_max_dist);
160  // and see if it is possible to go there in a random direction
161  b=Run(dist, random(8));
162  } while (b==false);
163  // Now adjust our energy balance
167 }
168 //---------------------------------------------------------------------------
173  if (m_MyMum) m_MyMum->ON_YoungKilled(this);
175  m_CurrentStateNo=-1;
176  m_MyMum=NULL;
177  m_StepDone=true;
178 }
179 //---------------------------------------------------------------------------
183 void THare::Walking(int a_dist, int a_direction)
184 {
185  while (!Run(a_dist, a_direction)) {
186  a_direction=random(8);
187  //a_dist=random(500); // This is just for cases like Illumø where it is possible to travel too far in all directions
188  a_dist--; // This is because hares can get stuck otherwise.
189  }
190 }
191 //---------------------------------------------------------------------------
192 
193 bool THare::Run(int a_dist, int a_direction)
194 {
195  // Need to move a_dist in direction a_direction
196  int Width=m_OurPopulationManager->SimW;
197  int Height=m_OurPopulationManager->SimH;
198  int tx=m_Location_x;
199  int ty=m_Location_y;
200  switch(a_direction)
201  {
202  case 0: // North
203  ty=m_Location_y-a_dist;
204  if (ty<0) ty+=Height;
205  break;
206  case 1: // NorthWest
207  // OK, OK I know, I should reduce the distance for the diagonal - but it
208  // costs two multiplications if I do, and this is used a lot
209  ty=m_Location_y-a_dist;
210  tx=m_Location_x+a_dist;
211  if (ty<0) ty+=Height;
212  if (tx>=Width) tx-=Width;
213  break;
214  case 2: // West
215  tx=m_Location_x+a_dist;
216  if (tx>=Width) tx-=Width;
217  break;
218  case 3: // SouthWest
219  ty=m_Location_y+a_dist;
220  tx=m_Location_x+a_dist;
221  if (tx>=Width) tx-=Width;
222  if (ty>=Height) ty-=Height;
223  break;
224  case 4: // South
225  ty=m_Location_y+a_dist;
226  if (ty>=Height) ty-=Height;
227  break;
228  case 5: // SouthEast
229  ty=m_Location_y+a_dist;
230  tx=m_Location_x-a_dist;
231  if (tx<0) tx+=Width;
232  if (ty>=Height) ty-=Height;
233  break;
234  case 6: // East
235  tx=m_Location_x-a_dist;
236  if (tx<0) tx+=Width;
237  break;
238  case 7: // NorthEast
239  ty=m_Location_y-a_dist;
240  tx=m_Location_x-a_dist;
241  if (tx<0) tx+=Width;
242  if (ty<0) ty+=Height;
243  break;
244  default: // No direction
245  break;
246 
247  }
248  // Now just before we do anything, check that we can go to tx,ty
250  switch (habitat) {
251  // Impossible stuff
252  case tole_Building:
253  case tole_Pond:
254  case tole_Freshwater:
255  case tole_River:
256  case tole_Saltwater:
257  case tole_Coast:
258  case tole_BareRock:
259  case tole_UrbanNoVeg:
260  case tole_UrbanPark:
261  case tole_SandDune:
262  case tole_Stream:
263  return false;
264  break;
265  default:
266  m_Location_x=tx;
267  m_Location_y=ty;
268  return true;
269  break;
270  }
271  // I know I can save code by only testing for boundary conditions
272  // at the end, but 50% of the time this will involve an unnecessary test and
273  // speed usually being the problem I think it is better this way
274 }
275 //---------------------------------------------------------------------------
276 
277 void THare::EnergyBalance(TTypeOfActivity a_activity, int dist)
278 {
283  switch (a_activity)
284  {
285  case activity_Resting:
287  break;
288  case activity_Running:
289  // Note here it is the fatReserve that is altered
290  // This is because this activity could be called at anytime, and we
291  // do not know if m_TodaysEnergy is set to anything sensible. fatReserve is
292  // always sensible though. Note this will potentially influence behaviour
293  // if running causes a low fatReserve.
294  m_fatReserve-=dist*m_KJRunning; // dist in metres
295  break;
296  case activity_Dispersal:
297  m_TodaysEnergy-=dist*m_KJWalking; // dist in metres
298  break;
299  case activity_Walking:
300  m_TodaysEnergy-=dist*m_KJWalking; // dist in metres
301  break;
302  case activity_Foraging:
303  m_TodaysEnergy-=dist*m_KJForaging; // dist in minutes
304  // Checking code
306  break;
307  default:
308  m_OurLandscape->Warn("THare::EnergyBalance - unknown activity",NULL);
309  exit(1);
310  }
311 }
312 //---------------------------------------------------------------------------
313 
314 void THare::TimeBudget(TTypeOfActivity a_activity, int dist)
315 {
319  switch (a_activity)
320  {
321  case activity_Resting:
322  m_ActivityTime-=dist; // dist is in time here (minutes)
323  break;
324  case activity_Running:
325  m_ActivityTime-=(int)(dist/m_SpeedRunning); // dist in metres
326  break;
327  case activity_Walking:
328  m_ActivityTime-=(int)(dist/m_SpeedWalking); // dist in metres
329  break;
330  case activity_Foraging:
331  m_ActivityTime-=dist; // dist in minutes
332  break;
333  case activity_Dispersal:
334  m_ActivityTime -= (int)(dist / m_SpeedWalking); // dist in metres
335  break;
336  case activity_Recovery:
337  m_ActivityTime-=dist; // dist in minutes
338  break;
339  default:
340  m_OurLandscape->Warn("THare::TimeBudget - unknown activity",NULL);
341  exit(1);
342  }
343 }
344 //---------------------------------------------------------------------------
345 
349 double THare::GetRMR() {
351 }
352 //---------------------------------------------------------------------------
353 
358  // This is only called by adult states, so don't call it from any other hare class
359 #ifdef __SIZERELATEDDEATH2
360  if (m_weight<cfg_hare_minimum_breeding_weight.value()) test*=2;
361 #endif
362 #ifdef __LOWFATRELATEDDEATH
363  if (m_Age>365) if (m_fatReserve<1.0) {
364  test= (int)(cfg_hare_lowfatextramort.value() * test); // Increase the chance of dying if fat reserves drop to low levels
365  }
366 #endif
368  return false;
369 }
370 //---------------------------------------------------------------------------
371 
377 {
378  switch (event)
379  {
380  case cattle_out:
381  case pigs_out:
382  // In these cases we want to move.
383  Running(cfg_hare_escape_dist.value());
384  return true; // This will ensure that the next event checked is sensible.
385  default:
386  break;
387  }
388  return false;
389 }
390 //---------------------------------------------------------------------------
tole_UrbanNoVeg
Definition: tole_declaration.h:78
cfg_hare_ExtEff
CfgFloat cfg_hare_ExtEff
tole_Saltwater
Definition: tole_declaration.h:66
THare::m_vegPalatability
static double * m_vegPalatability
Will hold and array of palatability for hare for each tov type. Most are 1, but unpalatable vegetatio...
Definition: Hare_all.h:318
THare_Population_Manager
The class that handles all the population lists for hares.
Definition: Hare_all.h:529
tole_Building
Definition: tole_declaration.h:62
tole_Freshwater
Definition: tole_declaration.h:64
Landscape::SupplyElementType
TTypesOfLandscapeElement SupplyElementType(int a_polyref)
Definition: Landscape.h:1110
activity_Running
Definition: Hare_all.h:91
THare::m_pesticidedegradationrate
double m_pesticidedegradationrate
State variable used to hold the daily degredation rate of the pesticide in the body.
Definition: Hare_all.h:306
THare::m_SpeedWalking
double m_SpeedWalking
m/min speed of walking per kg hare
Definition: Hare_all.h:248
tov_Undefined
Definition: tov_declaration.h:114
THare::m_Lifespan
int m_Lifespan
Physiolocal lifespan, assuming nothing else kills the hare (unlikely to reach this age)
Definition: Hare_all.h:198
tole_BareRock
Definition: tole_declaration.h:75
THare_Population_Manager::m_AdultMortRate
double m_AdultMortRate
Input variable - Adult mortality rate.
Definition: Hare_all.h:734
THare::WasPredated
virtual bool WasPredated()
Test for predation.
Definition: Hare_THare.cpp:357
TAnimal::m_OurLandscape
Landscape * m_OurLandscape
Definition: PopulationManager.h:229
THare_Population_Manager::GetHareRefNum
int GetHareRefNum()
Get the next ID number available.
Definition: Hare_all.h:548
activity_Recovery
Definition: Hare_all.h:95
THare::m_ActivityTime
int m_ActivityTime
Minutes of potential activity time per day.
Definition: Hare_all.h:203
Hare_Female::ON_YoungKilled
void ON_YoungKilled(THare *a_young)
A leveret has been killed.
Definition: Hare_all.cpp:3850
THare::~THare
virtual ~THare()
Destructor.
Definition: Hare_THare.cpp:111
THare::m_OurPopulationManager
THare_Population_Manager * m_OurPopulationManager
Pointer to the hare population manager.
Definition: Hare_all.h:194
cfg_hare_escape_dist
CfgInt cfg_hare_escape_dist
THare::loadVegPalatability
void loadVegPalatability(void)
Loads static member m_vegPalatability with data.
Definition: Hare_THare.cpp:116
cfg_hare_max_age_var
CfgInt cfg_hare_max_age_var
THare::m_KJForaging
double m_KJForaging
KJ/m cost of foraging per kg hare.
Definition: Hare_all.h:238
THare::GetRMR
double GetRMR()
Get todays RMR.
Definition: Hare_THare.cpp:349
tov_OCarrots
Definition: tov_declaration.h:43
THare::st_Dispersal
virtual TTypeOfHareState st_Dispersal()
Base implementation only - reimplemented.
Definition: Hare_THare.cpp:138
Population_Manager::SimW
int SimW
Definition: PopulationManager.h:511
tole_Stream
Definition: tole_declaration.h:89
THare::THareInit
void THareInit(int p_x, int p_y, THare_Population_Manager *p_PPM)
Object Initiation.
Definition: Hare_THare.cpp:72
tohs_DestroyObject
Definition: Hare_all.h:80
Landscape
The landscape class containing all environmental and topographical data.
Definition: Landscape.h:112
cattle_out
Definition: treatment.h:83
THare::m_KJWalking
double m_KJWalking
KJ/m cost of walking per kg hare.
Definition: Hare_all.h:233
THare::m_fatReserve
double m_fatReserve
State variable - the energy reserve of the hare.
Definition: Hare_all.h:213
THare::m_lastYearsDensity
int m_lastYearsDensity
State variable used in alternative density-dependent configurations.
Definition: Hare_all.h:276
THare::m_experiencedDensity
int m_experiencedDensity
State variable used in alternative density-dependent configurations.
Definition: Hare_all.h:271
THare::m_KJRunning
double m_KJRunning
KJ/m cost of running per kg hare.
Definition: Hare_all.h:228
tole_Pond
Definition: tole_declaration.h:101
tov_PotatoesIndustry
Definition: tov_declaration.h:50
activity_Foraging
Definition: Hare_all.h:92
cfg_hare_lowfatextramort
static CfgFloat cfg_hare_lowfatextramort("HARE_LOWFATEXTRAMORT", CFG_CUSTOM, 10.0)
TAnimal::m_Location_y
int m_Location_y
Definition: PopulationManager.h:228
THare::m_RefNum
int m_RefNum
Unique hare reference number, also functions as sex flag.
Definition: Hare_all.h:265
tov_PlantNursery
Definition: tov_declaration.h:66
cfg_ForageRestingRatio
CfgFloat cfg_ForageRestingRatio
tov_Carrots
Definition: tov_declaration.h:31
THare::m_pesticideInfluenced1
bool m_pesticideInfluenced1
Flag to indicate pesticide effects (e.g. can be used for endocrine distruptors with delayed effects u...
Definition: Hare_all.h:311
THare::Walking
void Walking(int a_dist, int a_direction)
Walking.
Definition: Hare_THare.cpp:183
TAnimal
The base class for all ALMaSS animal classes.
Definition: PopulationManager.h:205
activity_Dispersal
Definition: Hare_all.h:94
THare_Population_Manager::GetRMR
double GetRMR(int a_age, double a_size)
Returns the RMR given a specific age and mass.
Definition: Hare_all.cpp:1034
tole_UrbanPark
Definition: tole_declaration.h:79
THare::m_SpeedRunning
double m_SpeedRunning
m/min speed of running per kg hare
Definition: Hare_all.h:243
THare::m_ddindex
int m_ddindex
State variable used in alternative density-dependent configurations.
Definition: Hare_all.h:281
tov_Potatoes
Definition: tov_declaration.h:50
g_rand_uni
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
THare::m_TodaysEnergy
double m_TodaysEnergy
State variable - the amount of energy available today, can be in deficit.
Definition: Hare_all.h:218
cfg_Hare_Recovery_Time
CfgInt cfg_Hare_Recovery_Time
TALMaSSObject::m_StepDone
bool m_StepDone
Indicates whether the iterative step code is done for this timestep.
Definition: PopulationManager.h:118
THare::EnergyBalance
void EnergyBalance(TTypeOfActivity a_activity, int dist)
Adjust energy balance for an activity.
Definition: Hare_THare.cpp:277
THare::m_foragingenergy
double m_foragingenergy
Energy obtained from foraging/feeding.
Definition: Hare_all.h:252
tohs_InitialState
Definition: Hare_all.h:71
tole_SandDune
Definition: tole_declaration.h:81
THare::st_Dying
void st_Dying()
Tidy up before removing the object on death.
Definition: Hare_THare.cpp:172
tole_River
Definition: tole_declaration.h:65
THare::m_expDensity
int m_expDensity[365]
State variable used in alternative density-dependent configurations.
Definition: Hare_all.h:286
THare::m_DensitySum
int m_DensitySum
State variable used in alternative density-dependent configurations.
Definition: Hare_all.h:291
cfg_hare_adult_predation
CfgInt cfg_hare_adult_predation
THare::OnFarmEvent
bool OnFarmEvent(FarmToDo event)
Do we require a response to a farm event.
Definition: Hare_THare.cpp:372
THare::m_pesticide_burden
double m_pesticide_burden
State variable used to hold the current body-burden of pesticide.
Definition: Hare_all.h:301
THare::m_Age
int m_Age
State variale - hare age.
Definition: Hare_all.h:170
cfg_hare_minimum_breeding_weight
CfgInt cfg_hare_minimum_breeding_weight
THare::m_CurrentHState
TTypeOfHareState m_CurrentHState
Defines the current activity.
Definition: Hare_all.h:165
Population_Manager::SimH
int SimH
Definition: PopulationManager.h:511
TTypeOfActivity
TTypeOfActivity
Enumerator for hare activities.
Definition: Hare_all.h:88
THare::THare
THare(int p_x, int p_y, Landscape *p_L, THare_Population_Manager *p_PPM)
Constructor.
Definition: Hare_THare.cpp:66
THare::m_StarvationDays
int m_StarvationDays
State variable - the number of consecutive days in negative energy balance.
Definition: Hare_all.h:208
TTypesOfLandscapeElement
TTypesOfLandscapeElement
Definition: tole_declaration.h:36
cfg_hare_pesticidedegradationrate
static CfgFloat cfg_hare_pesticidedegradationrate("HARE_PESTICIDEDEGRADATIONRATE", CFG_CUSTOM, 0.0)
tov_NoGrowth
Definition: tov_declaration.h:38
tov_OPotatoes
Definition: tov_declaration.h:44
cfg_hare_max_age
CfgInt cfg_hare_max_age
THare::GetTotalWeight
double GetTotalWeight()
Provide the wet weight of the hare.
Definition: Hare_all.h:370
THare::Running
virtual void Running(int a_max_dist)
Run.
Definition: Hare_THare.cpp:152
THare::m_MyMum
Hare_Female * m_MyMum
Pointer to the hare's mum.
Definition: Hare_all.h:190
activity_Walking
Definition: Hare_all.h:93
THare::m_peg_y
int m_peg_y
peg y-coordinate
Definition: Hare_all.h:260
cfg_Hare_StdSpeedWalking
CfgFloat cfg_Hare_StdSpeedWalking
THare::m_weight
double m_weight
State variale - hare weight g.
Definition: Hare_all.h:180
THare::Run
bool Run(int a_dist, int a_direction)
Run a distance in a direction.
Definition: Hare_THare.cpp:193
FarmToDo
FarmToDo
Definition: treatment.h:31
TALMaSSObject::m_CurrentStateNo
int m_CurrentStateNo
The basic state number for all objects - '-1' indicates death.
Definition: PopulationManager.h:116
pigs_out
Definition: treatment.h:84
THare::TimeBudget
void TimeBudget(TTypeOfActivity a_activity, int dist)
Adjust time budger for an activity.
Definition: Hare_THare.cpp:314
Landscape::Warn
void Warn(std::string a_msg1, std::string a_msg2)
Definition: Landscape.h:1579
TTypeOfHareState
TTypeOfHareState
Enumerator for hare behavioural states.
Definition: Hare_all.h:69
TAnimal::m_Location_x
int m_Location_x
Definition: PopulationManager.h:225
tole_Coast
Definition: tole_declaration.h:67
THare::m_peg_x
int m_peg_x
peg x-coordinate
Definition: Hare_all.h:256
cfg_Hare_StdSpeedRunning
CfgFloat cfg_Hare_StdSpeedRunning
activity_Resting
Definition: Hare_all.h:90
tov_None
Definition: tov_declaration.h:39