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

FI_NaturalGrassland class
. More...

#include <FI_NaturalGrassland.h>

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

FI_NaturalGrassland class
.

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

◆ FI_NaturalGrassland()

FI_NaturalGrassland::FI_NaturalGrassland ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
91  : Crop(a_tov, a_toc, a_L)
92  {
93  // When we start it off, the first possible date for a farm operation
94  // This information is used by other crops when they decide how much post processing of
95  // the management is allowed after harvest before the next crop starts.
96  m_first_date = g_date->DayInYear(1, 5);
98  }

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

Member Function Documentation

◆ Do()

bool FI_NaturalGrassland::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 - in this case conventional spring barley Fodder.

Reimplemented from Crop.

99 {
100  m_field = a_field; // this is needed because of possible calls to other methods and currently we do not pass parameters.
101  m_farm = a_farm; // this is needed because of possible calls to other methods and currently we do not pass parameters.
102  m_ev = a_ev;
103  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
104  int d1 = 0;
105  // Depending what event has occured jump to the correct bit of code e.g. for ww_start jump to line 67 below
106  switch (a_ev->m_todo)
107  {
108  case fi_ng_start:
109  {
110  FI_NG_YEARS_AFTER_SOW = 0; //Here FI_NG_YEARS_AFTER_SOW flag should get randomly for each field a value from 1 to 5 ->
111  //THIS PART SHOULD BE SOMEWHERE ELSE OUTSIDE THE PLAN, SO THE STARTING CONDITIONS FOR FIELDS WITH PERMANENT GRASS (YEAR AFTER SOWING)
112  // IS SET ONLY ONCE AT THE SIMULATION START!!!
113  a_field->ClearManagementActionSum();
114 
115 // Check the next crop for early start, unless it is a spring crop
116  // in which case we ASSUME that no checking is necessary!!!!
117  // So DO NOT implement a crop that runs over the year boundary (i.e. from spring to spring!), at least not without fixing this.
118 
119  //new if: do the check only for non-optimising farms and if year>0. (030713 - m_rotation used only in the hidden year, so I modified the condition from >7 to >0)
120  //optimising farms not used for now so most of related code is removed (but not in 'start' case)
121  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
122  //Checking the future...
123  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
124  if (g_date->DayInYear(30, 12) >= a_ev->m_startday)
125  {
126  g_msg->Warn(WARN_BUG, "FINaturalGrassland::Do(): ", "Harvest too late for the next crop to start!!!");
127  int almassnum = a_field->GetLandscape()->BackTranslateVegTypes(a_ev->m_next_tov);
128  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
129  exit(1);
130  }
131  }
132  // Now no operations can be timed after the start of the next crop.
133 
134  if (!a_ev->m_first_year) {
135  // Are we before July 1st?
136  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
137  if (g_date->Date() < d1) {
138  // Yes, too early. We assumme this is because the last crop was late
139  printf("Poly: %d\n", a_field->GetPoly());
140  g_msg->Warn(WARN_BUG, "FINaturalGrassland::Do(): ", "Crop start attempt between 1st Jan & 1st July");
141  int prev = a_field->GetLandscape()->BackTranslateVegTypes(a_field->GetOwner()->GetPreviousTov(a_field->GetRotIndex()));
142  g_msg->Warn(WARN_BUG, "Previous Crop ", prev);
143  int almassnum = a_field->GetLandscape()->BackTranslateVegTypes(a_ev->m_next_tov);
144  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
145  }
146  else {
147  d1 = g_date->OldDays() + 365 + m_first_date; // Add 365 for spring crop
148  if (g_date->Date() > d1) {
149  // Yes too late - should not happen - raise an error
150  g_msg->Warn(WARN_BUG, "FINaturalGrassland::Do(): ", "Crop start attempt after last possible start date");
151  g_msg->Warn(WARN_BUG, "Previous Crop ", "");
152  a_field->GetOwner()->GetPreviousTov(a_field->GetRotIndex());
153  int almassnum = a_field->GetLandscape()->BackTranslateVegTypes(a_ev->m_next_tov);
154  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
155  }
156  }
157  }
158  else {
159  //only for the first year
160  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 5), fi_ng_sow, false);
161  break;
162  }
163  }//if
164 
165  // End single block date checking code. Please see next line comment as well.
166  // OK, let's go.
167  // Here we queue up the first event
168  //Each field has assign randomly a FI_NG_YEARS_AFTER_SOW flag value from 1 to 5
169 
170  if ((FI_NG_YEARS_AFTER_SOW + g_date->GetYearNumber()) % 2 == 2)
171  {
172  d1 = g_date->OldDays() + g_date->DayInYear(1, 1);
173  if (g_date->Date() >= d1) d1 += 365;
174  SimpleEvent(d1, fi_ng_sow, false);
175  }
176  else if ((FI_NG_YEARS_AFTER_SOW + g_date->GetYearNumber()) % 2 == 1)
177  {
178  d1 = g_date->OldDays() + g_date->DayInYear(1, 8);
179  if (g_date->Date() >= d1) d1 += 365;
180  SimpleEvent(d1, fi_ng_grazing1, false);
181  }
182  else if((FI_NG_YEARS_AFTER_SOW + g_date->GetYearNumber()) % 2 == 0)
183  {
184  d1 = g_date->OldDays() + g_date->DayInYear(1, 8);
185  if (g_date->Date() >= d1) d1 += 365;
186  SimpleEvent(d1, fi_ng_sleep_all_day, false);
187  }
188  break;
189  }
190  break; // this thread is only done the first year
191  case fi_ng_sow:
192  if (a_ev->m_lock || a_farm->DoIt(100)) {
193  if (!a_farm->SpringSow(a_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
194  // If we don't succeed on the first try, then try and try again (until 10/10 when we will succeed)
195  SimpleEvent(g_date->Date() + 1, fi_ng_sow, true);
196  break;
197  }
198  }
199  //here comes next event:
200  SimpleEvent(g_date->Date(), fi_ng_slurry, false);
201  break;
202  case fi_ng_slurry: //suggest 50% does this and the rest choose NPK fertilizer (crop scheme only say: 100% do Slurry/NPK)
203  if (a_ev->m_lock || a_farm->DoIt_prob(.50)) {
204  if (!a_farm->FA_Slurry(a_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
205  SimpleEvent(g_date->Date() + 1, fi_ng_slurry, true);
206  break;
207  }
208  }
209  else if (a_ev->m_lock || a_farm->DoIt_prob(.50/.50)){
210  SimpleEvent(g_date->Date(), fi_ng_npk, false);
211  break;
212  }
213  case fi_ng_npk: //suggest 50% does this and the rest choose NPK fertilizer (crop scheme only say: 100% do Slurry/NPK)
214  if (!a_farm->FA_NPK(a_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
215  SimpleEvent(g_date->Date() + 1, fi_ng_npk, true);
216  break;
217  }
219  break;
220  case fi_ng_cutting: // 100% do this
221  if (!a_farm->CutToSilage(a_field, 0.0,
222  g_date->DayInYear(30, 9) - g_date->DayInYear())) {
223  SimpleEvent(g_date->Date() + 1, fi_ng_cutting, true);
224  break;
225  }
226  done = true;
227  break;
228  case fi_ng_sleep_all_day: // every second year nothing is done
229  done = true;
230  break;
231  case fi_ng_grazing1: // 100% cut or grazed - suggests 50% each // every second year this thread
232  if (a_ev->m_lock || a_farm->DoIt(50)) {
233  if (!a_farm->CattleOut(a_field, 0.0,
234  g_date->DayInYear(30, 9) - g_date->DayInYear())) {
235  SimpleEvent(g_date->Date() + 1, fi_ng_grazing1, true);
236  break;
237  }
239  break;
240  }
241  else SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 8), fi_ng_cutting1, false);
242  break;
243  case fi_ng_cutting1: //
244  if (!a_farm->CutToSilage(a_field, 0.0,
245  g_date->DayInYear(30, 9) - g_date->DayInYear())) {
246  SimpleEvent(g_date->Date() + 1, fi_ng_cutting1, true);
247  break;
248  }
249  done = true;
250  break;
251  case fi_ng_cattle_is_out1: // Keep the cattle out there
252  // CattleIsOut() returns false if it is not time to stop grazing
253  if (!m_farm->CattleIsOut(m_field, 0.0, g_date->DayInYear(30, 9) - g_date->DayInYear(), g_date->DayInYear(30, 9))) {
255  break;
256  }
257  done = true;
258  break;
259  // So we are done, and somewhere else the farmer will queue up the start event of the next crop
260  // END OF MAIN THREAD
261  default:
262  g_msg->Warn(WARN_BUG, "FI_NaturalGrassland::Do(): "
263  "Unknown event type! ", "");
264  exit(1);
265  }
266  return done;
267 }

