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

#include <DummyCropPestTesting.h>

Inheritance diagram for DummyCropPestTesting:
Crop

Public Member Functions

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

◆ DummyCropPestTesting()

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

34 {
35  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
36  int d1 = 0;
37  // Depending what event has occured jump to the correct bit of code
38  switch (a_ev->m_todo)
39  {
40  case dcpt_start:
41  {
42  // dcpt_start just sets up all the starting conditions and reference dates that are needed to start a pl_sb
43  DCPT_APRIL_PEST = 0;
44  DCPT_MAY_PEST = 0;
45  DCPT_JUNE_PEST = 0;
46  DCPT_JULY_PEST = 0;
47  DCPT_SEPT_PEST = 0;
48  DCPT_OCT_PEST = 0;
49  a_field->ClearManagementActionSum();
50 
51 
52  // Set up the date management stuff
53  // The next bit of code just allows for altering dates after harvest if it is necessary
54  // to allow for a crop which starts its management early.
55 
56  // 5 start and stop dates for all 'movable' events for this crop
57  int noDates = 1;
58  a_field->SetMDates(0, 0, g_date->DayInYear(15, 11));
59  a_field->SetMDates(1, 0, g_date->DayInYear(15, 11));
60 
61  a_field->SetMConstants(0, 1);
62 
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 (i.e. from spring to spring!), at least not without fixing this.
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  //optimising farms not used for now so most of related code is removed (but not in 'start' case)
69  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
70 
71  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
72  if (a_field->GetMDates(0, 0) >= a_ev->m_startday)
73  {
74  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): ", "Harvest too late for the next crop to start!!!");
75  int almassnum = a_field->GetLandscape()->BackTranslateVegTypes(a_ev->m_next_tov);
76  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
77  }
78  // Now fix any late finishing problems
79  for (int i = 0; i < noDates; i++) {
80  if (a_field->GetMDates(0, i) >= a_ev->m_startday) {
81  a_field->SetMDates(0, i, a_ev->m_startday - 1); //move the starting date
82  }
83  if (a_field->GetMDates(1, i) >= a_ev->m_startday) {
84  a_field->SetMConstants(i, 0); //change the default value of the MConst (=1) to 0 (necessary to correctly execute farm events in case the finishing date (MDate) was moved)
85  a_field->SetMDates(1, i, a_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 (!a_ev->m_first_year) {
92  int today = g_date->Date();
93  d1 = g_date->OldDays() + m_first_date + 365; // Add 365 for spring crop
94  if (today > d1) {
95  // Yes too late - should not happen - raise an error
96  g_msg->Warn(WARN_BUG, "PLSpringBarleySpr::Do(): " "Crop start attempt after last possible start date", "");
97  exit(1);
98  }
99  }
100  else {
101  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 3), dcpt_March_pest1, false, a_farm, a_field);
102  break;
103  }
104  }//if
105 
106  // End single block date checking code. Please see next line
107  // comment as well.
108  // Reinit d1 to first possible starting date.
109  d1 = g_date->OldDays() + 365 + g_date->DayInYear(1, 3);
110  // OK, let's go.
111  SimpleEvent_(d1, dcpt_March_pest1, false, a_farm, a_field);
112  break;
113  }
114  break;
115 
116  // This is the first real farm operation
117  case dcpt_March_pest1:
118  if (a_ev->m_lock || a_farm->DoIt(3))
119  {
120  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 3) - g_date->DayInYear())) {
121  SimpleEvent_(g_date->Date() + 1, dcpt_March_pest1, true, a_farm, a_field);
122  break;
123  }
124  }
125  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 4), dcpt_April_pest1, false, a_farm, a_field);
126  break;
127  case dcpt_April_pest1:
128  if (a_ev->m_lock || a_farm->DoIt(29)) //40% will spray just once in April
129  {
130  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
131  SimpleEvent_(g_date->Date() + 1, dcpt_April_pest1, true, a_farm, a_field);
132  break;
133  }
134  DCPT_APRIL_PEST = 1;
135  }
136  SimpleEvent_(g_date->Date() + 10, dcpt_April_pest2, false, a_farm, a_field);
137  break;
138  case dcpt_April_pest2:
139  if (a_ev->m_lock || a_farm->DoIt(1) && (DCPT_APRIL_PEST == 1)) //1.08% will spray twice in April
140  {
141  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 4) - g_date->DayInYear())) {
142  SimpleEvent_(g_date->Date() + 1, dcpt_April_pest2, true, a_farm, a_field);
143  break;
144  }
145  }
146  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), dcpt_May_pest1, false, a_farm, a_field);
147  break;
148  case dcpt_May_pest1:
149  if (a_ev->m_lock || a_farm->DoIt(22)) //38% will spray just once
150  {
151  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
152  SimpleEvent_(g_date->Date() + 1, dcpt_May_pest1, true, a_farm, a_field);
153  break;
154  }
155  DCPT_MAY_PEST = 1;
156  }
157  SimpleEvent_(g_date->Date() + 10, dcpt_May_pest2, false, a_farm, a_field);
158  break;
159  case dcpt_May_pest2:
160  if (a_ev->m_lock || a_farm->DoIt(2) && (DCPT_MAY_PEST == 1)) //11.50% will spray twice
161  {
162  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
163  SimpleEvent_(g_date->Date() + 1, dcpt_May_pest2, true, a_farm, a_field);
164  break;
165  }
166  }
167  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 6), dcpt_June_pest1, false, a_farm, a_field);
168  break;
169  case dcpt_June_pest1:
170  if (a_ev->m_lock || a_farm->DoIt(12)) //9% will spray just once
171  {
172  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
173  SimpleEvent_(g_date->Date() + 1, dcpt_June_pest1, true, a_farm, a_field);
174  break;
175  }
176  DCPT_JUNE_PEST = 1;
177  }
178  SimpleEvent_(g_date->Date() + 10, dcpt_June_pest2, false, a_farm, a_field);
179  break;
180  case dcpt_June_pest2:
181  if (a_ev->m_lock || a_farm->DoIt(0) && (DCPT_JUNE_PEST == 1)) //0.41% will spray twice
182  {
183  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
184  SimpleEvent_(g_date->Date() + 1, dcpt_June_pest2, true, a_farm, a_field);
185  break;
186  }
187  }
188  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 7), dcpt_July_pest1, false, a_farm, a_field);
189  break;
190  case dcpt_July_pest1:
191  if (a_ev->m_lock || a_farm->DoIt(0)) //3% will spray just once
192  {
193  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 7) - g_date->DayInYear())) {
194  SimpleEvent_(g_date->Date() + 1, dcpt_July_pest1, true, a_farm, a_field);
195  break;
196  }
197  DCPT_JULY_PEST = 1;
198  }
199  SimpleEvent_(g_date->Date() + 10, dcpt_July_pest2, false, a_farm, a_field);
200  break;
201  case dcpt_July_pest2:
202  if (a_ev->m_lock || a_farm->DoIt(0) && (DCPT_JULY_PEST == 1)) //0.95% will spray twice
203  {
204  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 7) - g_date->DayInYear())) {
205  SimpleEvent_(g_date->Date() + 1, dcpt_July_pest2, true, a_farm, a_field);
206  break;
207  }
208  }
209  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 8), dcpt_August_pest1, false, a_farm, a_field);
210  break;
211  case dcpt_August_pest1:
212  if (a_ev->m_lock || a_farm->DoIt(1)) //0.02% will spray just once
213  {
214  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 8) - g_date->DayInYear())) {
215  SimpleEvent_(g_date->Date() + 1, dcpt_August_pest1, true, a_farm, a_field);
216  break;
217  }
218  }
219  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 9), dcpt_September_pest1, false, a_farm, a_field);
220  break;
222  if (a_ev->m_lock || a_farm->DoIt(3)) //2.90% will spray just once
223  {
224  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 9) - g_date->DayInYear())) {
225  SimpleEvent_(g_date->Date() + 1, dcpt_August_pest1, true, a_farm, a_field);
226  break;
227  }
228  DCPT_SEPT_PEST = 1;
229  }
230  SimpleEvent_(g_date->Date() + 10, dcpt_September_pest2, false, a_farm, a_field);
231  break;
233  if (a_ev->m_lock || a_farm->DoIt(21) && (DCPT_SEPT_PEST == 1)) //2.90% will spray just once
234  {
235  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 9) - g_date->DayInYear())) {
236  SimpleEvent_(g_date->Date() + 1, dcpt_August_pest1, true, a_farm, a_field);
237  break;
238  }
239  }
240  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 10), dcpt_October_pest1, false, a_farm, a_field);
241  break;
242  case dcpt_October_pest1:
243  if (a_ev->m_lock || a_farm->DoIt(4)) //1% will spray just once
244  {
245  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 10) - g_date->DayInYear())) {
246  SimpleEvent_(g_date->Date() + 1, dcpt_October_pest1, true, a_farm, a_field);
247  break;
248  }
249  DCPT_OCT_PEST = 1;
250  }
251  SimpleEvent_(g_date->Date() + 10, dcpt_October_pest2, false, a_farm, a_field);
252  break;
253  case dcpt_October_pest2:
254  if (a_ev->m_lock || a_farm->DoIt(1) && (DCPT_OCT_PEST == 1)) //1% will spray just once
255  {
256  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(31, 10) - g_date->DayInYear())) {
257  SimpleEvent_(g_date->Date() + 1, dcpt_October_pest1, true, a_farm, a_field);
258  break;
259  }
260  }
261  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 11), dcpt_November_pest1, false, a_farm, a_field);
262  break;
263  case dcpt_November_pest1:
264  if (a_ev->m_lock || a_farm->DoIt(0)) //1% will spray just once
265  {
266  if (!a_farm->InsecticideTreat(a_field, 0.0, g_date->DayInYear(30, 11) - g_date->DayInYear())) {
267  SimpleEvent_(g_date->Date() + 1, dcpt_October_pest1, true, a_farm, a_field);
268  break;
269  }
270  }
271  done = true;
272  break;
273 
274  default:
275  g_msg->Warn( WARN_BUG, "DummyCropPestTesting::Do(): "
276  "Unknown event type! ", "" );
277  exit( 1 );
278  }
279  return done;
280 }

References LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), DCPT_APRIL_PEST, dcpt_April_pest1, dcpt_April_pest2, dcpt_August_pest1, DCPT_JULY_PEST, dcpt_July_pest1, dcpt_July_pest2, DCPT_JUNE_PEST, dcpt_June_pest1, dcpt_June_pest2, dcpt_March_pest1, DCPT_MAY_PEST, dcpt_May_pest1, dcpt_May_pest2, dcpt_November_pest1, DCPT_OCT_PEST, dcpt_October_pest1, dcpt_October_pest2, DCPT_SEPT_PEST, dcpt_September_pest1, dcpt_September_pest2, dcpt_start, Farm::DoIt(), g_date, g_msg, LE::GetMDates(), Farm::GetType(), Calendar::GetYearNumber(), Farm::InsecticideTreat(), FarmEvent::m_first_year, FarmEvent::m_lock, FarmEvent::m_next_tov, FarmEvent::m_startday, FarmEvent::m_todo, Calendar::OldDays(), LE::SetMConstants(), LE::SetMDates(), tof_OptimisingFarm, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DummyCropPestTesting::SetUpFarmCategoryInformation ( )
inline
71  {
72  const int elements = 2 + (dcpt_foobar - DCPT_BASE);
74 
75  FarmManagementCategory catlist[elements] =
76  {
77  fmc_Others, // zero element unused but must be here
78  fmc_Others, // dcpt_start = 1, // Compulsory, start event must always be 1 (one).
79  fmc_Herbicide, // dcpt_March_pest1=DCPT_BASE,
80  fmc_Herbicide, // dcpt_April_pest1,
81  fmc_Herbicide, // dcpt_April_pest2,
82  fmc_Herbicide, // dcpt_May_pest1,
83  fmc_Herbicide, // dcpt_May_pest2,
84  fmc_Herbicide, // dcpt_June_pest1,
85  fmc_Herbicide, // dcpt_June_pest2,
86  fmc_Herbicide, // dcpt_July_pest1,
87  fmc_Herbicide, // dcpt_July_pest2,
88  fmc_Herbicide, // dcpt_August_pest1,
89  fmc_Herbicide, // dcpt_September_pest1,
90  fmc_Herbicide, // dcpt_September_pest2,
91  fmc_Herbicide, // dcpt_October_pest1,
92  fmc_Herbicide, // dcpt_October_pest2,
93  fmc_Herbicide // dcpt_November_pest1,
94 
95 
96  // no foobar entry
97 
98  };
99  // Iterate over the catlist elements and copy them to vector
100  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
101 
102  }

