ALMaSS Rodenticide Model ODdox  1.0
Population_Manager Class Reference

Base class for all population managers. More...

#include <PopulationManager.h>

Public Member Functions

bool BeginningOfMonth ()
 
virtual void BreedingPairsOutput (int)
 
virtual void BreedingSuccessProbeOutput (double, int, int, int, int, int, int, int)
 
virtual void Catastrophe (int)
 
bool CheckXY (int l, int i)
 Debug method to test for out of bounds coordinates. More...
 
void CloseTheCIPEGridOutputProbe ()
 
void CloseTheMonthlyRipleysOutputProbe ()
 
void CloseTheReallyBigOutputProbe ()
 
void CloseTheRipleysOutputProbe ()
 
virtual void DisplayLocations ()
 
unsigned int FarmAnimalCensus (unsigned int a_farm, unsigned int a_typeofanimal)
 
TAnimalFindClosest (int x, int y, unsigned Type)
 
virtual void FledgelingProbeOutput (int, int)
 
virtual void GeneticsResultsOutput (FILE *, unsigned)
 
unsigned GetLiveArraySize (int a_listindex)
 Gets the number of 'live' objects for a list index in the TheArray. More...
 
TTypesOfPopulation GetPopulationType ()
 
int GetSeasonNumber ()
 Get the season number. More...
 
virtual void ImpactedProbe ()
 
void ImpactProbeReport (int a_Time)
 
void IncLiveArraySize (int a_listindex)
 Increments the number of 'live' objects for a list index in the TheArray. More...
 
bool IsLast (unsigned listindex)
 
void LamdaBirth (int x, int y)
 
void LamdaBirth (int x, int y, int z)
 
void LamdaClear ()
 
void LamdaDeath (int x, int y)
 
void LamdaDumpOutput ()
 
void LOG (const char *fname)
 
virtual bool OpenTheBreedingPairsProbe ()
 
virtual bool OpenTheBreedingSuccessProbe ()
 
bool OpenTheCIPEGridOutputProbe ()
 
virtual bool OpenTheFledgelingProbe ()
 
bool OpenTheMonthlyRipleysOutputProbe ()
 
bool OpenTheReallyBigProbe ()
 
bool OpenTheRipleysOutputProbe ()
 
 Population_Manager (Landscape *L)
 
virtual float Probe (int ListIndex, probe_data *p_TheProbe)
 
int ProbeFileInput (char *p_Filename, int p_ProbeNo)
 
char * ProbeReport (int a_time)
 
char * ProbeReportTimed (int a_time)
 
virtual void Run (int NoTSteps)
 
void SetNoProbes (int a_pn)
 
char * SpeciesSpecificReporting (int a_species, int a_time)
 
virtual int SupplyCovPosx (int)
 
virtual int SupplyCovPosy (int)
 
unsigned SupplyListIndexSize ()
 
const char * SupplyListName (int i)
 
int SupplyListNameLength ()
 
unsigned SupplyListSize (unsigned listindex)
 
virtual void SupplyLocXY (unsigned listindex, unsigned j, int &x, int &y)
 
virtual int SupplyPegPosx (int)
 
virtual int SupplyPegPosy (int)
 
int SupplySimH ()
 
int SupplySimW ()
 
int SupplyState (unsigned listindex, unsigned j)
 
const char * SupplyStateNames (int i)
 
unsigned SupplyStateNamesLength ()
 
int SupplyStepSize ()
 
virtual int TheBreedingFemalesProbe (int)
 
virtual int TheBreedingSuccessProbe (int &, int &, int &, int &, int &, int &)
 
virtual void TheCIPEGridOutputProbe ()
 
virtual int TheFledgelingProbe ()
 
virtual void TheGeneticProbe (unsigned, int, unsigned &)
 
virtual void TheNWordOutputProbe ()
 
virtual void TheReallyBigOutputProbe ()
 
virtual void TheRipleysOutputProbe (FILE *a_prb)
 
virtual ~Population_Manager (void)
 

Public Attributes

int IndexArrayX [5][10000]
 
char m_SimulationName [255]
 
Landscapem_TheLandscape
 
bool ProbesSet
 
int SimH
 
unsigned SimHH
 
int SimW
 
unsigned SimWH
 
probe_dataTheProbe [100]
 

Protected Member Functions

virtual void Catastrophe ()
 
virtual void DoAfter ()
 
virtual void DoAlmostLast ()
 
virtual void DoBefore ()
 
virtual void DoFirst ()
 
virtual void DoLast ()
 
void EmptyTheArray ()
 Removes all objects from the TheArray by deleting them and clearing TheArray. More...
 
void NWordOutput ()
 The output section for the NWord probe.
. More...
 
unsigned PartitionLiveDead (unsigned Type)
 
void Shuffle (unsigned Type)
 
void Shuffle_or_Sort (unsigned Type)
 
void SortState (unsigned Type)
 
void SortStateR (unsigned Type)
 
void SortX (unsigned Type)
 
void SortXIndex (unsigned Type)
 
void SortY (unsigned Type)
 
virtual bool StepFinished ()
 Overrides the population manager StepFinished - there is no chance that hunters do not finish a step behaviour. More...
 

Protected Attributes

unsigned BeforeStepActions [10]
 
FILE * CIPEGridOutputPrb
 
FILE * CIPEGridOutputPrbB
 
long int lamdagrid [2][257][257]
 
FILE * m_AlleleFreqsFile
 
int m_catastrophestartyear
 
intm_cgridcount
 
int m_cgridcountwidth
 
int m_cipegridsize
 
FILE * m_EasyPopRes
 
FILE * m_GeneticsFile
 
intm_gridcount [4]
 
int m_gridcountsize [4]
 
int m_gridcountwidth [4]
 
unsigned m_ListNameLength
 
const char * m_ListNames [10]
 
vector< unsigned > m_LiveArraySize
 
int m_NoProbes
 
TTypesOfPopulation m_population_type
 
int m_SeasonNumber
 Holds the season number. Used when running goose and hunter sims. More...
 
int m_StepSize
 
FILE * NWordOutputPrb
 
FILE * ReallyBigOutputPrb
 
FILE * RipleysOutputPrb
 
FILE * RipleysOutputPrb1
 
FILE * RipleysOutputPrb10
 
FILE * RipleysOutputPrb11
 
FILE * RipleysOutputPrb12
 
FILE * RipleysOutputPrb2
 
FILE * RipleysOutputPrb3
 
FILE * RipleysOutputPrb4
 
FILE * RipleysOutputPrb5
 
FILE * RipleysOutputPrb6
 
FILE * RipleysOutputPrb7
 
FILE * RipleysOutputPrb8
 
FILE * RipleysOutputPrb9
 
const char * StateNames [100]
 
unsigned StateNamesLength
 
FILE * TestFile
 
FILE * TestFile2
 
vector< TListOfAnimalsTheArray
 

Detailed Description

Base class for all population managers.

The core of the handling of animal populations. All time-step code and most input/output is handled by this class and its descendents. This class effectively implements a state machine to facilitate simulation of animal behaviours and handle potential issues with concurrency. The PopulationManager class is never instantiated but must be used by deriving a descendent class.

Constructor & Destructor Documentation

Population_Manager::Population_Manager ( Landscape L)

Constructor for the Population_Manager class

References cfg_CipeGridSize(), and cfg_RipleysOutputMonthly_used().

222  {
223  // Keep a pointer to the landscape this population is in
224  m_TheLandscape = L;
225  // create 10 empty arrays as default, excess can be removed in descendent classes
226  TListOfAnimals alist;
227  TheArray.insert( TheArray.end(), 10, alist );
228  // Set the simulation bounds
233  for (int i = 0; i < 10; i++) {
234  // Set default BeforeStepActions
235  BeforeStepActions[ i ] = 0;
236  m_ListNames[ i ] = "Unknown";
237  m_LiveArraySize.push_back( 0 );
238  }
239  // modify this if they need to in descendent classes
240  StateNamesLength = 0; // initialise this variable.
241  m_catastrophestartyear=-1; // Default is don't do this
242 #ifdef __LAMBDA_RECORD
243  ofstream fout("LambdaGridOuput.txt", ios_base::out); // open for writing
244  fout.close();
245  LamdaClear();
246 #endif
247  if ( cfg_RipleysOutputMonthly_used.value() ) {
249  }
253  m_gridcountsize[0] = 50;
254  m_gridcountsize[1] = 100;
255  m_gridcountsize[2] = 200;
256  m_gridcountsize[3] = 500;
257  m_gridcountwidth[0] = SimW/50;
258  m_gridcountwidth[1] = SimW/100;
259  m_gridcountwidth[2] = SimW/200;
260  m_gridcountwidth[3] = SimW/500;
261  m_gridcount[0] = new int[ m_gridcountwidth[0] * m_gridcountwidth[0] ];
262  m_gridcount[1] = new int[ m_gridcountwidth[1] * m_gridcountwidth[1] ];
263  m_gridcount[2] = new int[ m_gridcountwidth[2] * m_gridcountwidth[2] ];
264  m_gridcount[3] = new int[ m_gridcountwidth[3] * m_gridcountwidth[3] ];
265  // Ensure the GUI pointer is NULL in case we are not in GUI mode
266 #ifdef __ALMASS_VISUAL
267  m_MainForm = NULL;
268 #endif
269 }
int m_catastrophestartyear
Definition: PopulationManager.h:502
static CfgInt cfg_CipeGridSize("G_CIPEGRIDSIZE", CFG_CUSTOM, 500)
unsigned BeforeStepActions[10]
Definition: PopulationManager.h:511
int * m_cgridcount
Definition: PopulationManager.h:571
void LamdaClear()
Definition: PopulationManager.h:590
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
int SupplySimAreaWidth(void)
Definition: landscape.h:1556
unsigned SimHH
Definition: PopulationManager.h:483
unsigned SimWH
Definition: PopulationManager.h:483
int SimH
Definition: PopulationManager.h:482
int m_gridcountsize[4]
Definition: PopulationManager.h:576
int m_cgridcountwidth
Definition: PopulationManager.h:573
unsigned StateNamesLength
Definition: PopulationManager.h:505
bool OpenTheMonthlyRipleysOutputProbe()
Definition: PopulationManager.cpp:853
int SimW
Definition: PopulationManager.h:482
CfgBool cfg_RipleysOutputMonthly_used("G_RIPLEYSOUTPUTMONTHLY_USED", CFG_CUSTOM, false)
int m_cipegridsize
Definition: PopulationManager.h:575
int SupplySimAreaHeight(void)
Definition: landscape.h:1561
int m_gridcountwidth[4]
Definition: PopulationManager.h:574
int * m_gridcount[4]
Definition: PopulationManager.h:572
vector< unsigned > m_LiveArraySize
Definition: PopulationManager.h:495
const char * m_ListNames[10]
Definition: PopulationManager.h:507
Landscape * m_TheLandscape
Definition: PopulationManager.h:486
Population_Manager::~Population_Manager ( void  )
virtual

