Loading [MathJax]/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
SetAside Class Reference

Rotational set-aside management class
. More...

#include <SetAside.h>

Inheritance diagram for SetAside:
Crop

Public Member Functions

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...
 
 SetAside (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

Rotational set-aside management class
.

SetAside.h::SetAsideToDo is the list of things that a farmer can do if he is has rotational setaside, at least following this basic plan. For setaside this list is pretty short, because he can't do much with standard setaside (rules as of DK, 2000). So all we have to do is figure out when to do the different things using SetAside::Do Once we have done some kind of management, then an event is triggered and the fact that this particular management is done is registered with the particular polygon. This information is available for any ALMaSS components to inspect - e.g. animals & birds.

Constructor & Destructor Documentation

◆ SetAside()

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

Member Function Documentation

◆ Do()

bool SetAside::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 m_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 rotational setaside.

Reimplemented from Crop.

87 {
88  m_farm = a_farm;
89  m_field = a_field;
90  m_ev = a_ev;
91  int d1 = 0;
92  int noDates = 3;
93  bool done = false;
94 
95  switch ( m_ev->m_todo ) {
96  case sa_start:
97  a_field->ClearManagementActionSum();
98 
99  // Special for set-aside:
100  m_field->SetVegPatchy( true );
101  // Set up the date management stuff
102  // Could save the start day in case it is needed later
103  // m_field->m_startday = m_ev->m_startday;
104  m_last_date=g_date->DayInYear(10,10);
105  // Start and stop dates for all events after harvest
106  m_field->SetMDates(0,0,g_date->DayInYear(30,6));
107  // Determined by harvest date - used to see if at all possible
108  m_field->SetMDates(1,0,g_date->DayInYear(25,8));
109  m_field->SetMDates(0,1,g_date->DayInYear(1,9));
110  m_field->SetMDates(1,1,g_date->DayInYear(15,9));
111  m_field->SetMDates(0,2,g_date->DayInYear(1,9));
112  m_field->SetMDates(1,2,g_date->DayInYear(10,10));
113  // Check the next crop for early start, unless it is a spring crop
114  // in which case we ASSUME that no checking is necessary!!!!
115  // So DO NOT implement a crop that runs over the year boundary
116 
117  //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)
119 
120  if (m_ev->m_startday>g_date->DayInYear(1,7)) {
121  if (m_field->GetMDates(0,0) >=m_ev->m_startday) {
122  g_msg->Warn( WARN_BUG, "Setaside::Do(): "
123  "Harvest too late for the next crop to start!!!", "" );
124  exit( 1 );
125  }
126  // Now fix any late finishing problems
127  for (int i=0; i<noDates; i++) {
128  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
129  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
130  }
131  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
132  m_field->SetMConstants(i,0);
133  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
134  }
135  }
136  }
137 
138  // Now no operations can be timed after the start of the next crop.
139  if ( ! m_ev->m_first_year ) {
140  // Are we before July 1st?
141  d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
142  if (g_date->Date() < d1) {
143  // Yes, too early. We assumme this is because the last crop was late
144  g_msg->Warn( WARN_BUG, "Setaside::Do(): "
145  "Crop start attempt between 1st Jan & 1st July", "" );
146  exit( 1 );
147  } else {
148  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
149  if (g_date->Date() > d1) {
150  // Yes too late - should not happen - raise an error
151  g_msg->Warn( WARN_BUG, "SetAside::Do(): "
152  "Crop start attempt after last possible start date",
153  "" );
154  exit( 1 );
155  }
156  }
157  }
158  }//if
159 
160  // New begin.
161  d1 = g_date->OldDays() + m_first_date;
162 
163  if ( ! m_ev->m_first_year ) {
164  d1 +=365 ;
165  }
166  if ( g_date->Date() > d1 ) {
167  d1 = g_date->Date();
168  }
169 
170  // ***CJT*** altered 16 August 2004 to be more similar to non-managed set-aside
171  // SimpleEvent( d1, sa_wait, false );
172  // break;
173 
174  SimpleEvent( d1, sa_cut_to_hay, false );
175  break;
176 
177  case sa_cut_to_hay:
178  if (!m_farm->CutToHay( m_field, 0.0, g_date->DayInYear( 30, 7 ) - g_date->DayInYear())) {
179  SimpleEvent( g_date->Date() + 1, sa_cut_to_hay, false );
180  break;
181  }
182  if ( !m_farm->IsStockFarmer())
183  {
184 
185  ChooseNextCrop (3);
186 
187  SimpleEvent( g_date->Date() + 1, sa_wait, false );
188  break;
189  }
190 
192  sa_cattle_out, false );
193  break;
194 
195  case sa_cattle_out:
196  if ( m_ev->m_lock || m_farm->DoIt( 15 )) {
197  if (m_field->GetMConstants(1)==0) {
198  if (!m_farm->CattleOut( m_field, 0.0, -1)) { //raise an error
199  g_msg->Warn( WARN_BUG, "Setaside::Do(): failure in 'CattleOut' execution", "" );
200  exit( 1 );
201  }
202  }
203  else {
204  if (!m_farm->CattleOut( m_field, 0.0, m_field->GetMDates(1,1) - g_date->DayInYear())) {
205  SimpleEvent( g_date->Date() + 1, sa_cattle_out, true );
206  break;
207  }
208  }
210  break;
211  }
213  break;
214 
215  case sa_cattle_is_out:
216  if (m_field->GetMConstants(2)==0) {
217  if (!m_farm->CattleIsOut( m_field, 0.0, -1, m_field->GetMDates(1,2))) { //raise an error
218  //added 28.08 - issue a warning only if we fail on the last day that this can be done, i.e. MDate
219  if(g_date->Date() == m_field->GetMDates(1,2)){
220  g_msg->Warn( WARN_BUG, "Setaside::Do(): failure in 'CattleIsOut' execution", "" );
221  exit( 1 );
222  }
223  }
224  }
225  else {
226  if (!m_farm->CattleIsOut( m_field, 0.0, m_field->GetMDates(1,2) - g_date->DayInYear(), m_field->GetMDates(1,2))) {
227  SimpleEvent( g_date->Date() + 1, sa_cattle_is_out, false );
228  break;
229  }
230  }
231  ChooseNextCrop (3);
232 
233  SimpleEvent( g_date->Date() + 1, sa_wait, false );
234  break;
235 
236  case sa_cut_to_silage:
237  if ( m_ev->m_lock || m_farm->DoIt( 15 )) {
238  if (m_field->GetMConstants(0)==0) {
239  if (!m_farm->CutToSilage( m_field, 0.0, -1)) { //raise an error
240  g_msg->Warn( WARN_BUG, "Setaside::Do(): failure in 'CutToSilage' execution", "" );
241  exit( 1 );
242  }
243  }
244  else {
245  if (!m_farm->CutToSilage( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
246  SimpleEvent( g_date->Date() + 1, sa_cut_to_silage, true );
247  break;
248  }
249  }
250  }
251 
252  ChooseNextCrop (3);
253 
254  SimpleEvent( g_date->Date() + 1, sa_wait, false );
255  break;
256 
257  case sa_wait:
258  // Cannot terminate too early otherwise will cause a rotation loop
259 
260  if ((g_date->DayInYear()-m_field->GetMDates(1,2))>=0)
261  {
262  //m_farm->Glyphosate(m_field,0.0,0);
263  // Special for set-aside:
264  m_field->SetVegPatchy( false );
265  done = true;
266  }
267  else // queue this up again
268  SimpleEvent( g_date->Date() + 1, sa_wait, true );
269  break;
270 
271  default:
272  g_msg->Warn( WARN_BUG, "SetAside::Do(): "
273  "Unknown event type! ", "" );
274  exit( 1 );
275  }
276 
277  return done;
278 }

