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

DK_OSetAside class
. More...

#include <DK_OSetAside.h>

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

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

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

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

Member Function Documentation

◆ Do()

bool DK_OSetAside::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.

Reimplemented from Crop.

88 {
89  m_field = a_field; // this is needed because of possible calls to other methods and currently we do not pass parameters.
90  m_farm = a_farm; // this is needed because of possible calls to other methods and currently we do not pass parameters.
91  m_ev = a_ev;
92  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
93  int d1 = 0;
95  // Depending what event has occured jump to the correct bit of code e.g. for ww_start jump to line 67 below
96  switch (a_ev->m_todo)
97  {
98  case dk_osa_start:
99  {
100  a_field->ClearManagementActionSum();
101  m_field->SetVegPatchy(true);
102  m_last_date = g_date->DayInYear(1, 7); // Should match the last flexdate below
103  //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
104  std::vector<std::vector<int>> flexdates(2 + 1, std::vector<int>(2, 0));
105  // Set up the date management stuff
106  // Start and stop dates for all events after harvest
107  flexdates[0][1] = g_date->DayInYear(15, 6); // last possible day of strigling in this case
108  // Now these are done in pairs, start & end for each operation. If its not used then -1
109  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
110  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
111  flexdates[2][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 2 (start op 2)
112  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
113 
114  // 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
115  int isSpring = 0;
116  if (StartUpCrop(isSpring, flexdates, int(dk_osa_cutting))) break;
117 
118  // End single block date checking code. Please see next line comment as well.
119  // Reinit d1 to first possible starting date.
120  // OK, let's go.
121  d1 = g_date->OldDays() + g_date->DayInYear(1, 9);
122  if (g_date->Date() >= d1) {
123  d1 = g_date->Date();
124  }
125  SimpleEvent(d1, dk_osa_wait1, false);
126  break;
127  }
128  break;
129 
130 
131  // 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
132 
133  case dk_osa_wait1:
134  if (!a_farm->SleepAllDay(a_field, 0.0, g_date->DayInYear(31, 12) - g_date->DayInYear())) {
135  SimpleEvent(g_date->Date() + 1, dk_osa_wait1, true);
136  break;
137  }
138  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 4) + 365, dk_osa_cutting, false);
139  break;
140 
141  case dk_osa_cutting: // only allowed between 1-30th of April (when spring cutting)
142  if (!a_farm->CutToHay(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
143  SimpleEvent(g_date->Date() + 1, dk_osa_cutting, true);
144  break;
145  }
146  SimpleEvent(g_date->Date() + 1, dk_osa_strigling, false);
147  break;
148 
149  case dk_osa_strigling:
150  if (a_ev->m_lock || a_farm->DoIt(100)) {
151  if (!a_farm->Strigling(a_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
152  SimpleEvent(g_date->Date() + 1, dk_osa_strigling, true);
153  break;
154  }
155  }
156  SimpleEvent(g_date->Date() + 14, dk_osa_swathing, false);
157  break;
158 
159  case dk_osa_swathing:
160  if (a_field->GetVegBiomass() > 0)
161  {
162  if (!a_farm->Swathing(a_field, 0.0, m_field->GetMDates(1, 2) - g_date->DayInYear())) {
163  SimpleEvent(g_date->Date() + 1, dk_osa_swathing, true);
164  break;
165  }
166  }
167  d1 = g_date->Date();
168  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 7)) {
169  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 7), dk_osa_wait2, false);
170  // Because we are ending harvest before 1.7 so we need to wait until the 1.7
171  break;
172  }
173  else {
174  done = true; // end of plan
175  }
176  case dk_osa_wait2:
177  // End of management
178  done = true;
179  m_field->SetVegPatchy(false);
180  break;
181  // So we are done, and somewhere else the farmer will queue up the start event of the next crop
182  // END OF MAIN THREAD
183  default:
184  g_msg->Warn(WARN_BUG, "DK_OSetAside::Do(): "
185  "Unknown event type! ", "");
186  exit(1);
187  }
188  return done;
189 }

References LE::ClearManagementActionSum(), Farm::CutToHay(), Calendar::Date(), Calendar::DayInYear(), dk_osa_cutting, dk_osa_start, dk_osa_strigling, dk_osa_swathing, dk_osa_wait1, dk_osa_wait2, Farm::DoIt(), g_date, g_msg, LE::GetMDates(), LE::GetVegBiomass(), 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_DKOSetAside, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DK_OSetAside::SetUpFarmCategoryInformation ( )
inline
100  {
101  const int elements = 2 + (dk_osa_foobar - DK_OSA_BASE);
103 
104  FarmManagementCategory catlist[elements] =
105  {
106  fmc_Others, // zero element unused but must be here
107  fmc_Others, // dk_osa_start = 1, // Compulsory, must always be 1 (one).
108  fmc_Cultivation, // dk_osa_harrow = DK_SA_BASE
109  fmc_Cultivation, // dk_osa_roll
110  fmc_Others, // dk_osa_wait1,
111  fmc_Others, // dk_osa_wait2,
112  fmc_Others, // dk_osa_sow,
113  fmc_Cutting, // dk_osa_cutting,
114  fmc_Cultivation, // dk_osa_strigling,
115  fmc_Cutting, // dk_osa_swathing,
116 
117  // no foobar entry
118 
119  };
120  // Iterate over the catlist elements and copy them to vector
121  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
122 
123  }

References DK_OSA_BASE, dk_osa_foobar, fmc_Cultivation, fmc_Cutting, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_OSetAside().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
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
tov_DKOSetAside
Definition: LandscapeFarmingEnums.h:393
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
dk_osa_swathing
Definition: DK_OSetAside.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
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
dk_osa_strigling
Definition: DK_OSetAside.h:74
dk_osa_wait1
Definition: DK_OSetAside.h:69
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
dk_osa_wait2
Definition: DK_OSetAside.h:70
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_OSA_BASE
#define DK_OSA_BASE
Definition: DK_OSetAside.h:56
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_osa_start
Definition: DK_OSetAside.h:67
dk_osa_foobar
Definition: DK_OSetAside.h:76
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
DK_OSetAside::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OSetAside.h:100
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
dk_osa_cutting
Definition: DK_OSetAside.h:73