Destructor for the Population_Manager class

References cfg_ReallyBigOutput_used(), cfg_RipleysOutput_used(), and cfg_RipleysOutputMonthly_used().

275  {
276  // clean-up
277  for ( unsigned i = 0; i < TheArray.size(); i++ ) {
278  // if objects in the list need to be deleted:
279  for ( unsigned j = 0; j < (unsigned) GetLiveArraySize(i); j++ ) {
280  delete TheArray[ i ] [ j ];
281  }
282  // empty the array
283  TheArray[ i ].clear();
284  // --
285  }
286  if ( cfg_RipleysOutput_used.value() ) {
288  fclose( NWordOutputPrb );
289  }
290  if ( cfg_RipleysOutputMonthly_used.value() ) {
292  }
293  if ( cfg_ReallyBigOutput_used.value() ) {
295  }
296  for (int d=0; d<4; d++) delete [] m_gridcount[d];
297  delete [] m_cgridcount;
298 }
unsigned GetLiveArraySize(int a_listindex)
Gets the number of &#39;live&#39; objects for a list index in the TheArray.
Definition: PopulationManager.h:408
FILE * NWordOutputPrb
Definition: PopulationManager.h:570
int * m_cgridcount
Definition: PopulationManager.h:571
void CloseTheMonthlyRipleysOutputProbe()
Definition: PopulationManager.cpp:960
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
void CloseTheRipleysOutputProbe()
Definition: PopulationManager.cpp:949
CfgBool cfg_RipleysOutputMonthly_used("G_RIPLEYSOUTPUTMONTHLY_USED", CFG_CUSTOM, false)
CfgBool cfg_ReallyBigOutput_used("G_REALLYBIGOUTPUT_USED", CFG_CUSTOM, false)
void CloseTheReallyBigOutputProbe()
Definition: PopulationManager.cpp:979
int * m_gridcount[4]
Definition: PopulationManager.h:572
CfgBool cfg_RipleysOutput_used("G_RIPLEYSOUTPUT_USED", CFG_CUSTOM, true)

Member Function Documentation

bool Population_Manager::BeginningOfMonth ( )

Is it the first day of the month?

References cfg_DayInMonth().

1171  {
1172  if ( m_TheLandscape->SupplyDayInMonth() == cfg_DayInMonth.value() ) return true;
1173  return false;
1174 }
int SupplyDayInMonth(void)
Definition: landscape.h:1530
static CfgInt cfg_DayInMonth("PRB_DAYINMONTH", CFG_CUSTOM, 1)
Landscape * m_TheLandscape
Definition: PopulationManager.h:486
virtual void Population_Manager::BreedingPairsOutput ( int  )
inlinevirtual
622  {
623  }
virtual void Population_Manager::BreedingSuccessProbeOutput ( double  ,
int  ,
int  ,
int  ,
int  ,
int  ,
int  ,
int   
)
inlinevirtual
630  {
631  }
virtual void Population_Manager::Catastrophe ( int  )
inlinevirtual
void Population_Manager::Catastrophe ( )
protectedvirtual

This method MUST be overidden in descendent classes if this functionality is does not match with the animals requirements

1178  {
1183  return;
1184 }
bool Population_Manager::CheckXY ( int  l,
int  i 
)

Debug method to test for out of bounds coordinates.

1588 {
1589  if (TheArray[l][i]->Supply_m_Location_x() > 10000) return true;
1590  if (TheArray[l][i]->Supply_m_Location_y() > 10000) return true;
1591  if (TheArray[l][i]->Supply_m_Location_x() < 0) return true;
1592  if (TheArray[l][i]->Supply_m_Location_y() < 0) return true;
1593  return false;
1594 }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
void Population_Manager::CloseTheCIPEGridOutputProbe ( )

close the probe

789  {
790  if ( CIPEGridOutputPrb != NULL )
791  fclose( CIPEGridOutputPrb );
792  fclose( CIPEGridOutputPrbB );
793 }
FILE * CIPEGridOutputPrb
Definition: PopulationManager.h:567
FILE * CIPEGridOutputPrbB
Definition: PopulationManager.h:568
void Population_Manager::CloseTheMonthlyRipleysOutputProbe ( )

close the monthly probes

960  {
961  fclose( RipleysOutputPrb1 );
962  fclose( RipleysOutputPrb2 );
963  fclose( RipleysOutputPrb3 );
964  fclose( RipleysOutputPrb4 );
965  fclose( RipleysOutputPrb5 );
966  fclose( RipleysOutputPrb6 );
967  fclose( RipleysOutputPrb7 );
968  fclose( RipleysOutputPrb8 );
969  fclose( RipleysOutputPrb9 );
970  fclose( RipleysOutputPrb10 );
971  fclose( RipleysOutputPrb11 );
972  fclose( RipleysOutputPrb12 );
973 }
FILE * RipleysOutputPrb3
Definition: PopulationManager.h:557
FILE * RipleysOutputPrb7
Definition: PopulationManager.h:561
FILE * RipleysOutputPrb4
Definition: PopulationManager.h:558
FILE * RipleysOutputPrb1
Definition: PopulationManager.h:555
FILE * RipleysOutputPrb10
Definition: PopulationManager.h:564
FILE * RipleysOutputPrb12
Definition: PopulationManager.h:566
FILE * RipleysOutputPrb9
Definition: PopulationManager.h:563
FILE * RipleysOutputPrb5
Definition: PopulationManager.h:559
FILE * RipleysOutputPrb8
Definition: PopulationManager.h:562
FILE * RipleysOutputPrb6
Definition: PopulationManager.h:560
FILE * RipleysOutputPrb11
Definition: PopulationManager.h:565
FILE * RipleysOutputPrb2
Definition: PopulationManager.h:556
void Population_Manager::CloseTheReallyBigOutputProbe ( )

close the probe

979  {
980  if ( ReallyBigOutputPrb != 0 )
981  fclose( ReallyBigOutputPrb );
983 }
FILE * ReallyBigOutputPrb
Definition: PopulationManager.h:569
void Population_Manager::CloseTheRipleysOutputProbe ( )

close the probe

References cfg_RipleysOutputMonthly_used().

949  {
950  if ( cfg_RipleysOutputMonthly_used.value() )
951  fclose( RipleysOutputPrb );
952  RipleysOutputPrb=NULL;
953 }
FILE * RipleysOutputPrb
Definition: PopulationManager.h:554
CfgBool cfg_RipleysOutputMonthly_used("G_RIPLEYSOUTPUTMONTHLY_USED", CFG_CUSTOM, false)
void Population_Manager::DisplayLocations ( )
virtual

Used to update the graphics when control is not returned to the ALMaSS_GUI between timesteps.

571 {
575 #ifdef __ALMASS_VISUAL
576  m_MainForm->UpdateGraphics();
577 #endif
578 }
void Population_Manager::DoAfter ( )
protectedvirtual

Can be used in descendent classes

523  {
524  //TODO: Add your source code here
525 }
void Population_Manager::DoAlmostLast ( )
protectedvirtual

Can be used in descendent classes

532  {
533  //TODO: Add your source code here
534 }
void Population_Manager::DoBefore ( )
protectedvirtual

Can be used in descendent classes

339  {
340 }
void Population_Manager::DoFirst ( )
protectedvirtual

Can be used in descendent classes

331  {
332 }
void Population_Manager::DoLast ( )
protectedvirtual

Collects some data to describe the number of animals in each state at the end of the day

540  {
541 
542 /*
543 #ifdef __UNIX__
544  for ( unsigned i = 0; i < 100; i++ ) {
545  StateList.n[ i ] = 0;
546  }
547 #else
548  // Zero results
549  for ( unsigned listindex = 0; listindex < m_ListNameLength; listindex++ ) {
550  for ( unsigned i = 0; i < 100; i++ ) {
551  Counts[ listindex ] [ i ] = 0;
552  }
553  }
554 #endif
555  // How many animals in each state?
556  for ( unsigned listindex = 0; listindex < TheArray.size(); listindex++ ) {
557  unsigned size = (unsigned) TheArray[ listindex ].size();
558  for ( unsigned j = 0; j < size; j++ ) {
559 #ifdef __UNIX__
560  StateList.n[ TheArray[ listindex ] [ j ]->WhatState() ] ++;
561 #else
562  Counts[ listindex ] [ TheArray[ listindex ] [ j ]->WhatState() ] ++;
563 #endif
564  }
565  }
566 */
567 }
void Population_Manager::EmptyTheArray ( )
protected

Removes all objects from the TheArray by deleting them and clearing TheArray.

Sort TheArray w.r.t. the m_Location_x attribute

1032 {
1033  for ( unsigned i = 0; i < TheArray.size(); i++ )
1034  {
1035  // if objects in the list need to be deleted:
1036  for (unsigned j = 0; j < (unsigned) TheArray[i].size(); j++)
1037  {
1038  delete TheArray[ i ] [ j ];
1039  }
1040  // empty the array
1041  TheArray[ i ].clear();
1042  }
1043 }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
unsigned int Population_Manager::FarmAnimalCensus ( unsigned int  a_farm,
unsigned int  a_typeofanimal 
)
1331 {
1332  unsigned int No = 0;
1333  unsigned sz = (unsigned)GetLiveArraySize( a_typeofanimal );
1334  for ( unsigned j = 0; j < sz; j++ )
1335  {
1336  if (a_farm == TheArray[ a_typeofanimal ] [ j ]->SupplyFarmOwnerRef()) No++;
1337  }
1338  return No;
1339 }
unsigned GetLiveArraySize(int a_listindex)
Gets the number of &#39;live&#39; objects for a list index in the TheArray.
Definition: PopulationManager.h:408
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
TAnimal * Population_Manager::FindClosest ( int  x,
int  y,
unsigned  Type 
)

Finds the closest individual to an x,y point

1006  {
1007  int distance = 100000000;
1008  TAnimal * TA = NULL;
1009  int dx, dy, d;
1010  for (unsigned j = 0; j < (unsigned)GetLiveArraySize( Type ); j++) {
1011  dx = TheArray[ Type ] [ j ]->Supply_m_Location_x();
1012  dy = TheArray[ Type ] [ j ]->Supply_m_Location_y();
1013  dx = ( dx - x );
1014  dx *= dx;
1015  dy = ( dy - y );
1016 
1017  dy *= dy;
1018  d = dx + dy;
1019  if ( d < distance ) {
1020  distance = d;
1021  TA = TheArray[ Type ] [ j ];
1022  }
1023  }
1024  return TA;
1025 }
unsigned GetLiveArraySize(int a_listindex)
Gets the number of &#39;live&#39; objects for a list index in the TheArray.
Definition: PopulationManager.h:408
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
The base class for all ALMaSS animal classes.
Definition: PopulationManager.h:201
virtual void Population_Manager::FledgelingProbeOutput ( int  ,
int   
)
inlinevirtual
635  {
636  }
virtual void Population_Manager::GeneticsResultsOutput ( FILE *  ,
unsigned   
)
inlinevirtual
639  {
640  }
unsigned Population_Manager::GetLiveArraySize ( int  a_listindex)
inline

