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

#include <DK_GrassLowYield_Perm.h>

Inheritance diagram for DK_GrassLowYield_Perm:
Crop

Public Member Functions

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

DK_GrassLowYield_Perm::DK_GrassLowYield_Perm ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
57  : Crop(a_tov, a_toc, a_L)
58  {
61  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

40 {
41  m_farm = a_farm;
42  m_field = a_field;
43  m_ev = a_ev;
44 
45  int d1;
46 
47  bool done = false;
49 
50  switch (m_ev->m_todo) {
51  case dk_glyp_start:
52  {
53  DK_GLYP_CUT_DATE = 0;
54  a_field->ClearManagementActionSum();
55 
56  m_last_date = g_date->DayInYear(1, 10); // Should match the last flexdate below
57  //Create a 2d array of 1 plus the number of operations you use. Change only 4+1 to what you need in the line below
58  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
59  // Set up the date management stuff
60  // Start and stop dates for all events after harvest
61  flexdates[0][1] = g_date->DayInYear(15, 9); // last possible day of harvest
62  // Now these are done in pairs, start & end for each operation. If its not used then -1
63  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
64  flexdates[1][1] = g_date->DayInYear(1, 10); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1)
65 
66  // Below if this is a spring crop use 365, otherwise first parameter is always 0, second parameter is fixed, and the third is the start up operation in the first year
67  int isSpring = 365;
68  if (StartUpCrop(isSpring, flexdates, int(dk_glyp_cut_to_hay))) break;
69 
70  // End single block date checking code. Please see next line comment as well.
71  // Reinit d1 to first possible starting date.
72  d1 = g_date->OldDays() + g_date->DayInYear(15, 5) + 365;
73  if (g_date->Date() > d1) {
74  d1 = g_date->Date();
75  }
76  // OK, let's go.
77  SimpleEvent(d1, dk_glyp_cut_to_hay, false);
78  }
79  break;
80 
81  case dk_glyp_cut_to_hay:
82  if (m_ev->m_lock || m_farm->DoIt(20)){
83  if (!m_farm->CutToHay(m_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
85  break;
86  }
87  // did cut to hay so try turning
88  else
89  {
91  dk_glyp_raking1, false);
93  }
94  break;
95  }
96  SimpleEvent(g_date->OldDays() + m_first_date, dk_glyp_cattle_out1, false); // non-cutters graze
97  break;
98 
99  case dk_glyp_raking1:
100  if (DK_GLYP_CUT_DATE + 20 >= g_date->Date()) m_ev->m_lock = true;
101  if (m_ev->m_lock || m_farm->DoIt(50)){
102  if (!m_farm->HayTurning(m_field, 0.0, g_date->DayInYear(25, 6) - g_date->DayInYear())){
103  SimpleEvent(g_date->Date() + 1, dk_glyp_raking1, true);
104  break;
105  }
106  SimpleEvent(g_date->Date() + 1, dk_glyp_raking2, false);
107  break;
108  }
109  ChooseNextCrop(1);
110  SimpleEvent(DK_GLYP_CUT_DATE + 21, dk_glyp_cattle_out1, false); // 100% of these graze
111  break;
112 
113  case dk_glyp_raking2:
114  if (m_ev->m_lock || m_farm->DoIt(25))
115  {
116  if (!m_farm->HayTurning(m_field, 0.0,
117  g_date->DayInYear(26, 6) - g_date->DayInYear())) {
118  SimpleEvent(g_date->Date() + 1, dk_glyp_raking2, true);
119  break;
120  }
121  }
123  break;
124 
126  if (!m_farm->HayBailing(m_field, 0.0, g_date->DayInYear(1, 7) - g_date->DayInYear())){
128  break;
129  }
130  // Did compress straw
131  ChooseNextCrop(1);
132 
133  SimpleEvent(DK_GLYP_CUT_DATE + 21, dk_glyp_cattle_out1, false); // 100% of these graze
134  break;
135 
136  case dk_glyp_cattle_out1:
137  ChooseNextCrop(1);
140 
141  if (m_field->GetMConstants(0) == 0) {
142  if (!m_farm->CattleOut(m_field, 0.0, -1, DK_GLYP_GRASS_READY)) {
143  //raise an error
144  g_msg->Warn(WARN_BUG, "DK_GrassLowYield_Perm::Do(): failure in 'CattleOut' execution", "");
145  exit(1);
146  }
147  }
148  else {
151  break;
152  }
153  }
155  break;
156 
157  case dk_glyp_cattle_out2:
158  if ((m_ev->m_lock || m_farm->DoIt(33))){
161  if (m_field->GetMConstants(0) == 0) {
162  if (!m_farm->CattleOut(m_field, 0.0, -1, DK_GLYP_GRASS_READY)) { //raise an error
163  g_msg->Warn(WARN_BUG, "DK_GrassLowYield_Perm::Do(): failure in 'CattleOut' execution", "");
164  exit(1);
165  }
166  }
167  else {
170  break;
171  }
172  }
173  // Success
175  break;
176  }
177  //Don't graze - but don't end too early;
178  SimpleEvent(g_date->OldDays() + g_date->DayInYear(2, 7), dk_glyp_wait, false);
179  break;
180 
181  case dk_glyp_wait:
182  done = true;
183  break;
184 
188  if (m_field->GetMConstants(0) == 0) {
189  if (!m_farm->CattleIsOut(m_field, 0.0, -1, m_field->GetMDates(1, 1), DK_GLYP_GRASS_READY)) { //raise an error
190  //added 28.08 - issue a warning only if we fail on the last day that this can be done, i.e. MDate
191  if (g_date->Date() == m_field->GetMDates(1, 0)){
192  g_msg->Warn(WARN_BUG, "DK_GrassLowYield_Perm::Do(): failure in 'CattleIsOut' execution", "");
193  exit(1);
194  }
195  }
196  }
197  else {
200  break;
201  }
202  }
203  // if they come in then send them out if too early
204  if (g_date->DayInYear() < g_date->DayInYear(10, 9))
205  {
207  break;
208  }
210  break;
211 
212  case dk_glyp_herbicide:
213  if ((m_ev->m_lock || m_farm->DoIt((int)(5 * cfg_herbi_app_prop.value() * m_farm->Prob_multiplier()))) && //modified probability
214  // --FN--
215  (g_date->DayInYear() < g_date->DayInYear(15, 8)))
216  {
217  if (!m_farm->HerbicideTreat(m_field, 0.0, g_date->DayInYear(15, 8) - g_date->DayInYear())) {
218  // --FN--
219  SimpleEvent(g_date->Date() + 1, dk_glyp_herbicide, true);
220  break;
221  }
222  }
224  dk_glyp_cut_weeds, false);
225  break;
226 
227  case dk_glyp_cut_weeds:
228  if ((m_ev->m_lock || m_farm->DoIt(25)) &&
229  //--FN--
230  (g_date->DayInYear() < g_date->DayInYear(15, 9)))
231  {
232  if (!m_farm->CutWeeds(m_field, 0.0,
233  m_field->GetMDates(0, 1) - g_date->DayInYear())) {
234  // --FN--
235  SimpleEvent(g_date->Date() + 1, dk_glyp_cut_weeds, true);
236  break;
237  }
238  }
240  break;
241 
242  case dk_glyp_force_growth: // Need to add this in the end to make sure grass decays in winter
243  if (g_date->DayInYear() < g_date->DayInYear(1, 11)) {
245  break;
246  }
247  else if (g_date->DayInYear() < g_date->DayInYear(31, 12)) {
248  a_field->ForceGrowthTest();
250  break;
251  }
252  done = true; // end of plan
253  break;
254 
255  default:
256  g_msg->Warn(WARN_BUG, "GrassLowYield_Perm::Do(): "
257  "Unknown event type! ", "");
258  exit(1);
259  }
260  return done;
261 }