References Farm::CattleIsOut(), Farm::CattleOut(), LE::ClearManagementActionSum(), Farm::CutToSilage(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), Farm::DoIt_prob(), Farm::FA_NPK(), Farm::FA_Slurry(), fi_ng_cattle_is_out1, fi_ng_cutting, fi_ng_cutting1, fi_ng_grazing1, fi_ng_npk, fi_ng_sleep_all_day, fi_ng_slurry, fi_ng_sow, fi_ng_start, FI_NG_YEARS_AFTER_SOW, g_date, g_msg, LE::GetOwner(), LE::GetPoly(), Farm::GetPreviousTov(), LE::GetRotIndex(), Farm::GetType(), Calendar::GetYearNumber(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_first_date, FarmEvent::m_first_year, FarmEvent::m_lock, FarmEvent::m_next_tov, FarmEvent::m_startday, FarmEvent::m_todo, Calendar::OldDays(), Crop::SimpleEvent(), Farm::SpringSow(), tof_OptimisingFarm, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void FI_NaturalGrassland::SetUpFarmCategoryInformation ( )
inline
99  {
100  const int elements = 2 + (fi_ng_foobar - FI_NG_BASE);
102 
103  FarmManagementCategory catlist[elements] =
104  {
105  fmc_Others, // zero element unused but must be here
106  fmc_Others, // fi_ng_start = 1, // Compulsory, must always be 1 (one).
107  fmc_Others, // fi_ng_sleep_all_day = FI_NG_BASE,
108  fmc_Others, // fi_ng_sow,
109  fmc_Fertilizer, // fi_ng_npk,
110  fmc_Fertilizer, // fi_ng_slurry,
111  fmc_Cutting, // fi_ng_cutting,
112  fmc_Grazing, // fi_ng_grazing1,
113  fmc_Grazing, // fi_ng_cattle_is_out1,
114  fmc_Cutting // fi_ng_cutting1,
115 
116 
117  // no foobar entry
118 
119  };
120  // Iterate over the catlist elements and copy them to vector
121  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
122 
123  }

References FI_NG_BASE, fi_ng_foobar, fmc_Cutting, fmc_Fertilizer, fmc_Grazing, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by FI_NaturalGrassland().


The documentation for this class was generated from the following files:
Farm::FA_Slurry
virtual bool FA_Slurry(LE *a_field, double a_user, int a_days)
Spready slurry on a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:1067
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
fi_ng_foobar
Definition: FI_NaturalGrassland.h:75
fi_ng_start
Definition: FI_NaturalGrassland.h:66
fi_ng_sow
Definition: FI_NaturalGrassland.h:68
fi_ng_sleep_all_day
Definition: FI_NaturalGrassland.h:67
Farm::CattleIsOut
virtual bool CattleIsOut(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out' event for every day the cattle are on a_field.
Definition: FarmFuncs.cpp:2470
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
Farm::CutToSilage
virtual bool CutToSilage(LE *a_field, double a_user, int a_days)
Cut vegetation for silage on a_field.
Definition: FarmFuncs.cpp:1644
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: Farm.cpp:856
Calendar::GetYearNumber
int GetYearNumber(void)
Definition: Calendar.h:72
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
LE::GetPoly
int GetPoly(void)
Returns the polyref number for this polygon.
Definition: Elements.h:238
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::GetPreviousTov
TTypesOfVegetation GetPreviousTov(int a_index)
Definition: Farm.h:966
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
Farm::GetType
TTypesOfFarm GetType(void)
Definition: Farm.h:956
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
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
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
fi_ng_cattle_is_out1
Definition: FI_NaturalGrassland.h:73
FI_NG_BASE
#define FI_NG_BASE
Definition: FI_NaturalGrassland.h:55
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
fi_ng_slurry
Definition: FI_NaturalGrassland.h:70
fi_ng_cutting
Definition: FI_NaturalGrassland.h:71
FI_NaturalGrassland::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: FI_NaturalGrassland.h:99
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fi_ng_npk
Definition: FI_NaturalGrassland.h:69
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
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
LE::GetRotIndex
int GetRotIndex(void)
Definition: Elements.h:373
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: Farm.h:390
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
fi_ng_cutting1
Definition: FI_NaturalGrassland.h:74
fi_ng_grazing1
Definition: FI_NaturalGrassland.h:72
FI_NG_YEARS_AFTER_SOW
#define FI_NG_YEARS_AFTER_SOW
Definition: FI_NaturalGrassland.h:53
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
LE::GetOwner
Farm * GetOwner(void)
Definition: Elements.h:256
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
Farm::CattleOut
virtual bool CattleOut(LE *a_field, double a_user, int a_days)
Start a grazing event on a_field today.
Definition: FarmFuncs.cpp:2368
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001