ALMaSS Rodenticide Model ODdox  1.0
RodenticideManager Class Reference

Class for management of bait locations. More...

#include <Rodenticide.h>

Public Member Functions

void Diffuse (int a_x, int a_y)
 Move poisoned mice around to twin map. More...
 
void DistributeRing (int a_x, int a_y, double a_amount)
 Distribute an amount to the twin map in a ring. More...
 
void DoDeath (void)
 Reduce each cell in twin map by m_deathRate. More...
 
void DoDiffuse (void)
 
void DoImmigration (void)
 
void DoPlaceBait ()
 Initiates bait placement for those bait locations necessary. More...
 
void DumpRodenticideMap (string a_fname)
 Dumps a map of rodenticide loads per 1m2 cells. More...
 
int GetBaitStartDate (TTypesBaitLocation)
 Determines when the bait will be placed within a season. More...
 
double GetMap (int a_x, int a_y)
 Get poisoned mice at x,y. More...
 
double GetMapTwin (int a_x, int a_y)
 Get poisoned mice at x,y on twin map. More...
 
double GetRodenticide (unsigned a_x, int a_y)
 Return the poisoned mice value at x,y. More...
 
void InitiateRodenticidePolyData (string a_fname)
 Opens and initiates the output file for polygon rodenticide information. More...
 
void RecordRodenticidePolyData (string a_fname)
 Records rodenticide loads per polygon. More...
 
 RodenticideManager (string fname, Landscape *a_land)
 RodenticideManager constructor. More...
 
void SetMap (int a_x, int a_y, double a_p)
 Set poisoned mice at x,y. More...
 
void SetMapTwin (int a_x, int a_y, double a_p)
 Set poisoned mice at x,y on twin map. More...
 
void SetMapTwinMult (int a_x, int a_y, double a_p)
 Multiply poisoned mice at x,y on twin map by constant. More...
 
void SetMapTwinP (int a_x, int a_y, double a_p)
 Add to poisoned mice at x,y on twin map. More...
 
bool ShouldPlaceBait (TTypesBaitLocation)
 Place bait dependent upon a frequency test. More...
 
void Tick (void)
 Advance one day. More...
 
virtual ~RodenticideManager (void)
 RodenticideManager destructor. More...
 

Protected Attributes

vector< BaitLocationm_BaitList
 List of bait locations. More...
 
double m_deathRate
 poisoned mice death rate More...
 
double m_diffusionRate
 poisoned mice diffusion rate More...
 
int m_gridsize
 rodenticide grid size - also affect diffusion rate More...
 
int m_height
 
int m_heightm1
 
double m_immigrationRate
 poisoned mice immigration rate More...
 
Landscapem_land
 Landscape pointer. More...
 
vector< double > m_pmouse_map_main
 Map of probability of encountering a poisoned mouse. More...
 
vector< double > m_pmouse_map_twin
 Temporary map for calculation poisoned mouse diffusion. More...
 
int m_seasonstartprob [tbl_foobar][1000]
 season start probability distribution More...
 
int m_width
 Landscape dimensions. More...
 

Detailed Description

Class for management of bait locations.

Constructor & Destructor Documentation

RodenticideManager::RodenticideManager ( string  fname,
Landscape a_land 
)

RodenticideManager constructor.

Uses the file name to open a file and read in all bait locations required for managemnet

Creates the rodenticide grid with its twin-map and fills them with zeros. The maps have a resolution which is defined by __RODENTICIDE_GRID_RES. Cannot have diffusion of >= map width or height - this needs checking to prevent wrapping around the world.

Read in and handle the probability distributions for seasonal start dates for bait locations. BaitLocationsSeasonalStartProbs.txt holds a column of daily probability for bait placement for each building type ()values range 0.0 to 1.0).

References cfg_rodenticide_deathRate(), cfg_rodenticide_diffusionRate(), cfg_rodenticide_gridsize(), cfg_rodenticide_immigrationRate(), BaitLocation::SetBLtype(), BaitLocation::SetX(), BaitLocation::SetY(), Landscape::SupplySimAreaWidth(), and tbl_foobar.