Gets the number of 'live' objects for a list index in the TheArray.

408  {
409  return m_LiveArraySize[a_listindex];
410  }
vector< unsigned > m_LiveArraySize
Definition: PopulationManager.h:495
TTypesOfPopulation Population_Manager::GetPopulationType ( )
inline
549 { return m_population_type; }
TTypesOfPopulation m_population_type
Definition: PopulationManager.h:553
int Population_Manager::GetSeasonNumber ( )
inline

Get the season number.

551 {return m_SeasonNumber;}
int m_SeasonNumber
Holds the season number. Used when running goose and hunter sims.
Definition: PopulationManager.h:513
void Population_Manager::ImpactedProbe ( )
virtual

Special pesticide related probe. Overidden in descendent classes

682  {
683 
684 }
void Population_Manager::ImpactProbeReport ( int  a_Time)

Special probe

References BeginningOfMonth().

1390  {
1391 
1392  for ( int ProbeNo = 0; ProbeNo < 1; ProbeNo++ ) {
1393  // See if we need to record/update this one
1394  // if time/months/years ==0 or every time
1395  if ( ( TheProbe[ ProbeNo ]->m_ReportInterval == 3 )
1396  || ( ( TheProbe[ ProbeNo ]->m_ReportInterval == 2 ) && ( BeginningOfMonth() ) )
1397  || ( ( TheProbe[ ProbeNo ]->m_ReportInterval == 1 ) && ( a_Time % 365 == 0 ) ) ) {
1398  ImpactedProbe();
1399  }
1400  }
1401 }
probe_data * TheProbe[100]
Definition: PopulationManager.h:481
virtual void ImpactedProbe()
Definition: PopulationManager.cpp:682
bool BeginningOfMonth()
Definition: PopulationManager.cpp:1171
void Population_Manager::IncLiveArraySize ( int  a_listindex)
inline

Increments the number of 'live' objects for a list index in the TheArray.

412  {
413  m_LiveArraySize[a_listindex]++;
414  }
vector< unsigned > m_LiveArraySize
Definition: PopulationManager.h:495
bool Population_Manager::IsLast ( unsigned  listindex)
inline
452  {
453  if ( TheArray[ listindex ].size() > 1 ) return false; else
454  return true;
455  }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
void Population_Manager::LamdaBirth ( int  x,
int  y 
)
inline
584  {
585  lamdagrid[0][x / __lgridsize][y / __lgridsize ]++;
586  }
long int lamdagrid[2][257][257]
Definition: PopulationManager.h:578
void Population_Manager::LamdaBirth ( int  x,
int  y,
int  z 
)
inline
587  {
588  lamdagrid[0][x / __lgridsize][y / __lgridsize ]+=z;
589  }
long int lamdagrid[2][257][257]
Definition: PopulationManager.h:578
void Population_Manager::LamdaClear ( )
inline
590  {
591  for (int i=0; i<257; i++ ) {
592  for (int j=0; j<257; j++) {
593  lamdagrid[0][i][j]=0;
594  lamdagrid[1][i][j]=0;
595  }
596  }
597  }
long int lamdagrid[2][257][257]
Definition: PopulationManager.h:578
void Population_Manager::LamdaDeath ( int  x,
int  y 
)
inline
580  {
581  // inlined for speed
582  lamdagrid[1][x / __lgridsize][y / __lgridsize ]++;
583  }
long int lamdagrid[2][257][257]
Definition: PopulationManager.h:578
void Population_Manager::LamdaDumpOutput ( )

Special probe

667  {
668  ofstream fout("LambdaGridOuput.txt", ios_base::app); // open for writing
669  for (int i=0; i<257; i++ ) {
670  for (int j=0; j<257; j++) {
671  fout << lamdagrid[0][i][j] << "\t" << lamdagrid[1][i][j] << endl;
672  }
673  }
674  //fout << "NEXT" << endl;
675  fout.close();
676 }
long int lamdagrid[2][257][257]
Definition: PopulationManager.h:578
void Population_Manager::LOG ( const char *  fname)

Debug function used to log whatever is needed - this is just a place to write whatever is needed at the time - so contents vary

References AnimalPosition::m_x, and AnimalPosition::m_y.

305  {
306  FILE * PFile = fopen(fname, "w" );
307  if (PFile) {
308  m_TheLandscape->Warn("PopulationManager::LOG - Could not open file ",fname);
309  exit(0);
310  }
311  AnimalPosition AP;
312  for ( unsigned listindex = 0; listindex < TheArray.size(); listindex++ ) {
313 #ifndef __BCB__
314  fprintf( PFile, "%s :\n", m_ListNames[ listindex ] );
315 #else
316  fprintf( PFile, "%s :\n", m_ListNames[ listindex ].c_str() );
317 #endif
318  for ( unsigned j = 0; j < (unsigned) m_LiveArraySize[listindex]; j++ ) {
319  AP = TheArray[ listindex ] [ j ]->SupplyPosition();
320  fprintf( PFile, "%i %i %i\n", j, AP.m_x, AP.m_y );
321  }
322  }
323  fclose( PFile );
324 }
A class defining an animals position.
Definition: PopulationManager.h:164
unsigned m_y
Definition: PopulationManager.h:169
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
unsigned m_x
Definition: PopulationManager.h:168
void Warn(std::string a_msg1, std::string a_msg2)
Definition: landscape.h:1503
vector< unsigned > m_LiveArraySize
Definition: PopulationManager.h:495
const char * m_ListNames[10]
Definition: PopulationManager.h:507
Landscape * m_TheLandscape
Definition: PopulationManager.h:486
void Population_Manager::NWordOutput ( )
protected

The output section for the NWord probe.
.

A common output stub for the NWord output probe. Specialist counting for each species occurs as part of the CIPE grid probe, then this method deals with the final output.

803  {
806  int Counted[4];
807  int totalcells[4];
808  int OccupiedCells[4];
809  for (int cellwidth=0; cellwidth<4; cellwidth++) {
810  Counted[cellwidth] = 0;
811  totalcells[cellwidth] = m_gridcountwidth[cellwidth] * m_gridcountwidth[cellwidth];
812  OccupiedCells[cellwidth] = 0;
813  for (int i=0; i<m_gridcountwidth[cellwidth]; i++) {
814  for (int j=0; j<m_gridcountwidth[cellwidth]; j++) {
815  int res=m_gridcount[cellwidth][i+j*m_gridcountwidth[cellwidth]];
816  Counted[cellwidth] += res;
817  if (res>0) OccupiedCells[cellwidth]++;
818  }
819  }
820  }
821  fprintf(NWordOutputPrb,"%d\t%d\t%d\t", m_TheLandscape->SupplyYearNumber() ,(int)m_TheLandscape->SupplyDayInYear(), Counted[0] );
822  for (int c=0; c<4; c++) {
823  fprintf(NWordOutputPrb,"%d\t%d\t", totalcells[c], OccupiedCells[c]);
824  }
825  fprintf(NWordOutputPrb,"\n");
826  fflush(NWordOutputPrb);
827 }
FILE * NWordOutputPrb
Definition: PopulationManager.h:570
int SupplyYearNumber(void)
Definition: landscape.h:1540
int SupplyDayInYear(void)
Definition: landscape.h:1520
int m_gridcountwidth[4]
Definition: PopulationManager.h:574
int * m_gridcount[4]
Definition: PopulationManager.h:572
Landscape * m_TheLandscape
Definition: PopulationManager.h:486
virtual bool Population_Manager::OpenTheBreedingPairsProbe ( )
inlinevirtual

Referenced by CreatePopulationManager().

616  {
617  return false;
618  }
virtual bool Population_Manager::OpenTheBreedingSuccessProbe ( )
inlinevirtual

Referenced by CreatePopulationManager().

619  {
620  return false;
621  }
bool Population_Manager::OpenTheCIPEGridOutputProbe ( )

open the probe

References cfg_CIPEGridOutput_filename(), and cfg_CIPEGridOutput_filenameB().

768  {
769  CIPEGridOutputPrb = fopen(cfg_CIPEGridOutput_filename.value(), "w" );
770  if ( !CIPEGridOutputPrb ) {
771  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheCIPEGridOutputProbe(): ""Unable to open probe file",
772  cfg_CIPEGridOutput_filename.value() );
773  exit( 1 );
774  }
775  CIPEGridOutputPrbB = fopen(cfg_CIPEGridOutput_filenameB.value(), "w" );
776  if ( !CIPEGridOutputPrbB ) {
777  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheCIPEGridOutputProbe(): ""Unable to open probe file",
779  exit( 1 );
780  }
781  return true;
782 }
CfgStr cfg_CIPEGridOutput_filename("G_CIPEGRIDOUTPUT_FILENAME", CFG_CUSTOM,"CIPEGridOutput.txt")
FILE * CIPEGridOutputPrb
Definition: PopulationManager.h:567
FILE * CIPEGridOutputPrbB
Definition: PopulationManager.h:568
CfgStr cfg_CIPEGridOutput_filenameB("G_CIPEGRIDOUTPUT_FILENAME_B", CFG_CUSTOM,"CIPEGridOutputB.txt")
virtual bool Population_Manager::OpenTheFledgelingProbe ( )
inlinevirtual

Referenced by CreatePopulationManager().

613  {
614  return false;
615  }
bool Population_Manager::OpenTheMonthlyRipleysOutputProbe ( )

open 12 ripley output probles, one for each month

References cfg_RipleysOutput_filename().

