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

#include <DK_OCerealLegume.h>

Inheritance diagram for DK_OCerealLegume:
Crop

Public Member Functions

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

DK_OCerealLegume::DK_OCerealLegume ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
65  : Crop(a_tov, a_toc, a_L)
66  {
69  }

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

Member Function Documentation

◆ Do()

bool DK_OCerealLegume::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_ocl_start:
49  {
50  a_field->ClearManagementActionSum();
51 
52  DK_OCL_FORCESPRING = false;
53 
54  m_last_date = g_date->DayInYear(10, 10); // Should match the last flexdate below
55  //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
56  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
57  // Set up the date management stuff
58  // Start and stop dates for all events after harvest
59  flexdates[0][1] = g_date->DayInYear(30, 9); // last possible day of plough in this case
60  // Now these are done in pairs, start & end for each operation. If its not used then -1
61  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
62  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
63 
64  // 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
65  int isSpring = 365;
66  if (StartUpCrop(isSpring, flexdates, int(dk_ocl_spring_harrow))) break;
67 
68  // End single block date checking code. Please see next line comment as well.
69  // Reinit d1 to first possible starting date.
70  d1 = g_date->OldDays() + g_date->DayInYear(1, 3) + isSpring;
71 
72  if (m_ev->m_forcespring) {
73  int day_num_shift = 365;
74  if (g_date->DayInYear() < 70) day_num_shift = 0;
75  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 3) + day_num_shift, dk_ocl_spring_harrow, false);
76  DK_OCL_FORCESPRING = true;
77  break;
78  }
79  else
80  // OK, let's go.
81  // Here we queue up the first event which changes dependent on whether it is a forced spring sow or not
83  break;
84  }
85  break;
86 
87  // done if many weeds, or waste plants from earlier catch crops
89  if (m_ev->m_lock || m_farm->DoIt_prob(1.00)) {
90  if (!m_farm->SpringHarrow(m_field, 0.0,
91  g_date->DayInYear(31, 3) - g_date->DayInYear())) {
93  break;
94  }
95  }
96  if (a_farm->IsStockFarmer()) {
97  SimpleEvent(g_date->Date() + 1, dk_ocl_manure1_s, false);
98  break;
99  }
100  else SimpleEvent(g_date->Date() + 1, dk_ocl_manure1_p, false);
101  break;
102 
103  case dk_ocl_manure1_s: // 75% do this (rest move to next event)
104  if (m_ev->m_lock || m_farm->DoIt_prob(0.75)) {
105  if (!m_farm->FA_Manure(m_field, 0.0,
106  g_date->DayInYear(1, 4) - g_date->DayInYear())) {
107  SimpleEvent(g_date->Date() + 1, dk_ocl_manure1_s, true);
108  break;
109  }
110  }
112  break;
113 
114  case dk_ocl_manure1_p: // 75% do this (rest move to next event)
115  if (m_ev->m_lock || m_farm->DoIt_prob(0.75)) {
116  if (!m_farm->FP_Manure(m_field, 0.0,
117  g_date->DayInYear(1, 4) - g_date->DayInYear())) {
118  SimpleEvent(g_date->Date() + 1, dk_ocl_manure1_p, true);
119  break;
120  }
121  }
123  break;
124 
126  if (m_ev->m_lock || m_farm->DoIt_prob(1.00)) {
127  if (!m_farm->SpringPlough(m_field, 0.0,
128  g_date->DayInYear(20, 4) - g_date->DayInYear())) {
130  break;
131  }
132  }
134  break;
135  case dk_ocl_spring_sow:
136  if (m_ev->m_lock || m_farm->DoIt_prob(1.00)) {
137  if (!m_farm->SpringSow(m_field, 0.0,
138  g_date->DayInYear(30, 4) - g_date->DayInYear())) {
139  SimpleEvent(g_date->Date() + 1, dk_ocl_spring_sow, true);
140  break;
141  }
142  } // 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
144  break;
146  if (m_ev->m_lock || m_farm->DoIt_prob(0.40)) {
147  if (!m_farm->SpringSow(m_field, 0.0,
148  g_date->DayInYear(5, 5) - g_date->DayInYear())) {
150  break;
151  }
152  SimpleEvent(g_date->Date(), dk_ocl_water_lo, false); // no dates for this
153  break;
154  } // the 50% will go straight to water
155  else if (m_ev->m_lock || m_farm->DoIt_prob(0.50 / 0.60)) {
156  SimpleEvent(g_date->Date(), dk_ocl_water_lo, false); // no dates for this
157  break;
158  }
159  // the 10% w/o lay-out will do strigling
160  else if (m_ev->m_lock || m_farm->DoIt_prob(0.10 / 0.10)) {
161  SimpleEvent(g_date->Date() + 3, dk_ocl_strigling1, false);
162  break;
163  }
164 
165  case dk_ocl_strigling1:
166  if (!m_farm->Strigling(m_field, 0.0,
167  g_date->DayInYear(5, 5) - g_date->DayInYear())) {
168  SimpleEvent(g_date->Date() + 1, dk_ocl_strigling1, true);
169  break;
170  }
171  SimpleEvent(g_date->Date() + 7, dk_ocl_strigling2, false);
172  break;
173  case dk_ocl_strigling2:
174  if (!m_farm->Strigling(m_field, 0.0,
175  g_date->DayInYear(15, 5) - g_date->DayInYear())) {
176  SimpleEvent(g_date->Date() + 1, dk_ocl_strigling2, true);
177  break;
178  }
179  SimpleEvent(g_date->Date(), dk_ocl_water, false); // no dates for this
180  break;
181  case dk_ocl_water_lo: // 50% do watering
182  if (m_ev->m_lock || m_farm->DoIt_prob(0.50)) {
183  if (!m_farm->Water(m_field, 0.0,
184  g_date->DayInYear(15, 6) - g_date->DayInYear())) {
185  SimpleEvent(g_date->Date() + 1, dk_ocl_water_lo, true);
186  break;
187  }
188  }
190  break;
191  case dk_ocl_water: // 50% do watering
192  if (m_ev->m_lock || m_farm->DoIt_prob(0.50)) {
193  if (!m_farm->Water(m_field, 0.0,
194  g_date->DayInYear(15, 6) - g_date->DayInYear())) {
195  SimpleEvent(g_date->Date() + 1, dk_ocl_water, true);
196  break;
197  }
198  }
200  break;
201 
202  case dk_ocl_harvest: // 100% do harvest
203  if (!m_farm->Harvest(m_field, 0.0,
204  g_date->DayInYear(1, 9) - g_date->DayInYear())) {
205  SimpleEvent(g_date->Date() + 1, dk_ocl_harvest, true);
206  break;
207  }
209  break;
210  case dk_ocl_harvest_lo: // 100% do harvest
211  if (!m_farm->Harvest(m_field, 0.0,
212  g_date->DayInYear(1, 9) - g_date->DayInYear())) {
213  SimpleEvent(g_date->Date() + 1, dk_ocl_harvest_lo, true);
214  break;
215  }
216  if (a_farm->IsStockFarmer()) {
217  SimpleEvent(g_date->Date() + 1, dk_ocl_manure2_s, false);
218  break;
219  }
220  else SimpleEvent(g_date->Date() + 1, dk_ocl_manure2_p, false);
221  break;
222 
223  case dk_ocl_manure2_s:
224  if (!m_farm->FA_Manure(m_field, 0.0,
225  g_date->DayInYear(2, 9) - g_date->DayInYear())) {
226  SimpleEvent(g_date->Date() + 1, dk_ocl_manure2_s, true);
227  break;
228  }
230  break;
231 
232  case dk_ocl_manure2_p:
233  if (!m_farm->FP_Manure(m_field, 0.0,
234  g_date->DayInYear(2, 9) - g_date->DayInYear())) {
235  SimpleEvent(g_date->Date() + 1, dk_ocl_manure2_p, true);
236  break;
237  }
239  break;
240 
242  if (!m_farm->AutumnPlough(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
244  break;
245  }
246  done = true;
247  break;
248  case dk_ocl_cutting1:
249  if (!m_farm->CutToHay(m_field, 0.0,
250  g_date->DayInYear(2, 9) - g_date->DayInYear())) {
251  SimpleEvent(g_date->Date() + 1, dk_ocl_cutting1, true);
252  break;
253  }
254  SimpleEvent(g_date->Date()+30, dk_ocl_cutting2, false);
255  break;
256  case dk_ocl_cutting2: //50% of the 90% with lay-out (45% in total) will do a second cut, 50% do grazing (next crop code)
257  if (a_ev->m_lock || a_farm->DoIt_prob(0.50)) {
258  if (!m_farm->CutToHay(m_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
259  SimpleEvent(g_date->Date() + 1, dk_ocl_cutting2, true);
260  break;
261  }
262  }
263  done = true;
264  break;
265 
266  default:
267  g_msg->Warn( WARN_BUG, "DK_OCerealLegume::Do(): "
268  "Unknown event type! ", "" );
269  exit( 1 );
270  }
271  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
272  return done;
273 }