References Farm::CattleIsOut(), Farm::CattleOut(), cfg_farm_cattle_grass_high, cfg_farm_cattle_grass_low, cfg_herbi_app_prop, Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Farm::CutToHay(), Farm::CutWeeds(), Calendar::Date(), Calendar::DayInYear(), dk_glyp_cattle_is_out, dk_glyp_cattle_out1, dk_glyp_cattle_out2, dk_glyp_compress_straw, DK_GLYP_CUT_DATE, dk_glyp_cut_to_hay, dk_glyp_cut_weeds, dk_glyp_force_growth, DK_GLYP_GRASS_READY, dk_glyp_herbicide, dk_glyp_raking1, dk_glyp_raking2, dk_glyp_start, dk_glyp_wait, Farm::DoIt(), LE::ForceGrowthTest(), g_date, g_msg, LE::GetMConstants(), LE::GetMDates(), LE::GetVegHeight(), Farm::HayBailing(), Farm::HayTurning(), Farm::HerbicideTreat(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_first_date, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), Farm::Prob_multiplier(), Crop::SimpleEvent(), Crop::StartUpCrop(), tov_DKGrassLowYield_Perm, CfgInt::value(), CfgFloat::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DK_GrassLowYield_Perm::SetUpFarmCategoryInformation ( )
inline
62  {
63  const int elements = 2 + (dk_glyp_foobar - DK_GLYP_BASE);
65 
66  FarmManagementCategory catlist[elements] =
67  {
68  fmc_Others, // zero element unused but must be here
69  fmc_Cutting, // dk_glyp_cut_to_hay = GLYP_BASE,
70  fmc_Grazing, // dk_glyp_cattle_out1,
71  fmc_Grazing, // dk_glyp_cattle_out2,
72  fmc_Grazing, // dk_glyp_cattle_is_out,
73  fmc_Cutting, // dk_glyp_cut_weeds,
74  fmc_Herbicide, // dk_glyp_herbicide,
75  fmc_Others, // dk_glyp_raking1,
76  fmc_Others, // dk_glyp_raking2,
77  fmc_Others, // dk_glyp_compress_straw,
78  fmc_Others, // dk_glyp_wait,
79  fmc_Others //dk_glyp_force_growth
80  // No foobar entry
81  };
82  // Iterate over the catlist elements and copy them to vector
83  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
84  }

