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

#include <OSeedGrass1.h>

Inheritance diagram for OSeedGrass1:
Crop

Public Member Functions

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

◆ OSeedGrass1()

OSeedGrass1::OSeedGrass1 ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
52  : Crop(a_tov, a_toc, a_L)
53  {
56  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

37 {
38  // NB IF SEED GRASS IS USED IN A ROTATION IT MUST FOLLOW AN UNDERSOWN CROP!!!
39 
40  m_farm = a_farm;
41  m_field = a_field;
42  m_ev = a_ev;
43 
44  bool done = false;
45 
46  switch ( m_ev->m_todo ) {
47  case osg1_start:
48  {
49  // End date checking block.
51  a_field->ClearManagementActionSum();
52 
53  // Set up the date management stuff
55  // Start and stop dates for all events after harvest
56  int noDates= 4;
57  m_field->SetMDates(0,0,g_date->DayInYear(10,7));
58  // Determined by harvest date - used to see if at all possible
59  m_field->SetMDates(1,0,g_date->DayInYear(20,7));
60  m_field->SetMDates(0,1,g_date->DayInYear(11,7));
61  m_field->SetMDates(1,1,g_date->DayInYear(25,7));
62  m_field->SetMDates(0,2,g_date->DayInYear(26,7));
63  m_field->SetMDates(1,2,g_date->DayInYear(20,7));
64  m_field->SetMDates(0,3,g_date->DayInYear(15,7));
65  m_field->SetMDates(1,3,g_date->DayInYear(15,8));
66  // Check the next crop for early start, unless it is a spring crop
67  // in which case we ASSUME that no checking is necessary!!!!
68  // So DO NOT implement a crop that runs over the year boundary
69 
70  //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)
71  int d1;
73 
74  if (m_ev->m_startday>g_date->DayInYear(1,7))
75  {
76  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
77  {
78  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): "
79  "Harvest too late for the next crop to start!!!", "" );
80  exit( 1 );
81  }
82  // Now fix any late finishing problems
83  for (int i=0; i<noDates; i++) {
84  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
85  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
86  }
87  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
88  m_field->SetMConstants(i,0);
89  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
90  }
91  }
92  }
93  // Now no operations can be timed after the start of the next crop.
94 
95  int today=g_date->Date();
96  d1 = g_date->OldDays() + m_first_date;
97  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
98  if (today > d1)
99  {
100  // Yes too late - should not happen - raise an error
101  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): "
102  "Crop start attempt after last possible start date", "" );
103  exit( 1 );
104  }
105  }//if
106 
107  // Reinit d1 to first possible starting date.
108  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
109  if ( g_date->Date() > d1 ) {
110  d1 = g_date->Date();
111  }
112  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
113  // OK, let's go.
114  SimpleEvent( d1, osg1_ferti_zero, false );
115  break;
116  }
117 
118  case osg1_ferti_zero:
119  if ( m_ev->m_lock || m_farm->DoIt( 60 )) {
120  if (!m_farm->FP_NPK( m_field, 0.0,
121  g_date->DayInYear( 15, 4 ) -
122  g_date->DayInYear())) {
123  SimpleEvent( g_date->Date() + 1, osg1_ferti_zero, true );
124  break;
125  }
126  }
127  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 5 ),
128  osg1_water_zero, false );
129  break;
130 
131  case osg1_water_zero:
132  if ( m_ev->m_lock || m_farm->DoIt( 70 ))
133  {
134  if ( !m_farm->Water( m_field, 0.0,
135  g_date->DayInYear( 30, 5 ) -
136  g_date->DayInYear())) {
137  SimpleEvent( g_date->Date() + 1, osg1_water_zero, true );
138  break;
139  }
141  {
142  int d1 = g_date->Date() + 7;
143  if ( d1 > g_date->OldDays() + g_date->DayInYear( 1, 6 ))
144  d1 = g_date->OldDays() + g_date->DayInYear( 1, 6 );
145  SimpleEvent( d1, osg1_water_zero_b, true );
146  break;
147  }
148  }
149  // Didn't do first water, so skip the second one too.
150  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10, 7 ),
151  osg1_swarth, false );
152  break;
153 
154  case osg1_water_zero_b:
155  if ( m_ev->m_lock )
156  {
157  if ( !m_farm->Water( m_field, 0.0, g_date->DayInYear( 30, 6 ) - g_date->DayInYear()))
158  {
159  SimpleEvent( g_date->Date() + 1, osg1_water_zero_b, true );
160  break;
161  }
163  }
164  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10, 7 ),
165  osg1_swarth, false );
166  break;
167 
168  case osg1_swarth:
169  if ( m_ev->m_lock || m_farm->DoIt( 5 )) {
170  if ( !m_farm->Swathing( m_field, 0.0,
171  g_date->DayInYear( 15, 7 ) -
172  g_date->DayInYear())) {
173  SimpleEvent( g_date->Date() + 1, osg1_swarth, true );
174  break;
175  }
176  ChooseNextCrop (4);
177  SimpleEvent( g_date->Date() + 2, osg1_harvest, false );
178  break;
179  }
180  ChooseNextCrop (4);
181  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10, 7 ), osg1_harvest, false );
182  break;
183 
184  case osg1_harvest:
185  if (m_field->GetMConstants(0)==0) {
186  if (!m_farm->Harvest( m_field, 0.0, -1)) { //raise an error
187  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): failure in 'Harvest' execution", "" );
188  exit( 1 );
189  }
190  }
191  else {
192  if ( !m_farm->Harvest( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
193  SimpleEvent( g_date->Date() + 1, osg1_harvest, false );
194  break;
195  }
196  }
197 
199  break;
200 
201  case osg1_strawchopping:
202  if ( m_ev->m_lock || m_farm->DoIt( 30 )) {
203  if (m_field->GetMConstants(0)==0) {
204  if (!m_farm->StrawChopping( m_field, 0.0, -1)) { //raise an error
205  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): failure in 'StrawChopping' execution", "" );
206  exit( 1 );
207  }
208  }
209  else {
210  if ( !m_farm->StrawChopping( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
211  SimpleEvent( g_date->Date() + 1, osg1_strawchopping, true );
212  break;
213  }
214  }
215  done = true;
216  break;
217  }
218 
219  {
220  int d1 = g_date->Date()+1;
221  int d2 = g_date->OldDays() + m_field->GetMDates(0,1);
222  if (d1>d2) d1=d2;
223  SimpleEvent( d1, osg1_compress, false );
224  }
225  break;
226 
227  case osg1_compress:
228  if ( m_ev->m_lock || m_farm->DoIt( 60 )) {
229  if (m_field->GetMConstants(1)==0) {
230  if (!m_farm->HayTurning( m_field, 0.0, -1)) { //raise an error
231  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): failure in 'HayTurning' execution", "" );
232  exit( 1 );
233  }
234  }
235  else {
236  if ( !m_farm->HayTurning( m_field, 0.0, m_field->GetMDates(1,1) - g_date->DayInYear())) {
237  SimpleEvent( g_date->Date() + 1, osg1_compress, true );
238  break;
239  }
240  }
241  }
242  {
243  int d1 = g_date->Date();
244  if ( d1 < g_date->OldDays() + m_field->GetMDates(0,3))
245  d1 = g_date->OldDays() + m_field->GetMDates(0,3);
246  SimpleEvent( d1, osg1_burn_straw, false );
247  }
248  break;
249 
250  case osg1_burn_straw:
251  if ( m_ev->m_lock || m_farm->DoIt( 60 )) {
252  if (m_field->GetMConstants(3)==0) {
253  if (!m_farm->BurnStrawStubble( m_field, 0.0, -1)) { //raise an error
254  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): failure in 'BurnStrawStubble' execution", "" );
255  exit( 1 );
256  }
257  }
258  else {
259  if ( !m_farm->BurnStrawStubble( m_field, 0.0,m_field->GetMDates(1,3) - g_date->DayInYear())) {
260  SimpleEvent( g_date->Date() + 1, osg1_burn_straw, true );
261  break;
262  }
263  }
264  }
265  done = true;
266  break;
267 
268  default:
269  g_msg->Warn( WARN_BUG, "OSeedGrass1::Do(): " "Unknown event type! ", "" );
270  exit( 1 );
271  }
272 
273  return done;
274 }

