ALMaSS Partridge ODdox  1.1
The partridge model description following ODdox protocol
CoveyManager Class Reference

The covey manager class. More...

#include <Partridge_Covey.h>

Public Member Functions

void SanityCheck1 ()
 A debug function. More...
 
void AddCovey (Partridge_Covey *a_covey)
 Add a new covey. More...
 
bool DelCovey (Partridge_Covey *a_covey)
 Remove a covey. More...
 
int CoveyDensity (int x, int y, int radius)
 Unused. More...
 
double BroodGeoMean ()
 Calculate the geometric mean of no of chicks. More...
 
void Setpar_force_ignore_below (double ff)
 Set the minimum interesting force. More...
 
double Getpar_force_ignore_below ()
 Get the minimum interesting force. More...
 
void Tick (void)
 Do the covey management for the time-step. More...
 
 CoveyManager (unsigned int a_world_width, unsigned int a_world_height, Landscape *a_map)
 Constructor. More...
 
 ~CoveyManager (void)
 Destructor. More...
 

Private Attributes

int m_id_counter
 Counter to keep track of covey ids. More...
 
int m_world_width
 Landscape width. More...
 
int m_world_height
 Landscape height. More...
 
int m_world_width_div2
 Half landscape width. More...
 
int m_world_height_div2
 Half landscape height. More...
 
Landscapem_map
 Pointer to the landscape. More...
 
double m_par_force_ignore_below
 Minimum interesting force. More...
 

Detailed Description

The covey manager class.

The covey manaer takes over the role of the Population_Manager for animal models. This is a design fault of historical origin and should be rectified one day with the Partridge_Population_Manager taking over this role.

Definition at line 792 of file Partridge_Covey.h.

Constructor & Destructor Documentation

◆ CoveyManager()

CoveyManager::CoveyManager ( unsigned int  a_world_width,
unsigned int  a_world_height,
Landscape a_map 
)

Constructor.

Definition at line 2072 of file Partridge_Covey.cpp.

2072  {
2073  m_world_width = a_world_width;
2074  m_world_height = a_world_height;
2077  m_map = a_map;
2078 
2079  g_trig_sin = new double[ TRIG_TABLE_LENGTH ];
2080  g_trig_cos = new double[ TRIG_TABLE_LENGTH ];
2081 
2083 
2084 
2085  if ( !g_trig_sin || !g_trig_cos ) {
2086  g_msg->Warn( WARN_MSG, "CoveyManager::CoveyManager(): Out of memory.", "" );
2087  exit( 1 );
2088  }
2089 
2090  double l_val = 0.0;
2091  double l_step = TWO_PI / TRIG_TABLE_LENGTH;
2092  for ( int i = 0; i < TRIG_TABLE_LENGTH; i++ ) {
2093  g_trig_sin[ i ] = sin( l_val );
2094  g_trig_cos[ i ] = cos( l_val );
2095  l_val += l_step;
2096  }
2097 }

References cfg_par_force_ignore_below, g_msg, g_trig_cos, g_trig_sin, m_map, m_world_height, m_world_height_div2, m_world_width, m_world_width_div2, Setpar_force_ignore_below(), TRIG_TABLE_LENGTH, CfgFloat::value(), MapErrorMsg::Warn(), and WARN_MSG.

◆ ~CoveyManager()

CoveyManager::~CoveyManager ( void  )

Destructor.

Definition at line 2099 of file Partridge_Covey.cpp.

2099  {
2100  delete g_trig_sin;
2101  delete g_trig_cos;
2102 }

References g_trig_cos, and g_trig_sin.

Member Function Documentation

◆ AddCovey()

void CoveyManager::AddCovey ( Partridge_Covey a_covey)

Add a new covey.

Definition at line 2222 of file Partridge_Covey.cpp.

2222  {
2223  unsigned int l_newindex = (int)g_covey_list.size();
2224  g_covey_list.resize( l_newindex + 1 );
2225  g_covey_list[ l_newindex ] = a_covey;
2226 }

