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

DE_Legumes class
. More...

#include <DE_Legumes.h>

Inheritance diagram for DE_Legumes:
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...
 
 DE_Legumes (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

DE_Legumes class
.

See DE_Legumes.h::DELegumesToDo for a complete list of all possible events triggered codes by the legumes 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

◆ DE_Legumes()

DE_Legumes::DE_Legumes ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
101  : Crop(a_tov, a_toc, a_L)
102  {
103  // When we start it off, the first possible date for a farm operation is 1st October
104  // This information is used by other crops when they decide how much post processing of
105  // the management is allowed after harvest before the next crop starts.
106  m_first_date = g_date->DayInYear( 10,3 );
108  }

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

Member Function Documentation

◆ Do()

bool DE_Legumes::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 m_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 - in this case conventional legumes.

Reimplemented from Crop.

92 {
93  /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
94  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
95  m_field = a_field;
96  m_ev = a_ev;
97  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).
98  bool flag = false;
99  int d1 = 0;
100  TTypesOfVegetation l_tov = tov_DELegumes; // The current type - change to match the crop you have
101 /**********************************************To Here *************************************************************************/
102 
103  switch (m_ev->m_todo)
104  {
105  case de_leg_start:
106  {
108 
109  m_last_date = g_date->DayInYear(31, 8); // Should match the last flexdate below
110  //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
111  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
112  // Set up the date management stuff
113  // Start and stop dates for all events after harvest
114  flexdates[0][1] = g_date->DayInYear(31, 8); // last possible day of harvest - this is in effect day before the earliest date that a following crop can use
115 
116  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
117  flexdates[1][1] = g_date->DayInYear(31, 8); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1)
118 
119  // 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
120  int isSpring = 365;
121  if (StartUpCrop(isSpring, flexdates, int(de_leg_spring_harrow))) break;
122 
123  // End single block date checking code. Please see next line comment as well.
124  // Reinit d1 to first possible starting date.
125  d1 = g_date->OldDays() + g_date->DayInYear(1, 3) + isSpring;
126  // OK, let's go.
128  break;
129  }
130  break;
132  if (!m_farm->SpringHarrow(m_field, 0.0, g_date->DayInYear(10, 3) - g_date->DayInYear())) {
134  break;
135  }
136  if (m_farm->IsStockFarmer()) //Stock Farmer
137  {
139  }
140  else SimpleEvent_(g_date->Date() + 1, de_leg_ferti_p1, false, m_farm, m_field);
141  break;
142  case de_leg_ferti_p1:
143  if (!m_farm->FP_SK(m_field, 0.0, g_date->DayInYear(20, 3) - g_date->DayInYear())) {
145  break;
146  }
148  break;
149  case de_leg_ferti_s1:
150  if (!m_farm->FA_SK(m_field, 0.0, g_date->DayInYear(20, 3) - g_date->DayInYear())) {
152  break;
153  }
155  break;
156  case de_leg_fungicide1:
157  if (!m_farm->FungicideTreat(m_field, 0.0, g_date->DayInYear(22, 3) - g_date->DayInYear())) {
159  break;
160  }
162  break;
163  case de_leg_spring_sow:
164  if (!m_farm->SpringSow(m_field, 0.0, g_date->DayInYear(30, 3) - g_date->DayInYear())) {
166  break;
167  }
168  d1 = g_date->Date() + 1;
169  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 4)) {
170  d1 = g_date->OldDays() + g_date->DayInYear(1, 4);
171  }
175  break;
176 
177 
178 
179  case de_leg_herbicide1:
180  if (!m_farm->HerbicideTreat(m_field, 0.0, g_date->DayInYear(10, 4) - g_date->DayInYear())) {
182  break;
183  }
185  break;
186  case de_leg_herbicide2:
187  if (!m_farm->HerbicideTreat(m_field, 0.0, g_date->DayInYear(18, 4) - g_date->DayInYear())) {
189  break;
190  }
192  break;
193  case de_leg_herbicide3:
194  if (!m_farm->HerbicideTreat(m_field, 0.0, g_date->DayInYear(26, 4) - g_date->DayInYear())) {
196  break;
197  }
198  d1 = g_date->Date() + 7;
199  if (d1 < g_date->OldDays() + g_date->DayInYear(15, 5)) {
200  d1 = g_date->OldDays() + g_date->DayInYear(15, 5);
201  }
203  break;
204  case de_leg_herbicide4:
205  if (!m_farm->HerbicideTreat(m_field, 0.0, g_date->DayInYear(20, 5) - g_date->DayInYear())) {
207  break;
208  }
210  break;
211  case de_leg_herbicide5:
212  if (m_ev->m_lock || m_farm->DoIt_prob(0.80)) {
213  if (!m_farm->HerbicideTreat(m_field, 0.0, g_date->DayInYear(15, 8) - g_date->DayInYear())) {
215  break;
216  }
217  }
218  d1 = g_date->Date() + 14;
219  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 8)) {
220  d1 = g_date->OldDays() + g_date->DayInYear(1, 8);
221  }
223  break;
224 
225 
226  case de_leg_insecticide1:
227  // here we check whether we are using ERA pesticide or not
228  d1 = g_date->DayInYear(15, 5) - g_date->DayInYear();
230  if (!cfg_pest_peas_on.value() || !m_field->GetLandscape()->SupplyShouldSpray()) // Not using pesticide spray
231  {
232  flag = m_farm->InsecticideTreat(m_field, 0.0, d1);
233  }
234  else {
235  flag = m_farm->ProductApplication(m_field, 0.0, d1, cfg_pest_product_amounts.value(0), ppp_1, false, 3);
236  }
237  if (!flag) {
239  break;
240  }
241  }
243  break;
244  case de_leg_insecticide2:
245  // here we check whether we are using ERA pesticide or not
246  d1 = g_date->DayInYear(16, 7) - g_date->DayInYear();
248  if (!cfg_pest_peas_on.value() || !m_field->GetLandscape()->SupplyShouldSpray()) // Not using pesticide spray
249  {
250  flag = m_farm->InsecticideTreat(m_field, 0.0, d1);
251  }
252  else {
253  flag = m_farm->ProductApplication(m_field, 0.0, d1, cfg_pest_product_amounts.value(0), ppp_1, false, 3);
254  }
255  if (!flag) {
257  break;
258  }
259  }
260  // end of thread
261  break;
262 
263  case de_leg_fungicide2:
264  if (!m_farm->FungicideTreat(m_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
266  break;
267  }
268  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 6), de_leg_fungicide3, false, m_farm, m_field); // Fungicide thread
269  break;
270  case de_leg_fungicide3:
271  // Here comes the fungicide thread
272  if (m_ev->m_lock || m_farm->DoIt_prob(0.30)) {
273  if (!m_farm->FungicideTreat(m_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
275  break;
276  }
277  }
279  break;
280  case de_leg_fungicide4:
281  if (m_ev->m_lock || m_farm->DoIt_prob(0.20)) {
282  if (!m_farm->FungicideTreat(m_field, 0.0, g_date->DayInYear(16, 7) - g_date->DayInYear())) {
284  break;
285  }
286  }
287  //End of thread
288  break;
289 
290 
291  case de_leg_harvest:
292  // Here the MAIN thread continues
293  // We don't move harvest days
294  if (!m_farm->Harvest(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
296  break;
297  }
298  done = true;
299  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
300  // END of MAIN THREAD
301  break;
302  default:
303  g_msg->Warn(WARN_BUG, "DE_Legumes::Do(): "
304  "Unknown event type! ", "");
305  exit(1);
306  }
307 
308  return done;
309 }

