ALMaSS Partridge ODdox  1.1
The partridge model description following ODdox protocol
Crop Class Reference

The base class for all crops. More...

#include <farm.h>

Public Member Functions

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

Protected Member Functions

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

Farmm_farm
 
LEm_field
 
FarmEventm_ev
 
int m_first_date
 
int m_count
 
int m_last_date
 
int m_ddegstoharvest
 
int m_CropClassification
 

Detailed Description

The base class for all crops.

Definition at line 534 of file farm.h.

Constructor & Destructor Documentation

◆ ~Crop()

virtual Crop::~Crop ( )
inlinevirtual

Definition at line 560 of file farm.h.

560 {}

◆ Crop()

Crop::Crop ( )

Definition at line 297 of file farm.cpp.

298 {
299  m_ddegstoharvest = -1; // Set to -1 to indicate that this is not using ddegs to harvest, this will be reset in descendent classes as needed
300  SetCropClassification(tocc_Winter); // Defualt classification is Winter - change this if necessary in the derived crop constructor
301 }

References tocc_Winter.

Member Function Documentation

◆ ChooseNextCrop()

void Crop::ChooseNextCrop ( int  a_no_dates)

Chooses the next crop to grow in a field.

The function finds the next crop to grow on a field where the current crop's management has finished. If necessary, it adjusts current crop's management to the new crop.

Definition at line 318 of file farm.cpp.

318  {
319 
323  if(cfg_OptimisingFarms.value()){ // do this only if we have optimising farms
324  if(!cfg_OptimiseBedriftsmodelCrops.value()){ // do this only if we use almass crops!!
325 
326  if (g_date->GetYearNumber()>0){ //changed 030713 since we dont use m_rotation anymore - but we do in the hidden year!
327  OptimisingFarm * opf;
328  if(m_farm->GetType() == tof_OptimisingFarm){ //take only optimising farms
329  opf = dynamic_cast<OptimisingFarm*>(m_farm);
331  //move MDates if necessary, use the new_startdate:
332  if (m_ev->m_startday > g_date->DayInYear(1,7)) {
333  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
334  {
335  g_msg->Warn( WARN_BUG, "Crop::ChooseNextCrop(): ","Harvest too late for the next crop to start!!!" );
336  exit( 1 );
337  }
338  // Now fix any late finishing problems
339  for (int i=0; i<a_no_dates; i++) {
340  if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
341  m_field->SetMDates(0,i,m_ev->m_startday-1); //move the starting date
342  }
343  if(m_field->GetMDates(1,i)>=m_ev->m_startday){
344  m_field->SetMConstants(i,0); //change the default value of the MConst (=1) to 0 (necessary to correctly execute farm events in case the finishing date (MDate) was moved)
345  m_field->SetMDates(1,i,m_ev->m_startday-1); //move the finishing date
346  }
347  }
348  }
349 
350  }
351  }
352  }
353  }
354 
355 }

References cfg_OptimiseBedriftsmodelCrops, cfg_OptimisingFarms, Calendar::DayInYear(), g_date, g_msg, Calendar::GetYearNumber(), OptimisingFarm::Match_crop_to_field(), tof_OptimisingFarm, CfgBool::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ Do()

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

Definition at line 303 of file farm.cpp.

303  {
304  return true;
305 }

◆ GetCropClassification()

int Crop::GetCropClassification ( )
inline

Definition at line 567 of file farm.h.

567 { return m_CropClassification; }

References m_CropClassification.

◆ GetFirstDate()

int Crop::GetFirstDate ( void  )
inline

Definition at line 562 of file farm.h.

562 { return m_first_date; }

References m_first_date.

◆ SetCropClassification()

void Crop::SetCropClassification ( int  a_classification)
inline

Definition at line 569 of file farm.h.

569 { m_CropClassification = a_classification; }

References m_CropClassification.

◆ SimpleEvent()

void Crop::SimpleEvent ( long  a_date,
int  a_todo,
bool  a_lock 
)
protected

Adds an event to this crop management.

Definition at line 307 of file farm.cpp.

