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

#include <PermanentGrassLowYield.h>

Inheritance diagram for PermanentGrassLowYield:
Crop

Public Member Functions

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

◆ PermanentGrassLowYield()

PermanentGrassLowYield::PermanentGrassLowYield ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
55  : Crop(a_tov, a_toc, a_L)
56  {
59  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

38 {
39  m_farm = a_farm;
40  m_field = a_field;
41  m_ev = a_ev;
42 
43  int d1;
44 
45  bool done = false;
46 
47  switch (m_ev->m_todo) {
48  case pgly_start:
49  {
50  a_field->ClearManagementActionSum();
51  PGLY_CUT_DATE = 0;
52  // Set up the date management stuff
53  m_last_date = g_date->DayInYear(1, 10);
54  // Start and stop dates for all events after harvest
55  int noDates = 1;
56  // Start and stop dates for all events after harvest
57  m_field->SetMDates(0, 0, g_date->DayInYear(15, 9));
58  // 0,0 determined by harvest date - used to see if at all possible
59  m_field->SetMDates(1, 0, g_date->DayInYear(1, 10));
60  // Check the next crop for early start, unless it is a spring crop
61  // in which case we ASSUME that no checking is necessary!!!!
62  // So DO NOT implement a crop that runs over the year boundary
63 
64  //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)
65  if (!(m_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)){
66 
67  if (m_ev->m_startday > g_date->DayInYear(1, 7))
68  {
69  if (m_field->GetMDates(0, 0) >= m_ev->m_startday)
70  {
71  g_msg->Warn(WARN_BUG, "PermanentGrassLowYield::Do(): "
72  "Harvest too late for the next crop to start!!!", "");
73  exit(1);
74  }
75  // Now fix any late finishing problems
76  for (int i = 0; i < noDates; i++) {
77  if (m_field->GetMDates(0, i) >= m_ev->m_startday) {
78  m_field->SetMDates(0, i, m_ev->m_startday - 1); //move the starting date
79  }
80  if (m_field->GetMDates(1, i) >= m_ev->m_startday){
81  m_field->SetMConstants(i, 0);
82  m_field->SetMDates(1, i, m_ev->m_startday - 1); //move the finishing date
83  }
84  }
85  }
86  // Now no operations can be timed after the start of the next crop.
87  int today = g_date->Date();
88  d1 = g_date->OldDays() + m_first_date + 365; // Add 365 for spring crop
89  if (today > d1)
90  {
91  // Yes too late - should not happen - raise an error
92  g_msg->Warn(WARN_BUG, " PermanentGrassLowYield::Do(): "
93  "Crop start attempt after last possible start date", "");
94  exit(1);
95  }
96  }
97  // Reinit d1 to first possible starting date.
98  d1 = g_date->OldDays() + m_first_date;
99  if (!m_ev->m_first_year) d1 += 365; // Add 365 for spring crop (not 1st yr)
100  if (g_date->Date() > d1) {
101  d1 = g_date->Date();
102  }
103  // OK, let's go.
104  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
105 
106  SimpleEvent(d1, pgly_cut_to_hay, false);
107  }
108  break;
109 
110  case pgly_cut_to_hay:
111  if (m_ev->m_lock || m_farm->DoIt(20))
112  {
113  if (!m_farm->CutToHay(m_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
114  SimpleEvent(g_date->Date() + 1, pgly_cut_to_hay, true);
115  break;
116  }
117  // did cut to hay so try turning
118  else
119  {
121  pgly_raking1, false);
123  }
124  break;
125  }
126  SimpleEvent(g_date->OldDays() + m_first_date, pgly_cattle_out1, false); // non-cutters graze
127 
128  break;
129 
130  case pgly_raking1:
131  if (PGLY_CUT_DATE + 20 >= g_date->Date()) m_ev->m_lock = true;
132  if (m_ev->m_lock || m_farm->DoIt(50))
133  {
134  if (!m_farm->HayTurning(m_field, 0.0,
135  g_date->DayInYear(25, 6) - g_date->DayInYear()))
136  {
137  SimpleEvent(g_date->Date() + 1, pgly_raking1, true);
138  break;
139  }
140  SimpleEvent(g_date->Date() + 1, pgly_raking2, false);
141  break;
142  }
143  ChooseNextCrop(1);
144  SimpleEvent(PGLY_CUT_DATE + 21, pgly_cattle_out1, false); // 100% of these graze
145  break;
146 
147  case pgly_raking2:
148  if (m_ev->m_lock || m_farm->DoIt(25))
149  {
150  if (!m_farm->HayTurning(m_field, 0.0,
151  g_date->DayInYear(26, 6) - g_date->DayInYear())) {
152  SimpleEvent(g_date->Date() + 1, pgly_raking2, true);
153  break;
154  }
155  }
156  SimpleEvent(g_date->Date() + 1, pgly_compress_straw, false);
157  break;
158 
159  case pgly_compress_straw:
160  if (!m_farm->HayBailing(m_field, 0.0,
161  g_date->DayInYear(1, 7) - g_date->DayInYear()))
162  {
164  break;
165  }
166  // Did compress straw
167 
168  ChooseNextCrop(1);
169 
170  SimpleEvent(PGLY_CUT_DATE + 21, pgly_cattle_out1, false); // 100% of these graze
171  break;
172 
173  case pgly_cattle_out1:
174  ChooseNextCrop(1);
175 
176  if (m_field->GetMConstants(0) == 0) {
177  if (!m_farm->CattleOut(m_field, 0.0, -1)) {
178  //raise an error
179  g_msg->Warn(WARN_BUG, "PermanentGrassLowYield::Do(): failure in 'CattleOut' execution", "");
180  exit(1);
181  }
182  }
183  else {
184  if (!m_farm->CattleOut(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
185  SimpleEvent(g_date->Date() + 1, pgly_cattle_out1, true);
186  break;
187  }
188  }
190  break;
191 
192  case pgly_cattle_out2:
193  if ((m_ev->m_lock || m_farm->DoIt(33)))
194  {
195  if (m_field->GetMConstants(0) == 0) {
196  if (!m_farm->CattleOut(m_field, 0.0, -1)) { //raise an error
197  g_msg->Warn(WARN_BUG, "PermanentGrassLowYield::Do(): failure in 'CattleOut' execution", "");
198  exit(1);
199  }
200  }
201  else {
202  if (!m_farm->CattleOut(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
203  SimpleEvent(g_date->Date() + 1, pgly_cattle_out2, true);
204  break;
205  }
206  }
207  // Success
209  break;
210  }
211  //Don't graze - but don't end too early;
212  SimpleEvent(g_date->OldDays() + g_date->DayInYear(2, 7), pgly_wait, false);
213  break;
214 
215  case pgly_wait:
216  done = true;
217  break;
218 
219  case pgly_cattle_is_out:
220  if (m_field->GetMConstants(0) == 0) {
221  if (!m_farm->CattleIsOut(m_field, 0.0, -1, m_field->GetMDates(1, 0))) { //raise an error
222  //added 28.08 - issue a warning only if we fail on the last day that this can be done, i.e. MDate
223  if (g_date->Date() == m_field->GetMDates(1, 0)){
224  g_msg->Warn(WARN_BUG, "PermanentGrassLowYield::Do(): failure in 'CattleIsOut' execution", "");
225  exit(1);
226  }
227  }
228  }
229  else {
230  if (!m_farm->CattleIsOut(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear(), m_field->GetMDates(1, 0))) {
231  SimpleEvent(g_date->Date() + 1, pgly_cattle_is_out, true);
232  break;
233  }
234  }
235  // if they come in then send them out if too early
236  if (g_date->DayInYear() < g_date->DayInYear(10, 9))
237  {
238  SimpleEvent(g_date->Date() + 1, pgly_cattle_out2, true);
239  break;
240  }
242  break;
243 
244  case pgly_herbicide:
245  if ((m_ev->m_lock || m_farm->DoIt((int)(5 * cfg_herbi_app_prop.value() * m_farm->Prob_multiplier()))) && //modified probability
246  // --FN--
247  (g_date->DayInYear() < g_date->DayInYear(15, 8)))
248  {
249  if (!m_farm->HerbicideTreat(m_field, 0.0, g_date->DayInYear(15, 8) - g_date->DayInYear())) {
250  // --FN--
251  SimpleEvent(g_date->Date() + 1, pgly_herbicide, true);
252  break;
253  }
254  }
256  pgly_cut_weeds, false);
257  break;
258 
259  case pgly_cut_weeds:
260  if ((m_ev->m_lock || m_farm->DoIt(25)) &&
261  //--FN--
262  (g_date->DayInYear() < g_date->DayInYear(15, 9)))
263  {
264  if (!m_farm->CutWeeds(m_field, 0.0,
265  g_date->DayInYear(15, 9) - g_date->DayInYear())) {
266  // --FN--
267  SimpleEvent(g_date->Date() + 1, pgly_cut_weeds, true);
268  break;
269  }
270  }
271  // END MAIN THREAD
272  done = true;
273  break;
274 
275  default:
276  g_msg->Warn(WARN_BUG, "PermanantGrassLowYield::Do(): "
277  "Unknown event type! ", "");
278  exit(1);
279  }
280  return done;
281 }

References Farm::CattleIsOut(), Farm::CattleOut(), cfg_herbi_app_prop, Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Farm::CutToHay(), Farm::CutWeeds(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), g_date, g_msg, LE::GetMConstants(), LE::GetMDates(), Farm::GetType(), Calendar::GetYearNumber(), Farm::HayBailing(), Farm::HayTurning(), Farm::HerbicideTreat(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_first_date, FarmEvent::m_first_year, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_startday, FarmEvent::m_todo, Calendar::OldDays(), pgly_cattle_is_out, pgly_cattle_out1, pgly_cattle_out2, pgly_compress_straw, PGLY_CUT_DATE, pgly_cut_to_hay, pgly_cut_weeds, pgly_herbicide, pgly_raking1, pgly_raking2, pgly_start, pgly_wait, Farm::Prob_multiplier(), LE::SetLastSownVeg(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent(), tof_OptimisingFarm, CfgFloat::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void PermanentGrassLowYield::SetUpFarmCategoryInformation ( )
inline
60  {
61  const int elements = 2 + (pgly_foobar - PGLY_BASE);
63 
64  FarmManagementCategory catlist[elements] =
65  {
66  fmc_Others, // zero element unused but must be here
67  fmc_Cutting, // pgly_cut_to_hay = PGLY_BASE,
68  fmc_Grazing, // pgly_cattle_out1,
69  fmc_Grazing, // pgly_cattle_out2,
70  fmc_Grazing, // pgly_cattle_is_out,
71  fmc_Cutting, // pgly_cut_weeds,
72  fmc_Herbicide, // pgly_herbicide,
73  fmc_Others, // pgly_raking1,
74  fmc_Others, // pgly_raking2,
75  fmc_Others, // pgly_compress_straw,
76  fmc_Others // pgly_wait,
77  // No foobar entry
78  };
79  // Iterate over the catlist elements and copy them to vector
80  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
81  }

References fmc_Cutting, fmc_Grazing, fmc_Herbicide, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, PGLY_BASE, and pgly_foobar.

Referenced by PermanentGrassLowYield().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
PGLY_BASE
#define PGLY_BASE
Definition: PermanentGrassLowYield.h:31
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
Farm::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: FarmFuncs.cpp:2025
pgly_herbicide
Definition: PermanentGrassLowYield.h:41
LE::SetLastSownVeg
void SetLastSownVeg(TTypesOfVegetation a_tov)
Records the last vegetation type to be sown.
Definition: Elements.h:357
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
LE::GetMConstants
int GetMConstants(int a)
Definition: Elements.h:407
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::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
pgly_cattle_out1
Definition: PermanentGrassLowYield.h:37
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
fmc_Herbicide
Definition: LandscapeFarmingEnums.h:1006
CfgFloat::value
double value() const
Definition: Configurator.h:142
Farm::GetType
TTypesOfFarm GetType(void)
Definition: Farm.h:956
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
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
cfg_herbi_app_prop
CfgFloat cfg_herbi_app_prop
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
PGLY_CUT_DATE
#define PGLY_CUT_DATE
Definition: PermanentGrassLowYield.h:32
Farm::Prob_multiplier
virtual double Prob_multiplier()
Definition: Farm.h:778
pgly_foobar
Definition: PermanentGrassLowYield.h:46
Calendar::Date
long Date(void)
Definition: Calendar.h:57
pgly_compress_straw
Definition: PermanentGrassLowYield.h:44
Farm::HayBailing
virtual bool HayBailing(LE *a_field, double a_user, int a_days)
Carry out hay bailing on a_field.
Definition: FarmFuncs.cpp:1507
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
pgly_cut_to_hay
Definition: PermanentGrassLowYield.h:36
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
pgly_cattle_is_out
Definition: PermanentGrassLowYield.h:39
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
pgly_wait
Definition: PermanentGrassLowYield.h:45
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
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
pgly_raking2
Definition: PermanentGrassLowYield.h:43
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
pgly_start
Definition: PermanentGrassLowYield.h:35
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
LE::SetMConstants
void SetMConstants(int a, int c)
Definition: Elements.h:408
PermanentGrassLowYield::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: PermanentGrassLowYield.h:60
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: Farm.cpp:756
Farm::HayTurning
virtual bool HayTurning(LE *a_field, double a_user, int a_days)
Carry out hay turning on a_field.
Definition: FarmFuncs.cpp:1491
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
pgly_cut_weeds
Definition: PermanentGrassLowYield.h:40
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
pgly_raking1
Definition: PermanentGrassLowYield.h:42
pgly_cattle_out2
Definition: PermanentGrassLowYield.h:38
Farm::CutWeeds
virtual bool CutWeeds(LE *a_field, double a_user, int a_days)
Carry out weed topping on a_field.
Definition: FarmFuncs.cpp:1629