References cfg_pest_peas_on, cfg_pest_product_amounts, LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), de_leg_ferti_p1, de_leg_ferti_s1, de_leg_fungicide1, de_leg_fungicide2, de_leg_fungicide3, de_leg_fungicide4, de_leg_harvest, de_leg_herbicide1, de_leg_herbicide2, de_leg_herbicide3, de_leg_herbicide4, de_leg_herbicide5, de_leg_insecticide1, de_leg_insecticide2, de_leg_spring_harrow, de_leg_spring_sow, de_leg_start, Farm::DoIt_prob(), Farm::FA_SK(), Farm::FP_SK(), Farm::FungicideTreat(), g_date, g_landscape_ptr, g_msg, LE::GetMDates(), Farm::Harvest(), Farm::HerbicideTreat(), Farm::InsecticideTreat(), Farm::IsStockFarmer(), Crop::m_date_modifier, Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), ppp_1, Farm::ProductApplication(), Crop::SimpleEvent_(), Farm::SpringHarrow(), Farm::SpringSow(), Crop::StartUpCrop(), Landscape::SupplyPestIncidenceFactor(), tov_DELegumes, CfgBool::value(), CfgArray_Double::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DE_Legumes::SetUpFarmCategoryInformation ( )
inline
109  {
110  const int elements = 2 + (de_leg_foobar - DE_LEG_BASE);
112 
113  FarmManagementCategory catlist[elements] =
114  {
115  fmc_Others, // zero element unused but must be here
116  // ALL THE NECESSARY ENTRIES HERE
117  fmc_Others, // de_leg_start = 1, // Compulsory, must always be 1 (one).
118  fmc_Others, // de_leg_sleep_all_day
119  fmc_Cultivation, // de_leg_autumn,
120  fmc_Cultivation, // de_leg_spring_harrow,
121  fmc_Fertilizer, // de_leg_ferti_p1,
122  fmc_Fertilizer, // de_leg_ferti_s1,
123  fmc_Fungicide, // de_leg_fungicide1,
124  fmc_Others, // de_leg_spring_sow,
125  fmc_Herbicide, // de_leg_herbicide1,
126  fmc_Herbicide, // de_leg_herbicide2,
127  fmc_Herbicide, // de_leg_herbicide3,
128  fmc_Insecticide, // de_leg_insecticide1,
129  fmc_Insecticide, // de_leg_insecticide2,
130  fmc_Herbicide, // de_leg_herbicide4,
131  fmc_Fungicide, // de_leg_fungicide2,
132  fmc_Fungicide, // de_leg_fungicide3,
133  fmc_Fungicide, // de_leg_fungicide4,
134  fmc_Herbicide, // de_leg_herbicide5,
135  fmc_Harvest, // de_leg_harvest
136  // no foobar entry
137 
138  };
139  // Iterate over the catlist elements and copy them to vector
140  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
141 
142  }

