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

#include <DE_OPeas.h>

Inheritance diagram for DE_OPeas:
Crop

Public Member Functions

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

◆ DE_OPeas()

DE_OPeas::DE_OPeas ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
57  : Crop(a_tov, a_toc, a_L)
58  {
61  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

34 {
35  /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
36  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
37  m_field = a_field;
38  m_ev = a_ev;
39  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true, m_farm, m_field).
40  bool flag = false;
41  int d1 = 0;
42  int d2 = 0;
43  TTypesOfVegetation l_tov = tov_DEOPeas; // The current type - change to match the crop you have
44 /**********************************************To Here *************************************************************************/
45 
46  switch (m_ev->m_todo)
47  {
48  case de_ope_start:
49  {
51 
52  m_last_date = g_date->DayInYear(5, 9); // Should match the last flexdate below
53  //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
54  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
55  // Set up the date management stuff
56  // Start and stop dates for all events after harvest
57  flexdates[0][1] = g_date->DayInYear(5, 9); // last possible day of harvest - this is in effect day before the earliest date that a following crop can use
58 
59  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
60  flexdates[1][1] = g_date->DayInYear(5, 9); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1)
61 
62  // 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
63  int isSpring = 365;
64  if (StartUpCrop(isSpring, flexdates, int(de_ope_spring_harrow1))) break;
65 
66  // End single block date checking code. Please see next line comment as well.
67  // Reinit d1 to first possible starting date.
68  d1 = g_date->OldDays() + g_date->DayInYear(1, 3) + isSpring;
69  // OK, let's go.
71  break;
72  }
73  break;
74 
75  // LKM: do spring harrow, do it before the 1st of April - if not done, try again +1 day until the 10th of April when we succeed - 100% of farmers do this
77  if (!m_farm->SpringHarrow(m_field, 0.0,
78  g_date->DayInYear(15, 3) - g_date->DayInYear())) {
80  break;
81  }
82  if (a_farm->IsStockFarmer())
83  {
85  break;
86  }
87  else SimpleEvent(g_date->OldDays() + g_date->DayInYear(20, 2), de_ope_ferti_p, false);
88  break;
89 
90  case de_ope_ferti_s:
91  if (m_ev->m_lock || m_farm->DoIt_prob(0.50))
92  {
93  if (!m_farm->FA_PKS(m_field, 0.0,
94  g_date->DayInYear(20, 3) - g_date->DayInYear())) {
95  SimpleEvent(g_date->Date() + 1, de_ope_ferti_s, true);
96  break;
97  }
98  }
99  // LKM: Queue up the next event - spring plough
101  break;
102 
103  case de_ope_ferti_p:
104  if (m_ev->m_lock || m_farm->DoIt_prob(0.50))
105  {
106  if (!m_farm->FP_PKS(m_field, 0.0,
107  g_date->DayInYear(20, 3) - g_date->DayInYear())) {
108  SimpleEvent(g_date->Date() + 1, de_ope_ferti_p, true);
109  break;
110  }
111  }
112  // LKM: Queue up the next event - spring plough
114  break;
115 
116  // 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
118  if (!m_farm->SpringPlough(m_field, 0.0,
119  g_date->DayInYear(25, 3) - g_date->DayInYear())) {
121  break;
122  }
123  // LKM: Queue up the next event - spring harrow just before sowing
125  break;
126 
127  // 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
129  if (m_ev->m_lock || m_farm->DoIt_prob(0.10))
130  {
131  if (!m_farm->ShallowHarrow(m_field, 0.0,
132  g_date->DayInYear(30, 3) - g_date->DayInYear())) {
134  break;
135  }
136  }
137  // 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
139  break;
140 
142  if (!m_farm->SpringSow(m_field, 0.0, g_date->DayInYear(31, 3) - g_date->DayInYear())) {
144  break;
145  }
146  //Queue up harrow/strigling 3-5 days after sow
147  SimpleEvent(g_date->Date() + 3, de_ope_strigling, false);
148  break;
149 
150  // LKM: strigling before the 5th of May - if not done, try again +3 days until the 5th of May when we succeed
151  case de_ope_strigling:
152  if (!m_farm->Strigling(m_field, 0.0,
153  g_date->DayInYear(5, 4) - g_date->DayInYear())) {
154  SimpleEvent(g_date->Date() + 1, de_ope_strigling, true);
155  break;
156  } //LKM: Queue up row cultivation 30-45 days after sow to clean field from weeds
158  break;
159 
161  if (!m_farm->RowCultivation(m_field, 0.0,
162  g_date->DayInYear(5, 5) - g_date->DayInYear())) {
164  break;
165  }
167  break;
169  if (m_ev->m_lock || m_farm->DoIt_prob(0.80))
170  {
171  if (!m_farm->RowCultivation(m_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
173  break;
174  }
175  }
177  de_ope_harvest, false);
178  break;
179  case de_ope_harvest:
180  // 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
181  if (!m_farm->Harvest(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
183  break;
184  }
185  // End Main Thread
186  done = true;
187  break;
188 
189  default:
190  g_msg->Warn(WARN_BUG, "OPeas::Do(): "
191  "Unknown event type! ", "");
192  exit(1);
193  }
194 
195  return done;
196 }

References LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), de_ope_ferti_p, de_ope_ferti_s, de_ope_harvest, de_ope_rowcultivation1, de_ope_rowcultivation2, de_ope_spring_harrow1, de_ope_spring_harrow2, de_ope_spring_plough, de_ope_spring_row_sow, de_ope_start, de_ope_strigling, Farm::DoIt_prob(), Farm::FA_PKS(), Farm::FP_PKS(), 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(), Farm::RowCultivation(), Farm::ShallowHarrow(), Crop::SimpleEvent(), Crop::SimpleEvent_(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringSow(), Crop::StartUpCrop(), Farm::Strigling(), tov_DEOPeas, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DE_OPeas::SetUpFarmCategoryInformation ( )
inline
62  {
63  const int elements = 2 + (de_ope_foobar - DE_OPEAS_BASE);
65 
66  FarmManagementCategory catlist[elements] =
67  {
68  fmc_Others, // zero element unused but must be here
69  fmc_Others, // de_ope_start = 1, // Compulsory, start event must always be 1 (one).
70  fmc_Others, // de_ope_sleep_all_day = DE_OPEAS_BASE,
71  fmc_Cultivation, // de_ope_spring_harrow1,
72  fmc_Cultivation, // de_ope_spring_plough,
73  fmc_Fertilizer, // de_ope_ferti_s,
74  fmc_Fertilizer, // de_ope_ferti_p,
75  fmc_Cultivation, // de_ope_spring_harrow2,
76  fmc_Others, // de_ope_spring_row_sow,
77  fmc_Cultivation, // de_ope_strigling,
78  fmc_Cultivation, // de_ope_rowcultivation1,
79  fmc_Cultivation, // de_ope_rowcultivation2,
80  fmc_Harvest, // de_ope_harvest,
81 
82  // no foobar entry
83 
84  };
85  // Iterate over the catlist elements and copy them to vector
86  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
87 
88  }

References de_ope_foobar, DE_OPEAS_BASE, fmc_Cultivation, fmc_Fertilizer, fmc_Harvest, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DE_OPeas().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
de_ope_spring_harrow1
Definition: DE_OPeas.h:38
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
de_ope_rowcultivation1
Definition: DE_OPeas.h:45
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
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
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
de_ope_ferti_s
Definition: DE_OPeas.h:40
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
de_ope_spring_harrow2
Definition: DE_OPeas.h:42
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
DE_OPEAS_BASE
#define DE_OPEAS_BASE
Definition: DE_OPeas.h:33
de_ope_rowcultivation2
Definition: DE_OPeas.h:46
DE_OPeas::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DE_OPeas.h:62
Farm::FP_PKS
virtual bool FP_PKS(LE *a_field, double a_user, int a_days)
Apply PKS fertilizer to a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:659
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
tov_DEOPeas
Definition: LandscapeFarmingEnums.h:488
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
de_ope_foobar
Definition: DE_OPeas.h:48
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::FA_PKS
virtual bool FA_PKS(LE *a_field, double a_user, int a_days)
Apply PKS fertilizer to a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:996
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
de_ope_start
Definition: DE_OPeas.h:36
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
de_ope_harvest
Definition: DE_OPeas.h:47
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
de_ope_strigling
Definition: DE_OPeas.h:44
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
de_ope_ferti_p
Definition: DE_OPeas.h:41
de_ope_spring_plough
Definition: DE_OPeas.h:39
de_ope_spring_row_sow
Definition: DE_OPeas.h:43
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
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
Crop::SimpleEvent_
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.
Definition: Farm.cpp:751