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

#include <DK_OCerealLegume_Whole.h>

Inheritance diagram for DK_OCerealLegume_Whole:
Crop

Public Member Functions

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

DK_OCerealLegume_Whole::DK_OCerealLegume_Whole ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
63  : Crop(a_tov, a_toc, a_L)
64  {
67  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

36 {
37 
38  m_farm = a_farm;
39  m_field = a_field;
40  m_ev = a_ev;
41  int d1 = 0;
42 
43  bool done = false;
45 
46  switch (m_ev->m_todo)
47  {
48  case dk_oclw_start:
49  {
50  a_field->ClearManagementActionSum();
51  m_last_date = g_date->DayInYear(10, 10); // Should match the last flexdate below
52  //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
53  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
54  // Set up the date management stuff
55  // Start and stop dates for all events after harvest
56  flexdates[0][1] = g_date->DayInYear(30, 9); // last possible day of plough in this case
57  // Now these are done in pairs, start & end for each operation. If its not used then -1
58  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
59  flexdates[1][1] = g_date->DayInYear(2, 10); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1) - cutting
60 
61  // 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
62  int isSpring = 365;
63  if (StartUpCrop(isSpring, flexdates, int(dk_oclw_spring_harrow))) break;
64 
65  // End single block date checking code. Please see next line comment as well.
66  // Reinit d1 to first possible starting date.
67  d1 = g_date->OldDays() + g_date->DayInYear(1, 3) + isSpring;
68  // OK, let's go.
69  // Here we queue up the first event which changes dependent on whether it is a forced spring sow or not
71  break;
72  }
73  break;
74 
75  // done if manye weeds, or waste plants from earlier catch crops
77  if (m_ev->m_lock || m_farm->DoIt_prob(1.00)) {
78  if (!m_farm->SpringHarrow(m_field, 0.0,
79  g_date->DayInYear(31, 3) - g_date->DayInYear())) {
81  break;
82  }
83  }
84  if (a_farm->IsStockFarmer()) {
85  SimpleEvent(g_date->Date() + 1, dk_oclw_manure1_s, false);
86  break;
87  }
88  else SimpleEvent(g_date->Date() + 1, dk_oclw_manure1_p, false);
89  break;
90 
91  case dk_oclw_manure1_s: // 75% do this (rest move to next event)
92  if (m_ev->m_lock || m_farm->DoIt_prob(0.75)) {
93  if (!m_farm->FA_Manure(m_field, 0.0,
94  g_date->DayInYear(15, 4) - g_date->DayInYear())) {
96  break;
97  }
98  }
100  break;
101 
102  case dk_oclw_manure1_p: // 75% do this (rest move to next event)
103  if (m_ev->m_lock || m_farm->DoIt_prob(0.75)) {
104  if (!m_farm->FP_Manure(m_field, 0.0,
105  g_date->DayInYear(15, 4) - g_date->DayInYear())) {
106  SimpleEvent(g_date->Date() + 1, dk_oclw_manure1_p, true);
107  break;
108  }
109  }
111  break;
112 
114  if (m_ev->m_lock || m_farm->DoIt_prob(1.00)) {
115  if (!m_farm->SpringPlough(m_field, 0.0,
116  g_date->DayInYear(20, 4) - g_date->DayInYear())) {
118  break;
119  }
120  }
122  break;
123  case dk_oclw_spring_sow:
124  if (m_ev->m_lock || m_farm->DoIt_prob(1.00)) {
125  if (!m_farm->SpringSow(m_field, 0.0,
126  g_date->DayInYear(30, 4) - g_date->DayInYear())) {
127  SimpleEvent(g_date->Date() + 1, dk_oclw_spring_sow, true);
128  break;
129  }
130  } // 50% sow combined (cereal, legume and lay-out), 40% sow ceread + legume, then lay-out, 10% sow w/o lay-out = 60% sow once, 40% sow twice
132  break;
134  if (m_ev->m_lock || m_farm->DoIt_prob(0.40)) {
135  if (!m_farm->SpringSow(m_field, 0.0,
136  g_date->DayInYear(5, 5) - g_date->DayInYear())) {
138  break;
139  }
140  SimpleEvent(g_date->Date(), dk_oclw_water_lo, false); // no dates for this
141  break;
142  } // the 50% will go straight to water
143  else if (m_ev->m_lock || m_farm->DoIt_prob(0.50 / 0.60)) {
144  SimpleEvent(g_date->Date(), dk_oclw_water_lo, false); // no dates for this
145  break;
146  }
147  // the 10% w/o lay-out will do strigling
148  else if (m_ev->m_lock || m_farm->DoIt_prob(0.10 / 0.10)) {
149  SimpleEvent(g_date->Date() + 3, dk_oclw_strigling1, false);
150  break;
151  }
152 
153  case dk_oclw_strigling1:
154  if (!m_farm->Strigling(m_field, 0.0,
155  g_date->DayInYear(5, 5) - g_date->DayInYear())) {
156  SimpleEvent(g_date->Date() + 1, dk_oclw_strigling1, true);
157  break;
158  }
159  SimpleEvent(g_date->Date() + 7, dk_oclw_strigling2, false);
160  break;
161  case dk_oclw_strigling2:
162  if (!m_farm->Strigling(m_field, 0.0,
163  g_date->DayInYear(15, 5) - g_date->DayInYear())) {
164  SimpleEvent(g_date->Date() + 1, dk_oclw_strigling2, true);
165  break;
166  }
167  SimpleEvent(g_date->Date(), dk_oclw_water, false); // no dates for this
168  break;
169  case dk_oclw_water_lo: // 50% do watering
170  if (m_ev->m_lock || m_farm->DoIt_prob(0.50)) {
171  if (!m_farm->Water(m_field, 0.0,
172  g_date->DayInYear(1, 8) - g_date->DayInYear())) {
173  SimpleEvent(g_date->Date() + 1, dk_oclw_water_lo, true);
174  break;
175  }
176  }
178  break;
179  case dk_oclw_water: // 100% do watering
180  if (m_ev->m_lock || m_farm->DoIt_prob(0.50)) {
181  if (!m_farm->Water(m_field, 0.0,
182  g_date->DayInYear(1, 8) - g_date->DayInYear())) {
183  SimpleEvent(g_date->Date() + 1, dk_oclw_water, true);
184  break;
185  }
186  }
188  break;
189 
190  case dk_oclw_harvest: // 100% do harvest
191  if (!m_farm->Harvest(m_field, 0.0,
192  g_date->DayInYear(25, 8) - g_date->DayInYear())) {
193  SimpleEvent(g_date->Date() + 1, dk_oclw_harvest, true);
194  break;
195  }
197  break;
198  case dk_oclw_harvest_lo: // 100% do harvest
199  if (!m_farm->Harvest(m_field, 0.0,
200  g_date->DayInYear(25, 8) - g_date->DayInYear())) {
201  SimpleEvent(g_date->Date() + 1, dk_oclw_harvest_lo, true);
202  break;
203  }
204  if (a_farm->IsStockFarmer()) {
205  SimpleEvent(g_date->Date() + 1, dk_oclw_manure2_s, false);
206  break;
207  }
208  else SimpleEvent(g_date->Date() + 1, dk_oclw_manure2_p, false);
209  break;
210 
211  case dk_oclw_manure2_s:
212  if (!m_farm->FA_Manure(m_field, 0.0,
213  g_date->DayInYear(26, 8) - g_date->DayInYear())) {
214  SimpleEvent(g_date->Date() + 1, dk_oclw_manure2_s, true);
215  break;
216  }
218  break;
219 
220  case dk_oclw_manure2_p:
221  if (!m_farm->FP_Manure(m_field, 0.0,
222  g_date->DayInYear(26, 8) - g_date->DayInYear())) {
223  SimpleEvent(g_date->Date() + 1, dk_oclw_manure2_p, true);
224  break;
225  }
227  break;
228 
230  if (!m_farm->AutumnPlough(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
232  break;
233  }
234  done = true;
235  break;
236  case dk_oclw_cutting1:
237  if (!m_farm->CutToHay(m_field, 0.0,
238  g_date->DayInYear(26, 8) - g_date->DayInYear())) {
239  SimpleEvent(g_date->Date() + 1, dk_oclw_cutting1, true);
240  break;
241  }
242  SimpleEvent(g_date->Date()+35, dk_oclw_cutting2, false);
243  break;
244  case dk_oclw_cutting2: //50% of the 90% with lay-out (45% in total) will do a second cut, 50% do grazing
245  if (a_ev->m_lock || a_farm->DoIt_prob(0.50)) {
246  if (!m_farm->CutToHay(m_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
247  SimpleEvent(g_date->Date() + 1, dk_oclw_cutting2, true);
248  break;
249  }
250  }
251  // End of management w lay-out and grazing
252  done = true;
253  break;
254 
255  default:
256  g_msg->Warn( WARN_BUG, "DK_OCerealLegume_Whole::Do(): "
257  "Unknown event type! ", "" );
258  exit( 1 );
259  }
260  return done;
261 }

References Farm::AutumnPlough(), LE::ClearManagementActionSum(), Farm::CutToHay(), Calendar::Date(), Calendar::DayInYear(), dk_oclw_autumn_plough, dk_oclw_cutting1, dk_oclw_cutting2, dk_oclw_harvest, dk_oclw_harvest_lo, dk_oclw_manure1_p, dk_oclw_manure1_s, dk_oclw_manure2_p, dk_oclw_manure2_s, dk_oclw_spring_harrow, dk_oclw_spring_plough, dk_oclw_spring_sow, dk_oclw_spring_sow_lo, dk_oclw_start, dk_oclw_strigling1, dk_oclw_strigling2, dk_oclw_water, dk_oclw_water_lo, Farm::DoIt_prob(), Farm::FA_Manure(), Farm::FP_Manure(), g_date, g_msg, LE::GetMDates(), Farm::Harvest(), Farm::IsStockFarmer(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringSow(), Crop::StartUpCrop(), Farm::Strigling(), tov_DKOCerealLegume_Whole, MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void DK_OCerealLegume_Whole::SetUpFarmCategoryInformation ( )
inline
68  {
69  const int elements = 2 + (dk_oclw_foobar - DK_OCLW_BASE);
71 
72  FarmManagementCategory catlist[elements] =
73  {
74  fmc_Others, // zero element unused but must be here
75  fmc_Others, // dk_oclw_start = 1, // Compulsory, start event must always be 1 (one).
76  fmc_Cultivation, // dk_oclw_spring_harrow = DK_OCLW_BASE,
77  fmc_Fertilizer, // dk_oclw_manure1_s,
78  fmc_Fertilizer, // dk_oclw_manure1_p,
79  fmc_Cultivation, // dk_oclw_spring_plough,
80  fmc_Others, // dk_oclw_spring_sow,
81  fmc_Others, // dk_oclw_spring_sow_lo,
82  fmc_Cultivation, // dk_oclw_strigling1,
83  fmc_Cultivation, // dk_oclw_strigling2,
84  fmc_Watering, // dk_oclw_water,
85  fmc_Watering, // dk_oclw_water_lo,
86  fmc_Cutting, // dk_oclw_swathing,
87  fmc_Cutting, // dk_oclw_swathing_lo,
88  fmc_Harvest, // dk_oclw_harvest,
89  fmc_Harvest, // dk_oclw_harvest_lo,
90  fmc_Fertilizer, // dk_oclw_manure2_s,
91  fmc_Fertilizer, // dk_oclw_manure2_p,
92  fmc_Cultivation, // dk_oclw_autumn_plough,
93  fmc_Cutting, // dk_oclw_cutting1,
94  fmc_Cutting, // dk_oclw_cutting2,
95 
96 
97  // no foobar entry
98 
99  };
100  // Iterate over the catlist elements and copy them to vector
101  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
102 
103  }

References DK_OCLW_BASE, dk_oclw_foobar, fmc_Cultivation, fmc_Cutting, fmc_Fertilizer, fmc_Harvest, fmc_Others, fmc_Watering, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_OCerealLegume_Whole().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
dk_oclw_cutting2
Definition: DK_OCerealLegume_Whole.h:53
DK_OCerealLegume_Whole::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OCerealLegume_Whole.h:68
dk_oclw_harvest_lo
Definition: DK_OCerealLegume_Whole.h:48
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
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
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
dk_oclw_foobar
Definition: DK_OCerealLegume_Whole.h:54
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
dk_oclw_cutting1
Definition: DK_OCerealLegume_Whole.h:52
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
dk_oclw_spring_sow
Definition: DK_OCerealLegume_Whole.h:39
Farm::FA_Manure
virtual bool FA_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:1110
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_oclw_manure2_s
Definition: DK_OCerealLegume_Whole.h:49
dk_oclw_manure2_p
Definition: DK_OCerealLegume_Whole.h:50
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
dk_oclw_harvest
Definition: DK_OCerealLegume_Whole.h:47
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_oclw_water
Definition: DK_OCerealLegume_Whole.h:43
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
Farm::FP_Manure
virtual bool FP_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:896
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
dk_oclw_autumn_plough
Definition: DK_OCerealLegume_Whole.h:51
Calendar::Date
long Date(void)
Definition: Calendar.h:57
dk_oclw_spring_sow_lo
Definition: DK_OCerealLegume_Whole.h:40
dk_oclw_strigling1
Definition: DK_OCerealLegume_Whole.h:41
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
dk_oclw_manure1_p
Definition: DK_OCerealLegume_Whole.h:37
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::Water
virtual bool Water(LE *a_field, double a_user, int a_days)
Carry out a watering on a_field.
Definition: FarmFuncs.cpp:1330
dk_oclw_start
Definition: DK_OCerealLegume_Whole.h:34
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
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
dk_oclw_strigling2
Definition: DK_OCerealLegume_Whole.h:42
dk_oclw_manure1_s
Definition: DK_OCerealLegume_Whole.h:36
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
dk_oclw_spring_harrow
Definition: DK_OCerealLegume_Whole.h:35
dk_oclw_spring_plough
Definition: DK_OCerealLegume_Whole.h:38
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
DK_OCLW_BASE
#define DK_OCLW_BASE
Definition: DK_OCerealLegume_Whole.h:31
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
dk_oclw_water_lo
Definition: DK_OCerealLegume_Whole.h:44
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
tov_DKOCerealLegume_Whole
Definition: LandscapeFarmingEnums.h:368