ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
AOR_Probe Class Reference

#include <AOR_Probe.h>

Inheritance diagram for AOR_Probe:
AOR_Probe_Goose

Public Member Functions

 AOR_Probe (Population_Manager *a_owner, Landscape *a_TheLandscape, string a_filename)
 
virtual ~AOR_Probe ()
 
virtual void CloseFile ()
 
void WriteData ()
 
void WriteDataHL ()
 
virtual void DoProbe (int a_lifestage)
 
virtual void DoProbeInHaitatType (int a_lifestage, TTypesOfLandscapeElement a_tole)
 Records the locations of all beetles and classifies them as to in a habitat type or not. More...
 

Protected Attributes

ofstream m_ProbeFile
 
ofstream m_ProbeFileHL
 
int m_gridcountwidth [4]
 
int m_gridcountheight [4]
 
int m_gridcountsize [4]
 
int m_totalcells [4]
 
ListOfCells m_gridcount [4]
 
ListOfCells m_gridcountHLoc [4]
 
Landscapem_TheLandscape
 
TTypesOfLandscapeElement m_target_tole
 
Population_Managerm_owner
 

Constructor & Destructor Documentation

◆ AOR_Probe()

AOR_Probe::AOR_Probe ( Population_Manager a_owner,
Landscape a_TheLandscape,
string  a_filename 
)
16 {
17  // Relies on a standard cfg_ to determine whether the AOR Habitat Location Probe is needed.
18  m_owner = a_owner;
19  m_TheLandscape = a_Landscape;
21  if (a_filename == "") a_filename = "NWordOutputPrb.txt"; // this is for backwards compatability - this output used to be called NWord
22  m_ProbeFile.open(a_filename, ios::out);
23  if (!m_ProbeFile) {
24  g_msg->Warn(WARN_FILE, "Population_Manager::AOR_Probe: ""Unable to open NWord probe file:", a_filename);
25  exit(1);
26  }
27  m_ProbeFile << "Year" << '\t' << "Day" << '\t' << "Total_no" << '\t' << "Cells50" << '\t' << "Occupied50" << '\t' << "Cells100" << '\t' << "Occupied100" << '\t' << "Cells200" << '\t' << "Occupied200" << '\t' << "Cells400" << '\t' << "Occupied400" << endl;
29  {
31  a_filename = std::regex_replace(a_filename, std::regex("\\.txt"), "_HabitatLocation.txt");
32  m_ProbeFileHL.open(a_filename, ios::out);
33  if (!m_ProbeFileHL) {
34  g_msg->Warn(WARN_FILE, "Population_Manager::AOR_Probe: ""Unable to open NWord probe file:", a_filename);
35  exit(1);
36  }
37  m_ProbeFileHL << "Habitat counted from is ALMaSS type " << cfg_AOR_Habitat_Location_Type.value() << endl;
38  m_ProbeFileHL << "Year" << '\t' << "Day" << '\t' << "Total_no" << '\t' << "Cells50" << '\t' << "Occupied50" << '\t' << "Cells100" << '\t' << "Occupied100" << '\t' << "Cells200" << '\t' << "Occupied200" << '\t' << "Cells400" << '\t' << "Occupied400" << endl;
39  }
40  m_gridcountsize[0] = 50;
41  m_gridcountsize[1] = 100;
42  m_gridcountsize[2] = 200;
43  m_gridcountsize[3] = 400;
44  for (int g = 0; g < 4; g++) {
46  if (m_TheLandscape->SupplySimAreaWidth() % m_gridcountsize[g] > 0) m_gridcountwidth[g]++; // add one if there is a bit of a square left
48  if (m_TheLandscape->SupplySimAreaHeight() % m_gridcountsize[g] > 0) m_gridcountheight[g]++; // add one if there is a bit of a square left
50  m_gridcount[g].resize(m_totalcells[g]);
51  m_gridcountHLoc[g].resize(m_totalcells[g]);
52  }
53 }

