File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
OGrazingPigs Class Reference

#include <OGrazingPigs.h>

Inheritance diagram for OGrazingPigs:
Crop

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 OGrazingPigs (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
void SetUpFarmCategoryInformation ()
 
- Public Member Functions inherited from Crop
virtual ~Crop ()
 
 Crop (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
int GetFirstDate (void)
 
void ChooseNextCrop (int a_no_dates)
 Chooses the next crop to grow in a field. More...
 
int GetCropClassification ()
 
void SetCropClassification (int a_classification)
 
void GetCropType (TTypesOfCrops a_toc)
 
TTypesOfCrops GetCropType ()
 
FarmManagementCategory LookUpManagementCategory (int a_todo)
 
bool GetForceSpringOK ()
 

Additional Inherited Members

- Public Attributes inherited from Crop
TTypesOfVegetation m_tov
 
- Protected Member Functions inherited from Crop
void SimpleEvent (long a_date, int a_todo, bool a_lock)
 Adds an event to this crop management. More...
 
void SimpleEvent_ (long a_date, int a_todo, bool a_lock, Farm *a_farm, LE *a_field)
 Adds an event to this crop management without relying on member variables. More...
 
bool StartUpCrop (int a_spring, std::vector< std::vector< int >> a_flexdates, int a_todo)
 
Holds the translation between the farm operation enum for each cropand the farm management category associated with it More...
 
bool AphidDamage (LE *a_field)
 Compares aphid numbers per m2 with a threshold to return true if threshold is exceeded. More...
 
- Protected Attributes inherited from Crop
Farmm_farm
 
LEm_field
 
FarmEventm_ev
 
int m_first_date
 
int m_count
 
int m_last_date
 
int m_ddegstoharvest
 
int m_base_elements_no
 
Landscapem_OurLandscape
 
bool m_forcespringpossible = false
 Used to signal that the crop can be forced to start in spring. More...
 
TTypesOfCrops m_toc
 The Crop type in terms of the TTypesOfCrops list (smaller list than tov, no country designation) More...
 
int m_CropClassification
 Contains information on whether this is a winter crop, spring crop, or catch crop that straddles the year boundary (0,1,2) More...
 
vector< FarmManagementCategorym_ManagementCategories
 Holds the translation between the farm operation enum for each crop and the farm management category associated with it. More...
 
- Static Protected Attributes inherited from Crop
static int m_date_modifier = 0
 Holds a value that shifts test pesticide use by this many days in crops modified to use it. More...
 

Constructor & Destructor Documentation

◆ OGrazingPigs()

OGrazingPigs::OGrazingPigs ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
49  : Crop(a_tov, a_toc, a_L)
50  {
53  }

References Calendar::DayInYear(), g_date, Crop::m_first_date, and SetUpFarmCategoryInformation().

Member Function Documentation

◆ Do()

bool OGrazingPigs::Do ( Farm a_farm,
LE a_field,
FarmEvent a_ev 
)
virtual

Reimplemented from Crop.

32 {
33  m_farm = a_farm;
34  m_field = a_field;
35  m_ev = a_ev;
36 
37  bool done = false;
38 
39  switch ( m_ev->m_todo )
40  {
41  case ogp_start:
42  {
43  a_field->ClearManagementActionSum();
44 
45  // Set up the date management stuff
47  m_field->SetMDates(0,0,g_date->DayInYear(2,11));
48  m_field->SetMDates(1,0,g_date->DayInYear(2,11));
49 
50  // This is a nasty one because it runs one year from when it starts, less one
51  // month
52  // So if the next crop is an autumn one - then it will push the year on one
53  // We cannot allow this - the rotation will be out of sync. So only spring crops
54  // can follow this
55  if ((m_ev->m_startday>g_date->DayInYear(1, 7)) && m_ev->m_startday<g_date->DayInYear(1, 11)) // This allows pigs to follow pigs
56  {
57  g_msg->Warn( WARN_BUG, "GrazingPigs::Do(): "
58  "Autumn Crop Following Grazing Pigs is not allowed!!!", "" );
59  exit( 1 );
60  }
61  if ( ! m_ev->m_first_year )
62  {
63  int today=g_date->Date();
64  // Are we before July 1st?
65  int d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
66  if (today < d1)
67  {
68  // Yes, too early. We assumme this is because the last crop was late
69  g_msg->Warn( WARN_BUG, "GrazingPigs::Do(): "
70  "Crop start attempt between 1st Jan & 1st July", "" );
71  exit( 1 );
72  }
73  else
74  {
75  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
76  if (today > d1)
77  {
78  // Yes too late - should not happen - raise an error
79  g_msg->Warn( WARN_BUG, "GrazingPigs::Do(): "
80  "Crop start attempt after last possible start date", "" );
81  exit( 1 );
82  }
83  }
84  }
85  // OK so if we reach here it is after 1/7 and before 1,11
86 
87  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
88 
89  int d1=g_date->OldDays() + m_first_date;
90  PGP_FIRST_PIGS_IN_DATE=d1+334; // 31 days less than one year
91  PGP_LAST_PIGS_IN_DATE=d1+355; // just less than one year later (So not near the max before 1,11)
92  SimpleEvent( d1, ogp_pigs_out, false );
93  break;
94  }
95  case ogp_pigs_out:
96  {
97  if (!m_farm->PigsOut( m_field, 0.0,
99  SimpleEvent( g_date->Date() + 1, ogp_pigs_out, true );
100  break;
101  }
103  break;
104 
106  // Keep the pigs out there
107  m_farm->PigsAreOutForced( m_field, 0.0, 0 );
108  // PGP_FIRST_PIGS_IN_DATE specifies the first day the pigs may come home.
109  // However this event type forces them to stay out. Thus we want to
110  // abandon this chain of events one day before PGP_FIRST_PIGS_IN_DATE.
111  if ( g_date->Date() < PGP_FIRST_PIGS_IN_DATE - 1 )
112  {
114  break;
115  }
116  SimpleEvent( g_date->Date() + 1, ogp_pigs_are_out, false );
117  }
118  break;
119 
120  case ogp_pigs_are_out:
121  // Start testing for taking the pigs home.
122  // PigsAreOut() returns false if it is not time to stop grazing
123  if (!m_farm->PigsAreOut( m_field, 0.0,
125  // --FN--
126  SimpleEvent( g_date->Date() + 1, ogp_pigs_are_out, true );
127  break;
128  }
129  done=true;
130  break;
131 
132  default:
133  g_msg->Warn( WARN_BUG, "OGrazingPigs::Do(): "
134  "Unknown event type! ", "" );
135  exit( 1 );
136  }
137 
138  return done;
139 }

References LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), g_date, g_msg, Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_first_date, FarmEvent::m_first_year, Crop::m_last_date, FarmEvent::m_startday, FarmEvent::m_todo, ogp_pigs_are_out, ogp_pigs_are_out_forced, ogp_pigs_out, ogp_start, Calendar::OldDays(), PGP_FIRST_PIGS_IN_DATE, PGP_LAST_PIGS_IN_DATE, Farm::PigsAreOut(), Farm::PigsAreOutForced(), Farm::PigsOut(), LE::SetLastSownVeg(), LE::SetMDates(), Crop::SimpleEvent(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void OGrazingPigs::SetUpFarmCategoryInformation ( )
inline
54  {
55  const int elements = 2 + (ogp_foobar - OGrazingPigs_BASE);
57 
58  FarmManagementCategory catlist[elements] =
59  {
60  fmc_Others, // zero element unused but must be here
61  fmc_Others, // ogp_start = 1, // Compulsory, start event must always be 1 (one).
62  fmc_Grazing, // ogp_pigs_out = OGrazingPigs_BASE,
63  fmc_Grazing, // ogp_pigs_are_out,
64  fmc_Grazing // ogp_pigs_are_out_forced,
65 
66 
67  // no foobar entry
68 
69  };
70  // Iterate over the catlist elements and copy them to vector
71  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
72 
73  }

References fmc_Grazing, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, ogp_foobar, and OGrazingPigs_BASE.

Referenced by OGrazingPigs().


The documentation for this class was generated from the following files:
Farm::PigsAreOut
virtual bool PigsAreOut(LE *a_field, double a_user, int a_days)
Start a pig grazing event on a_field today or soon.
Definition: FarmFuncs.cpp:2703
PGP_LAST_PIGS_IN_DATE
#define PGP_LAST_PIGS_IN_DATE
Definition: DK_OGrazingPigs_Perm.h:33
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
LE::SetLastSownVeg
void SetLastSownVeg(TTypesOfVegetation a_tov)
Records the last vegetation type to be sown.
Definition: Elements.h:357
Farm::PigsAreOutForced
virtual bool PigsAreOutForced(LE *a_field, double a_user, int a_days)
Start a pig grazing event on a_field today - no exceptions.
Definition: FarmFuncs.cpp:2679
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
ogp_pigs_are_out_forced
Definition: OGrazingPigs.h:39
ogp_start
Definition: OGrazingPigs.h:36
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
ogp_pigs_are_out
Definition: OGrazingPigs.h:38
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
ogp_pigs_out
Definition: OGrazingPigs.h:37
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
Crop::m_ManagementCategories
vector< FarmManagementCategory > m_ManagementCategories
Holds the translation between the farm operation enum for each crop and the farm management category ...
Definition: Farm.h:530
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
PGP_FIRST_PIGS_IN_DATE
#define PGP_FIRST_PIGS_IN_DATE
Definition: DK_OGrazingPigs_Perm.h:32
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
ogp_foobar
Definition: OGrazingPigs.h:40
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
OGrazingPigs::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OGrazingPigs.h:54
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
Farm::PigsOut
virtual bool PigsOut(LE *a_field, double a_user, int a_days)
Generate a 'pigs_out' event for every day the cattle are on a_field.
Definition: FarmFuncs.cpp:2650
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
OGrazingPigs_BASE
#define OGrazingPigs_BASE
Definition: OGrazingPigs.h:31
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001