References g_covey_list.

Referenced by Partridge_Covey::Partridge_Covey().

◆ BroodGeoMean()

double CoveyManager::BroodGeoMean ( void  )

Calculate the geometric mean of no of chicks.

Definition at line 2117 of file Partridge_Covey.cpp.

2117  {
2118  double product = 0;
2119  int NoBr = 0;
2120  int sz = (int)g_covey_list.size();
2121  if ( sz < 2000 ) {
2122  for ( int i = 0; i < sz; i++ ) {
2123  double chs = ( double )g_covey_list[ i ]->GetOurChicks();
2124  // only count those with chicks
2125  if ( chs > 0 ) {
2126  product += log10( chs );
2127  NoBr++;
2128  }
2129  }
2130  if ( NoBr > 0 ) {
2131  double power = 1.0 / NoBr;
2132  product *= power; // Mulitply log by the power
2133  // Antilog it
2134  double result = pow( 10, product );
2135  return result;
2136  }
2137  }
2138  return 0.0;
2139 }

References g_covey_list.

Referenced by Partridge_Population_Manager::DoFirst().

◆ CoveyDensity()

int CoveyManager::CoveyDensity ( int  x,
int  y,
int  radius 
)

Unused.

Search through the list of coveys and find out how many are within radius of x,y.

Definition at line 2178 of file Partridge_Covey.cpp.

2178  {
2180  int tx, ty;
2181  int No = 0;
2182  int x1 = x - radius;
2183  int x2 = x + radius;
2184  int y1 = y - radius;
2185  int y2 = y + radius;
2186  // As usual this is complicated by the fact that x,y, might overlap boundries
2187  //
2188  if ( ( x - radius < 0 ) || ( x + radius >= m_world_width ) || ( y - radius < 0 ) || ( y + radius >= m_world_height ) ) {
2189  // Danger of running into the edge of the world
2190  // Also for speed and ease of calculation our radius is that of a square
2191  //
2192  for ( int i = 0; i < (int) g_covey_list.size(); i++ ) {
2193  tx = g_covey_list[ i ]->X();
2194  ty = g_covey_list[ i ]->Y();
2195  int dx = abs( x - tx );
2196  int dy = abs( y - ty );
2197  if ( dx > m_world_width_div2 ) dx = m_world_width - dx;
2198  if ( dy > m_world_height_div2 ) dy = m_world_height - dy;
2199  if ( ( tx < x2 ) && ( tx >= x1 ) && ( ty >= y1 ) && ( ty < y2 ) ) {
2200  // We have found one
2201  No++;
2202  }
2203  }
2204  } else {
2205  // Simple case, not near to the edge
2206  // Also for speed and ease of calculation our radius is that of a square
2207  //
2208  for ( int i = 0; i < (int) (g_covey_list.size()); i++ ) {
2209  tx = g_covey_list[ i ]->X();
2210  ty = g_covey_list[ i ]->Y();
2211  if ( ( tx <= x2 ) && ( tx >= x1 ) && ( ty >= y1 ) && ( ty <= y2 ) ) {
2212  // We have found one
2213  No++;
2214  }
2215  }
2216  }
2217  return No;
2218 }

References g_covey_list, m_world_height, m_world_height_div2, m_world_width, and m_world_width_div2.

◆ DelCovey()

bool CoveyManager::DelCovey ( Partridge_Covey a_covey)

Remove a covey.

Definition at line 2230 of file Partridge_Covey.cpp.