116 {
117  // Read in input parameters
125  ifstream ifile(a_fname.c_str(), ios::in);
126  if ( !ifile.is_open() )
127  {
128  cout << "Cannot open input file " << a_fname << endl;
129  char ch;
130  cin >> ch;
131  exit(1);
132  }
133  int noBaits, x, y, blt;
134  TTypesBaitLocation BL_type = tbl_foobar;
135  BaitLocation Bait(0,0,BL_type);
136  ifile >> noBaits;
137  for (int i = 0; i < noBaits; i++)
138  {
139  ifile >> x >> y >> blt;
140  Bait.SetX(x >> m_gridsize);
141  Bait.SetY(y >> m_gridsize);
142  Bait.SetBLtype((TTypesBaitLocation)blt);
143  m_BaitList.push_back(Bait);
144  }
145  // Need to put actual baits out in the landscape
146  m_land = a_land;
153  m_heightm1 = m_height-1; // Saves many many calculations later.
154  m_pmouse_map_main.resize((m_width+1) * (m_height+1));
155  m_pmouse_map_twin.resize((m_width+1) * (m_height+1));
156  for (int i=0; i<m_width+1; ++i) for (int j=0; j<m_height+1; ++j)
157  {
158  m_pmouse_map_main[j*m_height + i] = 0;
159  m_pmouse_map_twin[j*m_height + i] = 0;
160  }
166  ifstream i2file("BaitLocationsSeasonalStartProbs.txt", ios::in);
167  if ( !ifile.is_open() )
168  {
169  cout << "Cannot open input file " << "BaitLocationsSeasonalStartProbs.txt" << endl;
170  char ch;
171  cin >> ch;
172  exit(1);
173  }
174  double temp[tbl_foobar][365];
175  for (int i = 0; i < 365; i++)
176  {
177  for (int j=0; j<tbl_foobar; j++)
178  {
179  i2file >> temp[j][i];
180  }
181  }
182  // BaitLocationsSeasonalStartProbs.txt data exists in temp.
183  // Next for each building type fill in the probability array in fractions of 0.1
184  // each entry corresponds to one day when bait might be started
185  for (int j=0; j<tbl_foobar; j++)
186  {
187  int index = 0;
188  for (int i = 0; i < 365; i++)
189  {
190  int prob = (int) floor((temp[j][i]*10)+0.5) + index; // input data sums to 100, so multiply by 10 is 1000
191  if (prob>1000) prob=1000;
192  for (int k=index; k<prob; k++) m_seasonstartprob[j][k] = i;
193  index=prob;
194  if (index>=1000) i=365;
195  }
196  }
197  InitiateRodenticidePolyData("RodenticidePolyData.txt");
198 }
Class used for describing the rodenticide bait location.
Definition: Rodenticide.h:20
int m_seasonstartprob[tbl_foobar][1000]
season start probability distribution
Definition: Rodenticide.h:95
double m_diffusionRate
poisoned mice diffusion rate
Definition: Rodenticide.h:89
int SupplySimAreaWidth(void)
Definition: landscape.h:1556
double m_immigrationRate
poisoned mice immigration rate
Definition: Rodenticide.h:91
vector< double > m_pmouse_map_main
Map of probability of encountering a poisoned mouse.
Definition: Rodenticide.h:79
CfgFloat cfg_rodenticide_deathRate("RODENTICIDE_DEATHRATE", CFG_CUSTOM, 0.048307)
vector< BaitLocation > m_BaitList
List of bait locations.
Definition: Rodenticide.h:77
Definition: Rodenticide.h:16
int m_height
Definition: Rodenticide.h:85
int SupplySimAreaHeight(void)
Definition: landscape.h:1561
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
void InitiateRodenticidePolyData(string a_fname)
Opens and initiates the output file for polygon rodenticide information.
Definition: Rodenticide.cpp:414
double m_deathRate
poisoned mice death rate
Definition: Rodenticide.h:93
CfgFloat cfg_rodenticide_immigrationRate("RODENTICIDE_IMMIGRATIONRATE", CFG_CUSTOM, 1.0)
CfgFloat cfg_rodenticide_diffusionRate("RODENTICIDE_DIFFUSIONRATE", CFG_CUSTOM, 0.5)
CfgInt cfg_rodenticide_gridsize("RODENTICIDE_GRIDSIZE", CFG_CUSTOM, 5)
int m_gridsize
rodenticide grid size - also affect diffusion rate
Definition: Rodenticide.h:87
TTypesBaitLocation
An enumeration listing the types of bait locations possible.
Definition: Rodenticide.h:10
vector< double > m_pmouse_map_twin
Temporary map for calculation poisoned mouse diffusion.
Definition: Rodenticide.h:81
int m_heightm1
Definition: Rodenticide.h:85
Landscape * m_land
Landscape pointer.
Definition: Rodenticide.h:83
RodenticideManager::~RodenticideManager ( void  )
virtual