References Farm::AutumnPlough(), LE::ClearManagementActionSum(), Farm::CutToHay(), Calendar::Date(), Calendar::DayInYear(), dk_ocl_autumn_plough, dk_ocl_cutting1, dk_ocl_cutting2, DK_OCL_FORCESPRING, dk_ocl_harvest, dk_ocl_harvest_lo, dk_ocl_manure1_p, dk_ocl_manure1_s, dk_ocl_manure2_p, dk_ocl_manure2_s, dk_ocl_spring_harrow, dk_ocl_spring_plough, dk_ocl_spring_sow, dk_ocl_spring_sow_lo, dk_ocl_start, dk_ocl_strigling1, dk_ocl_strigling2, dk_ocl_water, dk_ocl_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, FarmEvent::m_forcespring, 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, MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void DK_OCerealLegume::SetUpFarmCategoryInformation ( )
inline
70  {
71  const int elements = 2 + (dk_ocl_foobar - DK_OCL_BASE);
73 
74  FarmManagementCategory catlist[elements] =
75  {
76  fmc_Others, // zero element unused but must be here
77  fmc_Others, // dk_ocl_start = 1, // Compulsory, start event must always be 1 (one).
78  fmc_Cultivation, // dk_ocl_spring_harrow = DK_OCL_BASE,
79  fmc_Fertilizer, // dk_ocl_manure1_s,
80  fmc_Fertilizer, // dk_ocl_manure1_p,
81  fmc_Cultivation, // dk_ocl_spring_plough,
82  fmc_Others, // dk_ocl_spring_sow,
83  fmc_Others, // dk_ocl_spring_sow_lo,
84  fmc_Cultivation, // dk_ocl_strigling1,
85  fmc_Cultivation, // dk_ocl_strigling2,
86  fmc_Watering, // dk_ocl_water,
87  fmc_Watering, // dk_ocl_water_lo,
88  fmc_Cutting, // dk_ocl_swathing,
89  fmc_Cutting, // dk_ocl_swathing_lo,
90  fmc_Harvest, // dk_ocl_harvest,
91  fmc_Harvest, // dk_ocl_harvest_lo,
92  fmc_Fertilizer, // dk_ocl_manure2_s,
93  fmc_Fertilizer, // dk_ocl_manure2_p,
94  fmc_Cultivation, // dk_ocl_autumn_plough,
95  fmc_Cutting, // dk_ocl_cutting1,
96  fmc_Cutting, // dk_ocl_cutting2,
97 
98 
99  // no foobar entry
100 
101  };
102  // Iterate over the catlist elements and copy them to vector
103  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
104 
105  }