2230  {
2231  unsigned int l_id = a_covey->ID();
2232 
2233  if ( a_covey->ManagerIsPermanant() ) {
2234  // Raise hell. Someone thought a permanent landscape marker
2235  // belonged to them.
2236  assert( false );
2237  }
2238 
2239  for ( unsigned int i = 0; i < g_covey_list.size(); i++ ) {
2240  if ( l_id == g_covey_list[ i ]->ID() ) {
2241  // Throw away our local pointer to the covey by
2242  // moving the rest of the elements down in the list.
2243  for ( unsigned int j = i + 1; j < g_covey_list.size(); j++ ) {
2244  g_covey_list[ j - 1 ] = g_covey_list[ j ];
2245  }
2246  g_covey_list.resize( g_covey_list.size() - 1 );
2247  return true;
2248  }
2249  }
2250 
2251  // Didn't find requested ID.
2252  return false;
2253 }

References g_covey_list, Partridge_Covey::ID(), and Partridge_Covey::ManagerIsPermanant().

Referenced by Partridge_Covey::RemoveMember(), and Partridge_Covey::~Partridge_Covey().

◆ Getpar_force_ignore_below()

double CoveyManager::Getpar_force_ignore_below ( )
inline

Get the minimum interesting force.

Definition at line 822 of file Partridge_Covey.h.

822  {
824  }

References m_par_force_ignore_below.

Referenced by Partridge_Covey::ManagerRethinkPos().

◆ SanityCheck1()

void CoveyManager::SanityCheck1 ( void  )

A debug function.

Definition at line 2104 of file Partridge_Covey.cpp.

2104  {
2105  for ( PointerInt i = 0; i < (unsigned) g_covey_list.size(); i++ ) {
2106  if ( ( PointerInt )g_covey_list[ i ] < 1000 ) {
2107  g_msg->Warn( WARN_MSG, "CoveyManager::SanityCheck1(): NOT Sane", "" );
2108  exit( 0 );
2109  }
2110  }
2111 }

References g_covey_list, g_msg, MapErrorMsg::Warn(), and WARN_MSG.

◆ Setpar_force_ignore_below()

void CoveyManager::Setpar_force_ignore_below ( double  ff)

Set the minimum interesting force.

Definition at line 2113 of file Partridge_Covey.cpp.

2113  {
2115 }

References m_par_force_ignore_below.

Referenced by CoveyManager().

◆ Tick()

void CoveyManager::Tick ( void  )

Do the covey management for the time-step.

Moves all covey pegs as necessary and checks for merging

Definition at line 2144 of file Partridge_Covey.cpp.

2144  {
2145  // Copies m_center_*_float into m_new_center_*_float.
2146  for ( unsigned int i = 0; i < g_covey_list.size(); i++ ) {
2147  g_covey_list[ i ]->ManagerRethinkPos();
2148  }
2149 
2150  // Adds any deltas to m_new_center_*_float.
2151  for ( unsigned int i = 0; i < g_covey_list.size(); i++ ) {
2152  g_covey_list[ i ]->ManagerDriftPos();
2153  }
2154 
2155  // Copies the m_new_center_*_float position back
2156  // into m_center_*_float, updating covey positions.
2157  for ( unsigned int i = 0; i < g_covey_list.size(); i++ ) {
2158  g_covey_list[ i ]->ManagerUpdatePos();
2159  }
2160 
2161  // This code removed to stop merging 011004 CJT (why?)
2162  // Only test for merging between certain dates
2163  //
2165  || ( m_map->SupplyDayInYear() <= cfg_par_lastmerge.value() ) ) {
2166  for ( unsigned int i = 0; i < g_covey_list.size(); i++ ) {
2167  if ( g_covey_list[ i ]->AllFlocking() ) {
2168  // Only singles and barren pairs are allowed to initiate merging
2169  if ( g_covey_list[ i ]->GetCoveySize() < 3 ) g_covey_list[ i ]->ManagerCheckMerge();
2170  }
2171  }
2172  }
2173 //*/
2174 }

References cfg_par_firstmerge, cfg_par_lastmerge, g_covey_list, m_map, Landscape::SupplyDayInYear(), and CfgInt::value().

Referenced by Partridge_Population_Manager::DoFirst().

Member Data Documentation

◆ m_id_counter