References cfg_AOR_Habitat_Location_On, cfg_AOR_Habitat_Location_Type, g_msg, tole_Foobar, CfgInt::value(), CfgBool::value(), MapErrorMsg::Warn(), and WARN_FILE.

◆ ~AOR_Probe()

virtual AOR_Probe::~AOR_Probe ( )
inlinevirtual
21  {
22  CloseFile();
23  }

References CloseFile().

Member Function Documentation

◆ CloseFile()

virtual void AOR_Probe::CloseFile ( )
inlinevirtual
25  {
26  m_ProbeFile.close();
27  }

References m_ProbeFile.

Referenced by ~AOR_Probe().

◆ DoProbe()

void AOR_Probe::DoProbe ( int  a_lifestage)
virtual

Counts all a_lifestage animals in each grid of each size

Reimplemented in AOR_Probe_Goose.

104  {
106  unsigned int total = (unsigned)m_owner->GetLiveArraySize(a_lifestage);
107  // Empty old data
108  for (int grid = 0; grid < 4; grid++) {
109  for (int i = 0; i < m_totalcells[grid]; i++) m_gridcount[grid][i] = 0;
110  }
111  // For each animal get the location and place it in each of the (4) grids
112  for (unsigned j = 0; j < total; j++) //adult females
113  {
114  APoint pt = m_owner->SupplyAnimalPtr(a_lifestage, j)->SupplyPoint();
115  for (int grid = 0; grid < 4; grid++) {
116  int gx = pt.m_x / m_gridcountsize[grid];
117  int gy = pt.m_y / m_gridcountsize[grid];
118  m_gridcount[grid][gx + gy * m_gridcountwidth[grid]]++;
120  {
121  if (m_owner->SupplyAnimalPtr(a_lifestage, j)->SupplyPolygonType() == m_target_tole) m_gridcountHLoc[grid][gx + gy * m_gridcountwidth[grid]]++;
122  }
123 
124  }
125  }
126  WriteData();
127 }

References cfg_AOR_Habitat_Location_On, APoint::m_x, APoint::m_y, and CfgBool::value().

Referenced by Erigone_Population_Manager::TheAOROutputProbe(), Oedothorax_Population_Manager::TheAOROutputProbe(), Vole_Population_Manager::TheAOROutputProbe(), Osmia_Population_Manager::TheAOROutputProbe(), Ladybird_Population_Manager::TheAOROutputProbe(), Skylark_Population_Manager::TheAOROutputProbe(), THare_Population_Manager::TheAOROutputProbe(), and Beetle_Population_Manager::TheAOROutputProbe().

◆ DoProbeInHaitatType()

void AOR_Probe::DoProbeInHaitatType ( int  a_lifestage,
TTypesOfLandscapeElement  a_tole 
)
virtual

Records the locations of all beetles and classifies them as to in a habitat type or not.

Counts all a_lifestage animals in each grid of each size

165 {
167  unsigned int total = (unsigned)m_owner->GetLiveArraySize(a_lifestage);
168  // Empty old data
169  for (int grid = 0; grid < 4; grid++) {
170  for (int i = 0; i < m_totalcells[grid]; i++) m_gridcountHLoc[grid][i] = 0;
171  }
172  // For each animal get the location and place it in each of the (4) grids
173  for (unsigned j = 0; j < total; j++)
174  {
175  APoint pt = m_owner->SupplyAnimalPtr(a_lifestage, j)->SupplyPoint();
176  for (int grid = 0; grid < 4; grid++) {
177  int gx = pt.m_x / m_gridcountsize[grid];
178  int gy = pt.m_y / m_gridcountsize[grid];
179  m_gridcountHLoc[grid][gx + gy * m_gridcountwidth[grid]]++;
180  }
181  }
182  WriteData();
183 }

References Population_Manager::GetLiveArraySize(), m_gridcountHLoc, m_gridcountsize, m_gridcountwidth, m_owner, m_totalcells, APoint::m_x, APoint::m_y, Population_Manager::SupplyAnimalPtr(), TAnimal::SupplyPoint(), and WriteData().

◆ WriteData()

