ALMaSS Skylark ODDox  1.1
The skylark model description following ODdox protocol
Oats Class Reference

#include <Oats.h>

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 Oats ()
 
- Public Member Functions inherited from Crop
virtual ~Crop ()
 
 Crop ()
 
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)
 

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
Farmm_farm
 
LE * m_field
 
FarmEventm_ev
 
int m_first_date
 
int m_count
 
int m_last_date
 
int m_ddegstoharvest
 
int m_CropClassification
 

Constructor & Destructor Documentation

◆ Oats()

Oats::Oats ( )
inline
64  {
65  //m_first_date=g_date->DayInYear(1,10);
66  // Use below if no autumn plough
67  m_first_date=g_date->DayInYear(30,12);
68  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

36 {
37  double ins_app_prop = cfg_ins_app_prop1.value();
38  double herbi_app_prop = cfg_herbi_app_prop.value();
39 
40  m_farm = a_farm;
41  m_field = a_field;
42  m_ev = a_ev;
43  int d1;
44 
45  bool done = false;
46 
47  switch (m_ev->m_todo)
48  {
49  case oa_start:
50  {
52  // Set up the date management stuff
53  // Could save the start day in case it is needed later
54  // m_field->m_startday = m_ev->m_startday;
55  m_last_date = g_date->DayInYear(25, 8);
56  // Start and stop dates for all events after harvest
57  int noDates = 2;
58  m_field->SetMDates(0, 0, g_date->DayInYear(11, 8));
59  // Determined by harvest date - used to see if at all possible
60  m_field->SetMDates(1, 0, g_date->DayInYear(20, 8));
61  m_field->SetMDates(0, 1, g_date->DayInYear(25, 8));
62  m_field->SetMDates(1, 1, g_date->DayInYear(25, 8));
63  // Check the next crop for early start, unless it is a spring crop
64  // in which case we ASSUME that no checking is necessary!!!!
65  // So DO NOT implement a crop that runs over the year boundary
66 
67  //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  if (!(m_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
69 
70  if (m_ev->m_startday > g_date->DayInYear(1, 7))
71  {
72  if (m_field->GetMDates(0, 0) >= m_ev->m_startday)
73  {
74  g_msg->Warn(WARN_BUG, "Oats::Do(): "
75  "Harvest too late for the next crop to start!!!", "");
76  exit(1);
77  }
78  // Now fix any late finishing problems
79  for (int i = 0; i < noDates; i++) {
80  if (m_field->GetMDates(0, i) >= m_ev->m_startday) {
81  m_field->SetMDates(0, i, m_ev->m_startday - 1); //move the starting date
82  }
83  if (m_field->GetMDates(1, i) >= m_ev->m_startday) {
84  m_field->SetMConstants(i, 0);
85  m_field->SetMDates(1, i, m_ev->m_startday - 1); //move the finishing date
86  }
87  }
88  }
89  // Now no operations can be timed after the start of the next crop.
90 
91  if (!m_ev->m_first_year)
92  {
93  int today = g_date->Date();
94  // Are we before July 1st?
95  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
96  if (today < d1)
97  {
98  // Yes, too early. We assumme this is because the last crop was late
99  g_msg->Warn(WARN_BUG, " Oats::Do(): "
100  "Crop start attempt between 1st Jan & 1st July", "");
101  exit(1);
102  }
103  else
104  {
105  d1 = g_date->OldDays() + m_first_date + 365; // Add 365 for spring crop
106  if (today > d1)
107  {
108  // Yes too late - should not happen - raise an error
109  g_msg->Warn(WARN_BUG, " Oats::Do(): "
110  "Crop start attempt after last possible start date", "");
111  exit(1);
112  }
113  }
114  }
115  else
116  {
117  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 4),
118  oa_spring_harrow, false);
119  break;
120  }
121  }//if
122 
123  // End single block date checking code. Please see next line
124  // comment as well.
125  // Reinit d1 to first possible starting date.
126  d1 = g_date->OldDays() + m_first_date;
127  if (g_date->Date() > d1) {
128  d1 = g_date->Date();
129  }
130  // OK, let's go.
131  OA_SOW_DATE = 0;
132  OA_DID_STRIGLING_ONE = false;
133  SimpleEvent(g_date->OldDays() + g_date->DayInYear(5, 5),
134  oa_herbicide_one, false);
135  // Altered 30 6 2009 to prevent autumn plough
136  SimpleEvent(d1, oa_autumn_plough, false);
137  /*
138  if ( m_farm->IsStockFarmer()) {
139  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5, 3 ),
140  oa_fertmanure_stock, false );
141  } else {
142  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 5, 3 ),
143  oa_spring_plough, false );
144  }
145  */
146  }
147  break;
148 
149  case oa_herbicide_one:
150  if (m_ev->m_lock || m_farm->DoIt((int)floor(0.5 + 60 * herbi_app_prop * m_farm->Prob_multiplier()))) //modified probability
151  {
152  //new - for decision making
153  TTypesOfVegetation tov = m_field->GetVegType();
154  if (!m_ev->m_lock && !m_farm->Spraying_herbicides(tov)) {
155  Field * pf = dynamic_cast<Field*>(m_field);
156  pf->Add_missed_herb_app();
157  if (m_farm->DoIt(72)) pf->Add_missed_herb_app(); //the 2nd missed application
158  OA_DECIDE_TO_HERB = 0;
159  } //end of the part for dec. making
160  else {
161  if (!m_farm->HerbicideTreat(m_field, 0.0, g_date->DayInYear(15, 5) - g_date->DayInYear()))
162  {
163  SimpleEvent(g_date->Date() + 1, oa_herbicide_one, true);
164  break;
165  }
166  }
167  // Did first spray so see if should do another, 14 days later (min)
168  {
169  d1 = g_date->Date() + 10;
170  if (d1 < g_date->OldDays() + g_date->DayInYear(16, 5)) {
171  d1 = g_date->OldDays() + g_date->DayInYear(16, 5);
172  }
173  SimpleEvent(d1, oa_herbicide_two, false);
174  }
175  }
176  break;
177 
178  case oa_herbicide_two:
179  if (m_ev->m_lock || m_farm->DoIt((int)floor(0.5 + herbi_app_prop * 72 * OA_DECIDE_TO_HERB * m_farm->Prob_multiplier()))) //added *100 /16.04.13 - later 100 changed to 72. //modified probability
180  {
181  if (!m_farm->HerbicideTreat(m_field, 0.0, g_date->DayInYear(30, 5) - g_date->DayInYear())) {
182  SimpleEvent(g_date->Date() + 1, oa_herbicide_two, true);
183  break;
184  }
185  }
186  break;
187 
188  case oa_autumn_plough:
189  if (m_ev->m_lock || m_farm->DoIt(0)) // Altered here to remove this possibility
190  {
191  if (!m_farm->AutumnPlough(m_field, 0.0,
192  g_date->DayInYear(31, 12) -
193  g_date->DayInYear())) {
194  SimpleEvent(g_date->Date() + 1, oa_autumn_plough, true);
195  break;
196  }
197  // Did autumn plough, so skip to spring harrow.
198  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 4) + 365,
199  oa_spring_harrow, false);
200  break;
201  }
202  if (m_farm->IsStockFarmer()) {
203  SimpleEvent(g_date->OldDays() + g_date->DayInYear(5, 3) + 365,
204  oa_fertmanure_stock, false);
205  }
206  else {
207  SimpleEvent(g_date->OldDays() + g_date->DayInYear(5, 3) + 365,
208  oa_spring_plough, false);
209  }
210  break;
211 
212  case oa_fertmanure_stock:
213  if (m_ev->m_lock || m_farm->DoIt(70))
214  {
215  if (!m_farm->FA_Manure(m_field, 0.0,
216  g_date->DayInYear(30, 3) -
217  g_date->DayInYear())) {
218  SimpleEvent(g_date->Date() + 1, oa_fertmanure_stock, true);
219  break;
220  }
221  }
222  SimpleEvent(g_date->Date(), oa_spring_plough, false);
223  break;
224 
225  case oa_spring_plough:
226  if (!m_farm->SpringPlough(m_field, 0.0,
227  g_date->DayInYear(30, 3) -
228  g_date->DayInYear())) {
229  SimpleEvent(g_date->Date() + 1, oa_spring_plough, true);
230  break;
231  }
232  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 4),
233  oa_spring_harrow, false);
234  break;
235 
236  case oa_spring_harrow:
237  if (!m_farm->SpringHarrow(m_field, 0.0,
238  g_date->DayInYear(20, 4) -
239  g_date->DayInYear())) {
240  SimpleEvent(g_date->Date() + 1, oa_spring_harrow, true);
241  break;
242  }
243  if (m_farm->IsStockFarmer()) {
244  SimpleEvent(g_date->Date(), oa_fertslurry_stock, false);
245  }
246  else {
247  SimpleEvent(g_date->Date(), oa_spring_sow_one, false);
248  }
249  break;
250 
251  case oa_fertslurry_stock:
252  if (!m_farm->FA_Slurry(m_field, 0.0,
253  g_date->DayInYear(20, 4) -
254  g_date->DayInYear())) {
255  SimpleEvent(g_date->Date() + 1, oa_fertslurry_stock, true);
256  break;
257  }
258  SimpleEvent(g_date->Date(), oa_spring_sow_one, false);
259  break;
260 
261  case oa_spring_sow_one:
262  if (!m_farm->SpringSow(m_field, 0.0,
263  g_date->DayInYear(20, 4) -
264  g_date->DayInYear())) {
265  SimpleEvent(g_date->Date() + 1, oa_spring_sow_one, true);
266  break;
267  }
268  OA_SOW_DATE = g_date->Date();
269  if (m_farm->IsStockFarmer()) {
270  d1 = g_date->Date();
271  if (d1 < g_date->OldDays() + g_date->DayInYear(5, 4)) {
272  d1 = g_date->OldDays() + g_date->DayInYear(5, 4);
273  }
274  SimpleEvent(d1, oa_spring_roll, false);
275  }
276  else {
277  SimpleEvent(g_date->Date() + 1, oa_spring_sow_two, false);
278  }
279  break;
280 
281  case oa_spring_sow_two:
282  if (m_ev->m_lock || m_farm->DoIt(60))
283  {
284  if (!m_farm->SpringSow(m_field, 0.0,
285  g_date->DayInYear(22, 4) -
286  g_date->DayInYear())) {
287  SimpleEvent(g_date->Date() + 1, oa_spring_sow_two, true);
288  break;
289  }
290  OA_SOW_DATE = g_date->Date();
291  }
292  SimpleEvent(g_date->OldDays() + g_date->DayInYear(5, 4),
293  oa_spring_roll, false);
294  break;
295 
296  case oa_spring_roll:
297  if (m_ev->m_lock || m_farm->DoIt(80))
298  {
299  if (!m_farm->SpringRoll(m_field, 0.0,
300  g_date->DayInYear(20, 4) -
301  g_date->DayInYear())) {
302  SimpleEvent(g_date->Date() + 1, oa_spring_roll, true);
303  break;
304  }
305  }
306  d1 = g_date->OldDays() + g_date->DayInYear(15, 4);
307  if (d1 < OA_SOW_DATE + 10) {
308  d1 = OA_SOW_DATE + 10;
309  }
310  SimpleEvent(g_date->OldDays() + g_date->DayInYear(10, 6), oa_insecticide, false);
311  break;
312 
313  case oa_insecticide:
314  if (m_ev->m_lock || m_farm->DoIt((int)floor(0.5 + 62 * ins_app_prop * m_farm->Prob_multiplier()))) //modified probability
315  {
316  //new - for decision making
317  TTypesOfVegetation tov = m_field->GetVegType();
318  if (!m_ev->m_lock && !m_farm->Spraying_fungins(tov)) {
319  Field * pf = dynamic_cast<Field*>(m_field);
320  pf->Add_missed_fi_app();
321  } //end of the part for dec. making
322  else {
323  if (!m_farm->InsecticideTreat(m_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear()))
324  {
325  SimpleEvent(g_date->Date() + 1, oa_insecticide, true);
326  break;
327  }
328  }
329  }
330 
331  ChooseNextCrop(2);
332  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 8), oa_harvest, false);
333  break;
334 
335  case oa_harvest:
336  if (m_field->GetMConstants(0) == 0) {
337  if (!m_farm->Harvest(m_field, 0.0, -1)) { //raise an error
338  g_msg->Warn(WARN_BUG, "Oats::Do(): failure in 'Harvest' execution", "");
339  exit(1);
340  }
341  }
342  else {
343  if (!m_farm->Harvest(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
344  SimpleEvent(g_date->Date() + 1, oa_harvest, true);
345  break;
346  }
347  }
348  SimpleEvent(g_date->Date(), oa_straw_chopping, false);
349  break;
350 
351  case oa_straw_chopping:
352  if (m_ev->m_lock || m_farm->DoIt(80))
353  {
354  if (m_field->GetMConstants(1) == 0) {
355  if (!m_farm->StrawChopping(m_field, 0.0, -1)) { //raise an error
356  g_msg->Warn(WARN_BUG, "Oats::Do(): failure in 'StrawChopping' execution", "");
357  exit(1);
358  }
359  }
360  else {
361  if (!m_farm->StrawChopping(m_field, 0.0, m_field->GetMDates(0, 1) - g_date->DayInYear())) {
362  SimpleEvent(g_date->Date() + 1, oa_straw_chopping, true);
363  break;
364  }
365  }
366  done = true;
367  break;
368  }
369  SimpleEvent(g_date->Date(), oa_hay_bailing, false);
370  break;
371 
372  case oa_hay_bailing:
373  if (m_field->GetMConstants(1) == 0) {
374  if (!m_farm->HayBailing(m_field, 0.0, -1)) { //raise an error
375  g_msg->Warn(WARN_BUG, "Oats::Do(): failure in 'HayBailing' execution", "");
376  exit(1);
377  }
378  }
379  else {
380  if (!m_farm->HayBailing(m_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
381  SimpleEvent(g_date->Date() + 1, oa_hay_bailing, true);
382  break;
383  }
384  }
385  done = true;
386  break;
387 
388  default:
389  g_msg->Warn(WARN_BUG, "Oats::Do(): "
390  "Unknown event type! ", "");
391  exit(1);
392  }
393 
394  return done;
395 }