RodenticideManager destructor.

202 {
203  ;
204 }

Member Function Documentation

void RodenticideManager::Diffuse ( int  a_x,
int  a_y 
)

Move poisoned mice around to twin map.

248 {
249  double before = GetMap(a_x, a_y);
250  if (before < 0.00001)
251  {
252  SetMapTwinP(a_x, a_y,0); // Prevents infinitely small calculations
253  return;
254  }
255  double after = before * m_diffusionRate;
256  double diff_out = after/8;
257  SetMapTwinP(a_x, a_y,before-after);
258  DistributeRing(a_x,a_y,diff_out);
259 }
void SetMapTwinP(int a_x, int a_y, double a_p)
Add to poisoned mice at x,y on twin map.
Definition: Rodenticide.h:140
double m_diffusionRate
poisoned mice diffusion rate
Definition: Rodenticide.h:89
double GetMap(int a_x, int a_y)
Get poisoned mice at x,y.
Definition: Rodenticide.h:130
void DistributeRing(int a_x, int a_y, double a_amount)
Distribute an amount to the twin map in a ring.
Definition: Rodenticide.cpp:261
void RodenticideManager::DistributeRing ( int  a_x,
int  a_y,
double  a_amount 
)
inline

Distribute an amount to the twin map in a ring.

Distribute a_amount to the eight cells around m_x,m_y

262 {
264  int x1 = a_x - 1;
265  int y1 = a_y - 1;
266  int y2 = y1 + 2;
267  int x2 = x1 + 2;
268  if ((y1<0) || (y2==m_height) || (x1<0) || (x2==m_width))
269  {
270  // We need to do this to prevent the diffusion building a wall around the edge, but it could be assessed as to whether the speed penalty is worth it
271  x1 = (x1 + m_width) % m_width;
272  x2 = (x2 + m_width) % m_width;
273  y1 = (y1 + m_height) % m_height;
274  y2 = (y2 + m_height) % m_height;
275  }
276  SetMapTwinP(x1,y1,a_amount);
277  SetMapTwinP(x1,y2,a_amount);
278  SetMapTwinP(x1,a_y,a_amount);
279  SetMapTwinP(x2,y1,a_amount);
280  SetMapTwinP(x2,y2,a_amount);
281  SetMapTwinP(x2,a_y,a_amount);
282  SetMapTwinP(a_x,y1,a_amount);
283  SetMapTwinP(a_x,y2,a_amount);
284 }
void SetMapTwinP(int a_x, int a_y, double a_p)
Add to poisoned mice at x,y on twin map.
Definition: Rodenticide.h:140
int m_height
Definition: Rodenticide.h:85
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
void RodenticideManager::DoDeath ( void  )
inline

Reduce each cell in twin map by m_deathRate.