void AOR_Probe::WriteData ( )
57 {
58  int Counted[4];
59  int OccupiedCells[4];
60  for (int gsz = 0; gsz < 4; gsz++) {
61  Counted[gsz] = 0;
62  OccupiedCells[gsz] = 0;
63  for (int i = 0; i < m_gridcountwidth[gsz]; i++) {
64  for (int j = 0; j < m_gridcountheight[gsz]; j++) {
65  int res = m_gridcount[gsz][i + j * m_gridcountwidth[gsz]];
66  Counted[gsz] += res;
67  if (res > 0) OccupiedCells[gsz]++;
68  }
69  }
70  }
71  m_ProbeFile << m_TheLandscape->SupplyYearNumber() << '\t' << (int)m_TheLandscape->SupplyDayInYear() << '\t' << Counted[0] << '\t';
72  for (int c = 0; c < 3; c++) {
73  m_ProbeFile << m_totalcells[c] << '\t' << OccupiedCells[c] << '\t';
74  }
75  m_ProbeFile << m_totalcells[3] << '\t' << OccupiedCells[3] << endl;
77  {
78  WriteDataHL();
79  }
80 }

References cfg_AOR_Habitat_Location_On, and CfgBool::value().

Referenced by AOR_Probe_Goose::DoProbe(), and DoProbeInHaitatType().

◆ WriteDataHL()

void AOR_Probe::WriteDataHL ( )
83 {
84  int Counted[4];
85  int OccupiedCells[4];
86  for (int gsz = 0; gsz < 4; gsz++) {
87  Counted[gsz] = 0;
88  OccupiedCells[gsz] = 0;
89  for (int i = 0; i < m_gridcountwidth[gsz]; i++) {
90  for (int j = 0; j < m_gridcountheight[gsz]; j++) {
91  int res = m_gridcountHLoc[gsz][i + j * m_gridcountwidth[gsz]];
92  Counted[gsz] += res;
93  if (res > 0) OccupiedCells[gsz]++;
94  }
95  }
96  }
97  m_ProbeFileHL << m_TheLandscape->SupplyYearNumber() << '\t' << (int)m_TheLandscape->SupplyDayInYear() << '\t' << Counted[0] << '\t';
98  for (int c = 0; c < 3; c++) {
99  m_ProbeFileHL << m_totalcells[c] << '\t' << OccupiedCells[c] << '\t';
100  }
101  m_ProbeFileHL << m_totalcells[3] << '\t' << OccupiedCells[3] << endl;
102 }

Member Data Documentation

◆ m_gridcount

ListOfCells AOR_Probe::m_gridcount[4]
protected

◆ m_gridcountheight

int AOR_Probe::m_gridcountheight[4]
protected

◆ m_gridcountHLoc

ListOfCells AOR_Probe::m_gridcountHLoc[4]
protected

Referenced by DoProbeInHaitatType().

◆ m_gridcountsize

int AOR_Probe::m_gridcountsize[4]
protected

◆ m_gridcountwidth

int AOR_Probe::m_gridcountwidth[4]
protected

◆ m_owner

Population_Manager* AOR_Probe::m_owner
protected

◆ m_ProbeFile

ofstream AOR_Probe::m_ProbeFile
protected

Referenced by CloseFile().

◆ m_ProbeFileHL

ofstream AOR_Probe::m_ProbeFileHL
protected

◆ m_target_tole

TTypesOfLandscapeElement AOR_Probe::m_target_tole
protected

◆ m_TheLandscape

Landscape* AOR_Probe::m_TheLandscape
protected

◆ m_totalcells

int AOR_Probe::m_totalcells[4]
protected

Referenced by DoProbeInHaitatType().


