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
DK_GrassTussocky_Perm Class Reference

#include <DK_GrassTussocky_Perm.h>

Inheritance diagram for DK_GrassTussocky_Perm:
Crop

Public Member Functions

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

DK_GrassTussocky_Perm::DK_GrassTussocky_Perm ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

38  {
39  m_farm = a_farm;
40  m_field = a_field;
41  m_ev = a_ev;
42 
43  bool done = false;
44 
45  switch (m_ev->m_todo) {
46  case dk_gtp_start:
47  {
48  a_field->ClearManagementActionSum();
49  DK_GTP_CUT_DATE = 0;
51  // Set up the date management stuff
52  m_last_date = g_date->DayInYear(1, 10);
53  // Start and stop dates for all events after harvest
54  int noDates = 1;
55  // Start and stop dates for all events after harvest
56  m_field->SetMDates(0, 0, g_date->DayInYear(15, 9));
57  // 0,0 determined by harvest date - used to see if at all possible
58  m_field->SetMDates(1, 0, g_date->DayInYear(1, 10));
59  // Check the next crop for early start, unless it is a spring crop
60  // in which case we ASSUME that no checking is necessary!!!!
61  // So DO NOT implement a crop that runs over the year boundary
62  //new if: do the check only for non-optimising farms and if year>0. (030713 - m_rotation used only in the hidden year, so I modified the condition from >7 to >0)
63  int d1;
64  if (!(m_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
65  if (m_ev->m_startday > g_date->DayInYear(1, 7)) {
66  if (m_field->GetMDates(0, 0) >= m_ev->m_startday) {
67  g_msg->Warn(WARN_BUG, "DK_GrassTussocky_Perm::Do(): "
68  "Harvest too late for the next crop to start!!!", "");
69  exit(1);
70  }
71  // Now fix any late finishing problems
72  for (int i = 0; i < noDates; i++) {
73  if (m_field->GetMDates(0, i) >= m_ev->m_startday) {
74  m_field->SetMDates(0, i, m_ev->m_startday - 1); //move the starting date
75  }
76  if (m_field->GetMDates(1, i) >= m_ev->m_startday) {
77  m_field->SetMConstants(i, 0);
78  m_field->SetMDates(1, i, m_ev->m_startday - 1); //move the finishing date
79  }
80  }
81  }
82  // Now no operations can be timed after the start of the next crop.
83 
84  int today = g_date->Date();
85  d1 = g_date->OldDays() + m_first_date + 365; // Add 365 for spring crop
86  if (today > d1) {
87  // Yes too late - should not happen - raise an error
88  g_msg->Warn(WARN_BUG, " DK_GrassTussocky_Perm::Do(): "
89  "Crop start attempt after last possible start date", "");
90  exit(1);
91  }
92  }//if
93 
94  // Reinit d1 to first possible starting date.
95  d1 = g_date->OldDays() + m_first_date;;
96  if (!m_ev->m_first_year) d1 += 365; // Add 365 for spring crop (not 1st yr)
97  if (g_date->Date() > d1) {
98  d1 = g_date->Date();
99  }
100  // OK, let's go.
101  m_field->SetLastSownVeg(m_field->GetVegType()); //Force last sown, needed for goose habitat classification
102 
103  ChooseNextCrop(1);
104 
105  SimpleEvent(d1, dk_gtp_cattle_out1, false);
106  }
107  break;
108 
109  case dk_gtp_cattle_out1:
110  if (m_field->GetMConstants(0) == 0) {
113  if (!m_farm->CattleOut(m_field, 0.0, -1, DK_GTP_GRASS_READY)) { //raise an error
114  g_msg->Warn(WARN_BUG, "DK_GrassTussocky_Perm::Do(): failure in 'CattleOutLowGrazing' execution", "");
115  exit(1);
116  }
117  }
118  else {
120  SimpleEvent(g_date->Date() + 1, dk_gtp_cattle_out1, true);
121  break;
122  }
123  }
125  break;
126 
127  case dk_gtp_cattle_out2:
128  if ((m_ev->m_lock || m_farm->DoIt(33)) || (DK_GTP_FERTI_DATE != 0)) {
131  if (m_field->GetMConstants(0) == 0) {
132  if (!m_farm->CattleOut(m_field, 0.0, -1, DK_GTP_GRASS_READY)) { //raise an error
133  g_msg->Warn(WARN_BUG, "DK_GrassTussocky_Perm::Do(): failure in 'CattleOutLowGrazing' execution", "");
134  exit(1);
135  }
136  }
137  else {
139  SimpleEvent(g_date->Date() + 1, dk_gtp_cattle_out2, true);
140  break;
141  }
142  }
143  // Success
145  break;
146  }
147  //Don't graze - but don't end too early;
148  SimpleEvent(g_date->OldDays() + g_date->DayInYear(2, 7), dk_gtp_wait, false);
149  break;
150 
151  case dk_gtp_wait:
152  done = true;
153  break;
154 
158  if (m_field->GetMConstants(0) == 0) {
159  if (!m_farm->CattleIsOut(m_field, 0.0, -1, m_field->GetMDates(1, 0), DK_GTP_GRASS_READY)) { //raise an error
160  //added 28.08 - issue a warning only if we fail on the last day that this can be done, i.e. MDate
161  if (g_date->Date() == m_field->GetMDates(1, 0)) {
162  g_msg->Warn(WARN_BUG, "DK_GrassTussocky_Perm::Do(): failure in 'CattleIsOutLow' execution", "");
163  exit(1);
164  }
165  }
166  }
167  else {
170  break;
171  }
172  }
173  // if they come in then send them out if too early
174  if (g_date->DayInYear() < g_date->DayInYear(10, 9)) {
175  SimpleEvent(g_date->Date() + 1, dk_gtp_cattle_out2, true);
176  break;
177  }
179  break;
180 
181  case dk_gtp_force_growth: // Need to add this in the end to make sure grass decays in winter
182  if (g_date->DayInYear() < g_date->DayInYear(1, 11)) {
184  break;
185  }
186  else if (g_date->DayInYear() < g_date->DayInYear(31, 12)) {
187  a_field->ForceGrowthTest();
189  break;
190  }
191  done = true; // end of plan
192  break;
193 
194  default:
195  g_msg->Warn(WARN_BUG, "DK_GrassTussocky_Perm::Do(): "
196  "Unknown event type! ", "");
197  exit(1);
198  }
199  return done;
200 }