853  {
854  RipleysOutputPrb1 = fopen("RipleyOutput_Jan.txt", "w" );
855  if ( !RipleysOutputPrb1 ) {
856  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
857  cfg_RipleysOutput_filename.value() );
858  exit( 1 );
859  }
860  RipleysOutputPrb2 = fopen("RipleyOutput_Feb.txt", "w" );
861  if ( !RipleysOutputPrb2 ) {
862  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
863  cfg_RipleysOutput_filename.value() );
864  exit( 1 );
865  }
866  RipleysOutputPrb3 = fopen("RipleyOutput_Mar.txt", "w" );
867  if ( !RipleysOutputPrb3 ) {
868  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
869  cfg_RipleysOutput_filename.value() );
870  exit( 1 );
871  }
872  RipleysOutputPrb4 = fopen("RipleyOutput_Apr.txt", "w" );
873  if ( !RipleysOutputPrb4 ) {
874  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
875  cfg_RipleysOutput_filename.value() );
876  exit( 1 );
877  }
878  RipleysOutputPrb5 = fopen("RipleyOutput_May.txt", "w" );
879  if ( !RipleysOutputPrb5 ) {
880  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
881  cfg_RipleysOutput_filename.value() );
882  exit( 1 );
883  }
884  RipleysOutputPrb6 = fopen("RipleyOutput_Jun.txt", "w" );
885  if ( !RipleysOutputPrb6 ) {
886  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
887  cfg_RipleysOutput_filename.value() );
888  exit( 1 );
889  }
890  RipleysOutputPrb7 = fopen("RipleyOutput_Jul.txt", "w" );
891  if ( !RipleysOutputPrb7 ) {
892  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
893  cfg_RipleysOutput_filename.value() );
894  exit( 1 );
895  }
896  RipleysOutputPrb8 = fopen("RipleyOutput_Aug.txt", "w" );
897  if ( !RipleysOutputPrb8 ) {
898  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
899  cfg_RipleysOutput_filename.value() );
900  exit( 1 );
901  }
902  RipleysOutputPrb9 = fopen("RipleyOutput_Sep.txt", "w" );
903  if ( !RipleysOutputPrb9 ) {
904  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
905  cfg_RipleysOutput_filename.value() );
906  exit( 1 );
907  }
908  RipleysOutputPrb10 = fopen("RipleyOutput_Oct.txt", "w" );
909  if ( !RipleysOutputPrb10 ) {
910  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
911  cfg_RipleysOutput_filename.value() );
912  exit( 1 );
913  }
914  RipleysOutputPrb11 = fopen("RipleyOutput_Nov.txt", "w" );
915  if ( !RipleysOutputPrb11 ) {
916  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
917  cfg_RipleysOutput_filename.value() );
918  exit( 1 );
919  }
920  RipleysOutputPrb12 = fopen("RipleyOutput_Dec.txt", "w" );
921  if ( !RipleysOutputPrb12 ) {
922  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
923  cfg_RipleysOutput_filename.value() );
924  exit( 1 );
925  }
926  return true;
927 }
FILE * RipleysOutputPrb3
Definition: PopulationManager.h:557
FILE * RipleysOutputPrb7
Definition: PopulationManager.h:561
FILE * RipleysOutputPrb4
Definition: PopulationManager.h:558
FILE * RipleysOutputPrb1
Definition: PopulationManager.h:555
FILE * RipleysOutputPrb10
Definition: PopulationManager.h:564
FILE * RipleysOutputPrb12
Definition: PopulationManager.h:566
FILE * RipleysOutputPrb9
Definition: PopulationManager.h:563
FILE * RipleysOutputPrb5
Definition: PopulationManager.h:559
FILE * RipleysOutputPrb8
Definition: PopulationManager.h:562
static CfgStr cfg_RipleysOutput_filename("G_RIPLEYSOUTPUT_FILENAME", CFG_CUSTOM,"RipleysOutput.txt")
FILE * RipleysOutputPrb6
Definition: PopulationManager.h:560
FILE * RipleysOutputPrb11
Definition: PopulationManager.h:565
FILE * RipleysOutputPrb2
Definition: PopulationManager.h:556
bool Population_Manager::OpenTheReallyBigProbe ( )

open the probe

References cfg_ReallyBigOutput_filename().

934  {
935  ReallyBigOutputPrb = fopen(cfg_ReallyBigOutput_filename.value(), "w" );
936  if ( !ReallyBigOutputPrb ) {
937  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
939  exit( 1 );
940  }
941  return true;
942 }
FILE * ReallyBigOutputPrb
Definition: PopulationManager.h:569
static CfgStr cfg_ReallyBigOutput_filename("G_REALLYBIGOUTPUT_FILENAME", CFG_CUSTOM,"ReallyBigOutput.txt")
bool Population_Manager::OpenTheRipleysOutputProbe ( )

open the probe

References cfg_RipleysOutput_filename().

833  {
834  RipleysOutputPrb = fopen(cfg_RipleysOutput_filename.value(), "w" );
835  if ( !RipleysOutputPrb ) {
836  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheRipleysOutputProbe(): ""Unable to open probe file",
837  cfg_RipleysOutput_filename.value() );
838  exit( 1 );
839  }
840  NWordOutputPrb = fopen("NWordOutputPrb.txt", "w" );
841  if ( !NWordOutputPrb ) {
842  g_msg->Warn( WARN_FILE, "Population_Manager::OpenTheCIPEGridOutputProbe(): ""Unable to open NWord probe file", "" );
843  exit( 1 );
844  }
845  fprintf(NWordOutputPrb,"%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\t\n","Year","Day","Total no.","Cells50","Occupied50","Cells100","Occupied100","Cells200","Occupied200","Cells400","Occupied400");
846  return true;
847 }
FILE * NWordOutputPrb
Definition: PopulationManager.h:570
FILE * RipleysOutputPrb
Definition: PopulationManager.h:554
static CfgStr cfg_RipleysOutput_filename("G_RIPLEYSOUTPUT_FILENAME", CFG_CUSTOM,"RipleysOutput.txt")
unsigned Population_Manager::PartitionLiveDead ( unsigned  Type)
protected

Sort TheArray w.r.t. the current state attribute in reverse order

1084  {
1085  auto it = partition(TheArray[Type].begin(), TheArray[Type].begin() + m_LiveArraySize[Type], CompareStateAlive());
1086  // it now points at the first dead element
1087  // the number of live ones before it is it-TheArray[Type].begin(). This is the new vector size for live animals.
1088  return unsigned(it - TheArray[Type].begin());
1089 }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
Function to compare to TAnimal&#39;s m_CurrentStateNo to anything but -1.
Definition: PopulationManager.cpp:206
vector< unsigned > m_LiveArraySize
Definition: PopulationManager.h:495
float Population_Manager::Probe ( int  ListIndex,
probe_data p_TheProbe 
)
virtual

Default data probe. Rarely used in actuality but always available

References AnimalPosition::m_EleType, probe_data::m_NoAreas, probe_data::m_NoEleTypes, probe_data::m_NoFarms, probe_data::m_NoVegTypes, probe_data::m_Rect, probe_data::m_RefEle, probe_data::m_RefFarms, probe_data::m_RefVeg, AnimalPosition::m_VegType, AnimalPosition::m_x, rectangle::m_x1, rectangle::m_x2, AnimalPosition::m_y, rectangle::m_y1, and rectangle::m_y2.

690  {
691  // Counts through the list and goes through each area to see if the animal
692  // is standing there and if the farm, veg or element conditions are met
693  AnimalPosition Sp;
694  float NumberSk = 0;
695  // Four possibilites
696  // either NoVegTypes or NoElementTypes or NoFarmTypes is >0 or all==0
697  if ( p_TheProbe->m_NoFarms != 0 ) {
698  for (unsigned j = 0; j < (unsigned)GetLiveArraySize( ListIndex ); j++) {
699  Sp = TheArray[ ListIndex ] [ j ]->SupplyPosition();
700  unsigned Farm = TheArray[ ListIndex ] [ j ]->SupplyFarmOwnerRef();
701  for ( unsigned i = 0; i < p_TheProbe->m_NoAreas; i++ ) {
702  if ( ( Sp.m_x >= p_TheProbe->m_Rect[ i ].m_x1 ) && ( Sp.m_y >= p_TheProbe->m_Rect[ i ].m_y1 )
703  && ( Sp.m_x <= p_TheProbe->m_Rect[ i ].m_x2 ) && ( Sp.m_y <= p_TheProbe->m_Rect[ i ].m_y2 ) )
704  for ( unsigned k = 0; k < p_TheProbe->m_NoFarms; k++ ) {
705  if ( p_TheProbe->m_RefFarms[ k ] == Farm )
706  NumberSk++; // it is in the square so increment number
707  }
708 
709  }
710  }
711  } else if ( p_TheProbe->m_NoEleTypes != 0 ) {
712  for (unsigned j = 0; j < (unsigned)GetLiveArraySize( ListIndex ); j++) {
713  Sp = TheArray[ ListIndex ] [ j ]->SupplyPosition();
714  for ( unsigned i = 0; i < p_TheProbe->m_NoAreas; i++ ) {
715  if ( ( Sp.m_x >= p_TheProbe->m_Rect[ i ].m_x1 ) && ( Sp.m_y >= p_TheProbe->m_Rect[ i ].m_y1 )
716  && ( Sp.m_x <= p_TheProbe->m_Rect[ i ].m_x2 ) && ( Sp.m_y <= p_TheProbe->m_Rect[ i ].m_y2 ) )
717  for ( unsigned k = 0; k < p_TheProbe->m_NoEleTypes; k++ ) {
718  if ( p_TheProbe->m_RefEle[ k ] == Sp.m_EleType )
719  NumberSk++; // it is in the square so increment number
720  }
721  }
722  }
723  } else {
724  if ( p_TheProbe->m_NoVegTypes != 0 ) {
725  for (unsigned j = 0; j < (unsigned)GetLiveArraySize( ListIndex ); j++) {
726  Sp = TheArray[ ListIndex ] [ j ]->SupplyPosition();
727 
728  for ( unsigned i = 0; i < p_TheProbe->m_NoAreas; i++ ) {
729  if ( ( Sp.m_x >= p_TheProbe->m_Rect[ i ].m_x1 ) && ( Sp.m_y >= p_TheProbe->m_Rect[ i ].m_y1 )
730  && ( Sp.m_x <= p_TheProbe->m_Rect[ i ].m_x2 ) && ( Sp.m_y <= p_TheProbe->m_Rect[ i ].m_y2 ) ) {
731  for ( unsigned k = 0; k < p_TheProbe->m_NoVegTypes; k++ ) {
732  if ( p_TheProbe->m_RefVeg[ k ] == Sp.m_VegType )
733  NumberSk++; // it is in the square so increment number
734  }
735  }
736  }
737  }
738  } else // both must be zero
739  {
740  unsigned sz = (unsigned)GetLiveArraySize( ListIndex );
741  // It is worth checking whether we have a total dump of all individuals
742  // if so don't bother with asking each where it is
743  if (p_TheProbe->m_NoAreas==1) {
744  if ((p_TheProbe->m_Rect[0].m_x1==0) && (p_TheProbe->m_Rect[0].m_y1==0) && (p_TheProbe->m_Rect[0].m_x2==(unsigned)SimW) &&
745  (p_TheProbe->m_Rect[0].m_y2==(unsigned)SimH)) {
746  return (float) sz;
747  }
748  }
749  // Asking for a subset - need to test them all
750  for ( unsigned j = 0; j < sz; j++ ) {
751  Sp = TheArray[ ListIndex ] [ j ]->SupplyPosition();
752  for ( unsigned i = 0; i < p_TheProbe->m_NoAreas; i++ ) {
753  if ( ( Sp.m_x >= p_TheProbe->m_Rect[ i ].m_x1 ) && ( Sp.m_y >= p_TheProbe->m_Rect[ i ].m_y1 )
754  && ( Sp.m_x <= p_TheProbe->m_Rect[ i ].m_x2 ) && ( Sp.m_y <= p_TheProbe->m_Rect[ i ].m_y2 ) )
755  NumberSk++; // it is in the square so increment number
756  }
757  }
758  }
759  }
760  return NumberSk;
761 }
rectangle m_Rect[10]
Definition: PopulationManager.h:289
A class defining an animals position.
Definition: PopulationManager.h:164
unsigned GetLiveArraySize(int a_listindex)
Gets the number of &#39;live&#39; objects for a list index in the TheArray.
Definition: PopulationManager.h:408
TTypesOfLandscapeElement m_EleType
Definition: PopulationManager.h:170
unsigned m_NoAreas
Definition: PopulationManager.h:288
unsigned m_y
Definition: PopulationManager.h:169
unsigned m_RefFarms[25]
Definition: PopulationManager.h:295
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
unsigned m_NoVegTypes
Definition: PopulationManager.h:291
int SimH
Definition: PopulationManager.h:482
TTypesOfVegetation m_RefVeg[25]
Definition: PopulationManager.h:293
unsigned m_x1
Definition: PopulationManager.h:96
TTypesOfVegetation m_VegType
Definition: PopulationManager.h:171
int SimW
Definition: PopulationManager.h:482
TTypesOfLandscapeElement m_RefEle[25]
Definition: PopulationManager.h:294
unsigned m_NoEleTypes
Definition: PopulationManager.h:290
unsigned m_x
Definition: PopulationManager.h:168
unsigned m_y1
Definition: PopulationManager.h:97
unsigned m_NoFarms
Definition: PopulationManager.h:292
unsigned m_x2
Definition: PopulationManager.h:98
unsigned m_y2
Definition: PopulationManager.h:99
int Population_Manager::ProbeFileInput ( char *  p_Filename,
int  p_ProbeNo 
)