The documentation for this class was generated from the following files:
WARN_FILE
Definition: MapErrorMsg.h:37
cfg_AOR_Habitat_Location_On
static CfgBool cfg_AOR_Habitat_Location_On("G_AOR_HABITAT_ON", CFG_CUSTOM, false)
Flag for using the habitat location probe.
TAnimal::SupplyPoint
APoint SupplyPoint() const
Returns the objects location in ALMaSS coordinates.
Definition: PopulationManager.h:222
Population_Manager::SupplyAnimalPtr
virtual TAnimal * SupplyAnimalPtr(unsigned int a_index, unsigned int a_animal)
Returns the pointer indexed by a_index and a_animal. Note NO RANGE CHECK.
Definition: PopulationManager.h:678
tole_Foobar
Definition: LandscapeFarmingEnums.h:183
AOR_Probe::CloseFile
virtual void CloseFile()
Definition: AOR_Probe.h:25
CfgBool::value
bool value() const
Definition: Configurator.h:164
AOR_Probe::m_owner
Population_Manager * m_owner
Definition: AOR_Probe.h:18
Landscape::SupplySimAreaHeight
int SupplySimAreaHeight(void)
Gets the simulation landscape height.
Definition: Landscape.h:2302
Landscape::SupplySimAreaWidth
int SupplySimAreaWidth(void)
Gets the simulation landscape width.
Definition: Landscape.h:2297
Landscape::TranslateEleTypes
TTypesOfLandscapeElement TranslateEleTypes(int EleReference)
Returns element type translated from the ALMaSS reference number.
Definition: Landscape.h:2313
APoint
A simple class defining an x,y coordinate set.
Definition: ALMaSS_Setup.h:52
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
AOR_Probe::m_gridcountheight
int m_gridcountheight[4]
Definition: AOR_Probe.h:10
Landscape::SupplyDayInYear
int SupplyDayInYear(void)
Passes a request on to the associated Calendar class function, the day in the year.
Definition: Landscape.h:2267
AOR_Probe::m_ProbeFile
ofstream m_ProbeFile
Definition: AOR_Probe.h:7
APoint::m_x
int m_x
Definition: ALMaSS_Setup.h:55
AOR_Probe::m_totalcells
int m_totalcells[4]
Definition: AOR_Probe.h:12
Landscape::SupplyYearNumber
int SupplyYearNumber(void)
Passes a request on to the associated Calendar class function, returns m_simulationyear
Definition: Landscape.h:2287
AOR_Probe::m_gridcount
ListOfCells m_gridcount[4]
Definition: AOR_Probe.h:13
CfgInt::value
int value() const
Definition: Configurator.h:116
AOR_Probe::m_gridcountHLoc
ListOfCells m_gridcountHLoc[4]
Definition: AOR_Probe.h:14
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
Population_Manager::GetLiveArraySize
unsigned GetLiveArraySize(int a_listindex) override
Gets the number of 'live' objects for a list index in the TheArray.
Definition: PopulationManager.h:657
AOR_Probe::m_gridcountwidth
int m_gridcountwidth[4]
Definition: AOR_Probe.h:9
TAnimal::SupplyPolygonType
TTypesOfLandscapeElement SupplyPolygonType() const
Returns the polygon type where the object is located.
Definition: PopulationManager.h:233
AOR_Probe::m_TheLandscape
Landscape * m_TheLandscape
Definition: AOR_Probe.h:16
AOR_Probe::m_ProbeFileHL
ofstream m_ProbeFileHL
Definition: AOR_Probe.h:8
cfg_AOR_Habitat_Location_Type
static CfgInt cfg_AOR_Habitat_Location_Type("G_AOR_HABITAT_TYPE", CFG_CUSTOM, 20)
ALMaSS tole code for the habitat location probe to count in - default 20 = tole_Field.
AOR_Probe::WriteData
void WriteData()
Definition: AOR_Probe.cpp:56
APoint::m_y
int m_y
Definition: ALMaSS_Setup.h:56
AOR_Probe::WriteDataHL
void WriteDataHL()
Definition: AOR_Probe.cpp:82
AOR_Probe::m_target_tole
TTypesOfLandscapeElement m_target_tole
Definition: AOR_Probe.h:17
AOR_Probe::m_gridcountsize
int m_gridcountsize[4]
Definition: AOR_Probe.h:11