122  {
123  for (int i=0;i<m_width; i++)
124  for (int j=0; j<m_height; j++) SetMapTwinMult(i,j,m_deathRate);
125  }
void SetMapTwinMult(int a_x, int a_y, double a_p)
Multiply poisoned mice at x,y on twin map by constant.
Definition: Rodenticide.h:138
int m_height
Definition: Rodenticide.h:85
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
double m_deathRate
poisoned mice death rate
Definition: Rodenticide.h:93
void RodenticideManager::DoDiffuse ( void  )
inline
116  {
117  for (int i=0;i<m_width; i++)
118  for (int j=0; j<m_height; j++) this->Diffuse(i,j);
119  }
void Diffuse(int a_x, int a_y)
Move poisoned mice around to twin map.
Definition: Rodenticide.cpp:247
int m_height
Definition: Rodenticide.h:85
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
void RodenticideManager::DoImmigration ( void  )
233 {
234  unsigned sz = (unsigned) m_BaitList.size();
235  for (unsigned i=0; i<sz; i++)
236  {
237  if (m_BaitList[i].GetMass()>0)
238  {
239  m_BaitList[i].ReduceMass(1); // subtract 1 from mass
240  int x = m_BaitList[i].GetX();
241  int y = m_BaitList[i].GetY();
243  }
244  }
245 }
double m_immigrationRate
poisoned mice immigration rate
Definition: Rodenticide.h:91
vector< double > m_pmouse_map_main
Map of probability of encountering a poisoned mouse.
Definition: Rodenticide.h:79
vector< BaitLocation > m_BaitList
List of bait locations.
Definition: Rodenticide.h:77
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
void RodenticideManager::DoPlaceBait ( void  )

Initiates bait placement for those bait locations necessary.

Depending upon the bait type, whether the bait has been used this year and whether it is destined to be used this method will add mass to the bait locations.
Housekeeping on Jan 1st is to remove all masses and zero all flags for the start of the new year.
The first test is of date, since whether a BL is used is determined by the frequency of that BL type on Jan 1st.
The next test is on the season, determining the start of bait placement.
NB this not so time critical so no optimising of the loops is done here.

References cfg_rodenticide_BLchristmasstrees_Length(), cfg_rodenticide_BLcountry_Length(), cfg_rodenticide_BLtown_Length(), cfg_rodenticide_BLwoodland_Length(), tbl_christmasstrees, tbl_country, tbl_town, and tbl_woodland.

323 {
332  int day = m_land->SupplyDayInYear();
333  unsigned sz = (unsigned) m_BaitList.size();
334  if (day==0)
335  {
336  for (unsigned i=0; i<sz; i++)
337  {
338  m_BaitList[i].Reset();
339  if (ShouldPlaceBait(m_BaitList[i].GetBLtype()))
340  {
341  m_BaitList[i].SetUseFlag(true);
342  m_BaitList[i].SetstartDay(GetBaitStartDate(m_BaitList[i].GetBLtype()));
343  }
344  }
345  }
346  // Loop through all the BLs and initiate any needed doing today
347  for (unsigned i=0; i<sz; i++)
348  {
349  if (m_BaitList[i].GetUseFlag())
350  {
351  if (m_BaitList[i].GetstartDay() == day )
352  {
353  // Due to start today, so set bait mass & unset use flag because we have used it now.
354  // Find the bait mass
355  int mass;
356  switch (m_BaitList[i].GetBLtype())
357  {
358  case tbl_town:
359  mass = cfg_rodenticide_BLtown_Length.value();
360  break;
361  case tbl_country:
362  mass = cfg_rodenticide_BLcountry_Length.value();
363  break;
364  case tbl_woodland:
365  mass = cfg_rodenticide_BLwoodland_Length.value();
366  break;
367  case tbl_christmasstrees:
368  mass = cfg_rodenticide_BLchristmasstrees_Length.value(); // uses same as woodland
369  break;
370  default:
371  g_msg->Warn( WARN_FILE, "RodenticideManager::DoPlaceBait(void): Unknown bait type","");
372  exit( 0 );
373  }
374  m_BaitList[i].SetMass(mass);
375  m_BaitList[i].SetUseFlag(false);
376  // Add the bait to the main map
377  SetMap(m_BaitList[i].GetX(),m_BaitList[i].GetY(),1.0);
378  }
379  }
380  }
381 
382 }
void SetMap(int a_x, int a_y, double a_p)
Set poisoned mice at x,y.
Definition: Rodenticide.h:134
vector< BaitLocation > m_BaitList
List of bait locations.
Definition: Rodenticide.h:77
Definition: Rodenticide.h:12
bool ShouldPlaceBait(TTypesBaitLocation)
Place bait dependent upon a frequency test.
Definition: Rodenticide.cpp:286
CfgInt cfg_rodenticide_BLtown_Length("RODENTICIDE_BLTYPE_TOWN_LENGTH", CFG_CUSTOM, 34)
Definition: Rodenticide.h:14
int SupplyDayInYear(void)
Definition: landscape.h:1520
Definition: Rodenticide.h:15
CfgInt cfg_rodenticide_BLwoodland_Length("RODENTICIDE_BLTYPE_WOODLAND_LENGTH", CFG_CUSTOM, 82)
CfgInt cfg_rodenticide_BLcountry_Length("RODENTICIDE_BLTYPE_COUNTRY_LENGTH", CFG_CUSTOM, 34)
Definition: Rodenticide.h:13
int GetBaitStartDate(TTypesBaitLocation)
Determines when the bait will be placed within a season.
Definition: Rodenticide.cpp:316
CfgInt cfg_rodenticide_BLchristmasstrees_Length("RODENTICIDE_BLTYPE_CTREE_LENGTH", CFG_CUSTOM, 82)
Landscape * m_land
Landscape pointer.
Definition: Rodenticide.h:83
void RodenticideManager::DumpRodenticideMap ( string  a_fname)

