ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
SeedGrass2 Class Reference

#include <seedgrass2.h>

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 SeedGrass2 ()
 
- Public Member Functions inherited from Crop
void ChooseNextCrop (int a_no_dates)
 Chooses the next crop to grow in a field. More...
 
 Crop ()
 
int GetCropClassification ()
 
int GetFirstDate (void)
 
void SetCropClassification (int a_classification)
 
virtual ~Crop ()
 

Additional Inherited Members

- 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...
 
- Protected Attributes inherited from Crop
int m_count
 
int m_CropClassification
 
int m_ddegstoharvest
 
FarmEventm_ev
 
Farmm_farm
 
LE * m_field
 
int m_first_date
 
int m_last_date
 

Detailed Description

Definition at line 55 of file seedgrass2.h.

Constructor & Destructor Documentation

◆ SeedGrass2()

SeedGrass2::SeedGrass2 ( )
inline

Definition at line 59 of file seedgrass2.h.

60  {
61  m_first_date=g_date->DayInYear(14,3);
62  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

Definition at line 37 of file seedgrass2.cpp.

38 {
39  m_farm = a_farm;
40  m_field = a_field;
41  m_ev = a_ev;
42  int d1;
43 
44  bool done = false;
45 
46  switch ( m_ev->m_todo ) {
47  case sg2_start:
48  {
49  SG2_WATER_DATE = g_date->Date();
50  SG2_FUNGI_DATE = g_date->Date();
52  // Set up the date management stuff
53  m_last_date=g_date->DayInYear(15,8);
54  // Start and stop dates for all events after harvest
55  int noDates= 5;
56  m_field->SetMDates(0,0,g_date->DayInYear(10,7));
57  // Determined by harvest date - used to see if at all possible
58  m_field->SetMDates(1,0,g_date->DayInYear(20,7));
59  m_field->SetMDates(0,1,g_date->DayInYear(11,7));
60  m_field->SetMDates(1,1,g_date->DayInYear(25,7));
61  m_field->SetMDates(0,2,g_date->DayInYear(26,7));
62  m_field->SetMDates(1,2,g_date->DayInYear(20,7));
63  m_field->SetMDates(0,3,g_date->DayInYear(15,7));
64  m_field->SetMDates(1,3,g_date->DayInYear(15,8));
65  m_field->SetMDates(0,4,g_date->DayInYear(15,8));
66  m_field->SetMDates(1,4,g_date->DayInYear(20,8));
67  // Check the next crop for early start, unless it is a spring crop
68  // in which case we ASSUME that no checking is necessary!!!!
69  // So DO NOT implement a crop that runs over the year boundary
70 
71  //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)
72  if(!(m_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber()>0)){
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, "SeedGrass2::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  int today=g_date->Date();
95  d1 = g_date->OldDays() + m_first_date;
96  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
97  if (today > d1)
98  {
99  // Yes too late - should not happen - raise an error
100  g_msg->Warn( WARN_BUG, "SeedGrass2::Do(): "
101  "Crop start attempt after last possible start date", "" );
102  exit( 1 );
103  }
104  }//if
105 
106  // Reinit d1 to first possible starting date.
107  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
108  if ( g_date->Date() > d1 ) {
109  d1 = g_date->Date();
110  }
111  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
112  // OK, let's go.
113  SimpleEvent( d1, sg2_ferti_zero, false );
114  }
115  break;
116 
117  case sg2_ferti_zero:
118  if ( m_ev->m_lock || m_farm->DoIt( 60 )) {
119  if (!m_farm->FP_NPK( m_field, 0.0,
120  g_date->DayInYear( 15, 4 ) -
121  g_date->DayInYear())) {
122  SimpleEvent( g_date->Date() + 1, sg2_ferti_zero, true );
123  break;
124  }
125  }
126  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 4 ),
127  sg2_herbi_zero, false );
128  break;
129 
130  case sg2_herbi_zero:
131  if ( m_ev->m_lock || m_farm->DoIt( (int) (75*cfg_herbi_app_prop.value() * m_farm->Prob_multiplier()))) { //modified probability
132 
133  //new - for decision making
134  TTypesOfVegetation tov = m_field->GetVegType();
135  if(!m_ev->m_lock && !m_farm->Spraying_herbicides(tov)){
136  Field * pf = dynamic_cast<Field*>(m_field);
137  pf->Add_missed_herb_app();
138  if(m_farm->DoIt(67)) pf->Add_missed_herb_app(); //the 2nd missed application
140  } //end of the part for dec. making
141  else{
142  if (!m_farm->HerbicideTreat( m_field, 0.0, g_date->DayInYear( 25, 4 ) - g_date->DayInYear())) {
143  SimpleEvent( g_date->Date() + 1, sg2_herbi_zero, true );
144  break;
145  }
146  }
147  }
148  SimpleEvent( g_date->OldDays() + g_date->DayInYear() + 14,
149  sg2_herbi_one, false );
150  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 20, 5 ),
151  sg2_fungi_zero, false );
152  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 5 ),
153  sg2_water_zero, false );
154  break;
155 
156  case sg2_herbi_one:
157  if ( m_ev->m_lock || m_farm->DoIt( (int) (67*cfg_herbi_app_prop.value() * SG2_DECIDE_TO_HERB * m_farm->Prob_multiplier()))) { //modified probability
158  if (!m_farm->HerbicideTreat( m_field, 0.0, g_date->DayInYear( 25, 4 ) - g_date->DayInYear())) {
159  SimpleEvent( g_date->Date() + 1, sg2_herbi_zero, true );
160  break;
161  }
162  }
163  break;
164 
165  case sg2_fungi_zero:
166  if ( m_ev->m_lock || m_farm->DoIt( (int) (17 * m_farm->Prob_multiplier()) )) { //modified probability
167 
168  //new - for decision making
169  TTypesOfVegetation tov = m_field->GetVegType();
170  if(!m_ev->m_lock && !m_farm->Spraying_fungins(tov)){
171  Field * pf = dynamic_cast<Field*>(m_field);
172  pf->Add_missed_fi_app();
173  break;
174  } //end of the part for dec. making
175 
176  if ( SG2_WATER_DATE > g_date->Date() - 2 && SG2_WATER_DATE < g_date->Date() + 2 ) {
177  SimpleEvent( g_date->Date() + 1, sg2_fungi_zero, true );
178  break;
179  }
180  if ( !m_farm->FungicideTreat( m_field, 0.0,
181  g_date->DayInYear( 1, 6 ) -
182  g_date->DayInYear())) {
183  SimpleEvent( g_date->Date() + 1, sg2_fungi_zero, true );
184  break;
185  }
186  SG2_FUNGI_DATE = g_date->Date();
187  }
188  // End of thread.
189  break;
190 
191  case sg2_water_zero:
192  if ( m_ev->m_lock || m_farm->DoIt( 70 )) {
193  if ( SG2_FUNGI_DATE > g_date->Date() - 2 &&
194  SG2_FUNGI_DATE < g_date->Date() + 2 ) {
195  SimpleEvent( g_date->Date() + 1, sg2_water_zero, true );
196  break;
197  }
198  if ( !m_farm->Water( m_field, 0.0,
199  g_date->DayInYear( 30, 5 ) -
200  g_date->DayInYear())) {
201  SimpleEvent( g_date->Date() + 1, sg2_water_zero, true );
202  break;
203  }
204  SG2_WATER_DATE = g_date->Date();
205  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 6 ),
206  sg2_water_zero_b, false );
207  break;
208  }
209  // Din't water, so skip second one too.
210  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10, 7 ),
211  sg2_swarth, false );
212  break;
213 
214  case sg2_water_zero_b:
215  if ( m_ev->m_lock || m_farm->DoIt( 70 )) {
216  if ( SG2_FUNGI_DATE > g_date->Date() - 2 &&
217  SG2_FUNGI_DATE < g_date->Date() + 2 ) {
218  SimpleEvent( g_date->Date() + 1, sg2_water_zero_b, true );
219  break;
220  }
221  if ( !m_farm->Water( m_field, 0.0,
222  g_date->DayInYear( 30, 6 ) -
223  g_date->DayInYear())) {
224  SimpleEvent( g_date->Date() + 1, sg2_water_zero_b, true );
225  break;
226  }
227  SG2_WATER_DATE = g_date->Date();
228  }
229  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10, 7 ),
230  sg2_swarth, false );
231  break;
232 
233  case sg2_swarth:
234  if ( m_ev->m_lock || m_farm->DoIt( 5 )) {
235  if ( !m_farm->Swathing( m_field, 0.0,
236  g_date->DayInYear( 15, 7 ) -
237  g_date->DayInYear())) {
238  SimpleEvent( g_date->Date() + 1, sg2_swarth, true );
239  break;
240  }
241 
242  ChooseNextCrop (5);
243 
244  SimpleEvent( g_date->Date() + 2, sg2_harvest, false );
245  break;
246  }
247 
248  ChooseNextCrop (5);
249 
250  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 10, 7 ),
251  sg2_harvest, false );
252  break;
253 
254  case sg2_harvest:
255  if (m_field->GetMConstants(0)==0) {
256  if (!m_farm->Harvest( m_field, 0.0, -1)) { //raise an error
257  g_msg->Warn( WARN_BUG, "SeedGrass2::Do(): failure in 'Harvest' execution", "" );
258  exit( 1 );
259  }
260  }
261  else {
262  if ( !m_farm->Harvest( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
263  SimpleEvent( g_date->Date() + 1, sg2_harvest, false );
264  break;
265  }
266  }
267  SimpleEvent( g_date->Date(), sg2_strawchopping, false );
268  break;
269 
270  case sg2_strawchopping:
271  if ( m_ev->m_lock || m_farm->DoIt( 30 )) {
272  if (m_field->GetMConstants(0)==0) {
273  if (!m_farm->StrawChopping( m_field, 0.0, -1)) { //raise an error
274  g_msg->Warn( WARN_BUG, "SeedGrass2::Do(): failure in 'StrawChopping' execution", "" );
275  exit( 1 );
276  }
277  }
278  else {
279  if ( !m_farm->StrawChopping( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
280  SimpleEvent( g_date->Date() + 1, sg2_strawchopping, true );
281  break;
282  }
283  }
284  done=true;
285  break;
286  }
287  SimpleEvent( g_date->Date()+1, sg2_compress, false );
288  break;
289 
290  case sg2_compress:
291  if ( m_ev->m_lock || m_farm->DoIt( 60 )) {
292  if (m_field->GetMConstants(1)==0) {
293  if (!m_farm->HayTurning( m_field, 0.0, -1)) { //raise an error
294  g_msg->Warn( WARN_BUG, "SeedGrass2::Do(): failure in 'HayTurning' execution", "" );
295  exit( 1 );
296  }
297  }
298  else {
299  if ( !m_farm->HayTurning( m_field, 0.0, m_field->GetMDates(1,1) - g_date->DayInYear())) {
300  SimpleEvent( g_date->Date() + 1, sg2_compress, true );
301  break;
302  }
303  }
304  }
305  {
306  d1 = g_date->Date();
307  if ( d1 < g_date->OldDays() + m_field->GetMDates(0,3))
308  d1 = g_date->OldDays() + m_field->GetMDates(0,3);
309  SimpleEvent( d1, sg2_burnstrawstubble, false );
310  }
311  break;
312 
314  if ( m_ev->m_lock || m_farm->DoIt( 70 )) {
315  if (m_field->GetMConstants(3)==0) {
316  if (!m_farm->BurnStrawStubble( m_field, 0.0, -1)) { //raise an error
317  g_msg->Warn( WARN_BUG, "SeedGrass2::Do(): failure in 'BurnStrawStubble' execution", "" );
318  exit( 1 );
319  }
320  }
321  else {
322  if ( !m_farm->BurnStrawStubble( m_field, 0.0, m_field->GetMDates(1,3) - g_date->DayInYear())) {
323  SimpleEvent( g_date->Date() + 1, sg2_burnstrawstubble, true );
324  break;
325  }
326  }
327  done = true;
328  break;
329  }
330  SimpleEvent( g_date->Date(), sg2_growthregulation, false );
331  break;
332 
334  if ( m_ev->m_lock || m_farm->DoIt( 20 )) {
335  if (m_field->GetMConstants(4)==0) {
336  if (!m_farm->GrowthRegulator( m_field, 0.0, -1)) { //raise an error
337  g_msg->Warn( WARN_BUG, "SeedGrass2::Do(): failure in 'GrowthRegulator' execution", "" );
338  exit( 1 );
339  }
340  }
341  else {
342  if ( !m_farm->GrowthRegulator( m_field, 0.0, m_field->GetMDates(0,4) - g_date->DayInYear())) {
343  SimpleEvent( g_date->Date() + 1, sg2_growthregulation, true );
344  break;
345  }
346  }
347  done=true;
348  }
349  SimpleEvent( g_date->Date(), sg2_stubbleharrow, false );
350  break;
351 
352  case sg2_stubbleharrow:
353  if (m_field->GetMConstants(4)==0) {
354  if (!m_farm->StubbleHarrowing( m_field, 0.0, -1)) { //raise an error
355  g_msg->Warn( WARN_BUG, "SeedGrass2::Do(): failure in 'StubbleHarrowing' execution", "" );
356  exit( 1 );
357  }
358  }
359  else {
360  if ( !m_farm->StubbleHarrowing( m_field, 0.0, m_field->GetMDates(1,4) - g_date->DayInYear())) {
361  SimpleEvent( g_date->Date() + 1, sg2_stubbleharrow, true );
362  break;
363  }
364  }
365  done=true;
366  break;
367 
368  default:
369  g_msg->Warn( WARN_BUG, "SeedGrass2::Do(): "
370  "Unknown event type! ", "" );
371  exit( 1 );
372  }
373 
374  return done;
375 }

