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

#include <DK_OLegume.h>

Inheritance diagram for DK_OLegume:
Crop

Public Member Functions

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

DK_OLegume::DK_OLegume ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

34 {
35  m_farm = a_farm;
36  m_field = a_field;
37  m_ev = a_ev;
38 
39  bool done = false;
40  int d1 = 0;
41  int d2 = 0;
42 
43  switch (m_ev->m_todo)
44  {
45  case dk_ol_start:
46  {
47  a_field->ClearManagementActionSum();
48 
49  m_field->SetVegPatchy(true); // LKM: A crop with wide rows, so set patchy
50  if (g_rand_uni() <= 0.33) DK_OL_DO_CATCHCROP = true; else DK_OL_DO_CATCHCROP = false; // LKM: flags to mark that some farmers sow catch crop after harvest - date for finished management is different
51  // Set up the date management stuff - LKM: last day for a operation is 15th of September
52  m_last_date = g_date->DayInYear(15, 9);
53  // Start and stop dates for all events after harvest - LKM: events after harvest earliest at 26th of June
54  int noDates = 1;
55  if (!DK_OL_DO_CATCHCROP) m_field->SetMDates(0, 0, g_date->DayInYear(26, 6)); else m_field->SetMDates(0, 0, g_date->DayInYear(31, 12)); // 31/12 picked because it is the last date of the year, but the real date is the 15/1
56  // Determined by harvest date - used to see if at all possible - LKM: latest harvest date the 10th of September
57  m_field->SetMDates(1, 0, g_date->DayInYear(10, 9));
58  // Check the next crop for early start, unless it is a spring crop
59  // in which case we ASSUME that no checking is necessary!!!!
60  // So DO NOT implement a crop that runs over the year boundary
61  if (m_ev->m_startday > g_date->DayInYear(1, 7)) // LKM: to check if spring or winter crop
62  {
63  if (m_field->GetMDates(0, 0) >= m_ev->m_startday)
64  {
65  g_msg->Warn(WARN_BUG, "DK_OLegume::Do(): "
66  "Harvest too late for the next crop to start!!!", "");
67  exit(1);
68  }
69  }
70  if (!DK_OL_DO_CATCHCROP)
71  {
72  // Now fix any late finishing problems
73  for (int i = 0; i < noDates; i++)
74  {
75  if (m_field->GetMDates(0, i) >= m_ev->m_startday)
76  m_field->SetMDates(0, i, m_ev->m_startday - 1);
77  if (m_field->GetMDates(1, i) >= m_ev->m_startday)
78  m_field->SetMDates(1, i, m_ev->m_startday - 1);
79  }
80  }
81  // Now no operations can be timed after the start of the next crop.
82 
83  int d1;
84  int today = g_date->Date();
85  d1 = g_date->OldDays() + m_first_date + 365; // Add 365 for spring crop
86  if (today > d1)
87  {
88  // Yes too late - should not happen - raise an error
89  g_msg->Warn(WARN_BUG, "DK_OLegume::Do(): "
90  "Crop start attempt after last possible start date", "");
91  exit(1);
92  }
93  // End single block date checking code. Please see next line
94  // comment as well.
95  // Reinit d1 to first possible starting date.
96  d1 = g_date->OldDays() + m_first_date;;
97  if (!m_ev->m_first_year) d1 += 365; // Add 365 for spring crop (not 1st yr)
98  if (g_date->Date() > d1) {
99  d1 = g_date->Date();
100  }
101  // OK, let's go. - LKM: Queue first operation - start with spring harrow possible from 1st March - 10th April
102  SimpleEvent(d1, dk_ol_spring_harrow1, false);
103  }
104  break;
105  // LKM: do spring harrow, do it before the 10th of April - if not done, try again +1 day until the 10th of April when we succeed - 100% of farmers do this
107  if (!m_farm->SpringHarrow(m_field, 0.0,
108  g_date->DayInYear(10, 4) - g_date->DayInYear())) {
110  break;
111  }
112  // LKM: Queue up the next event - spring plough
113  SimpleEvent(g_date->Date() + 1, dk_ol_spring_plough, false);
114  break;
115  // LKM: do spring plough before the 15th of April - if not done, try again +1 day until the 15th of April when we succeed- 100% of farmers do this
116  case dk_ol_spring_plough:
117  if (!m_farm->SpringPlough(m_field, 0.0,
118  g_date->DayInYear(15, 4) - g_date->DayInYear())) {
120  break;
121  }
122  // LKM: Queue up the next event - K and S are added (new todo is needed - Maybe work from FP_PK? ks_ferti in system needs to be valid)
123  SimpleEvent(g_date->Date() + 1, dk_ol_ks_ferti, false);
124  break;
125  // LKM: add K and S before the 20th of April - if not done, try again +1 day until the 20th of April when we succeed- 100% of farmers do this
126  case dk_ol_ks_ferti:
127  if (!m_farm->FP_SK(m_field, 0.0,
128  g_date->DayInYear(20, 4) - g_date->DayInYear())) {
129  SimpleEvent(g_date->Date() + 1, dk_ol_ks_ferti, true);
130  break;
131  }
132  // LKM: Queue up the next event - spring harrow just before sowing
134  break;
135  // LKM: spring harrow only done if difficult to sow because of heavy rain (assume 10% will do this) before the 25th of April - if not done, try again +1 day until the 25th of April when we will succeed
137  if (m_ev->m_lock || m_farm->DoIt_prob(0.10))
138  {
139  if (!m_farm->ShallowHarrow(m_field, 0.0,
140  g_date->DayInYear(20, 4) - g_date->DayInYear())) {
142  break;
143  }
144  }
145  // LKM: Queue up the next event - spring row sow done before the 30th of April (and after 20th of March) - if not done, try again +1 day until the 30th of April when we will succeed
147  break;
149  if (!m_farm->SpringSow(m_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
151  break;
152  }
153  //Queue up harrow/strigling 3-5 days after sow
154  SimpleEvent(g_date->Date() + 3, dk_ol_strigling, false);
155  break;
156  // LKM: strigling before the 5th of May - if not done, try again +3 days until the 5th of May when we succeed
157  case dk_ol_strigling:
158  if (!m_farm->Strigling(m_field, 0.0,
159  g_date->DayInYear(5, 5) - g_date->DayInYear())) {
160  SimpleEvent(g_date->Date() + 1, dk_ol_strigling, true);
161  break;
162  } //LKM: Queue up row cultivation 30-45 days after sow to clean field from weeds
163  SimpleEvent(g_date->Date() + 30, dk_ol_rowcultivation, false);
164  break;
166  // LKM: row cultivation before the 15th of June - if not done, try again +30 days until the 15th of June when we succeed
167  if (!m_farm->RowCultivation(m_field, 0.0,
168  g_date->DayInYear(15, 6) - g_date->DayInYear())) {
170  break;
171  }
172  // LKM: Queue up the next event - in this case watering
173  SimpleEvent(g_date->Date() + 1, dk_ol_water, false);
174  break;
175  case dk_ol_water:
176  // LKM: water before the 25th of June - if not done, try again +1 days until the 25th of June when we succeed - 100% of farmers do this
177  if (!m_farm->Water(m_field, 0.0, g_date->DayInYear(25, 6) - g_date->DayInYear())) {
178  SimpleEvent(g_date->Date() + 1, dk_ol_water, true);
179  break;
180  }
181  // LKM: Queue up the next event - harvest (not before the 25th of June - need new farmfunc because the legumes are hand picked)
183  dk_ol_harvest, false);
184  break;
185  case dk_ol_harvest:
186  // LKM: harvest before the 25th of August - if not done, try again +1 days until the 10th of September when we succeed - 100% of farmers do this
187  if (!m_farm->Harvest(m_field, 0.0, g_date->DayInYear(10, 9) - g_date->DayInYear())) {
188  SimpleEvent(g_date->Date() + 1, dk_ol_harvest, true);
189  break;
190  }
191  // LKM: Queue up the next event - autumn harrow (not before the 25th of June)
193  dk_ol_autumn_harrow, false);
194  break;
195  // LKM: Autumn harrow before the 30th of August - if not done, try again +1 days until the 30th of August when we succeed
196  case dk_ol_autumn_harrow:
197  if (!m_farm->AutumnHarrow(m_field, 0.0, g_date->DayInYear(30, 8) - g_date->DayInYear())) {
199  break;
200  }
201  // LKM: Queue up the next event - autumn plough (not before the 1st of July)
203  dk_ol_autumn_plough, false);
204  break;
205  // LKM: autumn plough before the 5th of September - if not done, try again +1 days until the 5th of September when we succeed
206  case dk_ol_autumn_plough:
207  if (!m_farm->AutumnPlough(m_field, 0.0, g_date->DayInYear(5, 9) - g_date->DayInYear())) {
209  break;
210  }
211  //33% of the farmers that do normal spring sow w/o lay-out sow catch crop (in new cropprog)
213  {//END THREAD (sow catch crop in autumn)
214  done = true;
215  break;
216  }
217  else //LKM: 67% ready for winter crop in new cropprog
218  {
219  //END THREAD (sow winter crop)
220  }
221  m_field->SetVegPatchy(false);
222  done = true;
223  // End Main Thread
224  done = true;
225  break;
226 
227 
228 
229  default:
230  g_msg->Warn(WARN_BUG, "OLegume::Do(): "
231  "Unknown event type! ", "");
232  exit(1);
233  }
234 
235  return done;
236 }

