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

#include <DK_OGrassLowYield_Perm.h>

Inheritance diagram for DK_OGrassLowYield_Perm:
Crop

Public Member Functions

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

DK_OGrassLowYield_Perm::DK_OGrassLowYield_Perm ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
56  : Crop(a_tov, a_toc, a_L)
57  {
60  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

36 {
37  m_farm = a_farm;
38  m_field = a_field;
39  m_ev = a_ev;
40 
41  int d1;
42 
43  bool done = false;
45 
46  switch (m_ev->m_todo) {
47  case dk_oglyp_start:
48  {
49  a_field->ClearManagementActionSum();
51  a_field->ClearManagementActionSum();
52 
53  m_last_date = g_date->DayInYear(1, 10); // Should match the last flexdate below
54  //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
55  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
56  // Set up the date management stuff
57  // Start and stop dates for all events after harvest
58  flexdates[0][1] = g_date->DayInYear(15, 9); // last possible day of harvest
59  // Now these are done in pairs, start & end for each operation. If its not used then -1
60  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
61  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)
62 
63  // 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
64  if (StartUpCrop(365, flexdates, int(dk_oglyp_cut_to_hay))) break;
65 
66  // End single block date checking code. Please see next line comment as well.
67  // Reinit d1 to first possible starting date.
68  d1 = g_date->OldDays() + g_date->DayInYear(15, 5)+365;
69  if (g_date->Date() > d1) {
70  d1 = g_date->Date();
71  }
72  // OK, let's go.
73  SimpleEvent(d1, dk_oglyp_cut_to_hay, false);
74 
75  }
76  break;
77 
79  if (m_ev->m_lock || m_farm->DoIt(20))
80  {
81  if (!m_farm->CutToHay(m_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
83  break;
84  }
85  // did cut to hay so try turning
86  else
87  {
89  dk_oglyp_raking1, false);
91  }
92  break;
93  }
94  SimpleEvent(g_date->OldDays() + m_first_date, dk_oglyp_cattle_out1, false); // non-cutters graze
95 
96  break;
97 
98  case dk_oglyp_raking1:
99  if (DK_OGLYP_CUT_DATE + 20 >= g_date->Date()) m_ev->m_lock = true;
100  if (m_ev->m_lock || m_farm->DoIt(50))
101  {
102  if (!m_farm->HayTurning(m_field, 0.0,
103  g_date->DayInYear(25, 6) - g_date->DayInYear()))
104  {
105  SimpleEvent(g_date->Date() + 1, dk_oglyp_raking1, true);
106  break;
107  }
108  SimpleEvent(g_date->Date() + 1, dk_oglyp_raking2, false);
109  break;
110  }
111  ChooseNextCrop(1);
112  SimpleEvent(DK_OGLYP_CUT_DATE + 21, dk_oglyp_cattle_out1, false); // 100% of these graze
113  break;
114 
115  case dk_oglyp_raking2:
116  if (m_ev->m_lock || m_farm->DoIt(25))
117  {
118  if (!m_farm->HayTurning(m_field, 0.0,
119  g_date->DayInYear(26, 6) - g_date->DayInYear())) {
120  SimpleEvent(g_date->Date() + 1, dk_oglyp_raking2, true);
121  break;
122  }
123  }
125  break;
126 
128  if (!m_farm->HayBailing(m_field, 0.0,
129  g_date->DayInYear(1, 7) - g_date->DayInYear()))
130  {
132  break;
133  }
134  // Did compress straw
135 
136  ChooseNextCrop(1);
137 
138  SimpleEvent(DK_OGLYP_CUT_DATE + 21, dk_oglyp_cattle_out1, false); // 100% of these graze
139  break;
140 
142  ChooseNextCrop(1);
145  if (m_field->GetMConstants(0) == 0) {
146  if (!m_farm->CattleOut(m_field, 0.0, -1, DK_OGLYP_GRASS_READY)) {
147  //raise an error
148  g_msg->Warn(WARN_BUG, "DK_OGrassLowYield_Perm::Do(): failure in 'CattleOut' execution", "");
149  exit(1);
150  }
151  }
152  else {
155  break;
156  }
157  }
159  break;
160 
162  if ((m_ev->m_lock || m_farm->DoIt(33)))
163  {
166  if (m_field->GetMConstants(0) == 0) {
167  if (!m_farm->CattleOut(m_field, 0.0, -1, DK_OGLYP_GRASS_READY)) { //raise an error
168  g_msg->Warn(WARN_BUG, "DK_OGrassLowYield_Perm::Do(): failure in 'CattleOut' execution", "");
169  exit(1);
170  }
171  }
172  else {
175  break;
176  }
177  }
178  // Success
180  break;
181  }
182  //Don't graze - but don't end too early;
184  break;
185 
186  case dk_oglyp_wait:
187  done = true;
188  break;
189 
193  if (m_field->GetMConstants(0) == 0) {
194  if (!m_farm->CattleIsOut(m_field, 0.0, -1, m_field->GetMDates(1, 1), DK_OGLYP_GRASS_READY)) { //raise an error
195  //added 28.08 - issue a warning only if we fail on the last day that this can be done, i.e. MDate
196  if (g_date->Date() == m_field->GetMDates(1, 0)){
197  g_msg->Warn(WARN_BUG, "DK_OGrassLowYield_Perm::Do(): failure in 'CattleIsOut' execution", "");
198  exit(1);
199  }
200  }
201  }
202  else {
205  break;
206  }
207  }
208  // if they come in then send them out if too early
209  if (g_date->DayInYear() < g_date->DayInYear(10, 9))
210  {
212  break;
213  }
215  dk_oglyp_cut_weeds, false);
216  break;
217 
218  case dk_oglyp_cut_weeds:
219  if ((m_ev->m_lock || m_farm->DoIt(25)) &&
220  //--FN--
221  (g_date->DayInYear() < g_date->DayInYear(15, 9)))
222  {
223  if (!m_farm->CutWeeds(m_field, 0.0,
224  m_field->GetMDates(0, 1) - g_date->DayInYear())) {
225  // --FN--
226  SimpleEvent(g_date->Date() + 1, dk_oglyp_cut_weeds, true);
227  break;
228  }
229  }
231  break;
232 
233  case dk_oglyp_force_growth: // Need to add this in the end to make sure grass decays in winter
234  if (g_date->DayInYear() < g_date->DayInYear(1, 11)) {
236  break;
237  }
238  else if (g_date->DayInYear() < g_date->DayInYear(31, 12)) {
239  a_field->ForceGrowthTest();
241  break;
242  }
243  done = true; // end of plan
244  break;
245 
246  default:
247  g_msg->Warn(WARN_BUG, "DK_OGrassLowYield::Do(): "
248  "Unknown event type! ", "");
249  exit(1);
250  }
251  return done;
252 }