References DE_LEG_BASE, de_leg_foobar, fmc_Cultivation, fmc_Fertilizer, fmc_Fungicide, fmc_Harvest, fmc_Herbicide, fmc_Insecticide, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DE_Legumes().


The documentation for this class was generated from the following files:
de_leg_start
Definition: DE_Legumes.h:66
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
de_leg_herbicide5
Definition: DE_Legumes.h:83
fmc_Insecticide
Definition: LandscapeFarmingEnums.h:1005
Farm::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: FarmFuncs.cpp:2025
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
cfg_pest_product_amounts
CfgArray_Double cfg_pest_product_amounts
Amount of pesticide applied in grams of active substance per hectare for each of the 10 pesticides.
de_leg_insecticide2
Definition: DE_Legumes.h:78
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
Farm::ProductApplication
virtual bool ProductApplication(LE *a_field, double a_user, int a_days, double a_applicationrate, PlantProtectionProducts a_ppp, bool a_isgranularpesticide=false, int a_orcharddrifttype=0)
Apply test pesticide to a_field.
Definition: FarmFuncs.cpp:2267
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
fmc_Herbicide
Definition: LandscapeFarmingEnums.h:1006
de_leg_herbicide4
Definition: DE_Legumes.h:79
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_leg_ferti_p1
Definition: DE_Legumes.h:70
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
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
Farm::FungicideTreat
virtual bool FungicideTreat(LE *a_field, double a_user, int a_days)
Apply fungicide to a_field.
Definition: FarmFuncs.cpp:2101
de_leg_herbicide2
Definition: DE_Legumes.h:75
de_leg_spring_harrow
Definition: DE_Legumes.h:69
tov_DELegumes
Definition: LandscapeFarmingEnums.h:476
CfgBool::value
bool value() const
Definition: Configurator.h:164
de_leg_harvest
Definition: DE_Legumes.h:84
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
g_landscape_ptr
Landscape * g_landscape_ptr
Definition: Landscape.cpp:352
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
de_leg_herbicide1
Definition: DE_Legumes.h:74
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
Landscape::SupplyPestIncidenceFactor
double SupplyPestIncidenceFactor()
Returns Landscape::m_pestincidencefactor.
Definition: Landscape.h:325
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
CfgArray_Double::value
std::vector< double > value() const
Definition: Configurator.h:219
Farm::FA_SK
virtual bool FA_SK(LE *a_field, double a_user, int a_days)
Apply SK fertilizer, on a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:1052
de_leg_fungicide4
Definition: DE_Legumes.h:82
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
Farm::InsecticideTreat
virtual bool InsecticideTreat(LE *a_field, double a_user, int a_days)
Apply insecticide to a_field.
Definition: FarmFuncs.cpp:2135
de_leg_fungicide2
Definition: DE_Legumes.h:80
de_leg_insecticide1
Definition: DE_Legumes.h:77
de_leg_fungicide3
Definition: DE_Legumes.h:81
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
de_leg_fungicide1
Definition: DE_Legumes.h:72
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
de_leg_herbicide3
Definition: DE_Legumes.h:76
Crop::m_date_modifier
static int m_date_modifier
Holds a value that shifts test pesticide use by this many days in crops modified to use it.
Definition: Farm.h:514
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
DE_Legumes::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DE_Legumes.h:109
de_leg_foobar
Definition: DE_Legumes.h:85
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
DE_LEG_BASE
#define DE_LEG_BASE
Definition: DE_Legumes.h:55
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
cfg_pest_peas_on
CfgBool cfg_pest_peas_on
Turn on pesticides for peas.
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
de_leg_ferti_s1
Definition: DE_Legumes.h:71
WARN_BUG
Definition: MapErrorMsg.h:34
ppp_1
Definition: LandscapeFarmingEnums.h:1079
de_leg_spring_sow
Definition: DE_Legumes.h:73
fmc_Fungicide
Definition: LandscapeFarmingEnums.h:1007
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