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

#include <PermanentGrassTussocky.h>

Inheritance diagram for PermanentGrassTussocky:
Crop

Public Member Functions

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

◆ PermanentGrassTussocky()

PermanentGrassTussocky::PermanentGrassTussocky ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline

Member Function Documentation

◆ Do()

bool PermanentGrassTussocky::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  bool done = false;
44 
45  switch ( m_ev->m_todo ) {
46  case pgt_start:
47  {
48  a_field->ClearManagementActionSum();
49  PGT_CUT_DATE =0;
51  // Set up the date management stuff
53  // Start and stop dates for all events after harvest
54  int noDates= 1;
55  // Start and stop dates for all events after harvest
56  m_field->SetMDates(0,0,g_date->DayInYear(15,9));
57  // 0,0 determined by harvest date - used to see if at all possible
58  m_field->SetMDates( 1, 0, g_date->DayInYear(1,10) );
59  // Check the next crop for early start, unless it is a spring crop
60  // in which case we ASSUME that no checking is necessary!!!!
61  // So DO NOT implement a crop that runs over the year boundary
62 
63  //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)
64  int d1;
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, "PermanentGrassTussocky::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 
88  int today=g_date->Date();
89  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
90  if (today > d1)
91  {
92  // Yes too late - should not happen - raise an error
93  g_msg->Warn( WARN_BUG, " PermanentGrassTussocky::Do(): "
94  "Crop start attempt after last possible start date", "" );
95  exit( 1 );
96  }
97  }//if
98 
99  // Reinit d1 to first possible starting date.
100  d1 = g_date->OldDays()+m_first_date;;
101  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
102  if ( g_date->Date() > d1 ) {
103  d1 = g_date->Date();
104  }
105  // OK, let's go.
106  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
107 
108  ChooseNextCrop (1);
109 
110  SimpleEvent( d1, pgt_cattle_out1, false );
111  }
112  break;
113 
114  case pgt_cattle_out1:
115  if (m_field->GetMConstants(0)==0) {
116  if (!m_farm->CattleOutLowGrazing( m_field, 0.0, -1)) { //raise an error
117  g_msg->Warn( WARN_BUG, "PermanentGrassTussocky::Do(): failure in 'CattleOutLowGrazing' execution", "" );
118  exit( 1 );
119  }
120  }
121  else {
123  SimpleEvent( g_date->Date() + 1, pgt_cattle_out1, true );
124  break;
125  }
126  }
128  break;
129 
130  case pgt_cattle_out2:
131  if (( m_ev->m_lock || m_farm->DoIt( 33 )) || (PGT_FERTI_DATE!=0)) {
132  if (m_field->GetMConstants(0)==0) {
133  if (!m_farm->CattleOutLowGrazing( m_field, 0.0, -1)) { //raise an error
134  g_msg->Warn( WARN_BUG, "PermanentGrassTussocky::Do(): failure in 'CattleOutLowGrazing' execution", "" );
135  exit( 1 );
136  }
137  }
138  else {
140  SimpleEvent( g_date->Date() + 1, pgt_cattle_out2, true );
141  break;
142  }
143  }
144  // Success
146  break;
147  }
148  //Don't graze - but don't end too early;
149  SimpleEvent( g_date->OldDays() +g_date->DayInYear(2,7), pgt_wait, false );
150  break;
151 
152  case pgt_wait:
153  done=true;
154  break;
155 
156  case pgt_cattle_is_out:
157  if (m_field->GetMConstants(0)==0) {
158  if (!m_farm->CattleIsOutLow( m_field, 0.0, -1, m_field->GetMDates(1,0))) { //raise an error
159  //added 28.08 - issue a warning only if we fail on the last day that this can be done, i.e. MDate
160  if(g_date->Date() == m_field->GetMDates(1,0)){
161  g_msg->Warn( WARN_BUG, "PermanentGrassTussocky::Do(): failure in 'CattleIsOutLow' execution", "" );
162  exit( 1 );
163  }
164  }
165  }
166  else {
167  if (!m_farm->CattleIsOutLow( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear(), m_field->GetMDates(1,0))) {
168  SimpleEvent( g_date->Date() + 1, pgt_cattle_is_out, true );
169  break;
170  }
171  }
172  // if they come in then send them out if too early
173  if (g_date->DayInYear()<g_date->DayInYear(10,9))
174  {
175  SimpleEvent( g_date->Date()+1, pgt_cattle_out2, true );
176  break;
177  }
178  // END MAIN THREAD
179  done=true;
180  break;
181 
182  default:
183  g_msg->Warn( WARN_BUG, "PermanantGrassTussocky::Do(): "
184  "Unknown event type! ", "" );
185  exit( 1 );
186  }
187 
188  return done;
189 }

References Farm::CattleIsOutLow(), Farm::CattleOutLowGrazing(), Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), g_date, g_msg, LE::GetMConstants(), LE::GetMDates(), Farm::GetType(), Calendar::GetYearNumber(), 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(), pgt_cattle_is_out, pgt_cattle_out1, pgt_cattle_out2, PGT_CUT_DATE, PGT_FERTI_DATE, pgt_start, pgt_wait, LE::SetLastSownVeg(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent(), tof_OptimisingFarm, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void PermanentGrassTussocky::SetUpFarmCategoryInformation ( )
inline
55  {
56  const int elements = 2 + (pgt_foobar - PGT_BASE);
58 
59  FarmManagementCategory catlist[elements] =
60  {
61  fmc_Others, // zero element unused but must be here
62  fmc_Others,
67  // No foobar entry
68  };
69  // Iterate over the catlist elements and copy them to vector
70  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
71  }

References fmc_Grazing, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, PGT_BASE, and pgt_foobar.

Referenced by PermanentGrassTussocky().


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
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
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
pgt_cattle_out2
Definition: PermanentGrassTussocky.h:38
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
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::CattleIsOutLow
virtual bool CattleIsOutLow(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out_low' event for every day the cattle are on a_field.
Definition: FarmFuncs.cpp:2561
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
Farm::CattleOutLowGrazing
virtual bool CattleOutLowGrazing(LE *a_field, double a_user, int a_days)
Start a extensive grazing event on a_field today.
Definition: FarmFuncs.cpp:2439
PGT_BASE
#define PGT_BASE
Definition: PermanentGrassTussocky.h:31
pgt_foobar
Definition: PermanentGrassTussocky.h:41
PGT_FERTI_DATE
#define PGT_FERTI_DATE
Definition: PermanentGrassTussocky.h:33
pgt_cattle_out1
Definition: PermanentGrassTussocky.h:37
pgt_wait
Definition: PermanentGrassTussocky.h:40
Calendar::Date
long Date(void)
Definition: Calendar.h:57
PGT_CUT_DATE
#define PGT_CUT_DATE
Definition: PermanentGrassTussocky.h:32
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
pgt_cattle_is_out
Definition: PermanentGrassTussocky.h:39
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
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
PermanentGrassTussocky::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: PermanentGrassTussocky.h:55
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
pgt_start
Definition: PermanentGrassTussocky.h:36
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
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: Farm.cpp:756
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001