References Farm::CattleIsOut(), Farm::CattleOut(), cfg_farm_cattle_grass_high, cfg_farm_cattle_grass_low, Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Farm::CutToHay(), Farm::CutWeeds(), Calendar::Date(), Calendar::DayInYear(), dk_oglyp_cattle_is_out, dk_oglyp_cattle_out1, dk_oglyp_cattle_out2, dk_oglyp_compress_straw, DK_OGLYP_CUT_DATE, dk_oglyp_cut_to_hay, dk_oglyp_cut_weeds, dk_oglyp_force_growth, DK_OGLYP_GRASS_READY, dk_oglyp_raking1, dk_oglyp_raking2, dk_oglyp_start, dk_oglyp_wait, Farm::DoIt(), LE::ForceGrowthTest(), g_date, g_msg, LE::GetMConstants(), LE::GetMDates(), LE::GetVegHeight(), Farm::HayBailing(), Farm::HayTurning(), 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(), Crop::SimpleEvent(), Crop::StartUpCrop(), tov_DKOGrassLowYield_Perm, CfgInt::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DK_OGrassLowYield_Perm::SetUpFarmCategoryInformation ( )
inline
61  {
62  const int elements = 2 + (dk_oglyp_foobar - DK_OGLYP_BASE);
64 
65  FarmManagementCategory catlist[elements] =
66  {
67  fmc_Others, // zero element unused but must be here
68  fmc_Cutting, // dk_oglyp_cut_to_hay = GLYP_BASE,
69  fmc_Grazing, // dk_oglyp_cattle_out1,
70  fmc_Grazing, // dk_oglyp_cattle_out2,
71  fmc_Grazing, // dk_oglyp_cattle_is_out,
72  fmc_Cutting, // dk_oglyp_cut_weeds,
73  fmc_Others, // dk_oglyp_raking1,
74  fmc_Others, // dk_oglyp_raking2,
75  fmc_Others, // dk_oglyp_compress_straw,
76  fmc_Others, // dk_oglyp_force_growth
77  fmc_Others // dk_oglyp_wait,
78  // No foobar entry
79  };
80  // Iterate over the catlist elements and copy them to vector
81  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
82  }

References DK_OGLYP_BASE, dk_oglyp_foobar, fmc_Cutting, fmc_Grazing, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_OGrassLowYield_Perm().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
dk_oglyp_force_growth
Definition: DK_OGrassLowYield_Perm.h:46
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
LE::ForceGrowthTest
virtual void ForceGrowthTest(void)
Definition: Elements.h:188
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
dk_oglyp_cattle_out1
Definition: DK_OGrassLowYield_Perm.h:38
DK_OGLYP_GRASS_READY
#define DK_OGLYP_GRASS_READY
Definition: DK_OGrassLowYield_Perm.h:33
dk_oglyp_start
Definition: DK_OGrassLowYield_Perm.h:36
tov_DKOGrassLowYield_Perm
Definition: LandscapeFarmingEnums.h:455
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
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_oglyp_foobar
Definition: DK_OGrassLowYield_Perm.h:47
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
dk_oglyp_wait
Definition: DK_OGrassLowYield_Perm.h:45
dk_oglyp_cut_weeds
Definition: DK_OGrassLowYield_Perm.h:41
DK_OGrassLowYield_Perm::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OGrassLowYield_Perm.h:61
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
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
LE::GetVegHeight
virtual double GetVegHeight(void)
Definition: Elements.h:148
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
dk_oglyp_raking2
Definition: DK_OGrassLowYield_Perm.h:43
DK_OGLYP_BASE
#define DK_OGLYP_BASE
Definition: DK_OGrassLowYield_Perm.h:31
dk_oglyp_cattle_is_out
Definition: DK_OGrassLowYield_Perm.h:40
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
dk_oglyp_cattle_out2
Definition: DK_OGrassLowYield_Perm.h:39
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_OGLYP_CUT_DATE
#define DK_OGLYP_CUT_DATE
Definition: DK_OGrassLowYield_Perm.h:32
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
dk_oglyp_cut_to_hay
Definition: DK_OGrassLowYield_Perm.h:37
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
cfg_farm_cattle_grass_low
CfgInt cfg_farm_cattle_grass_low
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
dk_oglyp_raking1
Definition: DK_OGrassLowYield_Perm.h:42
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_oglyp_compress_straw
Definition: DK_OGrassLowYield_Perm.h:44
cfg_farm_cattle_grass_high
CfgInt cfg_farm_cattle_grass_high
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
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
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