Default probe file input

Referenced by GetProbeInput_ini().

584  {
585  FILE * PFile;
586  int data = 0;
587  int data2 = 0;
588  char S[ 255 ];
589  PFile = fopen(p_Filename, "r" );
590  if ( !PFile ) {
591  m_TheLandscape->Warn( "Population Manager - cannot open Probe File ", p_Filename );
592  exit( 0 );
593  }
594  fgets( S, 255, PFile ); // dummy line
595  fgets( S, 255, PFile ); // dummy line
596  fscanf( PFile, "%d\n", & data ); // Reporting interval
597  TheProbe[ p_ProbeNo ]->m_ReportInterval = data;
598  fgets( S, 255, PFile ); // dummy line
599  fscanf( PFile, "%d\n", & data ); // Write to file
600  if ( data == 0 ) TheProbe[ p_ProbeNo ]->m_FileRecord = false; else
601  TheProbe[ p_ProbeNo ]->m_FileRecord = true;
602  fgets( S, 255, PFile ); // dummy line
603  for ( int i = 0; i < 10; i++ ) {
604  fscanf( PFile, "%d", & data );
605  if ( data > 0 ) TheProbe[ p_ProbeNo ]->m_TargetTypes[ i ] = true; else
606  TheProbe[ p_ProbeNo ]->m_TargetTypes[ i ] = false;
607  }
608 
609  fgets( S, 255, PFile ); // dummy line
610  fgets( S, 255, PFile ); // dummy line
611  fscanf( PFile, "%d", & data );
612  TheProbe[ p_ProbeNo ]->m_NoAreas = data;
613  fgets( S, 255, PFile ); // dummy line
614  fgets( S, 255, PFile ); // dummy line
615  fscanf( PFile, "%d", & data2 ); // No References areas
616  fgets( S, 255, PFile ); // dummy line
617  fgets( S, 255, PFile ); // dummy line
618  fscanf( PFile, "%d", & data ); // Type reference for probe
619  if ( data == 1 ) TheProbe[ p_ProbeNo ]->m_NoEleTypes = data2; else
620  TheProbe[ p_ProbeNo ]->m_NoEleTypes = 0;
621  if ( data == 2 ) TheProbe[ p_ProbeNo ]->m_NoVegTypes = data2; else
622  TheProbe[ p_ProbeNo ]->m_NoVegTypes = 0;
623  if ( data == 3 ) TheProbe[ p_ProbeNo ]->m_NoFarms = data2; else
624  TheProbe[ p_ProbeNo ]->m_NoFarms = 0;
625  fgets( S, 255, PFile ); // dummy line
626  fgets( S, 255, PFile ); // dummy line
627  // Now read in the areas data
628  for ( int i = 0; i < 10; i++ ) {
629  fscanf( PFile, "%d", & data );
630  TheProbe[ p_ProbeNo ]->m_Rect[ i ].m_x1 = data;
631  fscanf( PFile, "%d", & data );
632  TheProbe[ p_ProbeNo ]->m_Rect[ i ].m_y1 = data;
633  fscanf( PFile, "%d", & data );
634  TheProbe[ p_ProbeNo ]->m_Rect[ i ].m_x2 = data;
635  fscanf( PFile, "%d", & data );
636  TheProbe[ p_ProbeNo ]->m_Rect[ i ].m_y2 = data;
637  }
638  fgets( S, 255, PFile ); // dummy line
639  fgets( S, 255, PFile ); // dummy line
640  if ( TheProbe[ p_ProbeNo ]->m_NoVegTypes > 0 ) {
641  for ( int i = 0; i < 25; i++ ) {
642  fscanf( PFile, "%d", & data );
643  if ( data != 999 )
644  TheProbe[ p_ProbeNo ]->m_RefVeg[ i ] = m_TheLandscape->TranslateVegTypes( data );
645  }
646  } else if ( TheProbe[ p_ProbeNo ]->m_NoFarms > 0 ) {
647  for ( int i = 0; i < 25; i++ ) {
648  fscanf( PFile, "%d", & data );
649  if ( data != 999 )
650  TheProbe[ p_ProbeNo ]->m_RefFarms[ i ] = data;
651  }
652  } else {
653  for ( int i = 0; i < 25; i++ ) {
654  fscanf( PFile, "%d", & data );
655  if ( data != 999 ) TheProbe[ p_ProbeNo ]->m_RefEle[ i ] = m_TheLandscape->TranslateEleTypes( data );
656  }
657  }
658  fclose( PFile );
659  return data2; // number of data references
660 }
rectangle m_Rect[10]
Definition: PopulationManager.h:289
bool m_TargetTypes[10]
Definition: PopulationManager.h:297
TTypesOfVegetation TranslateVegTypes(int VegReference)
Definition: landscape.h:1579
unsigned m_NoAreas
Definition: PopulationManager.h:288
unsigned m_RefFarms[25]
Definition: PopulationManager.h:295
TTypesOfLandscapeElement TranslateEleTypes(int EleReference)
Definition: landscape.h:1572
unsigned m_ReportInterval
Definition: PopulationManager.h:287
unsigned m_NoVegTypes
Definition: PopulationManager.h:291
probe_data * TheProbe[100]
Definition: PopulationManager.h:481
TTypesOfVegetation m_RefVeg[25]
Definition: PopulationManager.h:293
unsigned m_x1
Definition: PopulationManager.h:96
bool m_FileRecord
Definition: PopulationManager.h:286
TTypesOfLandscapeElement m_RefEle[25]
Definition: PopulationManager.h:294
unsigned m_NoEleTypes
Definition: PopulationManager.h:290
unsigned m_y1
Definition: PopulationManager.h:97
unsigned m_NoFarms
Definition: PopulationManager.h:292
void Warn(std::string a_msg1, std::string a_msg2)
Definition: landscape.h:1503
unsigned m_x2
Definition: PopulationManager.h:98
Landscape * m_TheLandscape
Definition: PopulationManager.h:486
unsigned m_y2
Definition: PopulationManager.h:99
char * Population_Manager::ProbeReport ( int  a_time)

References BeginningOfMonth(), and g_str.

1342  {
1343 
1344  int No;
1345  char str[100]; // 100 out to be enough!!
1346  strcpy(g_str,"");
1347  for ( int ProbeNo = 0; ProbeNo < m_NoProbes; ProbeNo++ ) {
1348  No = 0;
1349  // See if we need to record/update this one
1350  // if time/months/years ==0 or every time
1351  if ( ( TheProbe[ ProbeNo ]->m_ReportInterval == 3 )
1352  || ( ( TheProbe[ ProbeNo ]->m_ReportInterval == 2 ) && ( BeginningOfMonth() ) )
1353  || ( ( TheProbe[ ProbeNo ]->m_ReportInterval == 1 ) && ( Time % 365 == 0 ) ) ) {
1354  // Goes through each area and sends a value to OutputForm
1355  unsigned Index = SupplyListIndexSize();
1356  for ( unsigned listindex = 0; listindex < Index; listindex++ ) {
1357  if ( TheProbe[ ProbeNo ]->m_TargetTypes[ listindex ] )
1358  No += (int) Probe( listindex, TheProbe[ ProbeNo ] );
1359  }
1360  TheProbe[ ProbeNo ]->FileOutput( No, Time, ProbeNo );
1361  sprintf(str," %d ", No );
1362  strcat(g_str,str);
1363  }
1364  }
1365  return g_str;
1366 }
int m_NoProbes
Definition: PopulationManager.h:496
unsigned SupplyListIndexSize()
Definition: PopulationManager.h:439
virtual float Probe(int ListIndex, probe_data *p_TheProbe)
Definition: PopulationManager.cpp:690
void FileOutput(int No, int time, int ProbeNo)
Definition: PopulationManager.cpp:1516
probe_data * TheProbe[100]
Definition: PopulationManager.h:481
char g_str[255]
Definition: PopulationManager.cpp:130
bool BeginningOfMonth()
Definition: PopulationManager.cpp:1171
char * Population_Manager::ProbeReportTimed ( int  a_time)

References g_str.

1369  {
1370  int No;
1371  char str[100]; // 100 ought to be enough!!
1372  strcpy(g_str,"");
1373  for ( int ProbeNo = 0; ProbeNo < m_NoProbes; ProbeNo++ ) {
1374  No = 0;
1375  unsigned Index = SupplyListIndexSize();
1376  for ( unsigned listindex = 0; listindex < Index; listindex++ ) {
1377  if ( TheProbe[ ProbeNo ]->m_TargetTypes[ listindex ] ) No += (int) Probe( listindex, TheProbe[ ProbeNo ] );
1378  }
1379  TheProbe[ ProbeNo ]->FileOutput( No, Time, ProbeNo );
1380  sprintf(str," %d ", No );
1381  strcat(g_str,str);
1382  }
1383  return g_str;
1384 }
int m_NoProbes
Definition: PopulationManager.h:496
unsigned SupplyListIndexSize()
Definition: PopulationManager.h:439
virtual float Probe(int ListIndex, probe_data *p_TheProbe)
Definition: PopulationManager.cpp:690
void FileOutput(int No, int time, int ProbeNo)
Definition: PopulationManager.cpp:1516
probe_data * TheProbe[100]
Definition: PopulationManager.h:481
char g_str[255]
Definition: PopulationManager.cpp:130
void Population_Manager::Run ( int  NoTSteps)
virtual

