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

DE_OBushFruitPerm class
. More...

#include <DE_OBushFruitPerm.h>

Inheritance diagram for DE_OBushFruitPerm:
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_OBushFruitPerm (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_OBushFruitPerm class
.

See DE_OBushFruitPerm.h::DE_OBushFruitPermToDo for a complete list of all possible events triggered codes by the 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_OBushFruitPerm()

DE_OBushFruitPerm::DE_OBushFruitPerm ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
72  : Crop(a_tov, a_toc, a_L)
73  {
74  // When we start it off, the first possible date for a farm operation is ...
75  // This information is used by other crops when they decide how much post processing of
76  // the management is allowed after harvest before the next crop starts.
77  m_first_date=g_date->DayInYear( 31,3 );
79  }

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

Member Function Documentation

◆ Do()

bool DE_OBushFruitPerm::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 a_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.

Reimplemented from Crop.

55 {
56  m_farm = a_farm;
57  m_field = a_field;
58  m_ev = a_ev;
59  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).
60  bool flag = false;
61  int d1 = 0;
62  int noDates = 1;
63  int today = g_date->Date();
65  // Depending what event has occured jump to the correct bit of code
66  switch (m_ev->m_todo)
67  {
68  case de_obfp_start:
69  {
70  // de_obfp_start just sets up all the starting conditions and reference dates that are needed to start a dk_bfp1
71  DE_OBFP_EARLY_HARVEST = false;
72 
73  m_last_date = g_date->DayInYear(30, 12); // Should match the last flexdate below
74  //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
75  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
76  // Set up the date management stuff
77  // Start and stop dates for all events after harvest
78  flexdates[0][1] = g_date->DayInYear(30, 12); // last possible day of harvest - this is in effect day before the earliest date that a following crop can use - NO harvest here - this is herbicide2 instead
79  // Now these are done in pairs, start & end for each operation. If its not used then -1
80  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
81  flexdates[1][1] = g_date->DayInYear(30, 12); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1) - water2
82 
83  // 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
84  int isSpring = 365;
85  if (StartUpCrop(isSpring, flexdates, int(de_obfp_fertilizer1_s))) break;
86 
87  // End single block date checking code. Please see next line comment as well.
88  // Reinit d1 to first possible starting date.
89  d1 = g_date->OldDays() + g_date->DayInYear(1, 4) + isSpring;
90  // OK, let's go.
91  // LKM: Here we queue up the first event
92  if (a_farm->IsStockFarmer()) {
94  break;
95  }
96  else SimpleEvent(d1, de_obfp_fertilizer1_p, false);
97  break;
98  }
99  break;
100 
101  // LKM: This is the first real farm operation
102  case de_obfp_fertilizer1_s:
103  if (m_ev->m_lock || m_farm->DoIt_prob(1.0))
104  {
105  if (!a_farm->FA_NPK(m_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
107  break;
108  }
109  }
111  //SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 5), de_obfp_mow_margin1, false);
114  break;
115 
116  case de_obfp_fertilizer1_p:
117  if (m_ev->m_lock || m_farm->DoIt_prob(1.0))
118  {
119  if (!a_farm->FP_NPK(m_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
121  break;
122  }
123  }
125  //SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 5), de_obfp_mow_margin1, false);
128  break;
129 
131  if (!a_farm->ManualWeeding(m_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
133  break;
134  }
136  break;
137 
139  if (!a_farm->ManualWeeding(m_field, 0.0, g_date->DayInYear(30, 9) - g_date->DayInYear())) {
141  break;
142  }
143  break;
144 
145  case de_obfp_cover_on: // could be straw or fiber
146  if (!m_farm->StrawCovering(m_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
147  SimpleEvent(g_date->Date() + 1, de_obfp_cover_on, true);
148  break;
149  }
151  break;
152 
153  //case de_obfp_mow_margin1:
154  //if (!m_farm->CutWeeds(m_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
155  // SimpleEvent(g_date->Date() + 1, de_obfp_mow_margin1, true);
156  // break;
157  //}
158  //SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 8), de_obfp_mow_margin2, false);
159  //break;
160 
161  //case de_obfp_mow_margin2:
162  //if (!m_farm->CutWeeds(m_field, 0.0, g_date->DayInYear(31, 7) - g_date->DayInYear())) {
163  // SimpleEvent(g_date->Date() + 1, de_obfp_mow_margin2, true);
164  // break;
165  //}
166  //SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 9), de_obfp_manual_weeding2, false);
167  //break;
168 
169  //case de_obfp_mow_margin3:
170  //if (!m_farm->CutWeeds(m_field, 0.0, g_date->DayInYear(30, 9) - g_date->DayInYear())) {
171  // SimpleEvent(g_date->Date() + 1, de_obfp_mow_margin3, true);
172  // break;
173  //}
174  //break;
175 
176  case de_obfp_water1:
177  if (!m_farm->Water(m_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
178  SimpleEvent(g_date->Date() + 1, de_obfp_water1, true);
179  break;
180  }
181  SimpleEvent(g_date->Date()+14, de_obfp_water2, false);
182  break;
183 
184  case de_obfp_water2:
185  if (!m_farm->Water(m_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
186  SimpleEvent(g_date->Date() + 1, de_obfp_water2, true);
187  break;
188  }
189  break;
190 
191  case de_obfp_harvest:
192  // continuous harvesting till 31 July, every day
193  m_farm->FruitHarvest(m_field, 0.0, 0);
194  if (today < g_date->OldDays() + g_date->DayInYear(31, 7)) {
196  break;
197  }
198  //fork of events:
200  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 8), de_obfp_water3, false, m_farm, m_field); // main thread
201  if (a_farm->IsStockFarmer()) {
203  break;
204  }
206  break;
207 
209  if (m_farm->IsStockFarmer()) {
210  if (m_ev->m_lock || m_farm->DoIt_prob(1.0))
211  {
212  if (!a_farm->FA_NPK(m_field, 0.0, g_date->DayInYear(31, 8) - g_date->DayInYear())) {
214  break;
215  }
216  }
217  }
218  break;
219 
221  if (m_ev->m_lock || m_farm->DoIt_prob(1.0))
222  {
223  if (!a_farm->FP_NPK(m_field, 0.0, g_date->DayInYear(31, 8) - g_date->DayInYear())) {
225  break;
226  }
227  }
228  break;
229 
231  if (!a_farm->Swathing(m_field, 0.0, g_date->DayInYear(31, 8) - g_date->DayInYear())) {
233  break;
234  }
235  break;
236 
237  case de_obfp_water3:
238  if (!m_farm->Water(m_field, 0.0, g_date->DayInYear(31, 10) - g_date->DayInYear())) {
239  SimpleEvent(g_date->Date() + 1, de_obfp_water3, true);
240  break;
241  }
242  SimpleEvent(g_date->Date() + 14, de_obfp_water4, false);
243  break;
244 
245  case de_obfp_water4:
246  if (!m_farm->Water(m_field, 0.0, g_date->DayInYear(30, 9) - g_date->DayInYear())) {
247  SimpleEvent(g_date->Date() + 1, de_obfp_water4, true);
248  break;
249  }
250  d1 = g_date->Date() + 14;
251  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 10)) {
252  d1 = g_date->OldDays() + g_date->DayInYear(1, 10);
253  }
254  SimpleEvent(d1, de_obfp_water5, false);
255  break;
256 
257  case de_obfp_water5:
258  if (!m_farm->Water(m_field, 0.0, g_date->DayInYear(31, 10) - g_date->DayInYear())) {
259  SimpleEvent(g_date->Date() + 1, de_obfp_water5, true);
260  break;
261  }
262  done = true;
263  break;
264  // So we are done, and somewhere else the farmer will queue up the start event of the next crop (DE_OBushFruitPerm)
265  // END of MAIN THREAD
266  break;
267 
268  default:
269  g_msg->Warn(WARN_BUG, "DE_OBushFruitPerm::Do(): "
270  "Unknown event type! ", "");
271  exit(1);
272  }
273  return done;
274 }

References Calendar::Date(), Calendar::DayInYear(), de_obfp_cover_on, DE_OBFP_EARLY_HARVEST, de_obfp_fertilizer1_p, de_obfp_fertilizer1_s, de_obfp_fertilizer2_p, de_obfp_fertilizer2_s, de_obfp_harvest, de_obfp_manual_weeding1, de_obfp_manual_weeding2, de_obfp_mowing_fruit, de_obfp_start, de_obfp_water1, de_obfp_water2, de_obfp_water3, de_obfp_water4, de_obfp_water5, Farm::DoIt_prob(), Farm::FA_NPK(), Farm::FP_NPK(), Farm::FruitHarvest(), g_date, g_msg, Farm::IsStockFarmer(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Farm::ManualWeeding(), Calendar::OldDays(), Crop::SimpleEvent(), Crop::SimpleEvent_(), Crop::StartUpCrop(), Farm::StrawCovering(), Farm::Swathing(), tov_DEOBushFruitPerm, MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void DE_OBushFruitPerm::SetUpFarmCategoryInformation ( )
inline
80  {
81  const int elements = 2 + (de_obfp_foobar - DE_OBFP_BASE);
83 
84  FarmManagementCategory catlist[elements] =
85  {
86  fmc_Others, // zero element unused but must be here
87  fmc_Others, // de_obfp_start = 1, // Compulsory, must always be 1 (one).
88  fmc_Others, // de_obfp_sleep_all_day = DK_BFP2_BASE,
89  fmc_Others, // de_obfp_cover_on,
90  fmc_Fertilizer, // de_obfp_fertilizer1_s,
91  fmc_Fertilizer, // de_obfp_fertilizer1_p,
92  fmc_Cutting, // de_obfp_mow_margin1,
93  fmc_Cutting, // de_obfp_mow_margin2,
94  fmc_Cutting, // de_obfp_mow_margin3,
95  fmc_Watering, // de_obfp_water1,
96  fmc_Cultivation, // de_obfp_manual_weeding1,
97  fmc_Cultivation, // de_obfp_manual_weeding2,
98  fmc_Watering, // de_obfp_water2,
99  fmc_Harvest, // de_obfp_harvest,
100  fmc_Cutting, // de_obfp_mowing_fruit,
101  fmc_Fertilizer, // de_obfp_fertilizer2_s,
102  fmc_Fertilizer, // de_obfp_fertilizer2_p,
103  fmc_Watering, // de_obfp_water3,
104  fmc_Watering, // de_obfp_water4,
105  fmc_Watering, // de_obfp_water5,
106 
107  // no foobar entry
108 
109  };
110  // Iterate over the catlist elements and copy them to vector
111  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
112  }

References DE_OBFP_BASE, de_obfp_foobar, fmc_Cultivation, fmc_Cutting, fmc_Fertilizer, fmc_Harvest, fmc_Others, fmc_Watering, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DE_OBushFruitPerm().


The documentation for this class was generated from the following files:
de_obfp_water4
Definition: DE_OBushFruitPerm.h:55
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
de_obfp_manual_weeding2
Definition: DE_OBushFruitPerm.h:48
Farm::FP_NPK
virtual bool FP_NPK(LE *a_field, double a_user, int a_days)
Apply NPK fertilizer, on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:645
de_obfp_water1
Definition: DE_OBushFruitPerm.h:46
de_obfp_fertilizer1_p
Definition: DE_OBushFruitPerm.h:42
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
DE_OBushFruitPerm::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DE_OBushFruitPerm.h:80
de_obfp_mowing_fruit
Definition: DE_OBushFruitPerm.h:51
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
de_obfp_fertilizer2_p
Definition: DE_OBushFruitPerm.h:53
Farm::FA_NPK
virtual bool FA_NPK(LE *a_field, double a_user, int a_days)
Apply NPK fertilizer to a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:982
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
tov_DEOBushFruitPerm
Definition: LandscapeFarmingEnums.h:521
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
de_obfp_water5
Definition: DE_OBushFruitPerm.h:56
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
de_obfp_harvest
Definition: DE_OBushFruitPerm.h:50
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
de_obfp_manual_weeding1
Definition: DE_OBushFruitPerm.h:47
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
de_obfp_fertilizer2_s
Definition: DE_OBushFruitPerm.h:52
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
de_obfp_foobar
Definition: DE_OBushFruitPerm.h:57
de_obfp_start
Definition: DE_OBushFruitPerm.h:38
Farm::ManualWeeding
virtual bool ManualWeeding(LE *a_field, double a_user, int a_days)
Manual weeding on a_field - no tramlines since weeding by hand, the bush stays on field with same veg...
Definition: FarmFuncs.cpp:2002
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
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
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
Farm::StrawCovering
virtual bool StrawCovering(LE *a_field, double a_user, int a_days)
Straw covering applied on a_field.
Definition: FarmFuncs.cpp:1738
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
Farm::FruitHarvest
virtual bool FruitHarvest(LE *a_field, double a_user, int a_days)
FruitHarvest (harvest of the mature fruits, e.g., grapes) applied on a_field.
Definition: FarmFuncs.cpp:1959
DE_OBFP_BASE
#define DE_OBFP_BASE
Definition: DE_OBushFruitPerm.h:27
de_obfp_water2
Definition: DE_OBushFruitPerm.h:49
DE_OBFP_EARLY_HARVEST
#define DE_OBFP_EARLY_HARVEST
Definition: DE_OBushFruitPerm.h:25
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
de_obfp_cover_on
Definition: DE_OBushFruitPerm.h:40
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
Farm::Swathing
virtual bool Swathing(LE *a_field, double a_user, int a_days)
Cut the crop on a_field and leave it lying (probably rape)
Definition: FarmFuncs.cpp:1350
de_obfp_fertilizer1_s
Definition: DE_OBushFruitPerm.h:41
de_obfp_water3
Definition: DE_OBushFruitPerm.h:54
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
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