References Farm::CattleIsOut(), Farm::CattleOut(), cfg_farm_cattle_grass_high, cfg_farm_cattle_grass_low, Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), dk_gtp_cattle_is_out, dk_gtp_cattle_out1, dk_gtp_cattle_out2, DK_GTP_CUT_DATE, DK_GTP_FERTI_DATE, dk_gtp_force_growth, DK_GTP_GRASS_READY, dk_gtp_start, dk_gtp_wait, Farm::DoIt(), LE::ForceGrowthTest(), g_date, g_msg, LE::GetMConstants(), LE::GetMDates(), Farm::GetType(), LE::GetVegHeight(), Calendar::GetYearNumber(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_first_date, FarmEvent::m_first_year, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_startday, FarmEvent::m_todo, Calendar::OldDays(), LE::SetLastSownVeg(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent(), tof_OptimisingFarm, CfgInt::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DK_GrassTussocky_Perm::SetUpFarmCategoryInformation ( )
inline
57  {
58  const int elements = 2 + (dk_gtp_foobar - DK_GTP_BASE);
60 
61  FarmManagementCategory catlist[elements] =
62  {
63  fmc_Others, // zero element unused but must be here
64  fmc_Others,
68  fmc_Others,
70  // No foobar entry
71  };
72  // Iterate over the catlist elements and copy them to vector
73  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
74  }

References DK_GTP_BASE, dk_gtp_foobar, fmc_Grazing, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_GrassTussocky_Perm().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
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
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
LE::GetMConstants
int GetMConstants(int a)
Definition: Elements.h:407
Farm::CattleIsOut
virtual bool CattleIsOut(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out' event for every day the cattle are on a_field.
Definition: FarmFuncs.cpp:2470
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: Farm.cpp:856
Calendar::GetYearNumber
int GetYearNumber(void)
Definition: Calendar.h:72
DK_GTP_GRASS_READY
#define DK_GTP_GRASS_READY
Definition: DK_GrassTussocky_Perm.h:34
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
LE::ForceGrowthTest
virtual void ForceGrowthTest(void)
Definition: Elements.h:188
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
DK_GTP_FERTI_DATE
#define DK_GTP_FERTI_DATE
Definition: DK_GrassTussocky_Perm.h:33
Farm::GetType
TTypesOfFarm GetType(void)
Definition: Farm.h:956
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
cfg_farm_cattle_grass_low
CfgInt cfg_farm_cattle_grass_low
DK_GTP_BASE
#define DK_GTP_BASE
Definition: DK_GrassTussocky_Perm.h:31
cfg_farm_cattle_grass_high
CfgInt cfg_farm_cattle_grass_high
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
dk_gtp_force_growth
Definition: DK_GrassTussocky_Perm.h:42
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_GrassTussocky_Perm::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_GrassTussocky_Perm.h:57
dk_gtp_start
Definition: DK_GrassTussocky_Perm.h:37
dk_gtp_foobar
Definition: DK_GrassTussocky_Perm.h:43
Calendar::Date
long Date(void)
Definition: Calendar.h:57
dk_gtp_cattle_is_out
Definition: DK_GrassTussocky_Perm.h:40
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
LE::GetVegHeight
virtual double GetVegHeight(void)
Definition: Elements.h:148
dk_gtp_cattle_out1
Definition: DK_GrassTussocky_Perm.h:38
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
dk_gtp_wait
Definition: DK_GrassTussocky_Perm.h:41
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
CfgInt::value
int value() const
Definition: Configurator.h:116
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
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
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
dk_gtp_cattle_out2
Definition: DK_GrassTussocky_Perm.h:39
DK_GTP_CUT_DATE
#define DK_GTP_CUT_DATE
Definition: DK_GrassTussocky_Perm.h:32
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
LE::SetMConstants
void SetMConstants(int a, int c)
Definition: Elements.h:408
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: Farm.cpp:756
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
Farm::CattleOut
virtual bool CattleOut(LE *a_field, double a_user, int a_days)
Start a grazing event on a_field today.
Definition: FarmFuncs.cpp:2368
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001