Goose Management Model ODdox  1.02
GooseBarnacle_All.cpp
Go to the documentation of this file.
1 /*
2 *******************************************************************************************************
3 Copyright (c) 2013, 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 */
35 #include <iostream>
36 #include <fstream>
37 #include <list>
38 #include <vector>
39 #include <string>
40 #include "../Landscape/ls.h"
41 #include "../BatchALMaSS/PopulationManager.h"
42 #include "GooseMemoryMap.h"
43 #include "Goose_Base.h"
44 #include "../BatchALMaSS/CurveClasses.h"
45 #include "../Hunters/Hunters_all.h"
47 #include "GooseBarnacle_All.h"
48 #include "../BatchALMaSS/BoostRandomGenerators.h"
49 
51 extern boost::variate_generator<base_generator_type&, boost::uniform_real<> > g_rand_uni;
53 extern MapErrorMsg *g_msg;
54 
55 using namespace std;
56 
63 
64 //*******************************************************************************************************
65 //**********************************Goose_Barnacle_Base**************************************************
66 //*******************************************************************************************************
67 
68 Goose_Barnacle_Base::Goose_Barnacle_Base( Landscape* p_L, Goose_Population_Manager* p_NPM, double a_weight, bool a_sex, APoint a_roost ) : Goose_Base( p_L, p_NPM, a_weight, a_sex, a_roost ) {
69  Init(p_NPM, a_weight, a_sex, a_roost);
70  }
71 
72 void Goose_Barnacle_Base::Init(Goose_Population_Manager* p_NPM, double a_weight, bool a_sex, APoint a_roost) {
73  Goose_Base::Init(p_NPM, a_weight, a_sex, a_roost);
78  m_myspecies = gs_Barnacle;
79  double daylightprop = m_OurLandscape->SupplyDaylightProp();
80  double nighttimeprop = m_OurLandscape->SupplyNightProp();
81  double multiplier = cfg_goose_daytime_BMR_multiplier.value() * daylightprop + cfg_goose_nighttime_BMR_multiplier.value() * nighttimeprop;
84 }
85 
86 void Goose_Barnacle_Base::ReInit(Landscape* p_L, Goose_Population_Manager* p_NPM, double a_weight, bool a_sex, APoint a_roost) {
87  Goose_Base::ReInit(p_L, p_NPM, a_weight, a_sex, a_roost);
88  Init(p_NPM, a_weight, a_sex, a_roost);
89 }
90 //-------------------------------------------------------------------------------------------------------
91 
93 {
94  ;
95 }
96 //-------------------------------------------------------------------------------------------------------
97 
99 {
103  if (m_myForageIndex != -1)
104  {
106  }
107  m_myForageIndex = -1;
113  {
114  ChangeRoost();
115  }
116  FlyTo(m_MyRoost.m_x, m_MyRoost.m_y);
117  return togs_Roost;
118 }
119 //--------------------------------------------------------------------------------------------------------
120 
122 {
127  APoint pt;
128  if (m_MyRoost.m_x == m_Location_x && m_MyRoost.m_y == m_Location_y)
129  {
130  pt.m_x = (int)((g_rand_uni() * m_GooseForageDistX2[gs_Barnacle]) - m_GooseForageDist[gs_Barnacle] + m_MyRoost.m_x);
131  pt.m_y = (int)((g_rand_uni() * m_GooseForageDistX2[gs_Barnacle]) - m_GooseForageDist[gs_Barnacle] + m_MyRoost.m_y);
132  }
133  else {
134  pt.m_x = (int)((g_rand_uni() * m_GooseFieldForageDistX2[gs_Barnacle]) - m_GooseFieldForageDist[gs_Barnacle] + m_Location_x);
135  pt.m_y = (int)((g_rand_uni() * m_GooseFieldForageDistX2[gs_Barnacle]) - m_GooseFieldForageDist[gs_Barnacle] + m_Location_y);
136  }
137 
138  m_OurLandscape->CorrectCoordsPointNoWrap(pt);
141  return pt;
142 }
143 //--------------------------------------------------------------------------------------------------------
144 
145 //*******************************************************************************************************
146 //**********************************Goose_Barnacle_FamilyGroup*********************************************
147 //*******************************************************************************************************
149  int a_groupsize, APoint a_roost) : Goose_Barnacle_Base(p_L, p_NPM, a_weight, a_sex, a_roost)
150 {
151  Init(p_NPM, a_weight, a_sex, a_groupsize, a_roost);
152 }
153 //-------------------------------------------------------------------------------------------------------
154 void Goose_Barnacle_FamilyGroup::Init(Goose_Population_Manager* p_NPM, double a_weight, bool a_sex, int a_groupsize, APoint a_roost)
155 {
156  Goose_Barnacle_Base::Init(p_NPM, a_weight, a_sex, a_roost);
160  m_groupsize = a_groupsize;
162 }
163 //-------------------------------------------------------------------------------------------------------
164 
165 void Goose_Barnacle_FamilyGroup::ReInit(Landscape* p_L, Goose_Population_Manager* p_NPM, double a_weight, bool a_sex, int a_groupsize, APoint a_roost)
166 {
167  Goose_Barnacle_Base::ReInit(p_L, p_NPM, a_weight, a_sex, a_roost);
168  Init(p_NPM, a_weight, a_sex, a_groupsize, a_roost);
169 }
171 {
172  ;
173 }
174 //-------------------------------------------------------------------------------------------------------
175 
177 {
178  if (m_StepDone || m_CurrentStateNo == -1) return;
179  switch (CurrentGState)
180  {
181  case togs_InitialState: // Initial state always starts by setting the behaviour to togs_Roost
183  break;
186  m_StepDone = true;
187  break;
188  case togs_Forage:
190  m_StepDone = true;
191  break;
192  case togs_ToRoost:
194  m_StepDone = true;
195  break;
196  case togs_Roost:
198  m_StepDone = true;
199  break;
200  case togs_Emigrate:
202  break;
203  case togs_Die:
204  st_Dying(); // No return value - no behaviour after this
205  m_StepDone=true;
206  break;
207  default:
208  m_OurLandscape->Warn("Goose_Barnacle_FamilyGroup::Step()","unknown state - default");
209  exit(1);
210  }
211 }
212 //-------------------------------------------------------------------------------------------------------
213 //*******************************************************************************************************
214 
215 //*******************************************************************************************************
216 //**********************************Goose_Barnacle_NonBreeder**************************************************
217 //*******************************************************************************************************
218 Goose_Barnacle_NonBreeder::Goose_Barnacle_NonBreeder(Landscape* p_L, Goose_Population_Manager* p_NPM, double a_weight, bool a_sex, APoint a_roost) : Goose_Barnacle_Base(p_L, p_NPM, a_weight, a_sex, a_roost)
219 {
220  Init(p_NPM, a_weight, a_sex, a_roost);
221 }
222 //-------------------------------------------------------------------------------------------------------
223 void Goose_Barnacle_NonBreeder::Init(Goose_Population_Manager* p_NPM, double a_weight, bool a_sex, APoint a_roost) {
224  Goose_Barnacle_Base::Init(p_NPM, a_weight, a_sex, a_roost);
228  m_groupsize = 1;
230 }
231 //-------------------------------------------------------------------------------------------------------
232 void Goose_Barnacle_NonBreeder::ReInit(Landscape* p_L, Goose_Population_Manager* p_NPM, double a_weight, bool a_sex, APoint a_roost) {
233  Goose_Barnacle_Base::ReInit(p_L, p_NPM, a_weight, a_sex, a_roost);
234  Init(p_NPM, a_weight, a_sex, a_roost);
235 }
236 //-------------------------------------------------------------------------------------------------------
237 
239 {
240  ;
241 }
242 //-------------------------------------------------------------------------------------------------------
243 
245 {
246  if (m_StepDone || m_CurrentStateNo == -1) return;
247  switch (CurrentGState)
248  {
249  case togs_InitialState: // Initial state always starts by setting the behaviour to togs_Roost
251  break;
255  m_StepDone = true;
256  break;
257  case togs_Forage:
259  m_StepDone = true;
260  break;
261  case togs_ToRoost:
263  m_StepDone = true;
264  break;
265  case togs_Roost:
267  m_StepDone = true;
268  break;
269  case togs_Emigrate:
271  break;
272  case togs_Die:
273  st_Dying(); // No return value - no behaviour after this
274  m_StepDone = true;
275  break;
276  default:
277  m_OurLandscape->Warn("Goose_Barnacle_NonBreeder::Step()","unknown state - default");
278  exit(1);
279  }
280 }
281 //-------------------------------------------------------------------------------------------------------
282 
284 {
291  if (m_myForageIndex != -1)
292  {
294  }
295  if (--m_groupsize < 1)
296  {
297  delete m_MyMemory; // this is reinitisalised in the object pool.
298  TAnimal::KillThis();
299  }
300 }
301 //-------------------------------------------------------------------------------------------------------
302 //*******************************************************************************************************
303 
304 
Goose_Barnacle_FamilyGroup::Goose_Barnacle_FamilyGroup
Goose_Barnacle_FamilyGroup(Landscape *p_L, Goose_Population_Manager *p_NPM, double a_weight, bool a_sex, int a_groupsize, APoint a_roost)
Goose_Barnacle_FamilyGroup constructor.
Definition: GooseBarnacle_All.cpp:148
togs_Roost
Definition: Goose_Base.h:80
Goose_Barnacle_FamilyGroup::~Goose_Barnacle_FamilyGroup
virtual ~Goose_Barnacle_FamilyGroup()
Goose_Barnacle_FamilyGroup destructor.
Definition: GooseBarnacle_All.cpp:170
Goose_Base::st_Roost
TTypeOfGoose_BaseState st_Roost()
Roosting until next forage or next morning.
Definition: Goose_Base.cpp:550
Goose_Barnacle_FamilyGroup::Init
void Init(Goose_Population_Manager *p_NPM, double a_weight, bool a_sex, int a_groupsize, APoint a_roost)
Intitialise object.
Definition: GooseBarnacle_All.cpp:154
Goose_Base::m_myForageIndex
int m_myForageIndex
Temporary storage for a forage location index - this is a speed optimisation.
Definition: Goose_Base.h:291
Goose_Base::m_DEB
double m_DEB
The daily energy budget excluding flying (kJ)
Definition: Goose_Base.h:191
Goose_Base::m_groupsize
int m_groupsize
The size of the group this bird represents.
Definition: Goose_Base.h:171
togs_Die
Definition: Goose_Base.h:81
togs_ToRoost
Definition: Goose_Base.h:79
Goose_Barnacle_NonBreeder::Init
void Init(Goose_Population_Manager *p_NPM, double a_weight, bool a_sex, APoint a_roost)
Intitialise object.
Definition: GooseBarnacle_All.cpp:223
Goose_Base::m_GooseFieldForageDist
static double m_GooseFieldForageDist[gs_foobar]
The maximum distance travelled from roost to forage sites for each species of goose (m)
Definition: Goose_Base.h:247
Goose_Barnacle_FamilyGroup::Step
virtual void Step(void)
The Goose_Barnacle_FamilyGroup Step.
Definition: GooseBarnacle_All.cpp:176
Goose_Barnacle_FamilyGroup::KillThis
virtual void KillThis(void)
The FamilyGroup KillThis must be overridden for families.
Definition: GooseBarnacle_All.cpp:283
Goose_Base::st_ChooseForageLocation
TTypeOfGoose_BaseState st_ChooseForageLocation(void)
Selects a forage location based on past memory, or initiates an exploration.
Definition: Goose_Base.cpp:258
Goose_Base::ReInit
void ReInit(Landscape *p_L, Goose_Population_Manager *p_NPM, double a_weight, bool a_sex, APoint a_roost)
ReInit for object pool.
Definition: Goose_Base.cpp:168
Goose_Barnacle_Base::ChooseHopLoc
virtual APoint ChooseHopLoc()
Pick a hop location point within a_dist meters - must be overridden by descendent classes.
Definition: GooseBarnacle_All.cpp:121
togs_ChooseForageLocation
Definition: Goose_Base.h:77
Goose_Barnacle_Base::st_ToRoost
TTypeOfGoose_BaseState st_ToRoost()
Return to roost and assess whether to forage again that day.
Definition: GooseBarnacle_All.cpp:98
cfg_goose_nighttime_BMR_multiplier
CfgFloat cfg_goose_nighttime_BMR_multiplier
To calculate daily energy budget. This is the multiple of BMR spent during nighttime.
g_rand_uni
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
A random number generator (0-1)
g_msg
MapErrorMsg * g_msg
This pointer provides access the to the internal ALMaSS error message system.
Definition: maperrormsg.cpp:41
Goose_Base::m_GooseMaxAppetiteScaler
static double m_GooseMaxAppetiteScaler
Scaler to determine the max kJ possible to eat per day based on non-energy reserve weight.
Definition: Goose_Base.h:259
Goose_Base::m_GooseForageDistX2
static double m_GooseForageDistX2[gs_foobar]
Double the maximum distance travelled from roost to forage sites for each species of goose (m) - this...
Definition: Goose_Base.h:243
Landscape
The landscape class containing all environmental and topographical data.
Definition: landscape.h:112
Goose_Base::m_myspecies
GooseSpecies m_myspecies
Holds goose species.
Definition: Goose_Base.h:159
Goose_Barnacle_FamilyGroup::ReInit
void ReInit(Landscape *p_L, Goose_Population_Manager *p_NPM, double a_weight, bool a_sex, int a_groupsize, APoint a_roost)
ReInit for object pool.
Definition: GooseBarnacle_All.cpp:165
MapErrorMsg
Definition: maperrormsg.h:43
Goose_Barnacle_Base::Goose_Barnacle_Base
Goose_Barnacle_Base(Landscape *p_L, Goose_Population_Manager *p_NPM, double a_weight, bool a_sex, APoint a_roost)
Goose_Barnacle_Base constructor.
Definition: GooseBarnacle_All.cpp:68
Goose_Base::m_DailyMaxAppetite
double m_DailyMaxAppetite
The daily max kJ possible to get as intake.
Definition: Goose_Base.h:195
Goose_Barnacle_NonBreeder::~Goose_Barnacle_NonBreeder
virtual ~Goose_Barnacle_NonBreeder()
Goose_Barnacle_NonBreeder destructor.
Definition: GooseBarnacle_All.cpp:238
Goose_Base::Init
void Init(Goose_Population_Manager *p_NPM, double a_weight, bool a_sex, APoint a_roost)
Intitialise object.
Definition: Goose_Base.cpp:111
Goose_Base::CurrentGState
TTypeOfGoose_BaseState CurrentGState
Variable to record current behavioural state.
Definition: Goose_Base.h:147
Goose_Barnacle_NonBreeder::Goose_Barnacle_NonBreeder
Goose_Barnacle_NonBreeder(Landscape *p_L, Goose_Population_Manager *p_NPM, double a_weight, bool a_sex, APoint a_roost)
Goose_Barnacle_NonBreeder constructor.
Definition: GooseBarnacle_All.cpp:218
Goose_Base::st_Dying
void st_Dying(void)
Behavioural state dying.
Definition: Goose_Base.cpp:251
Goose_Population_Manager::GetThermalCosts
double GetThermalCosts(GooseSpecies a_goose)
Get daily thermal costs const.
Definition: Goose_Population_Manager.h:556
gst_BarnacleNonBreeder
Definition: Goose_Base.h:63
Goose_Base::m_GooseForageDist
static double m_GooseForageDist[gs_foobar]
The maximum distance travelled from roost to forage sites for each species of goose (m)
Definition: Goose_Base.h:239
Goose_Barnacle_Base::~Goose_Barnacle_Base
virtual ~Goose_Barnacle_Base()
Goose_Barnacle_Base destructor.
Definition: GooseBarnacle_All.cpp:92
Goose_Barnacle_NonBreeder::Step
virtual void Step(void)
The Goose_Barnacle_NonBreeder Step.
Definition: GooseBarnacle_All.cpp:244
Goose_Base::m_MyMemory
GooseMemoryMap * m_MyMemory
The Goose Memory.
Definition: Goose_Base.h:299
Goose_Population_Manager
The class to handle all goose population related matters.
Definition: Goose_Population_Manager.h:392
Goose_Base::On_Migrate
void On_Migrate(TTypeOfLeaveReason a_leavereason)
The goose is told to leave the simulation area (poss due to bad weather)
Definition: Goose_Base.cpp:722
cfg_goose_daytime_BMR_multiplier
CfgFloat cfg_goose_daytime_BMR_multiplier
To calculate daily energy budget. This is the multiple of BMR spent during daytime.
tolr_migration
Definition: Goose_Base.h:104
GooseMemoryMap.h
Header file for the Goose Memory Map and associated classes.
togs_InitialState
Definition: Goose_Base.h:76
CfgFloat::value
double value(void)
Definition: configurator.h:118
gst_BarnacleFamilyGroup
Definition: Goose_Base.h:62
Goose_Base::FlyTo
void FlyTo(int a_x, int a_y)
The goose flys to the location specified by a_x, a_y.
Definition: Goose_Base.cpp:409
Goose_Base::m_BMR
double m_BMR
The daily BMR.
Definition: Goose_Base.h:187
Goose_Base::EvaluateForageToHopLoc
void EvaluateForageToHopLoc(APoint a_HopLoc)
Do a forage evaluation from current location to a_HopLoc.
Definition: Goose_Base.cpp:593
Goose_Base.h
Goose_Base.h This is the header file for the goose base class
Goose_Base
A class to describe the goose base.
Definition: Goose_Base.h:131
Goose_Base::st_Forage
TTypeOfGoose_BaseState st_Forage()
Behavioural forage.
Definition: Goose_Base.cpp:433
CfgFloat
Double configurator entry class.
Definition: configurator.h:106
Goose_Base::m_myGooseSpeciesType
GooseSpeciesType m_myGooseSpeciesType
Holds the goose species type.
Definition: Goose_Base.h:163
Goose_Base::m_OurPopulationManager
Goose_Population_Manager * m_OurPopulationManager
This is a time saving pointer to the correct population manager object.
Definition: Goose_Base.h:151
Goose_Base::m_GooseFieldForageDistX2
static double m_GooseFieldForageDistX2[gs_foobar]
Double the maximum distance travelled from roost to forage sites for each species of goose (m) - this...
Definition: Goose_Base.h:251
TTypeOfGoose_BaseState
TTypeOfGoose_BaseState
Definition: Goose_Base.h:74
Goose_Population_Manager::RemoveGeeseFromForageLocation
void RemoveGeeseFromForageLocation(GooseSpeciesType a_type, int a_index, int a_number)
Removes a goose or geese to the forage location - requires an index.
Definition: Goose_Population_Manager.cpp:1812
Goose_Barnacle_Base::Init
void Init(Goose_Population_Manager *p_NPM, double a_weight, bool a_sex, APoint a_roost)
Intitialise object.
Definition: GooseBarnacle_All.cpp:72
Goose_Barnacle_Base::ReInit
void ReInit(Landscape *p_L, Goose_Population_Manager *p_NPM, double a_weight, bool a_sex, APoint a_roost)
ReInit for object pool.
Definition: GooseBarnacle_All.cpp:86
togs_Emigrate
Definition: Goose_Base.h:82
Goose_Barnacle_Base
A class to describe the Barnacle goose base.
Definition: GooseBarnacle_All.h:46
cfg_goose_roostchangechance
CfgFloat cfg_goose_roostchangechance
Chance of changing roost.
Goose_Barnacle_Base::ChangeRoost
virtual void ChangeRoost()
Find the closest roost.
Definition: GooseBarnacle_All.h:65
Goose_Base::m_MyRoost
APoint m_MyRoost
The current roost location.
Definition: Goose_Base.h:167
togs_Forage
Definition: Goose_Base.h:78
Goose_Population_Manager.h
Goose_Population_Manager.h This is the header file for the goose population manager class
Goose_Barnacle_NonBreeder::ReInit
void ReInit(Landscape *p_L, Goose_Population_Manager *p_NPM, double a_weight, bool a_sex, APoint a_roost)
ReInit for object pool.
Definition: GooseBarnacle_All.cpp:232
GooseBarnacle_All.h
BarnacleGoose_All.h This is the header file for the greylag goose classes