References DCPT_BASE, dcpt_foobar, fmc_Herbicide, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DummyCropPestTesting().


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
DCPT_APRIL_PEST
#define DCPT_APRIL_PEST
Definition: DummyCropPestTesting.h:33
dcpt_September_pest1
Definition: DummyCropPestTesting.h:52
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
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
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
DCPT_MAY_PEST
#define DCPT_MAY_PEST
Definition: DummyCropPestTesting.h:34
DCPT_SEPT_PEST
#define DCPT_SEPT_PEST
Definition: DummyCropPestTesting.h:37
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
dcpt_July_pest1
Definition: DummyCropPestTesting.h:49
fmc_Herbicide
Definition: LandscapeFarmingEnums.h:1006
DCPT_OCT_PEST
#define DCPT_OCT_PEST
Definition: DummyCropPestTesting.h:38
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
dcpt_October_pest2
Definition: DummyCropPestTesting.h:55
DummyCropPestTesting::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DummyCropPestTesting.h:71
dcpt_April_pest1
Definition: DummyCropPestTesting.h:43
DCPT_JULY_PEST
#define DCPT_JULY_PEST
Definition: DummyCropPestTesting.h:36
dcpt_October_pest1
Definition: DummyCropPestTesting.h:54
Calendar::Date
long Date(void)
Definition: Calendar.h:57
dcpt_June_pest2
Definition: DummyCropPestTesting.h:48
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
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: Farm.h:390
dcpt_September_pest2
Definition: DummyCropPestTesting.h:53
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
Farm::InsecticideTreat
virtual bool InsecticideTreat(LE *a_field, double a_user, int a_days)
Apply insecticide to a_field.
Definition: FarmFuncs.cpp:2135
dcpt_July_pest2
Definition: DummyCropPestTesting.h:50
DCPT_JUNE_PEST
#define DCPT_JUNE_PEST
Definition: DummyCropPestTesting.h:35
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
dcpt_March_pest1
Definition: DummyCropPestTesting.h:42
DCPT_BASE
#define DCPT_BASE
Definition: DummyCropPestTesting.h:31
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
dcpt_April_pest2
Definition: DummyCropPestTesting.h:44
dcpt_November_pest1
Definition: DummyCropPestTesting.h:56
dcpt_start
Definition: DummyCropPestTesting.h:41
dcpt_August_pest1
Definition: DummyCropPestTesting.h:51
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
dcpt_foobar
Definition: DummyCropPestTesting.h:57
LE::SetMConstants
void SetMConstants(int a, int c)
Definition: Elements.h:408
dcpt_June_pest1
Definition: DummyCropPestTesting.h:47
WARN_BUG
Definition: MapErrorMsg.h:34
dcpt_May_pest2
Definition: DummyCropPestTesting.h:46
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
dcpt_May_pest1
Definition: DummyCropPestTesting.h:45
Crop::SimpleEvent_
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.
Definition: Farm.cpp:751