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

#include <PermanentGrassGrazed.h>

Inheritance diagram for PermanentGrassGrazed:
Crop

Public Member Functions

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

◆ PermanentGrassGrazed()

PermanentGrassGrazed::PermanentGrassGrazed ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
58  : Crop(a_tov, a_toc, a_L)
59  {
62  }

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

Member Function Documentation

◆ Do()

bool PermanentGrassGrazed::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 pgg_start:
49  {
50  PGG_CUT_DATE =0;
52  a_field->ClearManagementActionSum();
53 
54  // Set up the date management stuff
56  // Start and stop dates for all events after harvest
57  int noDates= 1;
58  // Start and stop dates for all events after harvest
59  m_field->SetMDates(0,0,g_date->DayInYear(15,9));
60  // 0,0 determined by harvest date - used to see if at all possible
61  m_field->SetMDates( 1, 0, g_date->DayInYear(1,10) );
62  // Check the next crop for early start, unless it is a spring crop
63  // in which case we ASSUME that no checking is necessary!!!!
64  // So DO NOT implement a crop that runs over the year boundary
65 
66  //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)
68 
69  if (m_ev->m_startday>g_date->DayInYear(1,7))
70  {
71  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
72  {
73  g_msg->Warn( WARN_BUG, "PermanentGrassGrazed::Do(): "
74  "Harvest too late for the next crop to start!!!", "" );
75  exit( 1 );
76  }
77  // Now fix any late finishing problems
78  for (int i=0; i<noDates; i++) {
79  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
80  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
81  }
82  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
83  m_field->SetMConstants(i,0);
84  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
85  }
86  }
87  }
88  // Now no operations can be timed after the start of the next crop.
89  int today=g_date->Date();
90  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
91  if (today > d1)
92  {
93  // Yes too late - should not happen - raise an error
94  g_msg->Warn( WARN_BUG, " PermanentGrassGrazed::Do(): "
95  "Crop start attempt after last possible start date", "" );
96  exit( 1 );
97  }
98  }//if
99 
100  // Reinit d1 to first possible starting date.
101  d1 = g_date->OldDays()+m_first_date;;
102  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
103  if ( g_date->Date() > d1 ) {
104  d1 = g_date->Date();
105  }
106  // OK, let's go.
107  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
108 
109  if (m_farm->IsStockFarmer())
110  SimpleEvent(d1, pgg_ferti_s, false );
111  else
112  SimpleEvent(d1, pgg_ferti_p, false );
113  }
114  break;
115 
116  case pgg_ferti_s:
117  if ( m_ev->m_lock || m_farm->DoIt( 80 ))
118  {
119  if (!m_farm->FA_NPK( m_field, 0.0,
120  g_date->DayInYear( 15,6 ) - g_date->DayInYear())) {
121  SimpleEvent( g_date->Date() + 1, pgg_ferti_s, true );
122  break;
123  }
125  }
126  SimpleEvent( g_date->Date() + 28,pgg_cut_to_hay, false );
127  break;
128 
129  case pgg_ferti_p:
130  if ( m_ev->m_lock || m_farm->DoIt( 70 ))
131  {
132  if (!m_farm->FP_NPK( m_field, 0.0,
133  g_date->DayInYear( 15,6 ) - g_date->DayInYear())) {
134  SimpleEvent( g_date->Date() + 1, pgg_ferti_p, true );
135  break;
136  }
138  }
139  SimpleEvent( g_date->Date() + 28, pgg_cut_to_hay, false );
140  break;
141 
142  case pgg_cut_to_hay:
143  if ( m_ev->m_lock || m_farm->DoIt( 70 ))
144  {
145  if (!m_farm->CutToHay( m_field, 0.0,
146  g_date->DayInYear( 15,8 ) - g_date->DayInYear())) {
147  SimpleEvent( g_date->Date() + 1, pgg_cut_to_hay, true );
148  break;
149  }
150  // did cut to hay so try turning
151  else
152  {
153  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15,6 ),
154  pgg_raking1, false );
156  }
157  break;
158  }
159  if (PGG_FERTI_DATE+28 < g_date->DayInYear( 15, 6 ))
160  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 6 ),
161  pgg_cattle_out2, false ); // 80% of non-cutters graze
162  else
164  pgg_cattle_out2, false ); // 80% of non-cutters graze
165 
166  break;
167 
168  case pgg_raking1:
169  if (PGG_CUT_DATE+20>=g_date->Date()) m_ev->m_lock=true;
170  if ( m_ev->m_lock || m_farm->DoIt( 50 ))
171  {
172  if (!m_farm->HayTurning( m_field, 0.0,
173  g_date->DayInYear( 15,8 ) - g_date->DayInYear()))
174  {
175  SimpleEvent( g_date->Date() + 1, pgg_raking1, true );
176  break;
177  }
178  SimpleEvent( g_date->Date()+1, pgg_raking2, false );
179  break;
180  }
181  // Did cut but not rake
182  // --FN--
183 
184  ChooseNextCrop (1);
185 
187  // 100% of these graze
188  break;
189 
190  case pgg_raking2:
191  if ( m_ev->m_lock || m_farm->DoIt( 25 ))
192  {
193  if (!m_farm->HayTurning( m_field, 0.0,
194  g_date->DayInYear( 16,8 ) - g_date->DayInYear())) {
195  SimpleEvent( g_date->Date() + 1, pgg_raking2, true );
196  break;
197  }
198  }
199  SimpleEvent( g_date->Date() + 1, pgg_compress_straw, false );
200  break;
201 
202  case pgg_compress_straw:
203  if (!m_farm->HayBailing( m_field, 0.0,
204  g_date->DayInYear( 17,8 ) - g_date->DayInYear()))
205  {
206  SimpleEvent( g_date->Date() + 1, pgg_compress_straw, true );
207  break;
208  }
209  // Did compress straw
210 
211  ChooseNextCrop (1);
212 
213  SimpleEvent( g_date->Date() + 21,
214  pgg_cattle_out1, false ); // cut but no straw so 100% graze
215  break;
216 
217  case pgg_cattle_out1:
218  if (m_field->GetMConstants(0)==0) {
219  if (!m_farm->CattleOut( m_field, 0.0, -1)) { //raise an error
220  g_msg->Warn( WARN_BUG, "PermanentGrassGrazed::Do(): failure in 'CattleOut' execution", "" );
221  exit( 1 );
222  }
223  }
224  else {
225  if (!m_farm->CattleOut( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
226  SimpleEvent( g_date->Date() + 1, pgg_cattle_out1, true );
227  break;
228  }
229  }
231  break;
232 
233  case pgg_cattle_out2:
234  if (( m_ev->m_lock || m_farm->DoIt( 33 )) || (PGG_FERTI_DATE!=0)) {
235  if (m_field->GetMConstants(0)==0) {
236  if (!m_farm->CattleOut( m_field, 0.0, -1)) { //raise an error
237  g_msg->Warn( WARN_BUG, "PermanentGrassGrazed::Do(): failure in 'CattleOut' execution", "" );
238  exit( 1 );
239  }
240  }
241  else {
242  if (!m_farm->CattleOut( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
243  SimpleEvent( g_date->Date() + 1, pgg_cattle_out2, true );
244  break;
245  }
246  }
247  // Success
249  break;
250  }
251  //Don't graze - but don't end too early;
252  SimpleEvent( g_date->OldDays() +g_date->DayInYear(2,7), pgg_wait, false );
253  break;
254 
255  case pgg_wait:
256  done=true;
257  break;
258 
259  case pgg_cattle_is_out:
260  if (m_field->GetMConstants(0)==0) {
261  if (!m_farm->CattleIsOut( m_field, 0.0, -1, m_field->GetMDates(1,0))) { //raise an error
262  //added 28.08 - issue a warning only if we fail on the last day that this can be done, i.e. MDate
263  if(g_date->Date() == m_field->GetMDates(1,0)){
264  g_msg->Warn( WARN_BUG, "PermanentGrassGrazed::Do(): failure in 'CattleIsOut' execution", "" );
265  exit( 1 );
266  }
267  }
268  }
269  else {
270  if (!m_farm->CattleIsOut( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear(), m_field->GetMDates(1,0))){
271  SimpleEvent( g_date->Date() + 1, pgg_cattle_is_out, true );
272  break;
273  }
274  }
275  // if they come in then send them out if too early
276  if (g_date->DayInYear()<g_date->DayInYear(10,9))
277  {
278  SimpleEvent( g_date->Date()+1, pgg_cattle_out2, true );
279  break;
280  }
281  SimpleEvent( g_date->OldDays() +g_date->DayInYear(15,6), pgg_herbicide, false );
282  break;
283 
284  case pgg_herbicide:
285  if (( m_ev->m_lock || m_farm->DoIt( (int) (5*cfg_herbi_app_prop.value() * m_farm->Prob_multiplier()))) && //modified probability
286  // --FN--
287  (g_date->DayInYear()<g_date->DayInYear(15,8)))
288  {
289  if (!m_farm->HerbicideTreat( m_field, 0.0, g_date->DayInYear( 15,8 ) - g_date->DayInYear())) {
290  // --FN--
291  SimpleEvent( g_date->Date() + 1, pgg_herbicide, true );
292  break;
293  }
294  }
296  pgg_cut_weeds, false );
297  break;
298 
299  case pgg_cut_weeds:
300  if (( m_ev->m_lock || m_farm->DoIt( 25 ))&&
301  //--FN--
302  (g_date->DayInYear()<g_date->DayInYear(15,9)))
303  {
304  if (!m_farm->CutWeeds( m_field, 0.0,
305  g_date->DayInYear( 15,9 ) - g_date->DayInYear())) {
306  // --FN--
307  SimpleEvent( g_date->Date() + 1, pgg_cut_weeds, true );
308  break;
309  }
310  }
311  // END MAIN THREAD
312  done = true;
313  break;
314 
315  default:
316  g_msg->Warn( WARN_BUG, "PermanantGrassGrazed::Do(): "
317  "Unknown event type! ", "" );
318  exit( 1 );
319  }
320 
321  return done;
322 }

