Goose Management Model ODdox  1.02
GooseMemoryMap.h
Go to the documentation of this file.
1 
2 
5 /*
6 *******************************************************************************************************
7 Copyright (c) 2013, Christopher John Topping, University of Aarhus
8 All rights reserved.
9 
10 Redistribution and use in source and binary forms, with or without modification, are permitted provided
11 that the following conditions are met:
12 
13 Redistributions of source code must retain the above copyright notice, this list of conditions and the
14 following disclaimer.
15 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
16 the following disclaimer in the documentation and/or other materials provided with the distribution.
17 
18 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
19 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
20 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
21 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 ********************************************************************************************************
27 */
28 
29 
30 //---------------------------------------------------------------------------
31 #ifndef goosememorymapH
32 #define goosememorymapH
33 //----------------------------------------------------------------------------
34 
35 #define __DEBUG_GOOSE
36 
37 
38 class Goose_Base;
39 
42 {
43 public:
45  int m_age;
47  int m_x;
49  int m_y;
53  double m_grain;
55  double m_maize;
57  double m_grazing;
61  double m_threat;
63  double m_score;
66 
67 // Methods
70  m_age = 0; m_x = -1; m_y = -1; m_polygonid = -1, m_threat = 0, m_grain = 0; m_maize = 0.0; m_grazing = 0.0; m_foodresource = 0.0; m_infinitememorystop = 0;
71  }
73  bool operator<(const GooseMemoryLocation& gml)
74  {
75  return m_polygonid < gml.m_polygonid;
76  }
78  void CalcScore(int a_dist, double a_flightcost, int a_expectedforagingtime)
79  {
80  double cost = a_dist * a_flightcost;
81  double score = (m_foodresource * a_expectedforagingtime) - cost;
82  m_score = score * (1 - m_threat);
83  }
85  bool ShouldDelete() { return (m_age > m_infinitememorystop); }
86 
87  //-------------------------------------------------------------------------------------------------------
88 
89 };
90 //----------------------------------------------------------------------------
91 
94 {
95 protected:
103  std::vector<GooseMemoryLocation> m_memorylocations;
104 public:
107  GooseMemoryMap(Goose_Base* a_owner);
112  }
116  void MemAdd(GooseMemoryLocation a_gml);
117 
122  bool MemDel(int a_polyid);
123 
129  bool ChangeAddFoodRes(int a_polyid, double a_foodres);
130 
136  bool ChangeAddThreat(int a_polyid, double a_threat);
137 
143  bool ChangeMultFoodRes(int a_polyid, double a_foodres);
144 
152  bool ChangeSetFoodRes(int a_polyid, double a_grain, double a_maize, double a_grazing);
153 
159  bool ChangeMultThreat(int a_polyid, double a_threat);
160 
165  double GetFoodRes( int a_polyid );
166 
171  double GetThreat( int a_polyid );
172 
177 
184  double CalcScore(int a_dist, double a_foodresource, double a_threat);
185 
190  bool IsKnownArea( int a_polyid );
191 
193  void DecayAllMemory();
197  double GetTotalThreats( void );
201  void ClearAllMemory(void);
202 protected:
207  void GooseMemoryError(std::string a_str, int a_value);
208 };
209 //----------------------------------------------------------------------------
210 
211 
212 #endif
GooseMemoryMap::m_myOwner
Goose_Base * m_myOwner
pointer to the owner
Definition: GooseMemoryMap.h:97
GooseMemoryMap::ChangeAddFoodRes
bool ChangeAddFoodRes(int a_polyid, double a_foodres)
Add to food at a memory location.
Definition: GooseMemoryMap.cpp:105
GooseMemoryMap::MemDel
bool MemDel(int a_polyid)
Delete a memory location.
Definition: GooseMemoryMap.cpp:87
GooseMemoryMap::m_expectedforagingtime
int m_expectedforagingtime
the time in minutes a goose expects to be able to forage when evaluating cost benefit of flying to a ...
Definition: GooseMemoryMap.h:101
GooseMemoryLocation::ShouldDelete
bool ShouldDelete()
Test to see if a memory is too old to remember any longer.
Definition: GooseMemoryMap.h:85
GooseMemoryLocation
a data structure to hold goose memory location attributes
Definition: GooseMemoryMap.h:41
GooseMemoryLocation::m_score
double m_score
A score used to assess the location.
Definition: GooseMemoryMap.h:63
GooseMemoryLocation::m_grazing
double m_grazing
the grazing resource at the location as intake rate kJ/min
Definition: GooseMemoryMap.h:57
GooseMemoryMap::GetFoodRes
double GetFoodRes(int a_polyid)
Get the food resource at location.
Definition: GooseMemoryMap.cpp:206
GooseMemoryMap::ChangeSetFoodRes
bool ChangeSetFoodRes(int a_polyid, double a_grain, double a_maize, double a_grazing)
Set food at a memory location.
Definition: GooseMemoryMap.cpp:159
GooseMemoryMap::GooseMemoryError
void GooseMemoryError(std::string a_str, int a_value)
Error message functionality.
Definition: GooseMemoryMap.cpp:341
GooseMemoryLocation::m_age
int m_age
how old the memory is
Definition: GooseMemoryMap.h:45
GooseMemoryMap::ChangeAddThreat
bool ChangeAddThreat(int a_polyid, double a_threat)
Add to threat at a memory location.
Definition: GooseMemoryMap.cpp:123
GooseMemoryMap::CalcScore
double CalcScore(int a_dist, double a_foodresource, double a_threat)
Inline function to calulate overall score for a distance, resource and threat.
Definition: GooseMemoryMap.cpp:273
GooseMemoryMap::GooseMemoryMap
GooseMemoryMap(Goose_Base *a_owner)
Constructor.
Definition: GooseMemoryMap.cpp:39
GooseMemoryLocation::CalcScore
void CalcScore(int a_dist, double a_flightcost, int a_expectedforagingtime)
Updates the m_score value.
Definition: GooseMemoryMap.h:78
GooseMemoryLocation::m_foodresource
double m_foodresource
The max food intake rate (kJ/min) at the location.
Definition: GooseMemoryMap.h:59
GooseMemoryLocation::m_y
int m_y
y-coordinate
Definition: GooseMemoryMap.h:49
GooseMemoryLocation::m_infinitememorystop
static int m_infinitememorystop
the age at which a memory is removed.
Definition: GooseMemoryMap.h:65
GooseMemoryMap::ChangeMultFoodRes
bool ChangeMultFoodRes(int a_polyid, double a_foodres)
Multiply food at a memory location.
Definition: GooseMemoryMap.cpp:141
GooseMemoryMap::GetBestFeedingScore
GooseMemoryLocation GetBestFeedingScore()
Find the current best feeding location.
Definition: GooseMemoryMap.cpp:236
GooseMemoryMap::m_threatdecayrate
double m_threatdecayrate
The decay rate per day for threats.
Definition: GooseMemoryMap.h:99
GooseMemoryMap::GetTotalThreats
double GetTotalThreats(void)
Get total of threat currently remembered.
Definition: GooseMemoryMap.cpp:323
GooseMemoryLocation::m_maize
double m_maize
the maize resource at the location as intake rate kJ/min
Definition: GooseMemoryMap.h:55
GooseMemoryLocation::m_x
int m_x
x-coordinate
Definition: GooseMemoryMap.h:47
GooseMemoryMap::m_memorylocations
std::vector< GooseMemoryLocation > m_memorylocations
The list of memory locations.
Definition: GooseMemoryMap.h:103
GooseMemoryMap::GetThreat
double GetThreat(int a_polyid)
Get the threat level at location.
Definition: GooseMemoryMap.cpp:221
GooseMemoryMap::DecayAllMemory
void DecayAllMemory()
Decay all memory.
Definition: GooseMemoryMap.cpp:295
GooseMemoryMap::~GooseMemoryMap
~GooseMemoryMap()
Destructor.
Definition: GooseMemoryMap.h:110
GooseMemoryLocation::operator<
bool operator<(const GooseMemoryLocation &gml)
operator definition for comparing polygon id numbers
Definition: GooseMemoryMap.h:73
Goose_Base
A class to describe the goose base.
Definition: Goose_Base.h:131
GooseMemoryLocation::m_threat
double m_threat
the threat-level memory strength
Definition: GooseMemoryMap.h:61
GooseMemoryMap::ClearAllMemory
void ClearAllMemory(void)
Remove all memory.
Definition: GooseMemoryMap.cpp:335
GooseMemoryMap::IsKnownArea
bool IsKnownArea(int a_polyid)
Check if this location is known.
Definition: GooseMemoryMap.cpp:282
GooseMemoryLocation::m_polygonid
int m_polygonid
the unique polygon identification
Definition: GooseMemoryMap.h:51
GooseMemoryMap::MemAdd
void MemAdd(GooseMemoryLocation a_gml)
Add a new memory location.
Definition: GooseMemoryMap.cpp:50
GooseMemoryLocation::GooseMemoryLocation
GooseMemoryLocation()
GooseMemoryLocation default constructor.
Definition: GooseMemoryMap.h:69
GooseMemoryMap::ChangeMultThreat
bool ChangeMultThreat(int a_polyid, double a_threat)
Multiply threat at a memory location.
Definition: GooseMemoryMap.cpp:187
GooseMemoryLocation::m_grain
double m_grain
the grain resource at the location as intake rate kJ/min
Definition: GooseMemoryMap.h:53
GooseMemoryMap
The class describing both local and seasonal goose memories and cognition.
Definition: GooseMemoryMap.h:93