References Farm::BurnStrawStubble(), cfg_herbi_app_prop, Crop::ChooseNextCrop(), Farm::DoIt(), Farm::FP_NPK(), Farm::FungicideTreat(), Farm::GetType(), Farm::GrowthRegulator(), Farm::Harvest(), 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, Farm::Prob_multiplier(), sg2_burnstrawstubble, sg2_compress, SG2_DECIDE_TO_HERB, sg2_ferti_zero, SG2_FUNGI_DATE, sg2_fungi_zero, sg2_growthregulation, sg2_harvest, sg2_herbi_one, sg2_herbi_zero, sg2_start, sg2_strawchopping, sg2_stubbleharrow, sg2_swarth, SG2_WATER_DATE, sg2_water_zero, sg2_water_zero_b, Crop::SimpleEvent(), Farm::Spraying_fungins(), Farm::Spraying_herbicides(), Farm::StrawChopping(), Farm::StubbleHarrowing(), Farm::Swathing(), tof_OptimisingFarm, and Farm::Water().


The documentation for this class was generated from the following files:
Farm::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: farmfuncs.cpp:1156
sg2_water_zero_b
Definition: seedgrass2.h:43
sg2_water_zero
Definition: seedgrass2.h:42
Farm::Harvest
virtual bool Harvest(LE *a_field, double a_user, int a_days)
Carry out a harvest on a_field.
Definition: farmfuncs.cpp:1769
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
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:629
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
sg2_ferti_zero
Definition: seedgrass2.h:38
tof_OptimisingFarm
Definition: farm.h:273
sg2_fungi_zero
Definition: seedgrass2.h:41
sg2_herbi_one
Definition: seedgrass2.h:40
sg2_compress
Definition: seedgrass2.h:48
sg2_harvest
Definition: seedgrass2.h:45
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
Farm::FungicideTreat
virtual bool FungicideTreat(LE *a_field, double a_user, int a_days)
Apply fungicide to a_field.
Definition: farmfuncs.cpp:1279
sg2_herbi_zero
Definition: seedgrass2.h:39
sg2_stubbleharrow
Definition: seedgrass2.h:50
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
Farm::Prob_multiplier
virtual double Prob_multiplier()
Definition: farm.h:786
TTypesOfVegetation
TTypesOfVegetation
Definition: tov_declaration.h:30
sg2_start
Definition: seedgrass2.h:37
Farm::Spraying_herbicides
virtual bool Spraying_herbicides(TTypesOfVegetation)
Definition: farm.h:784
Farm::StrawChopping
virtual bool StrawChopping(LE *a_field, double a_user, int a_days)
Carry out straw chopping on a_field.
Definition: farmfuncs.cpp:2132
sg2_growthregulation
Definition: seedgrass2.h:49
sg2_swarth
Definition: seedgrass2.h:44
SG2_FUNGI_DATE
#define SG2_FUNGI_DATE
Definition: seedgrass2.h:33
Crop::m_farm
Farm * m_farm
Definition: farm.h:537
Crop::m_field
LE * m_field
Definition: farm.h:538
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
Farm::Water
virtual bool Water(LE *a_field, double a_user, int a_days)
Carry out a watering on a_field.
Definition: farmfuncs.cpp:1717
Crop::m_last_date
int m_last_date
Definition: farm.h:542
SG2_DECIDE_TO_HERB
#define SG2_DECIDE_TO_HERB
Definition: seedgrass2.h:34
Farm::GrowthRegulator
virtual bool GrowthRegulator(LE *a_field, double a_user, int a_days)
Apply growth regulator to a_field.
Definition: farmfuncs.cpp:1250
cfg_herbi_app_prop
CfgFloat cfg_herbi_app_prop
sg2_burnstrawstubble
Definition: seedgrass2.h:47
Farm::BurnStrawStubble
virtual bool BurnStrawStubble(LE *a_field, double a_user, int a_days)
Burn stubble on a_field.
Definition: farmfuncs.cpp:2236
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:1744
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: farm.cpp:318
Farm::HayTurning
virtual bool HayTurning(LE *a_field, double a_user, int a_days)
Carry out hay turning on a_field.
Definition: farmfuncs.cpp:2159
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539
SG2_WATER_DATE
#define SG2_WATER_DATE
Definition: seedgrass2.h:32
Farm::Spraying_fungins
virtual bool Spraying_fungins(TTypesOfVegetation)
Definition: farm.h:785
sg2_strawchopping
Definition: seedgrass2.h:46
Farm::StubbleHarrowing
virtual bool StubbleHarrowing(LE *a_field, double a_user, int a_days)
Carry out stubble harrowing on a_field.
Definition: farmfuncs.cpp:2209