References Farm::CattleIsOut(), Farm::CattleOut(), cfg_herbi_app_prop, Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Farm::CutToHay(), Farm::CutWeeds(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), Farm::FA_NPK(), Farm::FP_NPK(), g_date, g_msg, LE::GetMConstants(), LE::GetMDates(), Farm::GetType(), Calendar::GetYearNumber(), Farm::HayBailing(), Farm::HayTurning(), Farm::HerbicideTreat(), Farm::IsStockFarmer(), 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(), pgg_cattle_is_out, pgg_cattle_out1, pgg_cattle_out2, pgg_compress_straw, PGG_CUT_DATE, pgg_cut_to_hay, pgg_cut_weeds, PGG_FERTI_DATE, pgg_ferti_p, pgg_ferti_s, pgg_herbicide, pgg_raking1, pgg_raking2, pgg_start, pgg_wait, Farm::Prob_multiplier(), LE::SetLastSownVeg(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent(), tof_OptimisingFarm, CfgFloat::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void PermanentGrassGrazed::SetUpFarmCategoryInformation ( )
inline
63  {
64  const int elements = 2 + (pgg_foobar - PGG_BASE);
66 
67  FarmManagementCategory catlist[elements] =
68  {
69  fmc_Others, // zero element unused but must be here
70  fmc_Others, //pgg_start = 1, // Compulsory, start event must always be 1 (one).
71  fmc_Cutting, //pgg_cut_to_hay = PGG_BASE,
72  fmc_Grazing, //pgg_cattle_out1,
73  fmc_Grazing, //pgg_cattle_out2,
74  fmc_Grazing, //pgg_cattle_is_out,
75  fmc_Cutting, //pgg_cut_weeds,
76  fmc_Herbicide, //pgg_herbicide,
77  fmc_Fertilizer, //pgg_ferti_s,
78  fmc_Fertilizer, //pgg_ferti_p,
79  fmc_Others, //pgg_raking1,
80  fmc_Others, //pgg_raking2,
81  fmc_Others, //pgg_compress_straw,
82  fmc_Others //pgg_wait,
83  // No foobar entry
84  };
85  // Iterate over the catlist elements and copy them to vector
86  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
87  }

References fmc_Cutting, fmc_Fertilizer, fmc_Grazing, fmc_Herbicide, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, PGG_BASE, and pgg_foobar.

Referenced by PermanentGrassGrazed().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
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
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
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
pgg_cut_weeds
Definition: PermanentGrassGrazed.h:41
LE::GetMConstants
int GetMConstants(int a)
Definition: Elements.h:407
pgg_cut_to_hay
Definition: PermanentGrassGrazed.h:37
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::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
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
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
pgg_cattle_out1
Definition: PermanentGrassGrazed.h:38
fmc_Herbicide
Definition: LandscapeFarmingEnums.h:1006
PermanentGrassGrazed::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: PermanentGrassGrazed.h:63
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
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
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
Farm::Prob_multiplier
virtual double Prob_multiplier()
Definition: Farm.h:778
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
cfg_herbi_app_prop
CfgFloat cfg_herbi_app_prop
Calendar::Date
long Date(void)
Definition: Calendar.h:57
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
pgg_ferti_s
Definition: PermanentGrassGrazed.h:43
PGG_BASE
#define PGG_BASE
Definition: PermanentGrassGrazed.h:31
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
pgg_compress_straw
Definition: PermanentGrassGrazed.h:47
pgg_raking1
Definition: PermanentGrassGrazed.h:45
pgg_wait
Definition: PermanentGrassGrazed.h:48
pgg_cattle_is_out
Definition: PermanentGrassGrazed.h:40
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
pgg_raking2
Definition: PermanentGrassGrazed.h:46
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
pgg_foobar
Definition: PermanentGrassGrazed.h:49
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
pgg_herbicide
Definition: PermanentGrassGrazed.h:42
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
PGG_CUT_DATE
#define PGG_CUT_DATE
Definition: PermanentGrassGrazed.h:32
pgg_cattle_out2
Definition: PermanentGrassGrazed.h:39
LE::SetMConstants
void SetMConstants(int a, int c)
Definition: Elements.h:408
pgg_start
Definition: PermanentGrassGrazed.h:36
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
PGG_FERTI_DATE
#define PGG_FERTI_DATE
Definition: PermanentGrassGrazed.h:33
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
pgg_ferti_p
Definition: PermanentGrassGrazed.h:44
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
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