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

FI_Caraway2 class
. More...

#include <FI_Caraway2.h>

Inheritance diagram for FI_Caraway2:
Crop

Public Member Functions

virtual bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 The one and only method for a crop management plan. All farm actions go through here. More...
 
 FI_Caraway2 (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...
 

Detailed Description

FI_Caraway2 class
.

See FI_Caraway2.h::FI_Caraway2ToDo for a complete list of all possible events triggered codes by the Caraway2 management plan. When triggered these events are handled by Farm and are available as information for other objects such as animal and bird models.

Constructor & Destructor Documentation

◆ FI_Caraway2()

FI_Caraway2::FI_Caraway2 ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
87  : Crop(a_tov, a_toc, a_L)
88  {
89  // When we start it off, the first possible date for a farm operation is
90  // This information is used by other crops when they decide how much post processing of
91  // the management is allowed after harvest before the next crop starts.
92  m_first_date=g_date->DayInYear( 31,5 );
94  }

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

Member Function Documentation

◆ Do()

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

The one and only method for a crop management plan. All farm actions go through here.

Called every time something is done to the crop by the farmer in the first instance it is always called with a_ev->todo set to start, but susequently will be called whenever the farmer wants to carry out a new operation.
This method details all the management and relationships between operations necessary to grow and ALMaSS crop - in this case conventional Caraway1.

Reimplemented from Crop.

99 {
100  m_field = a_field; // this is needed because of possible calls to other methods and currently we do not pass parameters.
101  m_farm = a_farm; // this is needed because of possible calls to other methods and currently we do not pass parameters.
102  m_ev = a_ev;
103  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
104  bool flag = false;
105  int d1 = 0;
107  int l_nextcropstartdate;
108  // Depending what event has occured jump to the correct bit of code e.g. for ww_start jump to line 67 below
109  switch (a_ev->m_todo)
110  {
111  case fi_cw2_start:
112  {
113 
114  a_field->ClearManagementActionSum();
115 
116  m_last_date = g_date->DayInYear(31, 8); // Should match the last flexdate below
117  //Create a 2d array of 1 plus the number of operations you use. Change only 4+1 to what you need in the line below
118  std::vector<std::vector<int>> flexdates(2 + 1, std::vector<int>(2, 0));
119  // Set up the date management stuff
120  // Start and stop dates for all events after harvest
121  flexdates[0][1] = g_date->DayInYear(15, 8); // last possible day of strigling in this case
122  // Now these are done in pairs, start & end for each operation. If its not used then -1
123  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
124  flexdates[1][1] = g_date->DayInYear(20, 8); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1)
125  flexdates[2][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 2 (start op 2)
126  flexdates[2][1] = g_date->DayInYear(31, 8); // This date will be moved back as far as necessary and potentially to flexdates 2 (end op 2)
127 
128  // Below if this is a spring crop use 365, otherwise first parameter is always 0, second parameter is fixed, and the third is the start up operation in the first year
129  int isSpring = 365;
130  if (StartUpCrop(isSpring, flexdates, int(fi_cw2_nk))) break;
131 
132  d1 = g_date->OldDays() + g_date->DayInYear(1, 5) + 365;
133  if (m_ev->m_forcespring) {
134  int day_num_shift = 365;
135  if (g_date->DayInYear() < 70) day_num_shift = 0;
136  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 5) + day_num_shift, fi_cw2_nk, false);
137  break;
138  }
139  else
140  SimpleEvent(d1, fi_cw2_nk, false);
141  }
142  break;
143 
144 
145  // This is the first real farm operation - LKM: 15% do herbicide
146  case fi_cw2_nk:
147  if (a_ev->m_lock || a_farm->DoIt(15)) {
148  if (!a_farm->FP_NK(a_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
149  SimpleEvent(g_date->Date() + 1, fi_cw2_nk, true);
150  break;
151  }
153  break;
154  }
155  else SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 4), fi_cw2_npk1, false);
156  break;
157  case fi_cw2_npk1:
158  if (!a_farm->FP_NPK(a_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
159  SimpleEvent(g_date->Date() + 1, fi_cw2_npk1, true);
160  break;
161  }
163  break;
164  case fi_cw2_herbicide1:
165  if (a_ev->m_lock || a_farm->DoIt(5)) {
166  if (!a_farm->HerbicideTreat(a_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
167  SimpleEvent(g_date->Date() + 1, fi_cw2_herbicide1, true);
168  break;
169  }
170  }
172  break;
173  case fi_cw2_insecticide:
174  if (a_ev->m_lock || a_farm->DoIt(95)) {
175  // here we check whether we are using ERA pesticide or not
176  d1 = g_date->DayInYear(15, 6) - g_date->DayInYear();
177  if (!cfg_pest_caraway_on.value() || !m_field->GetLandscape()->SupplyShouldSpray()) // Not using pesticide spray
178  {
179  flag = m_farm->InsecticideTreat(m_field, 0.0, d1);
180  }
181  else {
183  }
184  if (!flag) {
186  break;
187  }
188  }
190  break;
191  case fi_cw2_fungicide:
192  if (a_ev->m_lock || a_farm->DoIt(10)) {
193  if (!a_farm->FungicideTreat(a_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
194  SimpleEvent(g_date->Date() + 1, fi_cw2_fungicide, true);
195  break;
196  }
197  }
199  break;
200  case fi_cw2_harvest:
201  if (!a_farm->Harvest(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
202  SimpleEvent(g_date->Date() + 1, fi_cw2_harvest, true);
203  break;
204  }
206  break;
207  case fi_cw2_herbicide2:
208  if (a_ev->m_lock || a_farm->DoIt(5)) {
209  if (!a_farm->HerbicideTreat(m_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
210  SimpleEvent(g_date->Date() + 1, fi_cw2_herbicide2, true);
211  break;
212  }
213  }
215  break;
217  if (!a_farm->FP_NPK(m_field, 0.0, m_field->GetMDates(1, 2) - g_date->DayInYear())) {
219  break;
220  }
221  done = true;
222  // So we are done, and somewhere else the farmer will queue up the start event of the next crop
223  // END OF MAIN THREAD
224  break;
225  default:
226  g_msg->Warn(WARN_BUG, "FI_Caraway2::Do(): "
227  "Unknown event type! ", "");
228  exit(1);
229  }
230  return done;
231 }

References cfg_pest_caraway_on, cfg_pest_product_amounts, LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), fi_cw2_fungicide, fi_cw2_harvest, fi_cw2_herbicide1, fi_cw2_herbicide2, fi_cw2_insecticide, fi_cw2_nk, fi_cw2_npk1, fi_cw2_npk2_for_next_year, fi_cw2_start, Farm::FP_NK(), Farm::FP_NPK(), Farm::FungicideTreat(), g_date, g_msg, LE::GetMDates(), Farm::Harvest(), Farm::HerbicideTreat(), Farm::InsecticideTreat(), Crop::m_date_modifier, Crop::m_ev, Crop::m_farm, Crop::m_field, FarmEvent::m_forcespring, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), ppp_1, Farm::ProductApplication(), Crop::SimpleEvent(), Crop::SimpleEvent_(), Crop::StartUpCrop(), tov_FICaraway2, CfgBool::value(), CfgArray_Double::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void FI_Caraway2::SetUpFarmCategoryInformation ( )
inline
95  {
96  const int elements = 2 + (fi_cw2_foobar - FI_CW2_BASE);
98 
99  FarmManagementCategory catlist[elements] =
100  {
101  fmc_Others, // zero element unused but must be here
102  fmc_Others, // fi_cw2_start = 1, // Compulsory, must always be 1 (one).
103  fmc_Others, // fi_cw2_sleep_all_day = FI_CW2_BASE,
104  fmc_Fertilizer, // fi_cw2_nk,
105  fmc_Fertilizer, // fi_cw2_npk1,
106  fmc_Herbicide, // fi_cw2_herbicide1,
107  fmc_Insecticide, // fi_cw2_insecticide,
108  fmc_Fungicide, // fi_cw2_fungicide,
109  fmc_Harvest, // fi_cw2_harvest,
110  fmc_Herbicide, // fi_cw2_herbicide2,
111  fmc_Fertilizer // fi_cw2_npk2_for_next_year,
112 
113 
114  // no foobar entry
115 
116  };
117  // Iterate over the catlist elements and copy them to vector
118  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
119 
120  }

References FI_CW2_BASE, fi_cw2_foobar, fmc_Fertilizer, fmc_Fungicide, fmc_Harvest, fmc_Herbicide, fmc_Insecticide, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by FI_Caraway2().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
FarmEvent::m_forcespring
bool m_forcespring
Definition: Farm.h:392
fmc_Insecticide
Definition: LandscapeFarmingEnums.h:1005
Farm::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: FarmFuncs.cpp:2025
cfg_pest_product_amounts
CfgArray_Double cfg_pest_product_amounts
Amount of pesticide applied in grams of active substance per hectare for each of the 10 pesticides.
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
Farm::ProductApplication
virtual bool ProductApplication(LE *a_field, double a_user, int a_days, double a_applicationrate, PlantProtectionProducts a_ppp, bool a_isgranularpesticide=false, int a_orcharddrifttype=0)
Apply test pesticide to a_field.
Definition: FarmFuncs.cpp:2267
fi_cw2_nk
Definition: FI_Caraway2.h:63
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
cfg_pest_caraway_on
CfgBool cfg_pest_caraway_on
Turn on pesticides for caraway.
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
fmc_Herbicide
Definition: LandscapeFarmingEnums.h:1006
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
fi_cw2_herbicide1
Definition: FI_Caraway2.h:65
Farm::FungicideTreat
virtual bool FungicideTreat(LE *a_field, double a_user, int a_days)
Apply fungicide to a_field.
Definition: FarmFuncs.cpp:2101
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
CfgBool::value
bool value() const
Definition: Configurator.h:164
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
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
Crop::StartUpCrop
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 a...
Definition: Farm.cpp:652
fi_cw2_npk2_for_next_year
Definition: FI_Caraway2.h:70
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
CfgArray_Double::value
std::vector< double > value() const
Definition: Configurator.h:219
fi_cw2_foobar
Definition: FI_Caraway2.h:71
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
tov_FICaraway2
Definition: LandscapeFarmingEnums.h:566
FI_Caraway2::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: FI_Caraway2.h:95
fi_cw2_harvest
Definition: FI_Caraway2.h:68
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
fi_cw2_npk1
Definition: FI_Caraway2.h:64
Crop::m_date_modifier
static int m_date_modifier
Holds a value that shifts test pesticide use by this many days in crops modified to use it.
Definition: Farm.h:514
fi_cw2_insecticide
Definition: FI_Caraway2.h:66
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
Farm::FP_NK
virtual bool FP_NK(LE *a_field, double a_user, int a_days)
Apply NK fertilizer, on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:766
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
FI_CW2_BASE
#define FI_CW2_BASE
Definition: FI_Caraway2.h:53
fi_cw2_fungicide
Definition: FI_Caraway2.h:67
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
fi_cw2_start
Definition: FI_Caraway2.h:61
WARN_BUG
Definition: MapErrorMsg.h:34
ppp_1
Definition: LandscapeFarmingEnums.h:1079
fmc_Fungicide
Definition: LandscapeFarmingEnums.h:1007
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
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
fi_cw2_herbicide2
Definition: FI_Caraway2.h:69