Dumps a map of rodenticide loads per 1m2 cells.

Uses the file name to open a file and saves the rodenticide value for each cell at the time this method is called.

386 {
390  ofstream ofile(a_fname.c_str(), ios::out);
391  if ( !ofile.is_open() )
392  {
393  cout << "Cannot open output file for rodenticide map dump " << a_fname << endl;
394  char ch;
395  cin >> ch;
396  exit(1);
397  }
398  int xext = m_land->SupplySimAreaWidth();
399  int yext = m_land->SupplySimAreaHeight();
400  ofile << "Width: "<< xext << endl;
401  ofile << "Height: "<< yext << endl;
402  for (int y=0; y<yext; y++)
403  {
404  for (int x=0; x<xext; x++)
405  {
406  ofile << m_land->SupplyRodenticide(x,y) << '\t';
407  }
408  ofile << endl;
409  }
410  ofile.close();
411 }
int SupplySimAreaWidth(void)
Definition: landscape.h:1556
int SupplySimAreaHeight(void)
Definition: landscape.h:1561
double SupplyRodenticide(int a_x, int a_y)
Gets total rodenticide for a location.
Definition: Landscape.cpp:470
Landscape * m_land
Landscape pointer.
Definition: Rodenticide.h:83
int RodenticideManager::GetBaitStartDate ( TTypesBaitLocation  a_BLt)

Determines when the bait will be placed within a season.

References g_rand_uni.

317 {
318  int chance = (int) floor((g_rand_uni() * 1000)+0.5);
319  return m_seasonstartprob[a_BLt][chance];
320 }
int m_seasonstartprob[tbl_foobar][1000]
season start probability distribution
Definition: Rodenticide.h:95
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
double RodenticideManager::GetMap ( int  a_x,
int  a_y 
)
inline

Get poisoned mice at x,y.

130 { return m_pmouse_map_main[a_y*m_width + a_x]; }
vector< double > m_pmouse_map_main
Map of probability of encountering a poisoned mouse.
Definition: Rodenticide.h:79
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
double RodenticideManager::GetMapTwin ( int  a_x,
int  a_y 
)
inline

Get poisoned mice at x,y on twin map.

132 { return m_pmouse_map_twin[a_y*m_width + a_x]; }
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
vector< double > m_pmouse_map_twin
Temporary map for calculation poisoned mouse diffusion.
Definition: Rodenticide.h:81
double RodenticideManager::GetRodenticide ( unsigned  a_x,
int  a_y 
)
inline

Return the poisoned mice value at x,y.

142 { return m_pmouse_map_main[(a_x >> m_gridsize) + (a_y >> m_gridsize)*m_width]; }
vector< double > m_pmouse_map_main
Map of probability of encountering a poisoned mouse.
Definition: Rodenticide.h:79
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
int m_gridsize
rodenticide grid size - also affect diffusion rate
Definition: Rodenticide.h:87
void RodenticideManager::InitiateRodenticidePolyData ( string  a_fname)

Opens and initiates the output file for polygon rodenticide information.