This is the main scheduling method for the population manager.
Note the structure of Shuffle_or_Sort(), DoFirst(), BeginStep, DoBefore(), Step looping until all are finished, DoAfter(), DoAlmostLast(), EndStep, DoLast().

Can do multiple time-steps here inside one landscape time-step (a day). This is used in the roe deer model to provide 10 minute behavioural time-steps.

It is necessary to remove any dead animals before the timestep starts. It is possible that animals are killed after their population manager Run method has been executed. This is the case with geese and hunters. Checking death first prevents this becomming a problem.

References cfg_CatastropheEventStartYear(), cfg_CIPEGridOutput_day(), cfg_CIPEGridOutput_Interval(), cfg_CIPEGridOutput_used(), cfg_ReallyBigOutput_day1(), cfg_ReallyBigOutput_day2(), cfg_ReallyBigOutput_day3(), cfg_ReallyBigOutput_day4(), cfg_ReallyBigOutput_interval(), cfg_ReallyBigOutput_used(), cfg_ReallyBigOutputFirstYear(), cfg_RipleysOutput_day(), cfg_RipleysOutput_interval(), cfg_RipleysOutput_used(), cfg_RipleysOutputFirstYear(), and cfg_RipleysOutputMonthly_used().

Referenced by RunTheSim().

348  {
352  for ( int TSteps = 0; TSteps < NoTSteps; TSteps++ )
353  {
354  unsigned size2;
355  unsigned size1 = (unsigned) TheArray.size();
360  for ( unsigned listindex = 0; listindex < size1; listindex++ )
361  {
362  // Must check each object in the list for m_CurrentStateNo==-1
363  m_LiveArraySize[listindex] = PartitionLiveDead(listindex);
364  }
365 #ifdef __ALMASS_VISUAL
366  if (m_MainForm!=NULL)
367  {
368  int n = 0;
369  for ( unsigned listindex = 0; listindex < size1; listindex++ ) n += (int) m_LiveArraySize[ listindex ];
371  //if (n>0) DisplayLocations();
372  }
373 #endif
374  // begin step actions ...
375  // set all stepdone to false.... is this really necessary??
376  for ( unsigned listindex = 0; listindex < size1; listindex++ )
377  {
378  size2 = (unsigned) GetLiveArraySize(listindex);
379  for ( unsigned j = 0; j < size2; j++ )
380  {
381  TheArray[ listindex ] [ j ]->SetStepDone( false );
382  }
383  }
384 
385  for ( unsigned listindex = 0; listindex < size1; listindex++ ) {
386  // Call the Shuffle/Sort procedures
387  Shuffle_or_Sort( listindex );
388  }
389  // Need to check if Ripleys Statistic needs to be saved
390  if ( cfg_RipleysOutput_used.value() ) {
391  int Year = m_TheLandscape->SupplyYearNumber();
392  if (Year>=cfg_RipleysOutputFirstYear.value()) {
393  if ( Year % cfg_RipleysOutput_interval.value() == 0 ) {
394  int day = m_TheLandscape->SupplyDayInYear();
395  if ( cfg_RipleysOutput_day.value() == day ) {
396  // Do the Ripley Probe
398  TheNWordOutputProbe(); // These two go hand in hand.
399  }
400  }
401  }
402  }
403  // Need to check if Monthly Ripleys Statistic needs to be saved
404  if ( cfg_RipleysOutputMonthly_used.value() ) {
405  if (m_TheLandscape->SupplyDayInMonth()==1) {
406  int Year = m_TheLandscape->SupplyYearNumber();
407  if (Year>=cfg_RipleysOutputFirstYear.value()) {
408  if ( Year % cfg_RipleysOutput_interval.value() == 0 ) {
409  int month = m_TheLandscape->SupplyMonth();
410  // Do the Ripley Probe
411  switch (month) {
413  break;
415  break;
417  break;
419  break;
421  break;
423  break;
425  break;
427  break;
429  break;
431  break;
433  break;
435  break;
436  }
437  }
438  }
439  }
440  }
441  // Need to check if Really Big Probe needs to be saved
442  if ( cfg_ReallyBigOutput_used.value() ) {
443  int Year = m_TheLandscape->SupplyYearNumber();
444  if (Year>=cfg_ReallyBigOutputFirstYear.value()) {
445  if ( Year % cfg_ReallyBigOutput_interval.value() == 0 ) {
446  int day = m_TheLandscape->SupplyDayInYear();
447  if (( cfg_ReallyBigOutput_day1.value() == day )|| ( cfg_ReallyBigOutput_day2.value() == day )|| ( cfg_ReallyBigOutput_day3.value() == day )|| ( cfg_ReallyBigOutput_day4.value() == day )||( cfg_ReallyBigOutput_day1.value() == -1 ))
448  {
449  // Do the Ripley Probe
451  }
452  }
453  }
454  }
455  // Need to check if CIPEGrid Statistic needs to be saved
456  if ( cfg_CIPEGridOutput_used.value() ) {
457  int Year = m_TheLandscape->SupplyYearNumber();
458  if ( Year % cfg_CIPEGridOutput_Interval.value() == 0 ) {
459  int day = m_TheLandscape->SupplyDayInYear();
460  if ( cfg_CIPEGridOutput_day.value() == day ) {
461  // Do the Ripley Probe
463  }
464  }
465  }
467  if ( yr > cfg_CatastropheEventStartYear.value() ) {
469  Catastrophe(); // This method must be overidden in descendent classes
470  }
471  DoFirst();
472  // call the begin-step-method of all objects
473  for ( unsigned listindex = 0; listindex < size1; listindex++ ) {
474  size2 = (unsigned)GetLiveArraySize( listindex );
475  for (unsigned j = 0; j < size2; j++)
476  TheArray[ listindex ] [ j ]->BeginStep();
477  }
478  DoBefore();
479  // call the step-method of all objects
480  do {
481  for ( unsigned listindex = 0; listindex < size1; listindex++ ) {
482  size2 = (unsigned)GetLiveArraySize( listindex );
483  for (unsigned j = 0; j < size2; j++) {
484  TheArray[ listindex ] [ j ]->Step();
485  }
486  } // for listindex
487  } while ( !StepFinished() );
488  DoAfter();
489  // call the end-step-method of all objects
490  for ( unsigned listindex = 0; listindex < size1; listindex++ ) {
491  size2 = (unsigned)GetLiveArraySize( listindex );
492  for (unsigned j = 0; j < size2; j++) {
493  TheArray[ listindex ] [ j ]->EndStep();
494  }
495  }
496  // ----------------
497  // end of this step actions
498  // For each animal list
499  DoAlmostLast();
500 
501 DoLast();
502  } // End of time step loop
503 }
FILE * RipleysOutputPrb3
Definition: PopulationManager.h:557
int m_catastrophestartyear
Definition: PopulationManager.h:502
virtual void DoAfter()
Definition: PopulationManager.cpp:523
CfgInt cfg_CatastropheEventStartYear("PM_CATASTROPHEEVENTSTARTYEAR", CFG_CUSTOM, 99999)
void Shuffle_or_Sort(unsigned Type)
Definition: PopulationManager.cpp:1142
static CfgInt cfg_ReallyBigOutput_day3("G_REALLYBIGOUTPUT_DAY_THREE", CFG_CUSTOM, 182)
unsigned GetLiveArraySize(int a_listindex)
Gets the number of &#39;live&#39; objects for a list index in the TheArray.
Definition: PopulationManager.h:408
int SupplyMonth(void)
Definition: landscape.h:1525
virtual void TheReallyBigOutputProbe()
Definition: PopulationManager.cpp:988
FILE * RipleysOutputPrb7
Definition: PopulationManager.h:561
FILE * RipleysOutputPrb4
Definition: PopulationManager.h:558
static CfgInt cfg_ReallyBigOutput_day1("G_REALLYBIGOUTPUT_DAY_ONE", CFG_CUSTOM, 1)
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
FILE * RipleysOutputPrb
Definition: PopulationManager.h:554
static CfgInt cfg_ReallyBigOutput_day2("G_REALLYBIGOUTPUT_DAY_TWO", CFG_CUSTOM, 91)
virtual void TheCIPEGridOutputProbe()
Definition: PopulationManager.cpp:798
virtual void TheNWordOutputProbe()
Definition: PopulationManager.h:542
FILE * RipleysOutputPrb1
Definition: PopulationManager.h:555
virtual bool StepFinished()
Overrides the population manager StepFinished - there is no chance that hunters do not finish a step ...
Definition: PopulationManager.cpp:508
virtual void DoAlmostLast()
Definition: PopulationManager.cpp:532
virtual void TheRipleysOutputProbe(FILE *a_prb)
Definition: PopulationManager.cpp:993
FILE * RipleysOutputPrb10
Definition: PopulationManager.h:564
int SupplyYearNumber(void)
Definition: landscape.h:1540
CfgInt cfg_CIPEGridOutput_day("G_CIPEGRIDOUTPUT_DAY", CFG_CUSTOM, 1)
FILE * RipleysOutputPrb12
Definition: PopulationManager.h:566
int SupplyDayInMonth(void)
Definition: landscape.h:1530
static CfgInt cfg_ReallyBigOutput_day4("G_REALLYBIGOUTPUT_DAY_FOUR", CFG_CUSTOM, 274)
FILE * RipleysOutputPrb9
Definition: PopulationManager.h:563
CfgBool cfg_CIPEGridOutput_used("G_CIPEGRIDOUTPUT_USED", CFG_CUSTOM, false)
FILE * RipleysOutputPrb5
Definition: PopulationManager.h:559
static CfgInt cfg_RipleysOutput_day("G_RIPLEYSOUTPUT_DAY", CFG_CUSTOM, 60)
FILE * RipleysOutputPrb8
Definition: PopulationManager.h:562
CfgBool cfg_RipleysOutputMonthly_used("G_RIPLEYSOUTPUTMONTHLY_USED", CFG_CUSTOM, false)
static CfgInt cfg_ReallyBigOutput_interval("G_REALLYBIGOUTPUT_INTERVAL", CFG_CUSTOM, 1)
CfgInt cfg_CIPEGridOutput_Interval("G_CIPEGRIDOUTPUT_INTERVAL", CFG_CUSTOM, 1)
int SupplyDayInYear(void)
Definition: landscape.h:1520
virtual void DoFirst()
Definition: PopulationManager.cpp:331
static CfgInt cfg_RipleysOutput_interval("G_RIPLEYSOUTPUT_INTERVAL", CFG_CUSTOM, 1)
static CfgInt cfg_ReallyBigOutputFirstYear("G_REALLYBIGOUTPUT_FIRSTYEAR", CFG_CUSTOM, 1)
virtual void DoLast()
Definition: PopulationManager.cpp:540
FILE * RipleysOutputPrb6
Definition: PopulationManager.h:560
static CfgInt cfg_RipleysOutputFirstYear("G_RIPLEYSOUTPUT_FIRSTYEAR", CFG_CUSTOM, 1)
unsigned PartitionLiveDead(unsigned Type)
Definition: PopulationManager.cpp:1084
virtual void Catastrophe()
Definition: PopulationManager.cpp:1178
CfgBool cfg_ReallyBigOutput_used("G_REALLYBIGOUTPUT_USED", CFG_CUSTOM, false)
vector< unsigned > m_LiveArraySize
Definition: PopulationManager.h:495
virtual void DoBefore()
Definition: PopulationManager.cpp:339
CfgBool cfg_RipleysOutput_used("G_RIPLEYSOUTPUT_USED", CFG_CUSTOM, true)
FILE * RipleysOutputPrb11
Definition: PopulationManager.h:565
Landscape * m_TheLandscape
Definition: PopulationManager.h:486
FILE * RipleysOutputPrb2
Definition: PopulationManager.h:556
void Population_Manager::SetNoProbes ( int  a_pn)
inline