References DK_GLYP_BASE, dk_glyp_foobar, fmc_Cutting, fmc_Grazing, fmc_Herbicide, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_GrassLowYield_Perm().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
Farm::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: FarmFuncs.cpp:2025
dk_glyp_force_growth
Definition: DK_GrassLowYield_Perm.h:47
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
cfg_farm_cattle_grass_high
CfgInt cfg_farm_cattle_grass_high
dk_glyp_raking2
Definition: DK_GrassLowYield_Perm.h:44
dk_glyp_herbicide
Definition: DK_GrassLowYield_Perm.h:42
LE::ForceGrowthTest
virtual void ForceGrowthTest(void)
Definition: Elements.h:188
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
fmc_Herbicide
Definition: LandscapeFarmingEnums.h:1006
dk_glyp_wait
Definition: DK_GrassLowYield_Perm.h:46
CfgFloat::value
double value() const
Definition: Configurator.h:142
dk_glyp_cattle_is_out
Definition: DK_GrassLowYield_Perm.h:40
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
dk_glyp_start
Definition: DK_GrassLowYield_Perm.h:36
Farm::CutToHay
virtual bool CutToHay(LE *a_field, double a_user, int a_days)
Carry out hay cutting on a_field.
Definition: FarmFuncs.cpp:1607
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
DK_GLYP_CUT_DATE
#define DK_GLYP_CUT_DATE
Definition: DK_GrassLowYield_Perm.h:32
dk_glyp_compress_straw
Definition: DK_GrassLowYield_Perm.h:45
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
Farm::Prob_multiplier
virtual double Prob_multiplier()
Definition: Farm.h:778
Calendar::Date
long Date(void)
Definition: Calendar.h:57
Farm::HayBailing
virtual bool HayBailing(LE *a_field, double a_user, int a_days)
Carry out hay bailing on a_field.
Definition: FarmFuncs.cpp:1507
tov_DKGrassLowYield_Perm
Definition: LandscapeFarmingEnums.h:461
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
LE::GetVegHeight
virtual double GetVegHeight(void)
Definition: Elements.h:148
DK_GrassLowYield_Perm::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_GrassLowYield_Perm.h:62
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::StartUpCrop
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 a...
Definition: Farm.cpp:652
dk_glyp_cut_weeds
Definition: DK_GrassLowYield_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
cfg_farm_cattle_grass_low
CfgInt cfg_farm_cattle_grass_low
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
dk_glyp_raking1
Definition: DK_GrassLowYield_Perm.h:43
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
DK_GLYP_BASE
#define DK_GLYP_BASE
Definition: DK_GrassLowYield_Perm.h:31
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
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
dk_glyp_cattle_out2
Definition: DK_GrassLowYield_Perm.h:39
dk_glyp_cattle_out1
Definition: DK_GrassLowYield_Perm.h:38
cfg_herbi_app_prop
CfgFloat cfg_herbi_app_prop
DK_GLYP_GRASS_READY
#define DK_GLYP_GRASS_READY
Definition: DK_GrassLowYield_Perm.h:33
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
dk_glyp_cut_to_hay
Definition: DK_GrassLowYield_Perm.h:37
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: Farm.cpp:756
Farm::HayTurning
virtual bool HayTurning(LE *a_field, double a_user, int a_days)
Carry out hay turning on a_field.
Definition: FarmFuncs.cpp:1491
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
dk_glyp_foobar
Definition: DK_GrassLowYield_Perm.h:48
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
Farm::CutWeeds
virtual bool CutWeeds(LE *a_field, double a_user, int a_days)
Carry out weed topping on a_field.
Definition: FarmFuncs.cpp:1629