References Farm::AutumnPlough(), cfg_herbi_app_prop, cfg_ins_app_prop1, Crop::ChooseNextCrop(), Farm::DoIt(), Farm::FA_Manure(), Farm::FA_Slurry(), Farm::GetType(), Farm::Harvest(), Farm::HayBailing(), Farm::HerbicideTreat(), Farm::InsecticideTreat(), 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, oa_autumn_plough, OA_DECIDE_TO_HERB, OA_DID_STRIGLING_ONE, oa_fertmanure_stock, oa_fertslurry_stock, oa_harvest, oa_hay_bailing, oa_herbicide_one, oa_herbicide_two, oa_insecticide, OA_SOW_DATE, oa_spring_harrow, oa_spring_plough, oa_spring_roll, oa_spring_sow_one, oa_spring_sow_two, oa_start, oa_straw_chopping, Farm::Prob_multiplier(), Crop::SimpleEvent(), Farm::Spraying_fungins(), Farm::Spraying_herbicides(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringRoll(), Farm::SpringSow(), Farm::StrawChopping(), and tof_OptimisingFarm.


The documentation for this class was generated from the following files:
Farm::SpringRoll
virtual bool SpringRoll(LE *a_field, double a_user, int a_days)
Carry out a roll event in the spring on a_field.
Definition: farmfuncs.cpp:525
Farm::FA_Slurry
virtual bool FA_Slurry(LE *a_field, double a_user, int a_days)
Spready slurry on a_field owned by an stock farmer.
Definition: farmfuncs.cpp:965
OA_SOW_DATE
#define OA_SOW_DATE
Definition: Oats.h:34
cfg_herbi_app_prop
CfgFloat cfg_herbi_app_prop
Farm::SpringPlough
virtual bool SpringPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the spring on a_field.
Definition: farmfuncs.cpp:444
Farm::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: farmfuncs.cpp:1156
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: farm.h:905
oa_insecticide
Definition: Oats.h:50
oa_herbicide_two
Definition: Oats.h:49
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
oa_spring_harrow
Definition: Oats.h:43
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
OA_DID_STRIGLING_ONE
#define OA_DID_STRIGLING_ONE
Definition: Oats.h:35
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
tof_OptimisingFarm
Definition: farm.h:273
oa_fertslurry_stock
Definition: Oats.h:44
Farm::FA_Manure
virtual bool FA_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an stock farmer.
Definition: farmfuncs.cpp:1036
oa_straw_chopping
Definition: Oats.h:52
oa_fertmanure_stock
Definition: Oats.h:41
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
cfg_ins_app_prop1
CfgFloat cfg_ins_app_prop1
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
oa_spring_plough
Definition: Oats.h:42
Farm::Prob_multiplier
virtual double Prob_multiplier()
Definition: farm.h:786
TTypesOfVegetation
TTypesOfVegetation
Definition: tov_declaration.h:30
OA_DECIDE_TO_HERB
#define OA_DECIDE_TO_HERB
Definition: Oats.h:36
Farm::Spraying_herbicides
virtual bool Spraying_herbicides(TTypesOfVegetation)
Definition: farm.h:784
Farm::HayBailing
virtual bool HayBailing(LE *a_field, double a_user, int a_days)
Carry out hay bailing on a_field.
Definition: farmfuncs.cpp:2184
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
oa_spring_sow_one
Definition: Oats.h:45
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::InsecticideTreat
virtual bool InsecticideTreat(LE *a_field, double a_user, int a_days)
Apply insecticide to a_field.
Definition: farmfuncs.cpp:1348
oa_spring_roll
Definition: Oats.h:47
Crop::m_last_date
int m_last_date
Definition: farm.h:542
Farm::AutumnPlough
virtual bool AutumnPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the autumn on a_field.
Definition: farmfuncs.cpp:132
Farm::SpringSow
virtual bool SpringSow(LE *a_field, double a_user, int a_days)
Carry out a sowing event in the spring on a_field.
Definition: farmfuncs.cpp:546
oa_harvest
Definition: Oats.h:51
oa_herbicide_one
Definition: Oats.h:48
oa_start
Definition: Oats.h:39
oa_hay_bailing
Definition: Oats.h:53
oa_autumn_plough
Definition: Oats.h:40
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: farm.cpp:318
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539
oa_spring_sow_two
Definition: Oats.h:46
Farm::Spraying_fungins
virtual bool Spraying_fungins(TTypesOfVegetation)
Definition: farm.h:785
Farm::SpringHarrow
virtual bool SpringHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the spring on a_field.
Definition: farmfuncs.cpp:471