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

DK_SetAside_SummerMow class
. More...

#include <DK_SetAside_SummerMow.h>

Inheritance diagram for DK_SetAside_SummerMow:
Crop

Public Member Functions

virtual bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 The one and only method for a crop management plan. All farm actions go through here. More...
 
 DK_SetAside_SummerMow (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...
 

Detailed Description

DK_SetAside_SummerMow class
.

See DK_SetAside_SummerMow.h::DK_SetAside_SummerMowToDo for a complete list of all possible events triggered codes by the DK_SetAside_SummerMow management plan. When triggered these events are handled by Farm and are available as information for other objects such as animal and bird models.

Constructor & Destructor Documentation

◆ DK_SetAside_SummerMow()

DK_SetAside_SummerMow::DK_SetAside_SummerMow ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
94  : Crop(a_tov, a_toc, a_L)
95  {
96  // When we start it off, the first possible date for a farm operation
97  // This information is used by other crops when they decide how much post processing of
98  // the management is allowed after harvest before the next crop starts.
99  m_first_date = g_date->DayInYear(31, 12);
101  }

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

Member Function Documentation

◆ Do()

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

The one and only method for a crop management plan. All farm actions go through here.

Called every time something is done to the crop by the farmer in the first instance it is always called with a_ev->todo set to start, but susequently will be called whenever the farmer wants to carry out a new operation.
This method details all the management and relationships between operations necessary to grow and ALMaSS crop - in this case conventional spring barley Fodder.

Reimplemented from Crop.

99 {
100  m_field = a_field; // this is needed because of possible calls to other methods and currently we do not pass parameters.
101  m_farm = a_farm; // this is needed because of possible calls to other methods and currently we do not pass parameters.
102  m_ev = a_ev;
103  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
104  int d1 = 0;
106  // Depending what event has occured jump to the correct bit of code e.g. for ww_start jump to line 67 below
107  switch (a_ev->m_todo)
108  {
109  case dk_sasm_start:
110  {
111  a_field->ClearManagementActionSum();
112  m_field->SetVegPatchy(true);
113  m_last_date = g_date->DayInYear(11, 11); // Should match the last flexdate below
114  //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
115  std::vector<std::vector<int>> flexdates(3 + 1, std::vector<int>(2, 0));
116  // Set up the date management stuff
117  // Start and stop dates for all events after harvest
118  flexdates[0][1] = g_date->DayInYear(25, 10); // last possible day of cutting in this case
119  // Now these are done in pairs, start & end for each operation. If its not used then -1
120  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
121  flexdates[1][1] = g_date->DayInYear(26, 10); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1) - strigling
122  flexdates[2][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 2 (start op 2)
123  flexdates[2][1] = g_date->DayInYear(26, 10); // This date will be moved back as far as necessary and potentially to flexdates 2 (end op 2) - herbicide
124  flexdates[3][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 3 (start op 3)
125  flexdates[3][1] = g_date->DayInYear(11, 11); // This date will be moved back as far as necessary and potentially to flexdates 3 (end op 3) - swathing
126 
127  // 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
128  if (StartUpCrop(0, flexdates, int(dk_sasm_wait1))) break;
129 
130  if (m_ev->m_forcespring) {
131  int day_num_shift = 365;
132  if (g_date->DayInYear() < 70) day_num_shift = 0;
133  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 3) + day_num_shift, dk_sasm_wait1, false);
134  break;
135  }
136  // End single block date checking code. Please see next line comment as well.
137  // Reinit d1 to first possible starting date.
138  d1 = g_date->OldDays() + g_date->DayInYear(1, 9);
139  // OK, let's go.
140  // Here we queue up the first event which changes dependent on whether it is a forced spring sow or no
141  if (g_date->Date() >= d1) {
142  d1 = g_date->Date();
143  }
144  SimpleEvent(d1, dk_sasm_wait2, false);
145  break;
146 
147  }
148  break;
149  // LKM: This is the first real farm operation
150 
151  case dk_sasm_wait2:
152  if (!a_farm->SleepAllDay(a_field, 0.0, g_date->DayInYear(31, 12) - g_date->DayInYear())) {
153  SimpleEvent(g_date->Date() + 1, dk_sasm_wait2, true);
154  break;
155  }
156  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 3) + 365, dk_sasm_wait1, false);
157  break;
158 
159  case dk_sasm_wait1:
160  if (!a_farm->SleepAllDay(a_field, 0.0, g_date->DayInYear(1, 8) - g_date->DayInYear())) {
161  SimpleEvent(g_date->Date() + 1, dk_sasm_wait1, true);
162  break;
163  }
165  break;
166 
167  case dk_sasm_cutting: // only allowed between 1 of aug to 25 of oct (when summer cutting)
168  if (!a_farm->CutToHay(a_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
169  SimpleEvent(g_date->Date() + 1, dk_sasm_cutting, true);
170  break;
171  }
173  break;
174 
175  case dk_sasm_strigling:
176  if (a_ev->m_lock || a_farm->DoIt(100)) {
177  if (!a_farm->Strigling(a_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
178  SimpleEvent(g_date->Date() + 1, dk_sasm_strigling, true);
179  break;
180  }
181  }
183  break;
184 
185  case dk_sasm_herbicide: // only allowed if risk of cross pollination - suggest to not include for now
186  if (a_ev->m_lock || a_farm->DoIt_prob(0.0)) {
187  if (!a_farm->HerbicideTreat(a_field, 0.0, m_field->GetMDates(1, 2) - g_date->DayInYear())) {
188  SimpleEvent(g_date->Date() + 1, dk_sasm_herbicide, true);
189  break;
190  }
191  }
192  SimpleEvent(g_date->Date()+14, dk_sasm_swathing, false);
193  break;
194 
195  case dk_sasm_swathing:
196  if (a_field->GetVegBiomass() > 0)
197  {
198  if (!a_farm->Swathing(a_field, 0.0, m_field->GetMDates(1, 3) - g_date->DayInYear())) {
199  SimpleEvent(g_date->Date() + 1, dk_sasm_swathing, true);
200  break;
201  }
202  }
203  d1 = g_date->Date();
204  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 7)) {
205  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 7), dk_sasm_wait, false);
206  // Because we are ending harvest before 1.7 so we need to wait until the 1.7
207  break;
208  }
209  else {
210  done = true; // end of plan
211  }
212  case dk_sasm_wait:
213  // End of management
214  done = true;
215  m_field->SetVegPatchy(false);
216  break;
217  // So we are done, and somewhere else the farmer will queue up the start event of the next crop
218  // END OF MAIN THREAD
219  // End of management
220 
221  default:
222  g_msg->Warn(WARN_BUG, "DK_SetAside_SummerMow::Do(): "
223  "Unknown event type! ", "");
224  exit(1);
225  }
226  if (done) m_ev->m_forcespring = true; // Here we need to force the next crop to spring operation, so set the ev->forcespring to true
227  return done;
228 }