References DK_OCL_BASE, dk_ocl_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().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
dk_ocl_strigling1
Definition: DK_OCerealLegume.h:43
FarmEvent::m_forcespring
bool m_forcespring
Definition: Farm.h:392
tov_DKOCerealLegume
Definition: LandscapeFarmingEnums.h:366
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
DK_OCL_BASE
#define DK_OCL_BASE
Definition: DK_OCerealLegume.h:31
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
dk_ocl_strigling2
Definition: DK_OCerealLegume.h:44
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::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
dk_ocl_manure1_p
Definition: DK_OCerealLegume.h:39
dk_ocl_water
Definition: DK_OCerealLegume.h:45
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
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
dk_ocl_manure2_s
Definition: DK_OCerealLegume.h:51
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
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
dk_ocl_spring_sow
Definition: DK_OCerealLegume.h:41
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
dk_ocl_cutting1
Definition: DK_OCerealLegume.h:54
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
dk_ocl_autumn_plough
Definition: DK_OCerealLegume.h:53
dk_ocl_cutting2
Definition: DK_OCerealLegume.h:55
dk_ocl_start
Definition: DK_OCerealLegume.h:36
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
dk_ocl_harvest_lo
Definition: DK_OCerealLegume.h:50
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
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_ocl_water_lo
Definition: DK_OCerealLegume.h:46
dk_ocl_spring_harrow
Definition: DK_OCerealLegume.h:37
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
dk_ocl_spring_sow_lo
Definition: DK_OCerealLegume.h:42
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_ocl_manure2_p
Definition: DK_OCerealLegume.h:52
DK_OCerealLegume::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OCerealLegume.h:70
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
dk_ocl_spring_plough
Definition: DK_OCerealLegume.h:40
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
dk_ocl_manure1_s
Definition: DK_OCerealLegume.h:38
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
dk_ocl_harvest
Definition: DK_OCerealLegume.h:49
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
DK_OCL_FORCESPRING
#define DK_OCL_FORCESPRING
Definition: DK_OCerealLegume.h:33
dk_ocl_foobar
Definition: DK_OCerealLegume.h:56
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