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

DK_SetAside class
. More...

#include <DK_SetAside.h>

Inheritance diagram for DK_SetAside:
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 (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 class
.

See DK_SetAside.h::DK_SetAsideToDo for a complete list of all possible events triggered codes by the DK_SetAside 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()

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

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

Member Function Documentation

◆ Do()

bool DK_SetAside::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_sa_start:
110  {
111  a_field->ClearManagementActionSum();
112  m_field->SetVegPatchy(true);
113  m_last_date = g_date->DayInYear(1, 7); // 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(2 + 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(15, 6); // last possible day of strigling 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(15, 6); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1) - herbicide
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(1, 7); // This date will be moved back as far as necessary and potentially to flexdates 2 (end op 2) - swathing
124 
125  // 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
126  int isSpring = 0;
127  if (StartUpCrop(isSpring, flexdates, int(dk_sa_cutting))) break;
128 
129  // End single block date checking code. Please see next line comment as well.
130  // Reinit d1 to first possible starting date.
131  // OK, let's go.
132  d1 = g_date->OldDays() + g_date->DayInYear(1, 9);
133  if (g_date->Date() >= d1) {
134  d1 = g_date->Date();
135  }
136  SimpleEvent(d1, dk_sa_wait1, false);
137  break;
138  }
139  break;
140 
141 
142  // LKM: This is the first real farm operation - soil cultivation only needed if establishment of flower og pollinator setaside (then cutting is not done in that year)- suggests 50%, otherwise straight to the cutting
143 
144  case dk_sa_wait1:
145  if (!a_farm->SleepAllDay(a_field, 0.0, g_date->DayInYear(31, 12) - g_date->DayInYear())) {
146  SimpleEvent(g_date->Date() + 1, dk_sa_wait1, true);
147  break;
148  }
149  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 4) + 365, dk_sa_cutting, false);
150  break;
151 
152  case dk_sa_cutting: // only allowed between 1-30th of April (when spring cutting)
153  if (!a_farm->CutToHay(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
154  SimpleEvent(g_date->Date() + 1, dk_sa_cutting, true);
155  break;
156  }
157  SimpleEvent(g_date->Date()+1, dk_sa_strigling, false);
158  break;
159 
160  case dk_sa_strigling:
161  if (a_ev->m_lock || a_farm->DoIt(100)) {
162  if (!a_farm->Strigling(a_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
163  SimpleEvent(g_date->Date() + 1, dk_sa_strigling, true);
164  break;
165  }
166  }
168  break;
169 
170  case dk_sa_herbicide: // only allowed if risk of cross pollination - suggest to not include for now
171  if (a_ev->m_lock || a_farm->DoIt_prob(0.0)) {
172  if (!a_farm->HerbicideTreat(a_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
173  SimpleEvent(g_date->Date() + 1, dk_sa_herbicide, true);
174  break;
175  }
176  }
177  SimpleEvent(g_date->Date()+14, dk_sa_swathing, false);
178  break;
179 
180  case dk_sa_swathing:
181  if (a_field->GetVegBiomass() > 0)
182  {
183  if (!a_farm->Swathing(a_field, 0.0, m_field->GetMDates(1, 2) - g_date->DayInYear())) {
184  SimpleEvent(g_date->Date() + 1, dk_sa_swathing, true);
185  break;
186  }
187  }
188  d1 = g_date->Date();
189  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 7)) {
190  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 7), dk_sa_wait2, false);
191  // Because we are ending harvest before 1.7 so we need to wait until the 1.7
192  break;
193  }
194  else {
195  done = true; // end of plan
196  }
197  case dk_sa_wait2:
198  // End of management
199  done = true;
200  m_field->SetVegPatchy(false);
201  break;
202  // So we are done, and somewhere else the farmer will queue up the start event of the next crop
203  // END OF MAIN THREAD
204  default:
205  g_msg->Warn(WARN_BUG, "DK_SetAside::Do(): "
206  "Unknown event type! ", "");
207  exit(1);
208  }
209  return done;
210 }

References LE::ClearManagementActionSum(), Farm::CutToHay(), Calendar::Date(), Calendar::DayInYear(), dk_sa_cutting, dk_sa_herbicide, dk_sa_start, dk_sa_strigling, dk_sa_swathing, dk_sa_wait1, dk_sa_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, 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, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DK_SetAside::SetUpFarmCategoryInformation ( )
inline
99  {
100  const int elements = 2 + (dk_sa_foobar - DK_SA_BASE);
102 
103  FarmManagementCategory catlist[elements] =
104  {
105  fmc_Others, // zero element unused but must be here
106  fmc_Others, // dk_sa_start = 1, // Compulsory, must always be 1 (one).
107  fmc_Others, // dk_sa_wait1, = DK_SA_BASE
108  fmc_Others, // dk_sa_wait2,
109  fmc_Cutting, // dk_sa_cutting,
110  fmc_Cultivation, // dk_sa_strigling,
111  fmc_Cutting, // dk_sa_swathing,
112  fmc_Herbicide, // dk_sa_herbicide,
113 
114  // no foobar entry
115 
116  };
117  // Iterate over the catlist elements and copy them to vector
118  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
119 
120  }

References DK_SA_BASE, dk_sa_foobar, fmc_Cultivation, fmc_Cutting, fmc_Herbicide, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_SetAside().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
dk_sa_wait2
Definition: DK_SetAside.h:70
dk_sa_foobar
Definition: DK_SetAside.h:75
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
DK_SA_BASE
#define DK_SA_BASE
Definition: DK_SetAside.h:57
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
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
dk_sa_swathing
Definition: DK_SetAside.h:73
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
tov_DKSetAside
Definition: LandscapeFarmingEnums.h:409
Calendar::Date
long Date(void)
Definition: Calendar.h:57
dk_sa_wait1
Definition: DK_SetAside.h:69
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
LE::SetVegPatchy
void SetVegPatchy(bool p)
Definition: Elements.h:229
DK_SetAside::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_SetAside.h:99
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
dk_sa_start
Definition: DK_SetAside.h:68
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
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
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_sa_strigling
Definition: DK_SetAside.h:72
dk_sa_cutting
Definition: DK_SetAside.h:71
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
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
dk_sa_herbicide
Definition: DK_SetAside.h:74