References Farm::CattleIsOut(), Farm::CattleOut(), Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Farm::CutToHay(), Farm::CutToSilage(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), g_date, g_msg, LE::GetMConstants(), LE::GetMDates(), Farm::GetType(), Calendar::GetYearNumber(), 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, Calendar::OldDays(), sa_cattle_is_out, sa_cattle_out, sa_cut_to_hay, sa_cut_to_silage, sa_start, sa_wait, LE::SetMConstants(), LE::SetMDates(), LE::SetVegPatchy(), Crop::SimpleEvent(), tof_OptimisingFarm, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void SetAside::SetUpFarmCategoryInformation ( )
inline
79  {
80  const int elements = 2 + (sa_foobar - SETASIDE_BASE);
82 
83  FarmManagementCategory catlist[elements] =
84  {
85  fmc_Others, // zero element unused but must be here
86  fmc_Others, // sa_start = 1, // Compulsory, start event must always be 1 (one).
87  fmc_Cutting, // sa_cut_to_hay = SETASIDE_BASE,
88  fmc_Grazing, // sa_cattle_out,
89  fmc_Grazing, // sa_cattle_is_out,
90  fmc_Cutting, // sa_cut_to_silage,
91  fmc_Others, // sa_wait,
92 
93 
94  // no foobar entry
95 
96  };
97  // Iterate over the catlist elements and copy them to vector
98  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
99  }

References fmc_Cutting, fmc_Grazing, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, sa_foobar, and SETASIDE_BASE.

Referenced by SetAside().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
sa_start
Definition: SetAside.h:49
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
LE::GetMConstants
int GetMConstants(int a)
Definition: Elements.h:407
Farm::CattleIsOut
virtual bool CattleIsOut(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out' event for every day the cattle are on a_field.
Definition: FarmFuncs.cpp:2470
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
Farm::CutToSilage
virtual bool CutToSilage(LE *a_field, double a_user, int a_days)
Cut vegetation for silage on a_field.
Definition: FarmFuncs.cpp:1644
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
SetAside::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: SetAside.h:79
sa_wait
Definition: SetAside.h:54
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
Farm::GetType
TTypesOfFarm GetType(void)
Definition: Farm.h:956
SETASIDE_BASE
#define SETASIDE_BASE
Definition: SetAside.h:44
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
Farm::CutToHay
virtual bool CutToHay(LE *a_field, double a_user, int a_days)
Carry out hay cutting on a_field.
Definition: FarmFuncs.cpp:1607
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
Calendar::Date
long Date(void)
Definition: Calendar.h:57
sa_cut_to_silage
Definition: SetAside.h:53
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
LE::SetVegPatchy
void SetVegPatchy(bool p)
Definition: Elements.h:229
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::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
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
sa_foobar
Definition: SetAside.h:55
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
sa_cut_to_hay
Definition: SetAside.h:50
sa_cattle_out
Definition: SetAside.h:51
sa_cattle_is_out
Definition: SetAside.h:52
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
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
Farm::CattleOut
virtual bool CattleOut(LE *a_field, double a_user, int a_days)
Start a grazing event on a_field today.
Definition: FarmFuncs.cpp:2368
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001