Referenced by CreatePopulationManager().

406 { m_NoProbes=a_pn; }
int m_NoProbes
Definition: PopulationManager.h:496
void Population_Manager::Shuffle ( unsigned  Type)
protected

Run once through the list swapping randomly chosen elements

References random().

1124  {
1125  unsigned s = (unsigned)GetLiveArraySize( Type );
1126  for ( unsigned i = 0; i < s; i++ ) {
1127  TAnimal * temp;
1128  unsigned a = random( s );
1129  unsigned b = random( s );
1130  temp = TheArray[ Type ] [ a ];
1131  TheArray[ Type ] [ a ] = TheArray[ Type ] [ b ];
1132  TheArray[ Type ] [ b ] = temp;
1133  }
1134 }
unsigned GetLiveArraySize(int a_listindex)
Gets the number of &#39;live&#39; objects for a list index in the TheArray.
Definition: PopulationManager.h:408
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
int random(int a_range)
Definition: ALMaSS_CmdLine.cpp:133
The base class for all ALMaSS animal classes.
Definition: PopulationManager.h:201
void Population_Manager::Shuffle_or_Sort ( unsigned  Type)
protected

This method is used to determine whether the array of animals should be shuffled or sorted.
To do nothing ensure that the BeforeStepActions[] is set appropriately // 0 = Shuffle, 1 = SortX, 2 = SortY, 3 = sortXIndex, 4 = do nothing

References g_rand_uni.

1142  {
1143  switch ( BeforeStepActions[ Type ] ) {
1144  case 0:
1145  Shuffle( Type );
1146  break;
1147  case 1:
1148  SortX( Type );
1149  break;
1150  case 2:
1151  SortY( Type );
1152  break;
1153  case 3:
1154  SortXIndex( Type );
1155  break;
1156  case 4: // Do nothing
1157  break;
1158  case 5:
1159  if (g_rand_uni() < double (1/500)) Shuffle( Type );
1160  break;
1161  default:
1162  m_TheLandscape->Warn( "Population_Manager::Shuffle_or_Sort- BeforeStepAction Unknown", NULL );
1163  exit( 1 );
1164  }
1165 }
void SortX(unsigned Type)
Definition: PopulationManager.cpp:1048
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
unsigned BeforeStepActions[10]
Definition: PopulationManager.h:511
void Shuffle(unsigned Type)
Definition: PopulationManager.cpp:1124
void SortXIndex(unsigned Type)
Definition: PopulationManager.cpp:1096
void SortY(unsigned Type)
Definition: PopulationManager.cpp:1058
void Warn(std::string a_msg1, std::string a_msg2)
Definition: landscape.h:1503
Landscape * m_TheLandscape
Definition: PopulationManager.h:486
void Population_Manager::SortState ( unsigned  Type)
protected

Sort TheArray w.r.t. the current state attribute

1068  {
1069  sort( TheArray[ Type ].begin(), TheArray[ Type ].end(), CompareState() );
1070 }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
Function to compare to TAnimal&#39;s Current behavioural state.
Definition: PopulationManager.cpp:172
void Population_Manager::SortStateR ( unsigned  Type)
protected

Sort TheArray w.r.t. the current state attribute in reverse order

1077  {
1078  sort(TheArray[Type].begin(), TheArray[Type].begin()+m_LiveArraySize[Type], CompareStateR());
1079 }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
Function to compare to TAnimal&#39;s m_CurrentStateNo.
Definition: PopulationManager.cpp:184
vector< unsigned > m_LiveArraySize
Definition: PopulationManager.h:495
void Population_Manager::SortX ( unsigned  Type)
protected

Sort TheArray w.r.t. the m_Location_x attribute

1048  {
1049  vector<TAnimal*>::iterator nth = TheArray[Type].begin() + m_LiveArraySize[Type];
1050  sort( TheArray[ Type ].begin(), nth, CompareX() );
1051 }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
vector< unsigned > m_LiveArraySize
Definition: PopulationManager.h:495
Function to compare to TAnimal&#39;s m_Location_x.
Definition: PopulationManager.cpp:147
void Population_Manager::SortXIndex ( unsigned  Type)
protected

Sort TheArray w.r.t. the m_Location_x attribute, and make an indexing array

1096  {
1097  vector<TAnimal*>::iterator nth = TheArray[Type].begin() + m_LiveArraySize[Type];
1098  sort(TheArray[Type].begin(), nth, CompareX());
1099  unsigned s = (unsigned)GetLiveArraySize( Type );
1100  // Now make the index array to X;
1101  int counter = 0;
1102  int x;
1103  // for each individual
1104  for ( unsigned i = 0; i < s; i++ ) {
1105  // Get Next co-ordiated
1106  x = TheArray[ Type ] [ i ]->Supply_m_Location_x();
1107  // fill gaps up to x
1108  while ( counter < x ) IndexArrayX[ Type ] [ counter++ ] = -1;
1109  if ( x == counter ) {
1110  IndexArrayX[ Type ] [ counter++ ] = i;
1111  }
1112  }
1113  // Fill up the rest of the array with -1;
1114  for ( int c = counter; c < 10000; c++ ) {
1115  IndexArrayX[ Type ] [ c ] = -1;
1116  }
1117 }
unsigned GetLiveArraySize(int a_listindex)
Gets the number of &#39;live&#39; objects for a list index in the TheArray.
Definition: PopulationManager.h:408
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
int IndexArrayX[5][10000]
Definition: PopulationManager.h:480
vector< unsigned > m_LiveArraySize
Definition: PopulationManager.h:495
Function to compare to TAnimal&#39;s m_Location_x.
Definition: PopulationManager.cpp:147
void Population_Manager::SortY ( unsigned  Type)
protected

Sort TheArray w.r.t. the m_Location_y attribute

1058  {
1059  vector<TAnimal*>::iterator nth = TheArray[Type].begin() + m_LiveArraySize[Type];
1060  sort(TheArray[Type].begin(), nth, CompareY());
1061 }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
Function to compare to TAnimal&#39;s m_Location_y.
Definition: PopulationManager.cpp:158
vector< unsigned > m_LiveArraySize
Definition: PopulationManager.h:495
char * Population_Manager::SpeciesSpecificReporting ( int  a_species,
int  a_time 
)

This method handles species specific outputs. This is one place to do it. More commonly this is done in descendent classes

References g_str, ImpactProbeReport(), and ProbeReport().

Referenced by RunTheSim().

1190  {
1191  strcpy(g_str,"");
1192 // Vole Model
1193  if ( a_species == 1 ) {
1194 /*
1195 // The next lines are obselete code from genetic simulations
1196 float MeanNoAlleles;
1197  float MeanHO;
1198  float MeanHE;
1199  unsigned size;
1200 
1201  if ( m_time % ( 365 * 24 * 60 ) == 0 ) // End of year
1202  {
1203 
1204  // empty the GenStruc data
1205  for ( int ProbeNo = 0; ProbeNo < ( int )m_NoProbes; ProbeNo++ ) {
1206  fprintf( m_GeneticsFile, "%d ", m_time );
1207  int TotalSize = 0;
1208  m_AManager->AlFreq->Flush();
1209  for ( unsigned listindex = 0; listindex <= 1; listindex++ ) {
1210  size = 0;
1211  m_AManager->TheGeneticProbe( listindex, ProbeNo, size );
1212  TotalSize += size;
1213  }
1214  if ( TotalSize > 0 ) {
1215  m_AManager->AlFreq->CalcAF();
1216  m_AManager->AlFreq->CalcNoAlleles();
1217  m_AManager->AlFreq->CalcHE();
1218  m_AManager->AlFreq->CalcHO( TotalSize );
1219  }
1220  // Get the means
1221  // For N alleles
1222  int NA = 0;
1223  float NHO = 0;
1224  float NHE = 0;
1225  for ( int l = 0; l < 16; l++ ) {
1226  NA += m_AManager->AlFreq->SupplyNoAlleles( l );
1227  }
1228  MeanNoAlleles = ( float )NA / 16.0;
1229  for ( int l = 0; l < 16; l++ ) {
1230  NHO += m_AManager->AlFreq->SupplyHO( l );
1231  }
1232  MeanHO = NHO / 16.0;
1233  for ( int l = 0; l < 16; l++ ) {
1234  NHE += m_AManager->AlFreq->SupplyHE( l );
1235  }
1236  MeanHE = NHE / 16.0;
1237 
1238  // Do some output
1239  // Output is to two files, the genetics file and the AllelerequencyFile
1240  fprintf( m_GeneticsFile, "%2.2f ", MeanNoAlleles );
1241  fprintf( m_GeneticsFile, "%1.3f ", MeanHO );
1242  fprintf( m_GeneticsFile, "%1.3f ", MeanHE );
1243  for ( int l = 0; l < 16; l++ ) {
1244  fprintf( m_GeneticsFile, "%04i ", m_AManager->AlFreq->SupplyNoAlleles( l ) );
1245  }
1246  for ( int l = 0; l < 16; l++ ) {
1247  fprintf( m_GeneticsFile, "%1.3f ", m_AManager->AlFreq->SupplyHO( l ) );
1248  }
1249  for ( int l = 0; l < 16; l++ ) {
1250  fprintf( m_GeneticsFile, "%1.3f ", m_AManager->AlFreq->SupplyHE( l ) );
1251  }
1252  fprintf( m_GeneticsFile, "\n" );
1253  fprintf( m_AlleleFreqsFile, "%d ", m_time );
1254  for ( int l = 0; l < 16; l++ ) {
1255  for ( int al = 0; al < 4; al++ ) {
1256  fprintf( m_AlleleFreqsFile, "%1.3f ", m_AManager->AlFreq->SupplyAF( l, al ) );
1257  }
1258  }
1259  fprintf( m_AlleleFreqsFile, "\n" );
1260  }
1261  // make sure progress reaches the disk
1262  fflush( m_GeneticsFile );
1263  fflush( m_AlleleFreqsFile );
1264  }
1265 
1266  if ( cfg_UseEasyPop.value()) {
1267  int targettime=a_time % ( 365 * 100 );
1268  if ( ( targettime == 59 ) ||(targettime == 181)||(targettime ==304)||(targettime ==59+365)||(targettime ==181+365)||(targettime ==304+365)) {
1269  for ( unsigned listindex = 0; listindex <= 1; listindex++ ) {
1270  GeneticsResultsOutput( m_EasyPopRes, listindex);
1271  }
1272  fflush( m_EasyPopRes );
1273  }
1274  }
1275 */
1276  /* Three times a year reporting
1277  if ( m_time % 365 == 60 ) ProbeReportNow( m_time );
1278  if ( m_time % 365 == 152 ) ProbeReportNow( m_time );
1279  if ( m_time % 365 == 273 ) ProbeReportNow( m_time ); */
1280  ProbeReport( a_time );
1281 #ifdef __SpecificPesticideEffectsVinclozolinLike__
1282  ImpactProbeReport( a_time );
1283 #endif
1284 #ifdef __WithinOrchardPesticideSim__
1285  ImpactProbeReport( a_time );
1286 #endif
1287 
1288  }
1289  // Skylark Model
1290  else if ( a_species == 0 ) {
1291  int No;
1292  int a_day = a_time % 365;
1293  if ( a_time % 365 == 364 )
1294  {
1295  //Write the Breeding Attempts Probe
1296  int BreedingFemales, YoungOfTheYear, TotalPop, TotalFemales, TotalMales, BreedingAttempts;
1297  int No = TheBreedingSuccessProbe( BreedingFemales, YoungOfTheYear, TotalPop, TotalFemales, TotalMales, BreedingAttempts );
1298  float bs = 0;
1299  if ( BreedingFemales > 0 ) {
1300  bs = No / ( float )BreedingFemales; //bs = successful breeding attempt per attempting to breed female
1301  }
1302  BreedingSuccessProbeOutput( bs, BreedingFemales, YoungOfTheYear, TotalPop,
1303  TotalFemales, TotalMales, a_time, BreedingAttempts );
1304  }
1305  if ( a_day == 152 ) {
1306  // Need to fill in the landscape from 1st June, it will change before
1307  // the count of fledgelings is needed
1309  }
1310  if ( a_day == 197 ) {
1311  for ( int ProbeNo = 0; ProbeNo < m_NoProbes; ProbeNo++ ) {
1312  No = TheFledgelingProbe();
1313  // Do some output
1314  FledgelingProbeOutput( No, a_time );
1315  }
1316  }
1317 #ifdef __SKPOM
1318  // This is clunky but for purposes of validation we want probes throughout the year
1319  // First get the breeding pairs data.
1320  BreedingPairsOutput(a_day);
1321 #else
1322  ProbeReport( a_time );
1323 #endif
1324  }
1325  else return ProbeReport( a_time );
1326  return g_str;
1327 }
int m_NoProbes
Definition: PopulationManager.h:496
virtual void BreedingSuccessProbeOutput(double, int, int, int, int, int, int, int)
Definition: PopulationManager.h:630
void FillVegAreaData()
Definition: Landscape.cpp:3399
virtual void BreedingPairsOutput(int)
Definition: PopulationManager.h:622
void ImpactProbeReport(int a_Time)
Definition: PopulationManager.cpp:1390
char * ProbeReport(int a_time)
Definition: PopulationManager.cpp:1342
virtual void FledgelingProbeOutput(int, int)
Definition: PopulationManager.h:635
char g_str[255]
Definition: PopulationManager.cpp:130
virtual int TheFledgelingProbe()
Definition: PopulationManager.h:627
virtual int TheBreedingSuccessProbe(int &, int &, int &, int &, int &, int &)
Definition: PopulationManager.h:632
Landscape * m_TheLandscape
Definition: PopulationManager.h:486
bool Population_Manager::StepFinished ( void  )
protectedvirtual

