ALMaSS Hare ODDox  1.1
The hare model description following ODdox protocol
PermanentGrassTussocky Class Reference

#include <PermanentGrassTussocky.h>

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 PermanentGrassTussocky ()
 
- Public Member Functions inherited from Crop
void ChooseNextCrop (int a_no_dates)
 Chooses the next crop to grow in a field. More...
 
 Crop ()
 
int GetCropClassification ()
 
int GetFirstDate (void)
 
void SetCropClassification (int a_classification)
 
virtual ~Crop ()
 

Additional Inherited Members

- 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...
 
- Protected Attributes inherited from Crop
int m_count
 
int m_CropClassification
 
int m_ddegstoharvest
 
FarmEventm_ev
 
Farmm_farm
 
LE * m_field
 
int m_first_date
 
int m_last_date
 

Detailed Description

Definition at line 45 of file PermanentGrassTussocky.h.

Constructor & Destructor Documentation

◆ PermanentGrassTussocky()

PermanentGrassTussocky::PermanentGrassTussocky ( )
inline

Definition at line 49 of file PermanentGrassTussocky.h.

50  {
51  m_first_date=g_date->DayInYear(1,6);
52  }

References Crop::m_first_date.

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

Definition at line 37 of file PermanentGrassTussocky.cpp.

38 {
39  m_farm = a_farm;
40  m_field = a_field;
41  m_ev = a_ev;
42 
43  bool done = false;
44 
45  switch ( m_ev->m_todo ) {
46  case pgt_start:
47  {
48  PGT_CUT_DATE =0;
50  // Set up the date management stuff
51  m_last_date=g_date->DayInYear(1,10);
52  // Start and stop dates for all events after harvest
53  int noDates= 1;
54  // Start and stop dates for all events after harvest
55  m_field->SetMDates(0,0,g_date->DayInYear(15,9));
56  // 0,0 determined by harvest date - used to see if at all possible
57  m_field->SetMDates( 1, 0, g_date->DayInYear(1,10) );
58  // Check the next crop for early start, unless it is a spring crop
59  // in which case we ASSUME that no checking is necessary!!!!
60  // So DO NOT implement a crop that runs over the year boundary
61 
62  //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)
63  int d1;
64  if(!(m_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber()>0)){
65 
66  if (m_ev->m_startday>g_date->DayInYear(1,7))
67  {
68  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
69  {
70  g_msg->Warn( WARN_BUG, "PermanentGrassTussocky::Do(): "
71  "Harvest too late for the next crop to start!!!", "" );
72  exit( 1 );
73  }
74  // Now fix any late finishing problems
75  for (int i=0; i<noDates; i++) {
76  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
77  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
78  }
79  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
80  m_field->SetMConstants(i,0);
81  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
82  }
83  }
84  }
85  // Now no operations can be timed after the start of the next crop.
86 
87  int today=g_date->Date();
88  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
89  if (today > d1)
90  {
91  // Yes too late - should not happen - raise an error
92  g_msg->Warn( WARN_BUG, " PermanentGrassTussocky::Do(): "
93  "Crop start attempt after last possible start date", "" );
94  exit( 1 );
95  }
96  }//if
97 
98  // Reinit d1 to first possible starting date.
99  d1 = g_date->OldDays()+m_first_date;;
100  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
101  if ( g_date->Date() > d1 ) {
102  d1 = g_date->Date();
103  }
104  // OK, let's go.
105  m_field->SetLastSownVeg( m_field->GetVegType() ); //Force last sown, needed for goose habitat classification
106 
107  ChooseNextCrop (1);
108 
109  SimpleEvent( d1, pgt_cattle_out1, false );
110  }
111  break;
112 
113  case pgt_cattle_out1:
114  if (m_field->GetMConstants(0)==0) {
115  if (!m_farm->CattleOutLowGrazing( m_field, 0.0, -1)) { //raise an error
116  g_msg->Warn( WARN_BUG, "PermanentGrassTussocky::Do(): failure in 'CattleOutLowGrazing' execution", "" );
117  exit( 1 );
118  }
119  }
120  else {
121  if (!m_farm->CattleOutLowGrazing( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
122  SimpleEvent( g_date->Date() + 1, pgt_cattle_out1, true );
123  break;
124  }
125  }
126  SimpleEvent( g_date->Date() + m_field->GetMConstants(0), pgt_cattle_is_out, false );
127  break;
128 
129  case pgt_cattle_out2:
130  if (( m_ev->m_lock || m_farm->DoIt( 33 )) || (PGT_FERTI_DATE!=0)) {
131  if (m_field->GetMConstants(0)==0) {
132  if (!m_farm->CattleOutLowGrazing( m_field, 0.0, -1)) { //raise an error
133  g_msg->Warn( WARN_BUG, "PermanentGrassTussocky::Do(): failure in 'CattleOutLowGrazing' execution", "" );
134  exit( 1 );
135  }
136  }
137  else {
138  if (!m_farm->CattleOutLowGrazing( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
139  SimpleEvent( g_date->Date() + 1, pgt_cattle_out2, true );
140  break;
141  }
142  }
143  // Success
144  SimpleEvent( g_date->Date() + m_field->GetMConstants(0), pgt_cattle_is_out, false );
145  break;
146  }
147  //Don't graze - but don't end too early;
148  SimpleEvent( g_date->OldDays() +g_date->DayInYear(2,7), pgt_wait, false );
149  break;
150 
151  case pgt_wait:
152  done=true;
153  break;
154 
155  case pgt_cattle_is_out:
156  if (m_field->GetMConstants(0)==0) {
157  if (!m_farm->CattleIsOutLow( m_field, 0.0, -1, m_field->GetMDates(1,0))) { //raise an error
158  //added 28.08 - issue a warning only if we fail on the last day that this can be done, i.e. MDate
159  if(g_date->Date() == m_field->GetMDates(1,0)){
160  g_msg->Warn( WARN_BUG, "PermanentGrassTussocky::Do(): failure in 'CattleIsOutLow' execution", "" );
161  exit( 1 );
162  }
163  }
164  }
165  else {
166  if (!m_farm->CattleIsOutLow( m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear(), m_field->GetMDates(1,0))) {
167  SimpleEvent( g_date->Date() + 1, pgt_cattle_is_out, true );
168  break;
169  }
170  }
171  // if they come in then send them out if too early
172  if (g_date->DayInYear()<g_date->DayInYear(10,9))
173  {
174  SimpleEvent( g_date->Date()+1, pgt_cattle_out2, true );
175  break;
176  }
177  // END MAIN THREAD
178  done=true;
179  break;
180 
181  default:
182  g_msg->Warn( WARN_BUG, "PermanantGrassTussocky::Do(): "
183  "Unknown event type! ", "" );
184  exit( 1 );
185  }
186 
187  return done;
188 }

References Farm::CattleIsOutLow(), Farm::CattleOutLowGrazing(), Crop::ChooseNextCrop(), Farm::DoIt(), Farm::GetType(), 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, pgt_cattle_is_out, pgt_cattle_out1, pgt_cattle_out2, PGT_CUT_DATE, PGT_FERTI_DATE, pgt_start, pgt_wait, Crop::SimpleEvent(), and tof_OptimisingFarm.


The documentation for this class was generated from the following files:
FarmEvent::m_lock
bool m_lock
Definition: farm.h:465
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: farm.cpp:800
pgt_cattle_out2
Definition: PermanentGrassTussocky.h:38
FarmEvent::m_first_year
bool m_first_year
Definition: farm.h:467
tof_OptimisingFarm
Definition: farm.h:273
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
Farm::CattleIsOutLow
virtual bool CattleIsOutLow(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out_low' event for every day the cattle are on a_field.
Definition: farmfuncs.cpp:2018
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: farm.cpp:307
Farm::CattleOutLowGrazing
virtual bool CattleOutLowGrazing(LE *a_field, double a_user, int a_days)
Start a extensive grazing event on a_field today.
Definition: farmfuncs.cpp:1944
PGT_FERTI_DATE
#define PGT_FERTI_DATE
Definition: PermanentGrassTussocky.h:33
pgt_cattle_out1
Definition: PermanentGrassTussocky.h:37
pgt_wait
Definition: PermanentGrassTussocky.h:40
PGT_CUT_DATE
#define PGT_CUT_DATE
Definition: PermanentGrassTussocky.h:32
pgt_cattle_is_out
Definition: PermanentGrassTussocky.h:39
Crop::m_farm
Farm * m_farm
Definition: farm.h:537
Crop::m_field
LE * m_field
Definition: farm.h:538
FarmEvent::m_todo
int m_todo
Definition: farm.h:469
Crop::m_last_date
int m_last_date
Definition: farm.h:542
pgt_start
Definition: PermanentGrassTussocky.h:36
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: farm.cpp:318
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539