Loading [MathJax]/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
DK_OGrazingPigs_Perm Class Reference

#include <DK_OGrazingPigs_Perm.h>

Inheritance diagram for DK_OGrazingPigs_Perm:
Crop

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 DK_OGrazingPigs_Perm (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

◆ DK_OGrazingPigs_Perm()

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

References LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), dk_ogpp_pigs_are_out, dk_ogpp_pigs_are_out_forced, dk_ogpp_pigs_out, dk_ogpp_start, 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, Calendar::OldDays(), PGP_FIRST_PIGS_IN_DATE, PGP_LAST_PIGS_IN_DATE, Farm::PigsAreOut(), Farm::PigsAreOutForced(), Farm::PigsOut(), LE::SetLastSownVeg(), LE::SetMDates(), Crop::SimpleEvent(), tov_DKOGrazingPigs_Perm, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DK_OGrazingPigs_Perm::SetUpFarmCategoryInformation ( )
inline
54  {
55  const int elements = 2 + (dk_ogpp_foobar - DK_OGPP_BASE);
57 
58  FarmManagementCategory catlist[elements] =
59  {
60  fmc_Others, // zero element unused but must be here
61  fmc_Others, // dk_ogpp_start = 1, // Compulsory, start event must always be 1 (one).
62  fmc_Grazing, // dk_ogpp_pigs_out = DK_OGPP_BASE,
63  fmc_Grazing, // dk_ogpp_pigs_are_out,
64  fmc_Grazing // dk_ogpp_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 DK_OGPP_BASE, dk_ogpp_foobar, fmc_Grazing, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_OGrazingPigs_Perm().


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
DK_OGPP_BASE
#define DK_OGPP_BASE
Definition: DK_OGrazingPigs_Perm.h:31
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
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
dk_ogpp_pigs_are_out_forced
Definition: DK_OGrazingPigs_Perm.h:39
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
dk_ogpp_start
Definition: DK_OGrazingPigs_Perm.h:36
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
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
dk_ogpp_foobar
Definition: DK_OGrazingPigs_Perm.h:40
dk_ogpp_pigs_out
Definition: DK_OGrazingPigs_Perm.h:37
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
dk_ogpp_pigs_are_out
Definition: DK_OGrazingPigs_Perm.h:38
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
DK_OGrazingPigs_Perm::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OGrazingPigs_Perm.h:54
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
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
tov_DKOGrazingPigs_Perm
Definition: LandscapeFarmingEnums.h:453
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001