Overrides the population manager StepFinished - there is no chance that hunters do not finish a step behaviour.

Returns true if and only if all objects have finished the current step

508  {
509  for ( unsigned listindex = 0; listindex < TheArray.size(); listindex++ ) {
510  for (unsigned j = 0; j < (unsigned)GetLiveArraySize( listindex ); j++) {
511  if ( TheArray[ listindex ] [ j ]->GetStepDone() == false ) {
512  return false;
513  }
514  }
515  }
516  return true;
517 }
unsigned GetLiveArraySize(int a_listindex)
Gets the number of &#39;live&#39; objects for a list index in the TheArray.
Definition: PopulationManager.h:408
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
virtual int Population_Manager::SupplyCovPosx ( int  )
inlinevirtual
607  {
608  return 0;
609  }
virtual int Population_Manager::SupplyCovPosy ( int  )
inlinevirtual
610  {
611  return 0;
612  }
unsigned Population_Manager::SupplyListIndexSize ( )
inline
439  {
440  return (unsigned)TheArray.size();
441  }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
const char* Population_Manager::SupplyListName ( int  i)
inline
449  {
450  return m_ListNames[ i ];
451  }
const char * m_ListNames[10]
Definition: PopulationManager.h:507
int Population_Manager::SupplyListNameLength ( )
inline
436  {
437  return m_ListNameLength;
438  }
unsigned m_ListNameLength
Definition: PopulationManager.h:508
unsigned Population_Manager::SupplyListSize ( unsigned  listindex)
inline
442  {
443  return (unsigned) TheArray[ listindex ].size();
444  }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
virtual void Population_Manager::SupplyLocXY ( unsigned  listindex,
unsigned  j,
int x,
int y 
)
inlinevirtual
464  {
465  x = TheArray[ listindex ] [ j ]->Supply_m_Location_x();
466  y = TheArray[ listindex ] [ j ]->Supply_m_Location_y();
467  }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
virtual int Population_Manager::SupplyPegPosx ( int  )
inlinevirtual
601  {
602  return 0;
603  }
virtual int Population_Manager::SupplyPegPosy ( int  )
inlinevirtual
604  {
605  return 0;
606  }
int Population_Manager::SupplySimH ( )
inline
430  {
431  return SimH;
432  }
int SimH
Definition: PopulationManager.h:482
int Population_Manager::SupplySimW ( )
inline
427  {
428  return SimW;
429  }
int SimW
Definition: PopulationManager.h:482
int Population_Manager::SupplyState ( unsigned  listindex,
unsigned  j 
)
inline

IntArray100 * SupplyStateList() { return & StateList; }

461  {
462  return TheArray[ listindex ] [ j ]->WhatState();
463  }
vector< TListOfAnimals > TheArray
Definition: PopulationManager.h:504
const char* Population_Manager::SupplyStateNames ( int  i)
inline
468  {
469  return StateNames[ i ];
470  }
const char * StateNames[100]
Definition: PopulationManager.h:501
unsigned Population_Manager::SupplyStateNamesLength ( )
inline
471  {
472  return StateNamesLength;
473  }
unsigned StateNamesLength
Definition: PopulationManager.h:505
int Population_Manager::SupplyStepSize ( )
inline
424  {
425  return m_StepSize;
426  }
int m_StepSize
Definition: PopulationManager.h:503
virtual int Population_Manager::TheBreedingFemalesProbe ( int  )
inlinevirtual
624  {
625  return 0;
626  }
virtual int Population_Manager::TheBreedingSuccessProbe ( int ,
int ,
int ,
int ,
int ,
int  
)
inlinevirtual
632  {
633  return 0;
634  }
void Population_Manager::TheCIPEGridOutputProbe ( )
virtual

This method MUST be overridden in descendent classes, if you want it to work

798  {
799 }
virtual int Population_Manager::TheFledgelingProbe ( )
inlinevirtual
627  {
628  return 0;
629  }
virtual void Population_Manager::TheGeneticProbe ( unsigned  ,
int  ,
unsigned &   
)
inlinevirtual
637  {
638  }
virtual void Population_Manager::TheNWordOutputProbe ( )
inlinevirtual
542 {};
void Population_Manager::TheReallyBigOutputProbe ( )
virtual

This method must be overridden in descendent classes

988  {
989 }
void Population_Manager::TheRipleysOutputProbe ( FILE *  a_prb)
virtual

This method must be overridden in descendent classes

993  {
994 }

Member Data Documentation

unsigned Population_Manager::BeforeStepActions[10]
protected
FILE* Population_Manager::CIPEGridOutputPrb
protected
FILE* Population_Manager::CIPEGridOutputPrbB
protected
int Population_Manager::IndexArrayX[5][10000]
long int Population_Manager::lamdagrid[2][257][257]
protected
FILE* Population_Manager::m_AlleleFreqsFile
protected
int Population_Manager::m_catastrophestartyear
protected
int* Population_Manager::m_cgridcount
protected
int Population_Manager::m_cgridcountwidth
protected
int Population_Manager::m_cipegridsize
protected
FILE* Population_Manager::m_EasyPopRes
protected
FILE* Population_Manager::m_GeneticsFile
protected
int* Population_Manager::m_gridcount[4]
protected
int Population_Manager::m_gridcountsize[4]
protected
int Population_Manager::m_gridcountwidth[4]
protected
unsigned Population_Manager::m_ListNameLength
protected
const char* Population_Manager::m_ListNames[10]
protected
vector<unsigned> Population_Manager::m_LiveArraySize
protected
int Population_Manager::m_NoProbes
protected
TTypesOfPopulation Population_Manager::m_population_type
protected
int Population_Manager::m_SeasonNumber
protected

Holds the season number. Used when running goose and hunter sims.

char Population_Manager::m_SimulationName[255]
int Population_Manager::m_StepSize
protected
FILE* Population_Manager::NWordOutputPrb
protected
bool Population_Manager::ProbesSet
FILE* Population_Manager::ReallyBigOutputPrb
protected
FILE* Population_Manager::RipleysOutputPrb
protected
FILE* Population_Manager::RipleysOutputPrb1
protected
FILE* Population_Manager::RipleysOutputPrb10
protected
FILE* Population_Manager::RipleysOutputPrb11
protected
FILE* Population_Manager::RipleysOutputPrb12
protected
FILE* Population_Manager::RipleysOutputPrb2
protected
FILE* Population_Manager::RipleysOutputPrb3
protected
FILE* Population_Manager::RipleysOutputPrb4
protected
FILE* Population_Manager::RipleysOutputPrb5
protected
FILE* Population_Manager::RipleysOutputPrb6
protected
FILE* Population_Manager::RipleysOutputPrb7
protected
FILE* Population_Manager::RipleysOutputPrb8
protected
FILE* Population_Manager::RipleysOutputPrb9
protected
int Population_Manager::SimH
unsigned Population_Manager::SimHH
int Population_Manager::SimW
unsigned Population_Manager::SimWH
const char* Population_Manager::StateNames[100]
protected
unsigned Population_Manager::StateNamesLength
protected
FILE* Population_Manager::TestFile
protected
FILE* Population_Manager::TestFile2
protected
vector< TListOfAnimals > Population_Manager::TheArray
protected
probe_data* Population_Manager::TheProbe[100]

Referenced by CloseDownSim(), and GetProbeInput_ini().


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