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

#include <OrchardCrop.h>

Inheritance diagram for OrchardCrop:
Crop

Public Member Functions

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

◆ OrchardCrop()

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

44 {
45  m_farm = a_farm;
46  m_field = a_field;
47  m_ev = a_ev;
48  bool done = false;
49  int d1;
50  int today = g_date->Date();
51  int noDates= 1;
53 
54  switch ( m_ev->m_todo ) {
55  case orch_start:
56  a_field->ClearManagementActionSum();
57 
58  // Set up the date management stuff
60  // Start and stop dates for all events after harvest
61  m_field->SetMDates(0,0,g_date->DayInYear(1,9));
62  // Determined by harvest date - used to see if at all possible
63  m_field->SetMDates(1,0,g_date->DayInYear(1,9));
64  // Check the next crop for early start, unless it is a spring crop
65  // in which case we ASSUME that no checking is necessary!!!!
66  // So DO NOT implement a crop that runs over the year boundary
67 
68  //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)
70 
71  if (m_ev->m_startday>g_date->DayInYear(1,7))
72  {
73  if (m_field->GetMDates(0,0) >=m_ev->m_startday){
74  g_msg->Warn( WARN_BUG, "OrchardCrop::Do(): Harvest too late for the next crop to start!!!", "" );
75  exit( 1 );
76  }
77  // Now fix any late finishing problems
78  for (int i=0; i<noDates; i++) {
79  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
80  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
81  }
82  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
83  m_field->SetMConstants(i,0);
84  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
85  }
86  }
87  }
88  // Now no operations can be timed after the start of the next crop.
89 
90  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
91  if (today > d1) {
92  // Yes too late - should not happen - raise an error
93  g_msg->Warn( WARN_BUG, " OrchardCrop::Do(): Crop start attempt after last possible start date", "" );
94  exit( 1 );
95  }
96  }//if
97  // Reinit d1 to first possible starting date.
98  d1 = g_date->OldDays()+m_first_date;;
99  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
100  if ( g_date->Date() > d1 ){
101  d1 = g_date->Date();
102  }
103  // OK, let's go.
104 
105  SimpleEvent( d1, orch_cut, false ); //call cutting orchard
106  SimpleEvent( d1, orch_insecticide1, false ); //call insecticide - so there are two threds
107  break;
108 
109 
110  case orch_cut:
111 
112  switch ( cfg_OrchardNoCutsDay.value() ) {
113  case 99:
114  if ( today == ( sprayday - 7 ) ) m_farm->CutOrch( m_field, 0.0, -1); //so cut no matter what. ok?
115  break;
116  case 4:
117  if ( ( today == 259 ) || ( today == 122 ) || ( today == 92 ) || ( today == 196 ) )
118  m_farm->CutOrch( m_field, 0.0, -1);
119  break;
120  case 3:
121  if ( ( today == 259 ) || ( today == 122 ) || ( today == 92 ) ) m_farm->CutOrch( m_field, 0.0, -1);
122  break;
123  case 2:
124  if ( ( today == 259 ) || ( today == 122 ) ) m_farm->CutOrch( m_field, 0.0, -1);
125  break;
126  case 1:
127  if ( ( today == 259 ) ) m_farm->CutOrch( m_field, 0.0, -1);
128  break;
129  default: // No cut
130  break;
131  }
132 
133  /* if (!m_farm->CutOrch( m_field, 0.0, g_date->DayInYear( 30, 7 ) - g_date->DayInYear())) {
134  SimpleEvent( g_date->Date() + 1, psa_cut_to_hay, false );
135  break;
136  }*/
138  break;
139 
142  break;
143 
145  done = true;
146  break;
147 
148  case orch_insecticide1:
149  if (!a_field->GetLandscape()->SupplyShouldSpray()) break; // * Added by Andrey
150  // This will prevent product usage outside the test period
151  if (a_field->GetLandscape()->SupplyYearNumber() < cfg_productapplicstartyear.value()) break;
152  if (a_field->GetLandscape()->SupplyYearNumber() >= cfg_productapplicendyear.value()) break;
153  if ( m_ev->m_lock || m_farm->DoIt( (int) (100*cfg_ins_app_prop1.value() ))) {
155  SimpleEvent( g_date->Date() + 1, orch_insecticide1, true );
156  break;
157  }
158  else {
161  break;
162  }
163  }
164  break;
165 
166  case orch_insecticide2:
167  if (!a_field->GetLandscape()->SupplyShouldSpray()) break; // * Added by Andrey
168  if ( m_ev->m_lock || m_farm->DoIt( (int)( 50*cfg_ins_app_prop1.value() ))) {
170  SimpleEvent( g_date->Date() + 1, orch_insecticide2, true );
171  break;
172  }
173  }
174  // End of thread
175 
176  ChooseNextCrop (1);
177 
178 
179  break;
180 
181 
182 
183  default:
184  g_msg->Warn( WARN_BUG, "OrchardCrop::Do(): Unknown event type! ", "" );
185  exit( 1 );
186  }
187 
188  return done;
189 }