Uses the file name to open a file and saves the rodenticide value for each polygon at the time this method is called.

415 {
419  ofstream ofile(a_fname.c_str(), ios::out);
420  if ( !ofile.is_open() )
421  {
422  cout << "Cannot open output file for rodenticide poly initiate " << a_fname << endl;
423  char ch;
424  cin >> ch;
425  exit(1);
426  }
427  int noPoly=m_land->SupplyNumberOfPolygons();
428  ofile << noPoly << endl;
429  for (int p=0; p<(noPoly-1); p++)
430  {
431  ofile << m_land->SupplyPolyRefVector(p) << '\t';
432  }
433  ofile << m_land->SupplyPolyRefVector(noPoly-1) << endl;
434  for (int p=0; p<(noPoly-1); p++)
435  {
436  ofile << m_land->SupplyElementTypeFromVector(p) << '\t';
437  }
438  ofile << m_land->SupplyElementTypeFromVector(noPoly-1) << endl;
439  for (int p=0; p<(noPoly-1); p++)
440  {
441  int area = (int) m_land->SupplyPolygonAreaVector(p);
442  ofile << area << '\t';
443  }
444  ofile << m_land->SupplyPolygonAreaVector(noPoly-1);
445  ofile.close();
446 }
TTypesOfLandscapeElement SupplyElementTypeFromVector(unsigned int a_index)
Definition: landscape.h:1023
int SupplyPolyRefVector(unsigned int a_index)
Definition: landscape.h:1375
unsigned int SupplyNumberOfPolygons(void)
Definition: landscape.h:1385
double SupplyPolygonAreaVector(int a_polyref)
Returns the area of a polygon using the vector index as a reference.
Definition: landscape.h:1119
Landscape * m_land
Landscape pointer.
Definition: Rodenticide.h:83
void RodenticideManager::RecordRodenticidePolyData ( string  a_fname)

Records rodenticide loads per polygon.

Uses the file name to open a file and saves the rodenticide value for each polygon at the time this method is called.

449 {
453  ofstream ofile(a_fname.c_str(), ios::app);
454  if ( !ofile.is_open() )
455  {
456  cout << "Cannot open output file for rodenticide poly data " << a_fname << endl;
457  char ch;
458  cin >> ch;
459  exit(1);
460  }
461  int noPoly=m_land->SupplyLargestPolyNumUsed()+1;
462  double* polyR = new double [noPoly];
463  for (int p=0; p<(noPoly); p++) polyR[p]=0.0;
464  int xext = m_land->SupplySimAreaWidth();
465  int yext = m_land->SupplySimAreaHeight();
466  for (int y=0; y<yext; y++)
467  {
468  for (int x=0; x<xext; x++)
469  {
470  double Rdt = m_land->SupplyRodenticide(x,y);
471  int pindex = m_land->SupplyPolyRefIndex(x,y);
472  polyR[pindex]+=Rdt;
473  }
474  }
475  ofile << endl; // Got to be here to easily allow an eof test later
476  for (int p=0; p<(noPoly-1); p++)
477  {
478  ofile << polyR[p] << '\t';
479  }
480  ofile << polyR[noPoly-1];
481  ofile.close();
482  delete polyR;
483 }
int SupplyLargestPolyNumUsed()
Definition: landscape.h:334
int SupplySimAreaWidth(void)
Definition: landscape.h:1556
int SupplySimAreaHeight(void)
Definition: landscape.h:1561
double SupplyRodenticide(int a_x, int a_y)
Gets total rodenticide for a location.
Definition: Landscape.cpp:470
int SupplyPolyRefIndex(int a_x, int a_y)
Definition: landscape.h:1417
Landscape * m_land
Landscape pointer.
Definition: Rodenticide.h:83
void RodenticideManager::SetMap ( int  a_x,
int  a_y,
double  a_p 
)
inline

Set poisoned mice at x,y.

134 { m_pmouse_map_main[a_y*m_width + a_x] = a_p; }
vector< double > m_pmouse_map_main
Map of probability of encountering a poisoned mouse.
Definition: Rodenticide.h:79
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
void RodenticideManager::SetMapTwin ( int  a_x,
int  a_y,
double  a_p 
)
inline