int CoveyManager::m_id_counter
private

Counter to keep track of covey ids.

Definition at line 794 of file Partridge_Covey.h.

◆ m_map

Landscape* CoveyManager::m_map
private

Pointer to the landscape.

Definition at line 804 of file Partridge_Covey.h.

Referenced by CoveyManager(), and Tick().

◆ m_par_force_ignore_below

double CoveyManager::m_par_force_ignore_below
private

Minimum interesting force.

Definition at line 806 of file Partridge_Covey.h.

Referenced by Getpar_force_ignore_below(), and Setpar_force_ignore_below().

◆ m_world_height

int CoveyManager::m_world_height
private

Landscape height.

Definition at line 798 of file Partridge_Covey.h.

Referenced by CoveyDensity(), and CoveyManager().

◆ m_world_height_div2

int CoveyManager::m_world_height_div2
private

Half landscape height.

Definition at line 802 of file Partridge_Covey.h.

Referenced by CoveyDensity(), and CoveyManager().

◆ m_world_width

int CoveyManager::m_world_width
private

Landscape width.

Definition at line 796 of file Partridge_Covey.h.

Referenced by CoveyDensity(), and CoveyManager().

◆ m_world_width_div2

int CoveyManager::m_world_width_div2
private

Half landscape width.

Definition at line 800 of file Partridge_Covey.h.

Referenced by CoveyDensity(), and CoveyManager().


The documentation for this class was generated from the following files:
CoveyManager::m_world_width_div2
int m_world_width_div2
Half landscape width.
Definition: Partridge_Covey.h:800
Partridge_Covey::ManagerIsPermanant
bool ManagerIsPermanant(void)
Unused
Definition: Partridge_Covey.h:767
CoveyManager::m_world_height
int m_world_height
Landscape height.
Definition: Partridge_Covey.h:798
g_covey_list
static vector< Partridge_Covey * > g_covey_list
Definition: Partridge_Covey.h:782
CoveyManager::m_world_width
int m_world_width
Landscape width.
Definition: Partridge_Covey.h:796
cfg_par_firstmerge
CfgInt cfg_par_firstmerge("PAR_FIRSTMERGE", CFG_CUSTOM, 150)
The Earliest merging date.
TRIG_TABLE_LENGTH
#define TRIG_TABLE_LENGTH
Definition: Partridge_Covey.cpp:233
g_msg
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:41
cfg_par_lastmerge
CfgInt cfg_par_lastmerge("PAR_LASTMERGE", CFG_CUSTOM, 59)
The latest merging date.
CoveyManager::m_par_force_ignore_below
double m_par_force_ignore_below
Minimum interesting force.
Definition: Partridge_Covey.h:806
CoveyManager::Setpar_force_ignore_below
void Setpar_force_ignore_below(double ff)
Set the minimum interesting force.
Definition: Partridge_Covey.cpp:2113
Partridge_Covey::ID
unsigned int ID(void)
Definition: Partridge_Covey.h:738
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
Landscape::SupplyDayInYear
int SupplyDayInYear(void)
Definition: landscape.h:1596
cfg_par_force_ignore_below
CfgFloat cfg_par_force_ignore_below("PAR_COVEY_FORCE_IGNORE_BELOW", CFG_CUSTOM, 0.0)
WARN_MSG
Definition: maperrormsg.h:38
CfgFloat::value
double value(void)
Definition: configurator.h:118
CoveyManager::m_world_height_div2
int m_world_height_div2
Half landscape height.
Definition: Partridge_Covey.h:802
g_trig_sin
static double * g_trig_sin
Definition: Partridge_Covey.cpp:235
g_trig_cos
static double * g_trig_cos
Definition: Partridge_Covey.cpp:236
CfgInt::value
int value(void)
Definition: configurator.h:98
CoveyManager::m_map
Landscape * m_map
Pointer to the landscape.
Definition: Partridge_Covey.h:804