References Farm::BurnStrawStubble(), Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), Farm::FP_NPK(), g_date, g_msg, LE::GetMConstants(), LE::GetMDates(), Farm::GetType(), Calendar::GetYearNumber(), Farm::Harvest(), Farm::HayTurning(), 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(), osg1_burn_straw, osg1_compress, osg1_ferti_zero, osg1_harvest, osg1_start, osg1_strawchopping, osg1_swarth, osg1_water_zero, osg1_water_zero_b, LE::SetLastSownVeg(), LE::SetMConstants(), LE::SetMDates(), SG1_WATER_DATE, Crop::SimpleEvent(), Farm::StrawChopping(), Farm::Swathing(), tof_OptimisingFarm, MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void OSeedGrass1::SetUpFarmCategoryInformation ( )
inline
57  {
58  const int elements = 2 + (osg1_foobar - OSEEDGRASS1_BASE);
60 
61  FarmManagementCategory catlist[elements] =
62  {
63  fmc_Others, // zero element unused but must be here
64  fmc_Others, // osg1_start = 1, // Compulsory, start event must always be 1 (one).
65  fmc_Fertilizer, // osg1_ferti_zero = OSEEDGRASS1_BASE,
66  fmc_Watering, // osg1_water_zero,
67  fmc_Watering, // osg1_water_zero_b,
68  fmc_Cutting, // osg1_swarth,
69  fmc_Harvest, // osg1_harvest,
70  fmc_Others, // osg1_strawchopping,
71  fmc_Others, // osg1_compress,
72  fmc_Others // osg1_burn_straw,
73 
74 
75  // no foobar entry
76 
77  };
78  // Iterate over the catlist elements and copy them to vector
79  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
80 
81  }

