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

#include <PermanentSetAside.h>

Inheritance diagram for PermanentSetAside:
Crop

Public Member Functions

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

◆ PermanentSetAside()

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

33 {
34  m_farm = a_farm;
35  m_field = a_field;
36  m_ev = a_ev;
37  bool done = false;
38  int d1;
39  int today=g_date->Date();
40  int noDates= 1;
41  switch ( m_ev->m_todo ) {
42  case psa_start:
43  a_field->ClearManagementActionSum();
44 
45  // Set up the date management stuff
47  // Start and stop dates for all events after harvest
48  m_field->SetMDates(0,0,g_date->DayInYear(1,9));
49  // Determined by harvest date - used to see if at all possible
50  m_field->SetMDates(1,0,g_date->DayInYear(1,9));
51  // Check the next crop for early start, unless it is a spring crop
52  // in which case we ASSUME that no checking is necessary!!!!
53  // So DO NOT implement a crop that runs over the year boundary
54 
55  //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)
57 
58  if (m_ev->m_startday>g_date->DayInYear(1,7))
59  {
60  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
61  {
62  g_msg->Warn( WARN_BUG, "PermanentSetAside::Do(): "
63  "Harvest too late for the next crop to start!!!", "" );
64  exit( 1 );
65  }
66  // Now fix any late finishing problems
67  for (int i=0; i<noDates; i++) {
68  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
69  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
70  }
71  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
72  m_field->SetMConstants(i,0);
73  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
74  }
75  }
76  }
77  // Now no operations can be timed after the start of the next crop.
78 
79  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
80  if (today > d1)
81  {
82  // Yes too late - should not happen - raise an error
83  g_msg->Warn( WARN_BUG, " PermanentSetAside::Do(): "
84  "Crop start attempt after last possible start date", "" );
85  exit( 1 );
86  }
87  }//if
88 
89  // Reinit d1 to first possible starting date.
90  d1 = g_date->OldDays()+m_first_date;;
91  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
92  if ( g_date->Date() > d1 )
93  {
94  d1 = g_date->Date();
95  }
96  // OK, let's go.
97  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
98 
99  // SimpleEvent( d1, psa_do_nothing_start, false );
100 
101  // ***CJT*** altered 16 August 2004 to be more similar to non-managed set-aside
102  // SimpleEvent( d1, sa_wait, false );
103  // break;
104 
105  SimpleEvent( d1, psa_cut_to_hay, false );
106  break;
107 
108  case psa_cut_to_hay:
109  if (!m_farm->CutToHay( m_field, 0.0,
110  g_date->DayInYear( 30, 7 ) - g_date->DayInYear())) {
111  SimpleEvent( g_date->Date() + 1, psa_cut_to_hay, false );
112  break;
113  }
114 
115  ChooseNextCrop (1);
116 
118  break;
119 
121  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 1, 9 ),
122  psa_do_nothing_stop, false );
123  break;
124 
125  case psa_do_nothing_stop:
126  done = true;
127  break;
128 
129  default:
130  g_msg->Warn( WARN_BUG, "PermanentSetAside::Do(): "
131  "Unknown event type! ", "" );
132  exit( 1 );
133  }
134 
135  return done;
136 }

References Crop::ChooseNextCrop(), LE::ClearManagementActionSum(), Farm::CutToHay(), Calendar::Date(), Calendar::DayInYear(), 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_startday, FarmEvent::m_todo, Calendar::OldDays(), psa_cut_to_hay, psa_do_nothing_start, psa_do_nothing_stop, psa_start, LE::SetLastSownVeg(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent(), tof_OptimisingFarm, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void PermanentSetAside::SetUpFarmCategoryInformation ( )
inline
52  {
53  const int elements = 2 + (psa_foobar - PERMANENTSETASIDE_BASE);
55 
56  FarmManagementCategory catlist[elements] =
57  {
58  fmc_Others, // zero element unused but must be here
59  fmc_Others, //psa_start = 1, // Compulsory, start event must always be 1 (one).
60  fmc_Others, //psa_do_nothing_start = PERMANENTSETASIDE_BASE,
61  fmc_Others, //psa_do_nothing_stop,
62  fmc_Cutting //psa_cut_to_hay,
63  // No foobar entry
64  };
65  // Iterate over the catlist elements and copy them to vector
66  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
67  }

References fmc_Cutting, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, PERMANENTSETASIDE_BASE, and psa_foobar.

Referenced by PermanentSetAside().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
psa_do_nothing_stop
Definition: PermanentSetAside.h:36
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
LE::SetLastSownVeg
void SetLastSownVeg(TTypesOfVegetation a_tov)
Records the last vegetation type to be sown.
Definition: Elements.h:357
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
Calendar::GetYearNumber
int GetYearNumber(void)
Definition: Calendar.h:72
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
PermanentSetAside::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: PermanentSetAside.h:52
Farm::GetType
TTypesOfFarm GetType(void)
Definition: Farm.h:956
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
PERMANENTSETASIDE_BASE
#define PERMANENTSETASIDE_BASE
Definition: PermanentSetAside.h:31
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
psa_do_nothing_start
Definition: PermanentSetAside.h:35
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::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
psa_foobar
Definition: PermanentSetAside.h:38
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
psa_start
Definition: PermanentSetAside.h:34
psa_cut_to_hay
Definition: PermanentSetAside.h:37
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
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001