307  {
308 
309  m_farm->AddNewEvent(m_field->GetVegType(), a_date, m_field, a_todo, m_field->GetRunNum(), a_lock, 0, false, (TTypesOfVegetation)0);
310 }

◆ SimpleEvent_()

void Crop::SimpleEvent_ ( long  a_date,
int  a_todo,
bool  a_lock,
Farm a_farm,
LE a_field 
)
protected

Adds an event to this crop management without relying on member variables.

Definition at line 312 of file farm.cpp.

312  {
313 
314  a_farm->AddNewEvent(a_field->GetVegType(), a_date, a_field, a_todo, a_field->GetRunNum(), a_lock, 0, false, (TTypesOfVegetation)0);
315 }

References Farm::AddNewEvent().

Member Data Documentation

◆ m_count

int Crop::m_count
protected

Definition at line 541 of file farm.h.

◆ m_CropClassification

int Crop::m_CropClassification
protected

Definition at line 545 of file farm.h.

Referenced by GetCropClassification(), and SetCropClassification().

◆ m_ddegstoharvest

int Crop::m_ddegstoharvest
protected

Definition at line 543 of file farm.h.

◆ m_ev

FarmEvent* Crop::m_ev
protected

Definition at line 539 of file farm.h.

◆ m_farm

Farm* Crop::m_farm
protected

Definition at line 537 of file farm.h.

◆ m_field

LE* Crop::m_field
protected

Definition at line 538 of file farm.h.

◆ m_first_date

int Crop::m_first_date
protected

Definition at line 540 of file farm.h.

Referenced by GetFirstDate().

◆ m_last_date

int Crop::m_last_date
protected

Definition at line 542 of file farm.h.


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: elements.h:341
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: elements.h:342
Crop::m_ddegstoharvest
int m_ddegstoharvest
Definition: farm.h:543
Calendar::GetYearNumber
int GetYearNumber(void)
Definition: calendar.h:68
tof_OptimisingFarm
Definition: farm.h:273
OptimisingFarm::Match_crop_to_field
void Match_crop_to_field(LE *a_field)
Finds a crop to be grown on a given field next year.
Definition: farm.cpp:9161
Farm::GetType
TTypesOfFarm GetType(void)
Definition: farm.h:901
WARN_BUG
Definition: maperrormsg.h:34
Crop::m_first_date
int m_first_date
Definition: farm.h:540
FarmEvent::m_startday
int m_startday
Definition: farm.h:466
g_msg
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:41
TTypesOfVegetation
TTypesOfVegetation
Definition: tov_declaration.h:30
Farm::AddNewEvent
void AddNewEvent(TTypesOfVegetation a_event, long a_date, LE *a_field, int a_todo, long a_num, bool a_lock, int a_start, bool a_first_year, TTypesOfVegetation a_crop)
Adds an event to the event queue for a farm.
Definition: farm.cpp:789
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:59
tocc_Winter
Definition: farm.h:214
Crop::m_farm
Farm * m_farm
Definition: farm.h:537
Crop::m_field
LE * m_field
Definition: farm.h:538
cfg_OptimisingFarms
CfgBool cfg_OptimisingFarms("OPTIMISING_FARMS", CFG_CUSTOM, false)
If set to true, the farmer decision making model is active.
Crop::m_CropClassification
int m_CropClassification
Definition: farm.h:545
OptimisingFarm
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:2028
Calendar::DayInYear
int DayInYear(void)
Definition: calendar.h:58
Crop::SetCropClassification
void SetCropClassification(int a_classification)
Definition: farm.h:569
g_date
class Calendar * g_date
Definition: calendar.cpp:38
cfg_OptimiseBedriftsmodelCrops
CfgBool cfg_OptimiseBedriftsmodelCrops("OPTIMISE_BEDRIFTSMODEL_CROPS", CFG_CUSTOM, false)
If set to true, the original farm optimisation model's crop set is used in the farmer decision making...
LE::SetMConstants
void SetMConstants(int a, int c)
Definition: elements.h:344
CfgBool::value
bool value(void)
Definition: configurator.h:135
Crop::m_ev
FarmEvent * m_ev
Definition: farm.h:539