References cfg_ins_app_prop1, cfg_OrchardNoCutsDay, cfg_pest_product_amounts, cfg_pest_productapplic_startdate, cfg_pest_productapplic_startdate2, cfg_productapplicendyear, cfg_productapplicstartyear, Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Farm::CutOrch(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), g_date, g_msg, LE::GetMDates(), Farm::GetType(), Calendar::GetYearNumber(), 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(), orch_cut, orch_do_nothing_start, orch_do_nothing_stop, orch_insecticide1, orch_insecticide2, orch_start, ppp_1, Farm::ProductApplication(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent(), tof_OptimisingFarm, CfgInt::value(), CfgFloat::value(), CfgArray_Double::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void OrchardCrop::SetUpFarmCategoryInformation ( )
inline
55  {
56  const int elements = 2 + (orch_foobar - ORCHARDCROP_BASE);
58 
59  FarmManagementCategory catlist[elements] =
60  {
61  fmc_Others, // zero element unused but must be here
62  fmc_Others, //orch_start = 1, // Compulsory, start event must always be 1 (one).
63  fmc_Others, //orch_do_nothing_start = ORCHARDCROP_BASE,
64  fmc_Others, //orch_do_nothing_stop,
65  fmc_Insecticide, //orch_insecticide1,
66  fmc_Insecticide, //orch_insecticide2,
67  fmc_Cutting //orch_cut
68  // No foobar entry
69  };
70  // Iterate over the catlist elements and copy them to vector
71  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
72  }

References fmc_Cutting, fmc_Insecticide, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, orch_foobar, and ORCHARDCROP_BASE.

Referenced by OrchardCrop().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
fmc_Insecticide
Definition: LandscapeFarmingEnums.h:1005
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
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
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
cfg_ins_app_prop1
CfgFloat cfg_ins_app_prop1
orch_insecticide2
Definition: OrchardCrop.h:41
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
CfgFloat::value
double value() const
Definition: Configurator.h:142
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
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
ORCHARDCROP_BASE
#define ORCHARDCROP_BASE
Definition: OrchardCrop.h:34
orch_do_nothing_stop
Definition: OrchardCrop.h:39
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
orch_cut
Definition: OrchardCrop.h:42
orch_insecticide1
Definition: OrchardCrop.h:40
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
Farm::CutOrch
virtual bool CutOrch(LE *a_field, double a_user, int a_days)
Cut vegetation on orchard crop. //based on cut to silage - values from cutting function of orchard.
Definition: FarmFuncs.cpp:1666
cfg_productapplicstartyear
CfgInt cfg_productapplicstartyear
orch_do_nothing_start
Definition: OrchardCrop.h:38
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
CfgInt::value
int value() const
Definition: Configurator.h:116
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
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
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.
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
orch_foobar
Definition: OrchardCrop.h:43
cfg_productapplicendyear
CfgInt cfg_productapplicendyear
orch_start
Definition: OrchardCrop.h:37
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
cfg_OrchardNoCutsDay
CfgInt cfg_OrchardNoCutsDay
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
cfg_pest_productapplic_startdate2
CfgInt cfg_pest_productapplic_startdate2
Start date for applying pesticide the second.
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
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
OrchardCrop::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: OrchardCrop.h:55
WARN_BUG
Definition: MapErrorMsg.h:34
ppp_1
Definition: LandscapeFarmingEnums.h:1079
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
cfg_pest_productapplic_startdate
CfgInt cfg_pest_productapplic_startdate
Start date for applying pesticide the first time.
Definition: Elements.cpp:166