References LE::ClearManagementActionSum(), Farm::CutToHay(), Calendar::Date(), Calendar::DayInYear(), dk_sasm_cutting, dk_sasm_herbicide, dk_sasm_start, dk_sasm_strigling, dk_sasm_swathing, dk_sasm_wait, dk_sasm_wait1, dk_sasm_wait2, Farm::DoIt(), Farm::DoIt_prob(), g_date, g_msg, LE::GetMDates(), LE::GetVegBiomass(), Farm::HerbicideTreat(), Crop::m_ev, Crop::m_farm, Crop::m_field, FarmEvent::m_forcespring, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), LE::SetVegPatchy(), Crop::SimpleEvent(), Farm::SleepAllDay(), Crop::StartUpCrop(), Farm::Strigling(), Farm::Swathing(), tov_DKSetAside_SummerMow, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DK_SetAside_SummerMow::SetUpFarmCategoryInformation ( )
inline
102  {
103  const int elements = 2 + (dk_sasm_foobar - DK_SASM_BASE);
105 
106  FarmManagementCategory catlist[elements] =
107  {
108  fmc_Others, // zero element unused but must be here
109  fmc_Others, // dk_sasm_start = 1, // Compulsory, must always be 1 (one).
110  fmc_Cultivation, // dk_sasm_harrow = DK_SASM_BASE
111  fmc_Cultivation, // dk_sasm_roll
112  fmc_Others, // dk_sasm_wait,
113  fmc_Others, // dk_sasm_wait1,
114  fmc_Others, // dk_sasm_wait2,
115  fmc_Others, // dk_sasm_sow,
116  fmc_Cutting, // dk_sasm_cutting,
117  fmc_Cultivation, // dk_sasm_strigling,
118  fmc_Cutting, // dk_sasm_swathing,
119  fmc_Herbicide, // dk_sasm_herbicide,
120 
121  // no foobar entry
122 
123  };
124  // Iterate over the catlist elements and copy them to vector
125  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
126 
127  }

References DK_SASM_BASE, dk_sasm_foobar, fmc_Cultivation, fmc_Cutting, fmc_Herbicide, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_SetAside_SummerMow().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
FarmEvent::m_forcespring
bool m_forcespring
Definition: Farm.h:392
Farm::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: FarmFuncs.cpp:2025
Farm::Strigling
virtual bool Strigling(LE *a_field, double a_user, int a_days)
Carry out a mechanical weeding on a_field.
Definition: FarmFuncs.cpp:1206
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
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
Farm::DoIt_prob
bool DoIt_prob(double a_probability)
Return chance out of 0 to 1.
Definition: Farm.cpp:864
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
fmc_Herbicide
Definition: LandscapeFarmingEnums.h:1006
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
dk_sasm_cutting
Definition: DK_SetAside_SummerMow.h:74
dk_sasm_strigling
Definition: DK_SetAside_SummerMow.h:75
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
LE::GetVegBiomass
virtual double GetVegBiomass(void)
Definition: Elements.h:164
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
tov_DKSetAside_SummerMow
Definition: LandscapeFarmingEnums.h:410
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
dk_sasm_wait
Definition: DK_SetAside_SummerMow.h:69
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
LE::SetVegPatchy
void SetVegPatchy(bool p)
Definition: Elements.h:229
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
dk_sasm_start
Definition: DK_SetAside_SummerMow.h:67
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
DK_SASM_BASE
#define DK_SASM_BASE
Definition: DK_SetAside_SummerMow.h:56
dk_sasm_wait1
Definition: DK_SetAside_SummerMow.h:70
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_sasm_swathing
Definition: DK_SetAside_SummerMow.h:76
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
dk_sasm_wait2
Definition: DK_SetAside_SummerMow.h:71
Farm::SleepAllDay
virtual bool SleepAllDay(LE *a_field, double a_user, int a_days)
Nothing to to today on a_field.
Definition: FarmFuncs.cpp:272
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
dk_sasm_foobar
Definition: DK_SetAside_SummerMow.h:78
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::Swathing
virtual bool Swathing(LE *a_field, double a_user, int a_days)
Cut the crop on a_field and leave it lying (probably rape)
Definition: FarmFuncs.cpp:1350
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
DK_SetAside_SummerMow::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_SetAside_SummerMow.h:102
dk_sasm_herbicide
Definition: DK_SetAside_SummerMow.h:77
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001