Set poisoned mice at x,y on twin map.

136 { m_pmouse_map_twin[a_y*m_width + a_x] = a_p; }
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
vector< double > m_pmouse_map_twin
Temporary map for calculation poisoned mouse diffusion.
Definition: Rodenticide.h:81
void RodenticideManager::SetMapTwinMult ( int  a_x,
int  a_y,
double  a_p 
)
inline

Multiply poisoned mice at x,y on twin map by constant.

138 { m_pmouse_map_twin[a_y*m_width + a_x] *= a_p; }
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
vector< double > m_pmouse_map_twin
Temporary map for calculation poisoned mouse diffusion.
Definition: Rodenticide.h:81
void RodenticideManager::SetMapTwinP ( int  a_x,
int  a_y,
double  a_p 
)
inline

Add to poisoned mice at x,y on twin map.

140 { m_pmouse_map_twin[a_y*m_width + a_x] += a_p; }
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
vector< double > m_pmouse_map_twin
Temporary map for calculation poisoned mouse diffusion.
Definition: Rodenticide.h:81
bool RodenticideManager::ShouldPlaceBait ( TTypesBaitLocation  a_BLt)

Place bait dependent upon a frequency test.

References cfg_rodenticide_BLchristmastrees_AnnFreq(), cfg_rodenticide_BLcountry_AnnFreq(), cfg_rodenticide_BLtown_AnnFreq(), cfg_rodenticide_BLwoodland_AnnFreq(), g_rand_uni, tbl_christmasstrees, tbl_country, tbl_foobar, tbl_town, and tbl_woodland.

287 {
288 #ifdef __RODENTICIDE_DISTRIBUTIONTEST
289  return true;
290 #endif
291  double chance = g_rand_uni();
292  switch (a_BLt)
293  {
294  case tbl_town:
295  if (chance < cfg_rodenticide_BLtown_AnnFreq.value()) return true;
296  break;
297  case tbl_country:
298  if (chance < cfg_rodenticide_BLcountry_AnnFreq.value()) return true;
299  break;
300  case tbl_woodland:
301  if (chance < cfg_rodenticide_BLwoodland_AnnFreq.value()) return true;
302  break;
303  case tbl_christmasstrees:
304  if (chance < cfg_rodenticide_BLchristmastrees_AnnFreq.value()) return true;
305  break;
306  case tbl_foobar:
307  cout << "Unknown building type" << endl;
308  char ch;
309  cin >> ch;
310  exit(1);
311  break;
312  }
313  return false;
314 }
CfgFloat cfg_rodenticide_BLchristmastrees_AnnFreq("RODENTICIDE_BLTYPE_CTREES_ANNFREQ", CFG_CUSTOM, 0.05 *(5/9))
Definition: Rodenticide.h:16
Definition: Rodenticide.h:12
CfgFloat cfg_rodenticide_BLcountry_AnnFreq("RODENTICIDE_BLTYPE_COUNTRY_ANNFREQ", CFG_CUSTOM, 0.33)
Definition: Rodenticide.h:14
Definition: Rodenticide.h:15
CfgFloat cfg_rodenticide_BLwoodland_AnnFreq("RODENTICIDE_BLTYPE_WOODLAND_ANNFREQ", CFG_CUSTOM, 0.01)
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
CfgFloat cfg_rodenticide_BLtown_AnnFreq("RODENTICIDE_BLTYPE_TOWN_ANNFREQ", CFG_CUSTOM, 0.05)
Definition: Rodenticide.h:13
void RodenticideManager::Tick ( void  )

Advance one day.

Check for bait location placement each day, but also do intialisation on Jan 1st.

For each bait location - first add immigration to the main map.

Then calculate diffusion for every cell - this is time consuming! Diffusion is added to twin map.

Apply mortalities to all cells in the twin map.

Finally swap the twin map and main map, then clear the twin map.

References cfg_rodenticide_dumpmapday(), cfg_rodenticide_dumpmapstartyear(), cfg_rodenticide_dumppolyendyear(), cfg_rodenticide_dumppolyinterval(), and cfg_rodenticide_dumppolystartyear().