References Farm::AutumnHarrow(), Farm::AutumnPlough(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), dk_ol_autumn_harrow, dk_ol_autumn_plough, DK_OL_DO_CATCHCROP, dk_ol_harvest, dk_ol_ks_ferti, dk_ol_rowcultivation, dk_ol_spring_harrow1, dk_ol_spring_harrow2, dk_ol_spring_plough, dk_ol_spring_row_sow, dk_ol_start, dk_ol_strigling, dk_ol_water, Farm::DoIt_prob(), Farm::FP_SK(), g_date, g_msg, LE::GetMDates(), Farm::Harvest(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_first_date, FarmEvent::m_first_year, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_startday, FarmEvent::m_todo, Calendar::OldDays(), Farm::RowCultivation(), LE::SetMDates(), LE::SetVegPatchy(), Farm::ShallowHarrow(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringSow(), Farm::Strigling(), MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void DK_OLegume::SetUpFarmCategoryInformation ( )
inline
62  {
63  const int elements = 2 + (dk_ol_foobar - DK_OL_BASE);
65 
66  FarmManagementCategory catlist[elements] =
67  {
68  fmc_Others, // zero element unused but must be here
69  fmc_Others, // dk_ol_start = 1, // Compulsory, start event must always be 1 (one).
70  fmc_Harvest, // dk_ol_harvest = DK_OL_BASE,
71  fmc_Cultivation, // dk_ol_spring_harrow1,
72  fmc_Cultivation, // dk_ol_spring_plough,
73  fmc_Fertilizer, // dk_ol_ks_ferti,
74  fmc_Cultivation, // dk_ol_spring_harrow2,
75  fmc_Others, // dk_ol_spring_row_sow,
76  fmc_Cultivation, // dk_ol_strigling,
77  fmc_Cultivation, // dk_ol_rowcultivation,
78  fmc_Watering, // dk_ol_water,
79  fmc_Cultivation, // dk_ol_autumn_harrow,
80  fmc_Cultivation // dk_ol_autumn_plough,
81 
82 
83  // no foobar entry
84 
85  };
86  // Iterate over the catlist elements and copy them to vector
87  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
88 
89  }

References DK_OL_BASE, dk_ol_foobar, fmc_Cultivation, fmc_Fertilizer, fmc_Harvest, fmc_Others, fmc_Watering, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_OLegume().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
dk_ol_spring_row_sow
Definition: DK_OLegume.h:42
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
Farm::SpringPlough
virtual bool SpringPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the spring on a_field.
Definition: FarmFuncs.cpp:421
dk_ol_strigling
Definition: DK_OLegume.h:43
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
Farm::Harvest
virtual bool Harvest(LE *a_field, double a_user, int a_days)
Carry out a harvest on a_field.
Definition: FarmFuncs.cpp:1364
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
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
Farm::SpringSow
virtual bool SpringSow(LE *a_field, double a_user, int a_days, double a_seed_coating_amount=-1, PlantProtectionProducts a_ppp=ppp_foobar)
Carry out a sowing event in the spring on a_field.
Definition: FarmFuncs.cpp:501
dk_ol_water
Definition: DK_OLegume.h:45
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
Farm::FP_SK
virtual bool FP_SK(LE *a_field, double a_user, int a_days)
Apply SK fertilizer, on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:794
dk_ol_foobar
Definition: DK_OLegume.h:48
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
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_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
dk_ol_ks_ferti
Definition: DK_OLegume.h:40
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
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
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
dk_ol_autumn_plough
Definition: DK_OLegume.h:47
DK_OL_DO_CATCHCROP
#define DK_OL_DO_CATCHCROP
A flag used to indicate do catch crop.
Definition: DK_OLegume.h:32
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
dk_ol_spring_plough
Definition: DK_OLegume.h:39
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_ol_rowcultivation
Definition: DK_OLegume.h:44
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
dk_ol_spring_harrow1
Definition: DK_OLegume.h:38
Farm::ShallowHarrow
virtual bool ShallowHarrow(LE *a_field, double a_user, int a_days)
Carry out a shallow harrow event on a_field, e.g., after grass cutting event.
Definition: FarmFuncs.cpp:473
DK_OL_BASE
#define DK_OL_BASE
Definition: DK_OLegume.h:33
Farm::RowCultivation
virtual bool RowCultivation(LE *a_field, double a_user, int a_days)
Carry out a harrowing between crop rows on a_field.
Definition: FarmFuncs.cpp:1183
Farm::Water
virtual bool Water(LE *a_field, double a_user, int a_days)
Carry out a watering on a_field.
Definition: FarmFuncs.cpp:1330
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
Farm::AutumnPlough
virtual bool AutumnPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the autumn on a_field.
Definition: FarmFuncs.cpp:212
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
Farm::AutumnHarrow
virtual bool AutumnHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the autumn on a_field.
Definition: FarmFuncs.cpp:285
dk_ol_start
Definition: DK_OLegume.h:36
dk_ol_autumn_harrow
Definition: DK_OLegume.h:46
dk_ol_harvest
Definition: DK_OLegume.h:37
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
DK_OLegume::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OLegume.h:62
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
dk_ol_spring_harrow2
Definition: DK_OLegume.h:41
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
Farm::SpringHarrow
virtual bool SpringHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the spring on a_field.
Definition: FarmFuncs.cpp:459