References fmc_Cutting, fmc_Fertilizer, fmc_Harvest, fmc_Others, fmc_Watering, Crop::m_base_elements_no, Crop::m_ManagementCategories, OSEEDGRASS1_BASE, and osg1_foobar.

Referenced by OSeedGrass1().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
osg1_foobar
Definition: OSeedGrass1.h:43
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
SG1_WATER_DATE
#define SG1_WATER_DATE
Definition: OSeedGrass1.h:31
LE::SetLastSownVeg
void SetLastSownVeg(TTypesOfVegetation a_tov)
Records the last vegetation type to be sown.
Definition: Elements.h:357
Farm::Harvest
virtual bool Harvest(LE *a_field, double a_user, int a_days)
Carry out a harvest on a_field.
Definition: FarmFuncs.cpp:1364
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::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
Farm::GetType
TTypesOfFarm GetType(void)
Definition: Farm.h:956
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
osg1_ferti_zero
Definition: OSeedGrass1.h:35
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
osg1_swarth
Definition: OSeedGrass1.h:38
osg1_harvest
Definition: OSeedGrass1.h:39
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
OSEEDGRASS1_BASE
#define OSEEDGRASS1_BASE
Definition: OSeedGrass1.h:30
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
osg1_compress
Definition: OSeedGrass1.h:41
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
Farm::StrawChopping
virtual bool StrawChopping(LE *a_field, double a_user, int a_days)
Carry out straw chopping on a_field.
Definition: FarmFuncs.cpp:1475
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
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
osg1_start
Definition: OSeedGrass1.h:34
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
OSeedGrass1::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OSeedGrass1.h:57
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
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
osg1_water_zero_b
Definition: OSeedGrass1.h:37
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
osg1_burn_straw
Definition: OSeedGrass1.h:42
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
Farm::BurnStrawStubble
virtual bool BurnStrawStubble(LE *a_field, double a_user, int a_days)
Burn stubble on a_field.
Definition: FarmFuncs.cpp:1567
osg1_strawchopping
Definition: OSeedGrass1.h:40
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
osg1_water_zero
Definition: OSeedGrass1.h:36
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
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
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001