207 {
209  DoPlaceBait();
211  DoImmigration();
213  DoDiffuse();
215  DoDeath();
217  m_pmouse_map_twin.swap(m_pmouse_map_main); // Swap the twim map to the main map
218  m_pmouse_map_twin.assign((m_width+1) * (m_height+1), 0); // clears the twin map
219  // OUTPUT
220  int year = m_land->SupplyYearNumber();
221  int today = m_land->SupplyDayInYear();
222  if ((cfg_rodenticide_dumpmapstartyear.value()>=year) && (cfg_rodenticide_dumpmapstartyear.value()<=year) &&(cfg_rodenticide_dumpmapday.value()==today) )
223  {
224  DumpRodenticideMap("RodenticideMap.txt");
225  }
226  if ((year >= cfg_rodenticide_dumppolystartyear.value()) && (year <= cfg_rodenticide_dumppolyendyear.value()) )
227  {
228  if (today % cfg_rodenticide_dumppolyinterval.value()==0) RecordRodenticidePolyData("RodenticidePolyData.txt");
229  }
230 }
CfgInt cfg_rodenticide_dumppolyendyear("RODENTICIDE_DUMPPOLYENDYEAR", CFG_CUSTOM,-1)
void DumpRodenticideMap(string a_fname)
Dumps a map of rodenticide loads per 1m2 cells.
Definition: Rodenticide.cpp:385
void DoPlaceBait()
Initiates bait placement for those bait locations necessary.
Definition: Rodenticide.cpp:322
void RecordRodenticidePolyData(string a_fname)
Records rodenticide loads per polygon.
Definition: Rodenticide.cpp:448
void DoDeath(void)
Reduce each cell in twin map by m_deathRate.
Definition: Rodenticide.h:121
CfgInt cfg_rodenticide_dumppolystartyear("RODENTICIDE_DUMPPOLYSTARTYEAR", CFG_CUSTOM, 99999)
vector< double > m_pmouse_map_main
Map of probability of encountering a poisoned mouse.
Definition: Rodenticide.h:79
CfgInt cfg_rodenticide_dumpmapstartyear("RODENTICIDE_DUMPMAPSTARTYEAR", CFG_CUSTOM, 99999)
CfgInt cfg_rodenticide_dumpmapday("RODENTICIDE_DUMPMAPDAY", CFG_CUSTOM, 180)
int SupplyYearNumber(void)
Definition: landscape.h:1540
CfgInt cfg_rodenticide_dumppolyinterval("RODENTICIDE_DUMPPOLYINTERVAL", CFG_CUSTOM, 180)
int m_height
Definition: Rodenticide.h:85
int SupplyDayInYear(void)
Definition: landscape.h:1520
int m_width
Landscape dimensions.
Definition: Rodenticide.h:85
void DoDiffuse(void)
Definition: Rodenticide.h:115
void DoImmigration(void)
Definition: Rodenticide.cpp:232
vector< double > m_pmouse_map_twin
Temporary map for calculation poisoned mouse diffusion.
Definition: Rodenticide.h:81
Landscape * m_land
Landscape pointer.
Definition: Rodenticide.h:83

Member Data Documentation

vector<BaitLocation> RodenticideManager::m_BaitList
protected

List of bait locations.

double RodenticideManager::m_deathRate
protected

poisoned mice death rate

double RodenticideManager::m_diffusionRate
protected

poisoned mice diffusion rate

int RodenticideManager::m_gridsize
protected

rodenticide grid size - also affect diffusion rate

int RodenticideManager::m_height
protected
int RodenticideManager::m_heightm1
protected
double RodenticideManager::m_immigrationRate
protected

poisoned mice immigration rate

Landscape* RodenticideManager::m_land
protected

Landscape pointer.

vector<double> RodenticideManager::m_pmouse_map_main
protected

Map of probability of encountering a poisoned mouse.

vector<double> RodenticideManager::m_pmouse_map_twin
protected

Temporary map for calculation poisoned mouse diffusion.

int RodenticideManager::m_seasonstartprob[tbl_foobar][1000]
protected

season start probability distribution

int RodenticideManager::m_width
protected

Landscape dimensions.


The documentation for this class was generated from the following files: