SetAside Class Reference

Rotational set-aside management class
. More...

#include <setaside.h>

List of all members.

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


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 (  )  [inline]

References Crop::m_first_date.

00087   {
00088       m_first_date=g_date->DayInYear(1,1); // was 30,6
00089   }


Member Function Documentation

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.

References Farm::CattleIsOut(), Farm::CattleOut(), cfg_sa_glyphosate_prop(), cfg_setaside_glyphosate(), Farm::CutToHay(), Farm::CutToSilage(), Farm::DoIt(), Farm::Glyphosate(), 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, sa_cattle_is_out, sa_cattle_out, sa_cut_to_hay, sa_cut_to_silage, SA_DID_GLYPHOSATE, sa_glyphosate, sa_start, sa_wait, and Crop::SimpleEvent().

Referenced by Farm::LeSwitch().

00066 {
00067   m_farm      = a_farm;
00068   m_field     = a_field;
00069   m_ev        = a_ev;
00070   int d1      = 0;
00071   int noDates = 3;
00072   bool done   = false;
00073 
00074   switch ( m_ev->m_todo ) {
00075   case sa_start:
00076     SA_DID_GLYPHOSATE = false;
00077         // Special for set-aside:
00078     m_field->SetVegPatchy( true );
00079     // Set up the date management stuff
00080     // Could save the start day in case it is needed later
00081     // m_field->m_startday = m_ev->m_startday;
00082     m_last_date=g_date->DayInYear(10,10);
00083     // Start and stop dates for all events after harvest
00084     m_field->SetMDates(0,0,g_date->DayInYear(30,6));
00085     // Determined by harvest date - used to see if at all possible
00086     m_field->SetMDates(1,0,g_date->DayInYear(25,8));
00087     m_field->SetMDates(0,1,g_date->DayInYear(1,9));
00088     m_field->SetMDates(1,1,g_date->DayInYear(15,9));
00089     m_field->SetMDates(0,2,g_date->DayInYear(1,9));
00090     m_field->SetMDates(1,2,g_date->DayInYear(10,10));
00091     // Check the next crop for early start, unless it is a spring crop
00092     // in which case we ASSUME that no checking is necessary!!!!
00093     // So DO NOT implement a crop that runs over the year boundary
00094     if (m_ev->m_startday>g_date->DayInYear(1,7)) {
00095       if (m_field->GetMDates(0,0) >=m_ev->m_startday) {
00096         g_msg->Warn( WARN_BUG, "Setaside::Do(): "
00097                      "Harvest too late for the next crop to start!!!", "" );
00098         exit( 1 );
00099       }
00100       // Now fix any late finishing problems
00101       for (int i=0; i<noDates; i++) {
00102         if  (m_field->GetMDates(0,i)>=m_ev->m_startday)
00103           m_field->SetMDates(0,i,m_ev->m_startday-1);
00104         if  (m_field->GetMDates(1,i)>=m_ev->m_startday)
00105           m_field->SetMDates(1,i,m_ev->m_startday-1);
00106       }
00107     }
00108 
00109     // Now no operations can be timed after the start of the next crop.
00110     if ( ! m_ev->m_first_year ) {
00111       // Are we before July 1st?
00112       d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
00113       if (g_date->Date() < d1) {
00114         // Yes, too early. We assumme this is because the last crop was late
00115         g_msg->Warn( WARN_BUG, "Setaside::Do(): "
00116                      "Crop start attempt between 1st Jan & 1st July", "" );
00117         exit( 1 );
00118       } else {
00119         d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
00120         if (g_date->Date() > d1) {
00121           // Yes too late - should not happen - raise an error
00122           g_msg->Warn( WARN_BUG, "SetAside::Do(): "
00123                        "Crop start attempt after last possible start date",
00124                        "" );
00125           exit( 1 );
00126         }
00127       }
00128     }
00129 
00130     // New begin.
00131     d1 = g_date->OldDays() + m_first_date;
00132 
00133     if ( ! m_ev->m_first_year ) {
00134         d1 +=365 ;
00135     }
00136     if ( g_date->Date() > d1 ) {
00137       d1 = g_date->Date();
00138     }
00139 
00140     // ***CJT*** altered 16 August 2004 to be more similar to non-managed set-aside
00141           SimpleEvent( d1, sa_glyphosate, false );
00142           break;
00143     /*
00144         SimpleEvent( d1, sa_cut_to_hay, false );
00145     break;
00146         */
00147     
00148   case sa_cut_to_hay:
00149     if (!m_farm->CutToHay( m_field, 0.0,
00150          g_date->DayInYear( 30, 7 ) - g_date->DayInYear())) {
00151       SimpleEvent( g_date->Date() + 1, sa_cut_to_hay, false );
00152       break;
00153     }
00154     if ( !m_farm->IsStockFarmer())
00155     {
00156       SimpleEvent( g_date->Date() + 1, sa_glyphosate, false );
00157       break;
00158     }
00159     SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,1),
00160                    sa_cattle_out, false );
00161     break;
00162 
00163   case sa_cattle_out:
00164     if ( m_ev->m_lock || m_farm->DoIt( 15 ))
00165     {
00166       if (!m_farm->CattleOut( m_field, 0.0,
00167            m_field->GetMDates(1,1) - g_date->DayInYear())) {
00168         SimpleEvent( g_date->Date() + 1, sa_cattle_out, true );
00169         break;
00170       }
00171             SimpleEvent( g_date->Date() + 1, sa_cattle_is_out, false );
00172       break;
00173     }
00174     SimpleEvent( g_date->OldDays() + m_field->GetMDates(0,1),
00175                  sa_cut_to_silage, false );
00176     break;
00177 
00178   case sa_cattle_is_out:
00179     if (!m_farm->CattleIsOut( m_field, 0.0,
00180          m_field->GetMDates(1,2) - g_date->DayInYear(),m_field->GetMDates(1,2)))
00181     {
00182       SimpleEvent( g_date->Date() + 1, sa_cattle_is_out, false );
00183       break;
00184     }
00185     SimpleEvent( g_date->Date() + 1, sa_glyphosate, false );
00186     break;
00187 
00188   case sa_cut_to_silage:
00189     if ( m_ev->m_lock || m_farm->DoIt( 15 ))
00190     {
00191       if (!m_farm->CutToSilage( m_field, 0.0,
00192            m_field->GetMDates(1,0) - g_date->DayInYear())) {
00193         SimpleEvent( g_date->Date() + 1, sa_cut_to_silage, true );
00194         break;
00195       }
00196     }
00197     SimpleEvent( g_date->Date() + 1, sa_glyphosate, false );
00198     break;
00199 
00200   case sa_glyphosate:
00201     if ( m_ev->m_lock || m_farm->DoIt( (int) (100*cfg_sa_glyphosate_prop.value() )))
00202     {
00203           if (cfg_setaside_glyphosate.value()==-999) {
00204             SimpleEvent( g_date->Date() + 1, sa_wait, false );
00205                 break;
00206           }
00207           else if (g_date->DayInYear()>cfg_setaside_glyphosate.value()) {
00208             SimpleEvent( g_date->Date() + 1, sa_wait, false );
00209                 break;
00210           }
00211                   else if (g_date->DayInYear()==cfg_setaside_glyphosate.value()) {
00212                     m_farm->Glyphosate(m_field,0,0);
00213                         SA_DID_GLYPHOSATE = true;
00214                         SimpleEvent( g_date->Date() + 1, sa_wait, false );
00215                         break;
00216                   }
00217                   else SimpleEvent( g_date->Date() + 1, sa_glyphosate, true );
00218         }
00219         else SimpleEvent( g_date->Date() + 1, sa_wait, false );
00220         break;
00221 
00222   case sa_wait:
00223 
00224         d1= g_date->DayInYear();
00225         if (SA_DID_GLYPHOSATE) {
00226                 if ((g_date->DayInYear()>=cfg_setaside_glyphosate.value()) && (g_date->DayInYear()<=cfg_setaside_glyphosate.value()+20)) {
00227                 m_farm->Glyphosate(m_field,0,0);
00228                 }
00229         }
00230         // Cannot terminate too early otherwise will cause a rotation loop
00231 
00232     if ((g_date->DayInYear()-g_date->DayInYear(20,8))>=0)
00233     {
00234       // Special for set-aside:
00235       m_field->SetVegPatchy( false );
00236       done = true;
00237     }
00238     else // queue this up again
00239     SimpleEvent( g_date->Date() + 1, sa_wait, true );
00240     break;
00241 
00242   default:
00243     g_msg->Warn( WARN_BUG, "SetAside::Do(): "
00244                  "Unknown event type! ", "" );
00245     exit( 1 );
00246   }
00247 
00248   return done;
00249 }


The documentation for this class was generated from the following files:


SetAside Class Reference, 1.0