ALMaSS Rabbit ODdox  1.00
The rabbit model description following ODdox protocol
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
OptimisingCattleFarm Class Reference

Subclass of the AnimalFarm. More...

#include <farm.h>

Inheritance diagram for OptimisingCattleFarm:
AnimalFarm OptimisingFarm Farm

Public Member Functions

 OptimisingCattleFarm (FarmManager *a_myfarmmanager, int a_No)
 
virtual ~OptimisingCattleFarm ()
 
- Public Member Functions inherited from AnimalFarm
 AnimalFarm (FarmManager *a_myfarmmanager, int a_No)
 
virtual ~AnimalFarm ()
 
- Public Member Functions inherited from OptimisingFarm
 OptimisingFarm (FarmManager *a_myfarmmanager, int a_No)
 The constructor. More...
 
virtual ~OptimisingFarm ()
 
TTypesOfOptFarms Get_farmType (void)
 
TTypesOfSoils Get_soilType (void)
 
TTypesOfFarmSize Get_farmSize (void)
 
int Get_farmRealID (void)
 
int Get_soilSubType (void)
 
int Get_almass_no (void)
 
CropOptimisedGet_crop (int i)
 
int Get_cropsSize (void)
 
void Set_Livestock (Livestock *p_lvs)
 
void Set_Crop (CropOptimised *p_crop)
 
void Set_Neighbour (OptimisingFarm *farm)
 
int Get_NeighboursSize (void)
 
OptimisingFarmGet_Neighbour (int i)
 
vector< AlmassCropGet_rotational_crops ()
 
vector< AlmassCropGet_rotational_crops_visible ()
 
double Get_actual_profit ()
 
double Get_actual_aggregated_yield ()
 
int GetFarmCentroidX ()
 
int GetFarmCentroidY ()
 
void Set_main_goal (TTypeOfFarmerGoal a_goal)
 
TTypeOfFarmerGoal Get_main_goal ()
 
void Set_animals_no (int a_number)
 
int Get_decision_mode_counters (int index)
 
bool Harvest (LE *a_field, double a_user, int a_days)
 OptimisingFarm's virtual version of Farm::Harvest(). Saves information on biomass of a crop at harvest. More...
 
void Match_crop_to_field (LE *a_field)
 Finds a crop to be grown on a given field next year. More...
 
OptimisingFarmFind_neighbour_to_imitate ()
 Picks randomly a farmer to imitate/compare with. It chooses among neighbouring farmers with similar farms. More...
 
void ActualProfit ()
 Function that determines actual crop yields and profit in a given year. More...
 
void Save_last_years_crops ()
 It saves the OptimisingFarm::m_rotational_crops in a vector m_rotational_crops_visible which is accessible for other farmers if they decide to copy it in the following year. More...
 
void ChooseDecisionMode ()
 Function determines which decision mode to use. The choice depends on the values of need satisfaction and uncertainty. More...
 
virtual bool Spraying_herbicides (TTypesOfVegetation a_tov_type)
 Returns true if a farmer decided to treat a given crop with herbicides. More...
 
virtual bool Spraying_fungins (TTypesOfVegetation a_tov_type)
 Returns true if a farmer decided to treat a given crop with fung- and insecticides. More...
 
virtual double Prob_multiplier ()
 Used when determining whether there should be a spraying event (i.e. pesticides application) or not. For yield maximizer it increases the chance of spraying event to account for his 'just in case' spraying. More...
 
void Init (ofstream *ap_output_file)
 Function carrying out the initial calculations at a farm level (including the initial optimisation). More...
 
- Public Member Functions inherited from Farm
virtual void Management (void)
 Starts the main management loop for the farm and performs some error checking. More...
 
void AddField (LE *a_newfield)
 Adds a field to a farm. More...
 
void RemoveField (LE *a_field)
 Removes a field from a farm. More...
 
 Farm (FarmManager *a_manager)
 Farm constructor - creates an instance of each possible crop type. More...
 
virtual ~Farm (void)
 Farm destructor - deletes all crop instances and empties event queues. More...
 
void SetFarmNumber (int a_farm_num)
 
int GetFarmNumber (void)
 
void Assign_rotation (vector< TTypesOfVegetation >a_new_rotation)
 
polylistListOpenFields (int a_openness)
 Returns a list of fields with openness above a_openness. More...
 
void Centroids ()
 Finds farm's centroids - x and y. More...
 
int GetNoFields ()
 Returns the number of the fields owned. More...
 
int GetNoOpenFields (int a_openness)
 Returns the number of the fields above an openness of a_openness. More...
 
int GetAreaOpenFields (int a_openness)
 Returns the area of the fields above an openness of a_openness. More...
 
APoint GetValidCoords ()
 Returns the valid coordinates of the first field owned by a farm. More...
 
int GetMaxOpenness ()
 Returns the maximum openness score of the fields. More...
 
virtual bool SleepAllDay (LE *a_field, double a_user, int a_days)
 Nothing to to today on a_field. More...
 
virtual bool AutumnPlough (LE *a_field, double a_user, int a_days)
 Carry out a ploughing event in the autumn on a_field. More...
 
virtual bool AutumnHarrow (LE *a_field, double a_user, int a_days)
 Carry out a harrow event in the autumn on a_field. More...
 
virtual bool AutumnRoll (LE *a_field, double a_user, int a_days)
 Carry out a roll event in the autumn on a_field. More...
 
virtual bool AutumnSow (LE *a_field, double a_user, int a_days)
 Carry out a sowing event in the autumn on a_field. More...
 
virtual bool WinterPlough (LE *a_field, double a_user, int a_days)
 Carry out a ploughing event in the winter on a_field. More...
 
virtual bool DeepPlough (LE *a_field, double a_user, int a_days)
 Carry out a deep ploughing event on a_field. More...
 
virtual bool SpringPlough (LE *a_field, double a_user, int a_days)
 Carry out a ploughing event in the spring on a_field. More...
 
virtual bool SpringHarrow (LE *a_field, double a_user, int a_days)
 Carry out a harrow event in the spring on a_field. More...
 
virtual bool SpringRoll (LE *a_field, double a_user, int a_days)
 Carry out a roll event in the spring on a_field. More...
 
virtual bool SpringSow (LE *a_field, double a_user, int a_days)
 Carry out a sowing event in the spring on a_field. More...
 
virtual bool GrowthRegulator (LE *a_field, double a_user, int a_days)
 Apply growth regulator to a_field. More...
 
virtual bool SynInsecticideTreat (LE *a_field, double a_user, int a_days)
 Apply special insecticide to a_field. More...
 
virtual bool ProductApplication0 (LE *a_field, double a_user, int a_days)
 Apply test pesticide to a_field. More...
 
virtual bool ProductApplication1 (LE *a_field, double a_user, int a_days)
 Apply test pesticide to a_field. More...
 
virtual bool Molluscicide (LE *a_field, double a_user, int a_days)
 Apply molluscidie to a_field. More...
 
virtual bool RowCultivation (LE *a_field, double a_user, int a_days)
 Carry out a harrowing between crop rows on a_field. More...
 
virtual bool Strigling (LE *a_field, double a_user, int a_days)
 Carry out a mechanical weeding on a_field. More...
 
virtual bool StriglingSow (LE *a_field, double a_user, int a_days)
 Carry out a mechanical weeding followed by sowing on a_field. More...
 
virtual bool HillingUp (LE *a_field, double a_user, int a_days)
 Do hilling up on a_field, probably of potatoes. More...
 
virtual bool Water (LE *a_field, double a_user, int a_days)
 Carry out a watering on a_field. More...
 
virtual bool Swathing (LE *a_field, double a_user, int a_days)
 Cut the crop on a_field and leave it lying (probably rape) More...
 
virtual bool HarvestLong (LE *a_field, double a_user, int a_days)
 Carry out a harvest on a_field. More...
 
virtual bool CattleOut (LE *a_field, double a_user, int a_days)
 Start a grazing event on a_field today. More...
 
virtual bool CattleOutLowGrazing (LE *a_field, double a_user, int a_days)
 Start a extensive grazing event on a_field today. More...
 
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. More...
 
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. More...
 
virtual bool PigsOut (LE *a_field, double a_user, int a_days)
 Generate a 'pigs_out' event for every day the cattle are on a_field. More...
 
virtual bool PigsAreOut (LE *a_field, double a_user, int a_days)
 Start a pig grazing event on a_field today or soon. More...
 
virtual bool PigsAreOutForced (LE *a_field, double a_user, int a_days)
 Start a pig grazing event on a_field today - no exceptions. More...
 
virtual bool CutToHay (LE *a_field, double a_user, int a_days)
 Carry out hay cutting on a_field. More...
 
virtual bool CutWeeds (LE *a_field, double a_user, int a_days)
 Carry out weed topping on a_field. More...
 
virtual bool CutToSilage (LE *a_field, double a_user, int a_days)
 Cut vegetation for silage on a_field. More...
 
virtual bool CutOrch (LE *a_field, double a_user, int a_days)
 Cut vegetation on orchard crop. //based on cut to silage - values from cutting function of orchard. More...
 
virtual bool StrawChopping (LE *a_field, double a_user, int a_days)
 Carry out straw chopping on a_field. More...
 
virtual bool HayTurning (LE *a_field, double a_user, int a_days)
 Carry out hay turning on a_field. More...
 
virtual bool HayBailing (LE *a_field, double a_user, int a_days)
 Carry out hay bailing on a_field. More...
 
virtual bool BurnStrawStubble (LE *a_field, double a_user, int a_days)
 Burn stubble on a_field. More...
 
virtual bool StubbleHarrowing (LE *a_field, double a_user, int a_days)
 Carry out stubble harrowing on a_field. More...
 
virtual bool FP_NPKS (LE *a_field, double a_user, int a_days)
 Apply NPKS fertilizer, on a_field owned by an arable farmer. More...
 
virtual bool FP_NPK (LE *a_field, double a_user, int a_days)
 Apply NPK fertilizer, on a_field owned by an arable farmer. More...
 
virtual bool FP_PK (LE *a_field, double a_user, int a_days)
 Apply PK fertilizer, on a_field owned by an arable farmer. More...
 
virtual bool FP_LiquidNH3 (LE *a_field, double a_user, int a_days)
 Apply liquid ammonia fertilizer to a_field owned by an arable farmer. More...
 
virtual bool FP_Slurry (LE *a_field, double a_user, int a_days)
 Apply slurry to a_field owned by an arable farmer. More...
 
virtual bool FP_ManganeseSulphate (LE *a_field, double a_user, int a_days)
 Apply Manganse Sulphate to a_field owned by an arable farmer. More...
 
virtual bool FP_Manure (LE *a_field, double a_user, int a_days)
 Spread manure on a_field owned by an arable farmer. More...
 
virtual bool FP_GreenManure (LE *a_field, double a_user, int a_days)
 Spread green manure on a_field owned by an arable farmer. More...
 
virtual bool FP_Sludge (LE *a_field, double a_user, int a_days)
 Spread sewege on a_field owned by an arable farmer. More...
 
virtual bool FA_NPK (LE *a_field, double a_user, int a_days)
 Apply NPK fertilizer to a_field owned by an stock farmer. More...
 
virtual bool FA_PK (LE *a_field, double a_user, int a_days)
 Apply PK fertilizer to a_field owned by an stock farmer. More...
 
virtual bool FA_Slurry (LE *a_field, double a_user, int a_days)
 Spready slurry on a_field owned by an stock farmer. More...
 
virtual bool FA_AmmoniumSulphate (LE *a_field, double a_user, int a_days)
 Apply ammonium supahte to a_field owned by an stock farmer. More...
 
virtual bool FA_Manure (LE *a_field, double a_user, int a_days)
 Spread manure on a_field owned by an stock farmer. More...
 
virtual bool FA_GreenManure (LE *a_field, double a_user, int a_days)
 Spread green manure on a_field owned by an stock farmer. More...
 
virtual bool FA_Sludge (LE *a_field, double a_user, int a_days)
 Spread sewege sludge on a_field owned by an stock farmer. More...
 
virtual bool Trial_PesticideTreat (LE *a_field, double a_user, int a_days)
 Special pesticide trial functionality. More...
 
virtual bool Trial_PesticideTreat_DateLimited (LE *a_field, double, int)
 Special pesticide trial functionality. More...
 
virtual bool Trial_PesticideTreat_GS (LE *a_field, double a_user, int a_days)
 Special pesticide trial functionality. More...
 
virtual bool Trial_ToxicControl (LE *a_field, double a_user, int a_days)
 Special pesticide trial functionality. More...
 
virtual bool Trial_Control (LE *a_field, double a_user, int a_days)
 Special pesticide trial functionality. More...
 
virtual bool Glyphosate (LE *a_field, double a_user, int a_days)
 
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. More...
 
bool DoIt (int a_probability)
 Return chance out of 100. More...
 
TTypesOfFarm GetType (void)
 
int GetArea (void)
 Returns the area of arable fields owned by that farm. More...
 
int GetTotalArea (void)
 Returns the area of all fields owned by that farm. More...
 
double GetAreaDouble (void)
 Returns the area of arable fields owned by that farm. More...
 
bool IsStockFarmer (void)
 
virtual void MakeStockFarmer (void)
 
int GetIntensity (void)
 
APoint GetCentroids ()
 
TTypesOfVegetation GetPreviousCrop (int a_index)
 
TTypesOfVegetation GetCrop (int a_index)
 
TTypesOfVegetation GetNextCrop (int a_index)
 
void AddHunter (Hunter *a_hunter)
 
bool RemoveHunter (Hunter *a_hunter)
 

Protected Member Functions

virtual void checkRestrictions ()
 Checks if the restrictions are fulfilled and corrects crops' areas if necessary. More...
 
void checkCattleRotation ()
 Checks if the cattle restriction is fulfilled - in the Bedriftsmodel (original farm optimization model) crop mode. More...
 
void checkCattleRotation_almass ()
 Checks if the cattle restriction is fulfilled - in the ALMaSS crops mode. More...
 
void setCattleCropsAtMin ()
 Decreases area of cattle crops to their min. required area. More...
 
virtual void preventCashCrops ()
 Prevents small cattle farms from growing cash crops and maize silage. More...
 
- Protected Member Functions inherited from AnimalFarm
virtual void createCropsLists (int a_foobar)
 Creates lists of crops. More...
 
virtual void determineAreas (int a_foobar)
 Determines areas of variable crops. More...
 
void createFodderCrops (int a_foobar)
 Creates a list of pointers to all fodder crops. More...
 
void findFodderCropSavings ()
 Determines the savings resulting from growing a fodder crop relative to purchasing fodder. More...
 
void correctFodderDemand (int a_foobar)
 Determines how much fodder is produced from fixed crops and min. areas of variable crops. More...
 
void determineFodderAreas (int a_foobar)
 Determines areas of fodder crops and corrects areas of non-fodder crops. More...
 
void determineMinFodder (int a_foobar)
 Covers the min. required fodder production for animal farms. More...
 
virtual void checkWinterRotation1 ()
 Animal farm version of the OptimisingFarm::checkWinterRotation1() function (accounts for fodder changes). More...
 
virtual void checkWinterCrops ()
 Animal farm version of the checkWinterCrops() function (accounts for fodder changes). More...
 
virtual void increaseCrops (vector< CropSort >cropsToIncrease, double &howMuchToIncrease)
 Increases area of cropsToIncrease by howMuchToIncrease. More...
 
virtual void decreaseCrops (vector< CropSort >cropsToDecrease, double &howMuchToDecrease)
 Decreases area of cropsToDecrease by howMuchToDecrease. More...
 
- Protected Member Functions inherited from OptimisingFarm
virtual void InitiateManagement (void)
 Kicks off the farm's management. More...
 
void Initialize (FarmManager *a_pfm)
 Assigns to each farm its farm type, farm size, farm's real ID number, and soil type. It creates livestock and crops. More...
 
virtual void HandleEvents (void)
 If there are events to carry out do this, and perhaps start a new crop. More...
 
virtual bool FungicideTreat (LE *a_field, double, int a_days)
 Carries out fungicide application. Saves information on each application for a given crop. More...
 
virtual bool InsecticideTreat (LE *a_field, double, int a_days)
 Carries out insecticide application. Saves information on each application for a given crop. More...
 
virtual bool HerbicideTreat (LE *a_field, double, int a_days)
 Carries out herbicide application. Saves information on each application for a given crop. More...
 
void createVariableCrops (int a_foobar)
 Creates a list of pointers to all variable crops included in the optimisation and a list of pointers to fixed crops. More...
 
void FarmLevelCalculation ()
 Calls functions determining farm level values before the initial optimisation. More...
 
void OptimiseFarm (int a_foobar)
 Carries out the whole farm optimisation. More...
 
void Check_SG_and_CGG ()
 Modifies areas of SeedGrass1 and SeedGrass2, CloverGrassGrazed1 and CloverGrassGrazed2 to be even. Used only in ALMaSS crops mode (in Bedriftsmodel (original farm optimization model) crops mode this is taken care of in Translate_crops_to_almass()). More...
 
void findTotalArea ()
 Determines m_totalArea of a farm. More...
 
void findTotalNanim ()
 Determines total animal fertilizer (m_totalNanim) available at a farm. More...
 
void findNanim ()
 Determines amount of animal fertilizer per ha (m_Nanim) at a farm. More...
 
virtual void findFodderDemand ()
 Determines farm's total demand for fodder (m_totalFUdemand). More...
 
void optimizeCrops (int a_foobar)
 Carries out crop optimisation at a farm. More...
 
void findFertilizer (CropOptimised *a_crop, int a_foobar, double benefit)
 Determines the optimal amounts of: total fertilizer (CropOptimised::m_n) and purchased fertilizer (CropOptimised::m_nt) for a given crop at a farm. More...
 
void findResponse (CropOptimised *a_crop, int a_foobar)
 Determines the response (CropOptimised::m_resp) of a crop at a farm. More...
 
void findBIs (CropOptimised *a_crop, double benefit)
 Determines the optimal Treatment frequency indices (behandling index, BI in Danish) (CropOptimised::m_BIHerb, CropOptimised::m_BIFi, CropOptimised::m_BI) for a given crop at a farm. More...
 
void fixBI ()
 Sets values of Treatment frequency indices (BI) for crops with fixed amount of pesticides (CropOptimised::m_BIHerb for FodderBeet and both CropOptimised::m_BIHerb and CropOptimised::m_BIFi for PotatoesIndustry and Potatoes). More...
 
void findMWeedControl (CropOptimised *a_crop)
 Determines the optimal mechanical weed control means (CropOptimised::m_grooming, CropOptimised::m_hoeing, CropOptimised::m_weeding) for a given crop at a farm. More...
 
void findYieldLoss (CropOptimised *a_crop)
 Determines the yield losses (CropOptimised::m_lossHerb, CropOptimised::m_lossFi, CropOptimised::m_totalLoss) for a given crop at a farm. More...
 
void findGrossMargin (CropOptimised *a_crop, int a_foobar, double benefit)
 Determines the gross margin (CropOptimised::m_GM) for a given crop at a farm. More...
 
void assignFixed ()
 Adds areas of fixed crops to the variable m_assigned. For each fixed crop it saves its area under variable CropOptimised::m_areaPercent. More...
 
void sumMinAreas ()
 Adds minimum required areas of variable crops to the variable m_assigned. More...
 
void determineAreas_ha (vector< CropOptimised * >crops)
 Determines areas of crops in ha. More...
 
void setRotationCropsAtMax ()
 Increases area of winter rotation crops to their max. allowed area. More...
 
double crop_parameter (int index, string par_name)
 Reads in crop parameters that do NOT vary with any farm level parameters. More...
 
CropOptimisedfindCropByName (string crop_name)
 Returns a pointer to a crop whose name is specified as the argument (bedriftsmodel, i.e. original farm optimization model, crops mode). More...
 
CropOptimisedfindCropByName_almass (string crop_name)
 Returns a pointer to almass crop whose name is specified as the argument (ALMaSS crops mode). More...
 
CropOptimisedfindCropByName_almass (TTypesOfVegetation a_tov_type)
 Returns a pointer to almass crop whose tov type is specified as the argument. More...
 
double total (TTypesOfCropVariables variable_name)
 Function for determining total values per farm after initial optimisation. More...
 
void sortCrops (vector< CropSort > &cropsToSort, string sortingKey)
 Sorts structs of type CropSort. More...
 
void randomizeCropList (vector< CropSort > &listToRandomize, string key)
 Swaps randomly elements of the list holding same values of the key (according to which the list was previosuly sorted). More...
 
void Print_FarmVariables (ofstream *ap_output_file)
 Prints farm-level variables to a text file (one file for all farms). More...
 
void Make_rotations ()
 Creates m_rotation. Not used in ALMaSS crop mode. More...
 
void Check_if_area_100 ()
 Checks if the sum of crops' areaPercent is 100%. More...
 
void Translate_crops_to_almass ()
 Translates crops from Bedriftsmodel (original farm optimization model) to Almass crops. Used in Bedriftsmodel crop mode. More...
 
void Make_almass_crops_vector ()
 Creates a vector storing crops with positive area. Used in ALMaSS crop mode. More...
 
void Make_rotational_crops ()
 Creates a vector m_rotational_crops using the results of optimisation. More...
 
void Print_rotations (ofstream *ap_output_file)
 Prints the content of a farm's m_rotation. Not used in ALMaSS crop mode. More...
 
- Protected Member Functions inherited from Farm
int GetFirstDate (TTypesOfVegetation a_tov)
 Gets the start date for a crop type. More...
 
int GetNextCropStartDate (LE *a_field, TTypesOfVegetation &a_curr_veg)
 Returns the start date of the next crop in the rotation. More...
 
virtual int GetFirstCropIndex (TTypesOfLandscapeElement a_type)
 Gets the first crop for the farm. More...
 
virtual int GetNextCropIndex (int a_rot_index)
 Returns the next crop in the rotation. More...
 
bool LeSwitch (FarmEvent *ev)
 Call do function for any crop with an outstanding event. Signal if the crop has terminated. More...
 
void CheckRotationManagementLoop (FarmEvent *ev)
 
void ReadRotation (std::string fname)
 Reads a rotation file into the rotation. More...
 
void AssignPermanentCrop (TTypesOfVegetation tov, int pct)
 Used to assign a permanent crop to an otherwise rotational field polygon. More...
 
int InvIntPartition (vector< tpct > *items, int target)
 Finds all possible sums of the integers in the items array. More...
 

Protected Attributes

vector< CropSortm_cattleCrops
 Vector of crops used in checkCattleRotation. More...
 
vector< CropSortm_cattleCrops_almass
 Vector of crops used in checkCattleRotation_almass. More...
 
- Protected Attributes inherited from AnimalFarm
CropOptimisedm_fakeCrop
 Crop used to fill up area of a farm up to 100% in case its non-fodder crops do not sum to 100% in determineAreas. Later this crop is removed in the function determineFodderAreas. More...
 
bool m_fakeCropTest
 Set to true if the fake crop is present after determineAreas function. More...
 
vector< CropSortm_fodderCrops
 List of pointers to variable (non-fixed) fodder crops. More...
 
double m_totalFodderToProduce
 Fodder that has to be produced by a farm to fulfill the min. fodder production restriction. [fodder units]. More...
 
double m_fodderToProduce
 Fodder that has to be produced to fulfill the min. fodder production restriction at the end of a year (should be zero). Accounts for fodder from fixed crops and from min. areas of variable crops. [fodder units]. More...
 
double m_fodderToProduceBefore
 Fodder that has to be produced to fulfill the min. fodder production restriction at the beginning of a year. Accounts for fodder from fixed crops and from min. areas of variable crops. Should be zero at the end of a year. [fodder units]. More...
 
bool cash_crops_allowed
 Sets to true if cash crops are allowed. True by default. More...
 
- Protected Attributes inherited from OptimisingFarm
TTypeOfFarmerGoal m_main_goal
 Farmer's main goal (determined by a farmer's type) . More...
 
vector< OptimisingFarm * > m_neighbours
 Vector of pointers to the farms considered neighbours (fulfilling the neighbourship condition) of a given farm. More...
 
double m_need_satisfaction_level
 Farmer's actual satisfaction level. More...
 
double m_certainty_level
 Farmer's certainty level. More...
 
vector< int > m_decision_mode_counters
 Vector with counters for each decision mode. 0 - imitation, 1 - social comparison, 2 - repeat, 3 - deliberation. More...
 
double m_actual_profit
 An actual profit realised at a farm in a given year. More...
 
double m_exp_profit
 An expected farm's profit for a given year. More...
 
double m_actual_income
 An actual income at a farm in a given year. More...
 
double m_exp_income
 An expected farm's income at a farm in a given year. More...
 
double m_actual_costs
 Actual costs at a farm in a given year. More...
 
double m_exp_costs
 Expected costs at a farm in a given year. More...
 
double m_actual_aggregated_yield
 Actual aggregated yield at a farm in a given year. More...
 
double m_exp_aggregated_yield
 Expected aggregated yield at a farm in a given year. More...
 
vector< double > m_previous_profits
 Vector of profits from previous years. More...
 
vector< double > m_previous_incomes
 Vector of incomes from previous years. More...
 
vector< double > m_previous_costs
 Vector of costs from previous years. More...
 
vector< double > m_previous_aggregated_yields
 Vector of aggregated yields from previous years. More...
 
vector< double > m_previous_satisfaction_levels
 Vector of satisfaction levels in five previous years. More...
 
OptimisingFarmm_previously_imitated_neighbour
 The neighbouring farmer whose crops might be copied in imitation and social comparison decision modes. More...
 
vector< double > m_animals_numbers
 Vector for storing numbers of animals at a farm in previous years (3). More...
 
bool force_deliberation
 If set to true, a farm must use deliberation as a decision strategy. More...
 
int animals_no
 Holds the number of animals in a farm at a particular day in a year (depends on a species). More...
 
vector< Livestock * > m_livestock
 Vector of pointers to animals belonging to a farm. More...
 
vector< CropOptimised * > m_crops
 Vector of pointers to all crops. More...
 
vector< CropSortm_variableCrops
 Vector of structs containing pointers to crops which are not fixed. More...
 
vector< CropSortm_variableCrops2
 Vector of structs containing pointers to crops which are not fixed and: in case of the winter rotation restriction - exclude winter rotation crops, in case of the cattle rotation restriction - exclude the three crops that form the condition of the restriction and winter wheat. More...
 
vector< CropOptimised * > m_grownVariableCrops
 Vector of pointers to variable crops that are grown on area larger than areaMin (after determineAreas function was called). More...
 
vector< CropOptimised * > m_fixedCrops
 Vector of pointers to fixed crops. More...
 
vector< CropSortm_rotationCrops
 Vector of structs containing pointers to (winter) rotation crops. More...
 
vector< CropSortm_winterCrops
 Vector of structs containing pointers to winter crops. More...
 
vector< AlmassCropm_crops_almass
 Vector of structs with almass type crops with positive areas in % (result of optimisation). More...
 
vector< AlmassCropm_rotational_crops
 Vector of structs with almass type crops with positive areas in % (result of optimisation): includes only rotational crops. More...
 
vector< AlmassCropm_rotational_crops_copy
 A copy of m_rotational_crops used when matching crops to fields. More...
 
vector< AlmassCropm_rotational_crops_visible
 Stores a copy of m_rotational_crops from a previous year and is accessible to farmers who want to copy this farm's crops (in imitation or social comparison decision mode). More...
 
TTypesOfOptFarms m_farmType
 Farm's type (cattle, pig, plant, other). More...
 
TTypesOfSoils m_soilType
 Farm's soil type (sandy, clay, other). More...
 
TTypesOfFarmSize m_farmSize
 Scale of the farm - business (size above 10 ha) or private (size below 10 ha). More...
 
int m_farmRealID
 Farm's real ID number. More...
 
int m_soilSubType
 Farm's soil subtype. Defined only for cattle farms on sandy soil (0-bad, 1-good, 2-undefined). More...
 
int m_almass_no
 Farm's almass number. More...
 
double m_totalArea
 Total area of a farm. A sum of initial crop areas (if in bedriftsmodel, i.e. original farm optimization model, crops mode) or a sum of farm's fields area (if in ALMaSS crops mode). [ha]. More...
 
double m_totalArea_original
 Total area of a farm as in bedriftsmodel, i.e. original farm optimization model. [ha]. More...
 
double m_area_scaling_factor
 Factor used to scale areas of fixed crops and livestock numbers. Used to adjust these values to the farm's area used in ALMaSS crops mode. More...
 
double m_totalNanim
 Total animal fertilizer at a farm. A sum of Livestock::m_NanimUsable (from all types of livestock). [kg]. More...
 
double m_Nanim
 Amount of animal fertilizer available at a farm per hectar. [kg/ha]. More...
 
double m_totalFUdemandBefore
 Farm's total demand for fodder. [fodder units] More...
 
double m_totalFUdemand
 Farm's total demand for fodder (it is covered by growing fodder crops and/or purchasing fodder and thus, at the end of a year it should not be positive). [fodder units] More...
 
double m_totalFUt
 Fodder from trade (has to be purchased). [fodder units]. More...
 
double m_totalFUgrown
 Fodder grown, i.e. obtained from growing fodder crops. [fodder units]. More...
 
double m_assigned
 Variable holding a value of area already reserved for certain crops at a farm. [0-100%]. More...
 
double m_totalN
 Total amount of fertilizer used at a farm. [kg]. More...
 
double m_totalNt
 Total amount of fertilizer purchased at a farm. [kg]. More...
 
double m_totalBIHerb
 Total amount of herbicides which is planned to be applied at a farm. Expressed as a Treatment frequency index (behandling indeks, BI in Danish). More...
 
double m_totalBIFi
 Total amount of fung- and insecticides which is planned to be applied at a farm. Expressed as a Treatment frequency index (behandling indeks, BI in Danish). More...
 
double m_totalBI
 Total amount of pesticides (sum of m_totalBIHerb and m_totalBIFi) which is planned to be applied at a farm. Expressed as a Treatment frequency index (behandling indeks, BI in Danish). More...
 
double m_totalGrooming
 Total grooming planned at a farm. More...
 
double m_totalHoeing
 Total hoeing planned at a farm. More...
 
double m_totalWeeding
 Total manual weeding planned at a farm. More...
 
double m_totalCosts
 Planned total costs of growing crops at a farm. [DKK]. More...
 
double m_totalIncome
 Planned total income from growing crops at a farm. [DKK]. More...
 
double m_totalProfit
 Planned total profit (= income - costs) at a farm. In case of animal farms costs of purchased fodder is subtracted from the profit. [DKK]. More...
 
double m_area_rot
 Area assigned to rotational crops. [ha]. More...
 
- Protected Attributes inherited from Farm
FarmManagerm_OurManager
 Pointer to the FarmManager. More...
 
LowPriority< FarmEvent * > m_queue
 
vector< LE * > m_fields
 
vector< TTypesOfVegetationm_rotation
 
vector< PermCropDatam_PermCrops
 
TTypesOfFarm m_farmtype
 
HunterList m_HuntersList
 A list of hunters allocated to this farm. More...
 
bool m_stockfarmer
 
int m_farm_num
 
int m_rotation_sync_index
 
int m_intensity
 
int m_farm_centroidx
 Farm's centroid, value x. Equal to the average of the x centroid values of all farm's fields. More...
 
int m_farm_centroidy
 Farm's centroid, value y. Equal to the average of the y centroid values of all farm's fields. More...
 
Carrots * m_carrots
 
BroadBeans * m_broadbeans
 
FodderGrass * m_foddergrass
 
CloverGrassGrazed1 * m_CGG1
 
CloverGrassGrazed2 * m_CGG2
 
FieldPeas * m_fieldpeas
 
FieldPeasSilage * m_fieldpeassilage
 
Fodderbeet * m_fodderbeet
 
Sugarbeet * m_sugarbeet
 
OFodderbeet * m_ofodderbeet
 
Maize * m_maize
 
MaizeSilage * m_maizesilage
 
OMaizeSilage * m_omaizesilage
 
OBarleyPeaCloverGrass * m_OBarleyPCG
 
OCarrots * m_ocarrots
 
OCloverGrassGrazed1 * m_OCGG1
 
OCloverGrassGrazed2 * m_OCGG2
 
OCloverGrassSilage1 * m_OCGS1
 
OFieldPeas * m_ofieldpeas
 
OFieldPeasSilage * m_ofieldpeassilage
 
OFirstYearDanger * m_ofirstyeardanger
 
OGrazingPigs * m_ograzingpigs
 
OrchardCrop * m_orchardcrop
 
Oats * m_oats
 
OOats * m_ooats
 
OPermanentGrassGrazed * m_opermgrassgrazed
 
OPotatoes * m_opotatoes
 
OSeedGrass1 * m_oseedgrass1
 
OSeedGrass2 * m_oseedgrass2
 
OSpringBarley * m_ospringbarley
 
OSpringBarleyExt * m_ospringbarleyext
 
OSpringBarleyPigs * m_ospringbarleypigs
 
OSBarleySilage * m_osbarleysilage
 
OTriticale * m_otriticale
 
OWinterBarley * m_owinterbarley
 
OWinterBarleyExt * m_owinterbarleyext
 
OWinterRape * m_owinterrape
 
OWinterRye * m_owinterrye
 
OWinterWheatUndersown * m_owinterwheatundersown
 
OWinterWheat * m_owinterwheat
 
OWinterWheatUndersownExt * m_owinterwheatundersownext
 
PermanentGrassGrazed * m_permgrassgrazed
 
PermanentGrassLowYield * m_permgrasslowyield
 
PermanentGrassTussocky * m_permgrasstussocky
 
PermanentSetAside * m_permanentsetaside
 
Potatoes * m_potatoes
 
PotatoesIndustry * m_potatoesindustry
 
SeedGrass1 * m_seedgrass1
 
SeedGrass2 * m_seedgrass2
 
SetAside * m_setaside
 
SpringBarley * m_springbarley
 
SpringBarleySpr * m_springbarleyspr
 
SpringBarleySKManagement * m_springbarleyskmanagement
 
SpringBarleyPTreatment * m_springbarleyptreatment
 
SpringBarleyCloverGrass * m_sbarleyclovergrass
 
SpringBarleySeed * m_springbarleyseed
 
SpringBarleySilage * m_springbarleysilage
 
SpringRape * m_springrape
 
Triticale * m_triticale
 
WinterBarley * m_winterbarley
 
WinterRape * m_winterrape
 
WinterRye * m_winterrye
 
WinterWheat * m_winterwheat
 
WWheatPControl * m_wwheatpcontrol
 
WWheatPToxicControl * m_wwheatptoxiccontrol
 
WWheatPTreatment * m_wwheatptreatment
 
AgroChemIndustryCereal * m_agrochemindustrycereal
 
WinterWheatStrigling * m_winterwheatstrigling
 
WinterWheatStriglingCulm * m_winterwheatstriglingculm
 
WinterWheatStriglingSingle * m_winterwheatstriglingsingle
 
SpringBarleyCloverGrassStrigling * m_springbarleyclovergrassstrigling
 
SpringBarleyStrigling * m_springbarleystrigling
 
SpringBarleyStriglingCulm * m_springbarleystriglingculm
 
SpringBarleyStriglingSingle * m_springbarleystriglingsingle
 
MaizeStrigling * m_maizestrigling
 
WinterRapeStrigling * m_winterrapestrigling
 
WinterRyeStrigling * m_winterryestrigling
 
WinterBarleyStrigling * m_winterbarleystrigling
 
FieldPeasStrigling * m_fieldpeasstrigling
 
SpringBarleyPeaCloverGrassStrigling * m_springbarleypeaclovergrassstrigling
 
YoungForestCrop * m_youngforest
 

Detailed Description

Subclass of the AnimalFarm.

Definition at line 2305 of file farm.h.

Constructor & Destructor Documentation

OptimisingCattleFarm::OptimisingCattleFarm ( FarmManager a_myfarmmanager,
int  a_No 
)

Definition at line 4807 of file farm.cpp.

4807  :AnimalFarm(a_myfarmmanager, a_No){
4808 }
AnimalFarm(FarmManager *a_myfarmmanager, int a_No)
Definition: farm.cpp:4793
virtual OptimisingCattleFarm::~OptimisingCattleFarm ( )
inlinevirtual

Definition at line 2308 of file farm.h.

2308 {};

Member Function Documentation

void OptimisingCattleFarm::checkCattleRotation ( )
protected

Checks if the cattle restriction is fulfilled - in the Bedriftsmodel (original farm optimization model) crop mode.

Used in the Bedriftsmodel crop mode. Function checking if the restriction for cattle farms on attachment of spring barley, clover-grass and grass seed is fulfilled. If not, it corrects crops' areas - if possible, reduces the area of grass clover and/or seed grass and increases area of other crops. The function first checks if it pays off to substitute one or two of the cattle crops (clovergrass and grass seed) with a variable crop other than Spring Barley. If yes, it decreases the area of one or two of the cattle crops. If the condition is not fulfilled yet, the function reduces the area of one or two of the cattle crops and adds a corresponding area to the Spring Barley. None of the three crops in the condition is fixed. Spring barley and grass-clover are fodder crops.

Definition at line 6576 of file farm.cpp.

References OptimisingFarm::decreaseCrops(), OptimisingFarm::findCropByName(), DataForOptimisation::Get_fodder(), DataForOptimisation::Get_FUKey(), OptimisingFarm::increaseCrops(), OptimisingFarm::m_almass_no, CropOptimised::m_areaPercent, OptimisingFarm::m_farmType, CropOptimised::m_GM_Savings, Farm::m_OurManager, CropOptimised::m_resp, CropOptimised::m_rotationMax, OptimisingFarm::m_totalArea, OptimisingFarm::m_totalFUgrown, OptimisingFarm::m_totalFUt, CropOptimised::m_totalLoss, OptimisingFarm::m_variableCrops, OptimisingFarm::m_variableCrops2, FarmManager::pm_data, OptimisingFarm::sortCrops(), toc_Foobar, and toc_SBarley.

6576  {
6584 //This function can be called only after fodder crops were assigned areas because two of them are fodder crops! So before assiging the fodder crops, their areas will be zero!
6585 
6586 
6587  CropOptimised *sBarley = findCropByName("SBarley"); //fodder
6588  CropOptimised *gClover = findCropByName("GrassClover"); //fodder
6589  CropOptimised *gSeed = findCropByName("GrassSeed");
6590 
6591  CropOptimised *wWheat = findCropByName("WWheat");
6592 
6593  double areaSBarley = sBarley->m_areaPercent;
6594  double areaGClover = gClover->m_areaPercent;
6595  double areaGSeed = gSeed->m_areaPercent;
6596 
6597  double diff = areaGClover + areaGSeed - areaSBarley;
6598 
6599  if(diff > 0){ //restriction is not fulfilled
6600 
6601  //1. Make a vector of (two) cattle crops and sort them from highest to lowest GM/Savings
6602  CropSort cs1 = {0., gClover}; //an object with a key for sorting and a pointer to crop
6603  CropSort cs2 = {0., gSeed};
6604  m_cattleCrops.push_back(cs1);
6605  m_cattleCrops.push_back(cs2);
6606 
6607  sortCrops(m_cattleCrops, "GM_Savings"); //sorting the two crops
6608 
6609  //2. Make a new list of variable crops - excluding all crops forming the condition
6610  m_variableCrops2 = m_variableCrops; //initiate the new list and remove all three crops:
6611  for(int s=(int)m_variableCrops2.size()-1; s>=0; s--){
6612  if(m_variableCrops2[s].crop==sBarley || m_variableCrops2[s].crop==gClover || m_variableCrops2[s].crop==gSeed || m_variableCrops2[s].crop==wWheat){ //14.02 - added winter wheat - do not increase it!maybe i should even add here all winter crops...
6613  m_variableCrops2.erase(m_variableCrops2.begin() + s);
6614  }
6615  }
6616 
6617  //3. check if it pays off to substitute one of the two cattle crops with variable crops other than SBarley; if so - change the areas
6618  for(int i=(int)m_cattleCrops.size()-1; i>=0 && diff>0; i--){ //start with the worse one
6619  double areaCC = m_cattleCrops[i].crop->m_areaPercent; //don't know which of the two it is, so have to get the values this way
6620  double areaMinCC = m_cattleCrops[i].crop->m_rotationMin;
6621  double areaCCBefore = areaCC;
6622  if(areaCC > areaMinCC){
6623  bool cCropAtMin = false;
6624  for(int j=0; j<(int)m_variableCrops2.size() && cCropAtMin==false; j++){ //start with the best variable crop
6625  double GM_SBarley = sBarley->m_GM_Savings;
6626  double GM_CC = m_cattleCrops[i].crop->m_GM_Savings; //in case it is a fodder crop - then it takes savings, as now, after findFodderCropSavings() - savings are saved under GM_Savings for fodder crops
6627  double GM_var = m_variableCrops2[j].crop->m_GM_Savings;
6628  if(GM_SBarley + GM_CC > 2*GM_var){
6629  //yes: it doesn't pay off to remove this cattle crop; go to the next part of the cattle rot. function: increase SBarley, cut one of the cattle crops
6630  }
6631  else{
6632  double areaVar = m_variableCrops2[j].crop->m_areaPercent;
6633  double areaMaxVar = m_variableCrops2[j].crop->m_rotationMax;
6634  double areaVarBefore = areaVar;
6635 
6636  if(areaCC - areaMinCC >= diff){
6637  if(areaMaxVar - areaVar >= diff){
6638  areaCC -= diff;
6639  areaVar += diff;
6640  diff = 0; //finished -> cattle rotation fulfilled
6641  cCropAtMin = true; //stop the inner loop!!!
6642  }
6643  else{
6644  diff -= (areaMaxVar - areaVar);
6645  areaCC -= (areaMaxVar - areaVar);
6646  areaVar = areaMaxVar; //go to the next var. crop (j++)
6647  }
6648  }
6649  else{
6650  if(areaMaxVar - areaVar >= areaCC - areaMinCC){
6651  diff -= areaCC - areaMinCC;
6652  areaVar += areaCC - areaMinCC;
6653  areaCC = areaMinCC;
6654  cCropAtMin = true; //stop the inner loop - take the next cattle crop(i--)
6655  }
6656  else{
6657  diff -= areaMaxVar - areaVar;
6658  areaCC -= areaMaxVar - areaVar;
6659  areaVar = areaMaxVar; //go to the next var crop (j++)
6660  }
6661  }
6662 
6663  //save the areas
6664  m_variableCrops2[j].crop->m_areaPercent = areaVar;
6665  m_cattleCrops[i].crop->m_areaPercent = areaCC;
6666 
6667  //correct fodder variables for the changes - both for cattle and var crop
6668 
6669  if(areaVar > areaVarBefore){
6670  int index = toc_Foobar*m_farmType + m_variableCrops[j].crop->m_cropType;
6671  bool fodder = m_OurManager->pm_data->Get_fodder(index);
6672  if(fodder){ //this is a fodder crop - so you need to buy less fodder - totalFUt
6673  double resp = m_variableCrops[j].crop->m_resp;
6674  double loss = m_variableCrops[j].crop->m_totalLoss;
6675  double FUKey = m_OurManager->pm_data->Get_FUKey(index);
6676  double FUha = resp * (1-loss/100) * FUKey; //[ha * hkg/ha * FU/hkg = FU]
6677  double changeFU = (areaVar - areaVarBefore) * m_totalArea/100 * FUha; //positive
6678  m_totalFUt -= changeFU;
6679  m_totalFUgrown += changeFU;
6680  }
6681  }
6682 
6683  if(areaCC < areaCCBefore){
6684  int index = toc_Foobar*m_farmType + m_cattleCrops[i].crop->m_cropType;
6685  bool fodder = m_OurManager->pm_data->Get_fodder(index);
6686  if(fodder){ //this is a fodder crop - so you need to buy less fodder - totalFUt
6687  double resp = m_cattleCrops[i].crop->m_resp;
6688  double loss = m_cattleCrops[i].crop->m_totalLoss;
6689  double FUKey = m_OurManager->pm_data->Get_FUKey(index);
6690  double FUha = resp * (1-loss/100) * FUKey; //[ha * hkg/ha * FU/hkg = FU]
6691  double changeFU = (areaCCBefore - areaCC) * m_totalArea/100 * FUha; //positive
6692  m_totalFUt += changeFU;
6693  m_totalFUgrown -= changeFU;
6694  }
6695  }
6696  }
6697 
6698  }//inner for
6699  }
6700  else{
6701  //nothing - go to the next cattle crop; if there's no more - then the diff must be zero - so the loop will stop
6702  }
6703 
6704  }//outer for
6705 
6706  //4. Check if diff is still > 0 (after point 3.), if so - substitute some area of one of the cattle crops with SBarley
6707 
6708  if(diff>0){
6709 
6710  double areaSBarleyMax = sBarley->m_rotationMax;
6711  double SBarleyAvailableArea = areaSBarleyMax-areaSBarley;
6712  double areaSBarleyBefore = areaSBarley;
6713 
6714  double available = 0; //available to cut from GClover and GSeed
6715  for(int i=0; i<(int)m_cattleCrops.size(); i++){ //or simply: i<2
6716  double areaMin = m_cattleCrops[i].crop->m_rotationMin;
6717  double area = m_cattleCrops[i].crop->m_areaPercent;
6718  available += (area - areaMin);
6719  }
6720 
6721  if(areaSBarley < areaSBarleyMax){ //Y1
6722  if(SBarleyAvailableArea >= diff/2){ //Y2
6723  if(available >= diff/2){ //Y 3.2
6724  areaSBarley += diff/2; //increase Sbarley by diff/2
6725  diff /= 2; //updating diff
6726  decreaseCrops(m_cattleCrops, diff);//decrease the two crops by diff/2 (now=to diff)
6727  }
6728 
6729  else{ //N 3.2
6730  areaSBarley += available;
6731  diff -= 2 * available;//update diff
6732  setCattleCropsAtMin(); //decrease the two crops to min each (by available<diff/2),
6733 
6734  if(SBarleyAvailableArea >= diff){//if possible:
6735  areaSBarley += diff;//increase Sbarley by diff
6736  decreaseCrops(m_variableCrops2, diff);//& decrease the worst (available) normal crop by diff
6737  }
6738  else{
6739  //do as much as possible
6740  double toDecrease = areaSBarleyMax - areaSBarley; //neccesary -area has changed
6741  areaSBarley = areaSBarleyMax; //increase Sbarley to max
6742  diff-=toDecrease; //update diff
6743  decreaseCrops(m_variableCrops2, toDecrease);//decrease normal crops
6744  //and throw an exception! restriction must be violated
6745  ofstream ofile("Restrictions.txt",ios::app); //changed 06.06 out to app
6746  ofile << m_almass_no << '\t' << "cattle restriction: broken after N 3.2" << endl;
6747  ofile.close();
6748  }
6749  }
6750  }
6751  else{ //N2
6752  //increase SBarley to max in both cases
6753  if(available >= SBarleyAvailableArea){ //Y 3.1
6754  areaSBarley = areaSBarleyMax; //increase Sbarley to max
6755  diff -= 2 * SBarleyAvailableArea; //update diff
6756  available -= SBarleyAvailableArea; //decrease by what you add in the next line
6757  decreaseCrops(m_cattleCrops, SBarleyAvailableArea);//increase needed by
6758 
6759  double diffBefore = diff;
6760  if(available >= diff){
6761  decreaseCrops(m_cattleCrops, diff);//decrease the two crops by diff
6762  increaseCrops(m_variableCrops2, diffBefore);//increase normal crops by diff
6763  }
6764  else{
6765  //do as much as possible
6767  diff -= available; //update diff
6768  double toDecrease = available;
6769  increaseCrops(m_variableCrops2, toDecrease); //add some normal crops!
6770  //and throw exception - restriction must be violated!
6771  ofstream ofile("Restrictions.txt",ios::out);
6772  ofile << m_almass_no << '\t' << "cattle restriction: broken after Y 3.1" << endl;
6773  ofile.close();
6774  }
6775  }
6776  else{ //N 3.1 - restriction violated, but try to do as much as possible
6777  areaSBarley += available;
6779  diff -= 2 * available; //update diff
6780  double toDecrease = areaSBarleyMax - areaSBarley; //here it is necessary! because the area has changed
6781  areaSBarley = areaSBarleyMax;//
6782  diff -= toDecrease; //update diff
6783  decreaseCrops(m_variableCrops2, toDecrease);//add normal crops-but still-violation!
6784  //AND !!! throw an exception - violation
6785  ofstream ofile("Restrictions.txt",ios::out);
6786  ofile << m_almass_no << '\t' << "cattle restriction: broken after N 3.1" << endl;
6787  ofile.close();
6788  }
6789  }
6790 
6791  sBarley->m_areaPercent = areaSBarley;
6792 
6793  //this is a fodder crop - so you need to buy less fodder - totalFUt
6794  double resp = sBarley->m_resp;
6795  double loss = sBarley->m_totalLoss;
6796  double FUKey = m_OurManager->pm_data->Get_FUKey (toc_SBarley);
6797  double FUha = resp * (1-loss/100) * FUKey; //[ha * hkg/ha * FU/hkg = FU]
6798  double changeFU = (areaSBarley - areaSBarleyBefore) * m_totalArea/100 * FUha; //positive
6799  m_totalFUt -= changeFU;
6800  m_totalFUgrown += changeFU;
6801  }
6802 
6803  else{ // N 1
6804  if(available >= diff){
6805  double diffBefore = diff;
6806  decreaseCrops(m_cattleCrops, diff); //cover the diff
6807  increaseCrops(m_variableCrops2, diffBefore); //increase some normal crops
6808  }
6809  else{//restr must be violated
6810  setCattleCropsAtMin(); //set the two crops at min
6811  diff -= available;
6812  double toIncrease = available;
6813  increaseCrops(m_variableCrops2, toIncrease);
6814  //throw an exception - restriction must be violated!
6815  ofstream ofile("Restrictions.txt",ios::out);
6816  ofile << m_almass_no << '\t' << "cattle restriction: broken after N 1" << endl;
6817  ofile.close();
6818  }
6819  }
6820 
6821  }//end of the second if(diff>0)
6822 
6823  }//end of the if(diff>0)?
6824 
6825 }//end of check CattleRotation
virtual void decreaseCrops(vector< CropSort >cropsToDecrease, double &howMuchToDecrease)
Decreases area of cropsToDecrease by howMuchToDecrease.
Definition: farm.cpp:7454
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
double m_totalFUgrown
Fodder grown, i.e. obtained from growing fodder crops. [fodder units].
Definition: farm.h:2097
virtual void increaseCrops(vector< CropSort >cropsToIncrease, double &howMuchToIncrease)
Increases area of cropsToIncrease by howMuchToIncrease.
Definition: farm.cpp:7397
void setCattleCropsAtMin()
Decreases area of cattle crops to their min. required area.
Definition: farm.cpp:6550
CropOptimised * findCropByName(string crop_name)
Returns a pointer to a crop whose name is specified as the argument (bedriftsmodel, i.e. original farm optimization model, crops mode).
Definition: farm.cpp:7285
vector< CropSort > m_variableCrops
Vector of structs containing pointers to crops which are not fixed.
Definition: farm.h:2042
double Get_FUKey(int i)
Definition: farm.h:561
double m_areaPercent
Area of a crop in percent of a farm&#39;s total area [%].
Definition: farm.h:1552
double m_resp
Response - yield of a crop per ha [hkg/ha].
Definition: farm.h:1522
double m_totalFUt
Fodder from trade (has to be purchased). [fodder units].
Definition: farm.h:2095
double m_totalArea
Total area of a farm. A sum of initial crop areas (if in bedriftsmodel, i.e. original farm optimizati...
Definition: farm.h:2081
vector< CropSort > m_variableCrops2
Vector of structs containing pointers to crops which are not fixed and: in case of the winter rotatio...
Definition: farm.h:2047
double m_totalLoss
Summary value of the yield loss due to the limited use of herbicides and fung- and insecticides [%]...
Definition: farm.h:1540
bool Get_fodder(int i)
Definition: farm.h:559
vector< CropSort > m_cattleCrops
Vector of crops used in checkCattleRotation.
Definition: farm.h:2308
A class for storing all parameters and results of crop optimisation.
Definition: farm.h:1491
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
double m_GM_Savings
Holds the value of m_GM in case of non-fodder crops and a value of m_savings in case of fodder crops ...
Definition: farm.h:1550
double m_rotationMax
Maximum area in percent of farm&#39;s arable area for a given crop (depends on a farm size...
Definition: farm.h:1507
void sortCrops(vector< CropSort > &cropsToSort, string sortingKey)
Sorts structs of type CropSort.
Definition: farm.cpp:7311
int m_almass_no
Farm&#39;s almass number.
Definition: farm.h:2077
void OptimisingCattleFarm::checkCattleRotation_almass ( )
protected

Checks if the cattle restriction is fulfilled - in the ALMaSS crops mode.

Used in ALMaSS crop mode. Function checks if the restriction for cattle farms on attachment of spring barley, CloverGrassGrazed1 and CloverGrassGrazed2 is fulfilled. If not, it corrects these crops' areas.

Definition at line 6827 of file farm.cpp.

References OptimisingFarm::decreaseCrops(), OptimisingFarm::findCropByName_almass(), DataForOptimisation::Get_FUKey(), CropOptimised::m_areaPercent, OptimisingFarm::m_farmType, Farm::m_OurManager, CropOptimised::m_resp, OptimisingFarm::m_totalArea, OptimisingFarm::m_totalFUgrown, OptimisingFarm::m_totalFUt, CropOptimised::m_totalLoss, OptimisingFarm::m_variableCrops, OptimisingFarm::m_variableCrops2, FarmManager::pm_data, tov_CloverGrassGrazed1, tov_SpringBarley, and tov_Undefined.

6827  {
6831  CropOptimised *sBarley = findCropByName_almass("SpringBarley"); //fodder
6832  CropOptimised *CGG1 = findCropByName_almass("CloverGrassGrazed1"); //fodder
6833  CropOptimised *CGG2 = findCropByName_almass("CloverGrassGrazed2"); //fodder
6834 
6835  double areaSBarley = sBarley->m_areaPercent;
6836  double areaCGG = 2*(CGG1->m_areaPercent); //cgg1 and 2 have equal areas - it waa checked in Check_sg_and_cgg (called in check restrictions)
6837 
6838  double diff = areaCGG/2 - areaSBarley; //SpringBarley has to have an area at least as big as CGG1 = CGG2 = areaCGG/2.
6839 
6840  if(diff > 0){ //restriction is not fulfilled
6841 
6842  //need to make new variableCrops2 - without the grasses and sbarley!
6843  m_variableCrops2 = m_variableCrops; //initiate the new list and remove crops:
6844  for(int s=(int)m_variableCrops2.size()-1; s>=0; s--){
6845  if(m_variableCrops2[s].crop==sBarley || m_variableCrops2[s].crop==CGG1 || m_variableCrops2[s].crop==CGG2){
6846  m_variableCrops2.erase(m_variableCrops2.begin() + s);
6847  }
6848  }
6849 
6850  double new_area_sbarley = areaSBarley;
6851  double new_area_cgg = areaCGG;
6852 
6853  double available=0; //all area except for fixed crops and min. areas of variable crops
6854  for(int i=0; i<(int)m_variableCrops.size(); i++){ //can't use m_grownVariableCrops - it doesn't include fodder crops!
6855  double areaVariableCrop = m_variableCrops[i].crop->m_areaPercent - m_variableCrops[i].crop->m_rotationMin;
6856  available += areaVariableCrop;
6857  }
6858 
6859  if(areaCGG/2 *3 <= available){ //then Sbarley can get as much as each CGG1; cgg area doesn't change
6860  new_area_sbarley = areaCGG/2;
6861  double area_to_decrease = new_area_sbarley - areaSBarley; // must be > 0 if this code is executed
6862  decreaseCrops(m_variableCrops2, area_to_decrease);
6863  }
6864  else{ //need to also cut grass, not just increase sbarley
6865  new_area_cgg = available/3 * 2; // = new area for sbarley = cgg1 = cgg2 (these 3 crops take all available area)
6866  new_area_sbarley = available/3;
6867  double current_sbarley_and_grasses = areaSBarley + areaCGG; // so other crops area (variable area) = 100 - current_sbarley_and_grasses
6868  double other_crops_area = available - current_sbarley_and_grasses;
6869  if(current_sbarley_and_grasses < available){ //there are other crops - and we're now substituting them with sbarley
6870  decreaseCrops(m_variableCrops2, other_crops_area);
6871  }
6872  //else - just these 3 crops - do nothing - grass is already cut :), sbarley area is increased
6873  }
6874 
6875  //correct fodder....
6876  double resp = sBarley->m_resp;
6877  double loss = sBarley->m_totalLoss;
6879  double FUKey = m_OurManager->pm_data->Get_FUKey(index);
6880  double FUha = resp * (1-loss/100) * FUKey; //[ha * hkg/ha * FU/hkg = FU]
6881  double changeFU = (new_area_sbarley - areaSBarley) * m_totalArea/100 * FUha; //positive
6882  m_totalFUt -= changeFU;
6883  m_totalFUgrown += changeFU;
6884 
6885  resp = CGG1->m_resp;
6886  loss = CGG1->m_totalLoss;
6888  FUKey = m_OurManager->pm_data->Get_FUKey(index);
6889  FUha = resp * (1-loss/100) * FUKey; //[ha * hkg/ha * FU/hkg = FU]
6890  changeFU = (areaCGG - new_area_cgg) * m_totalArea/100 * FUha; //positive
6891  m_totalFUt += changeFU;
6892  m_totalFUgrown -= changeFU;
6893 
6894  //and change the areas
6895  CGG1->m_areaPercent = new_area_cgg/2; //areaCGG is a summary area for both CGG
6896  CGG2->m_areaPercent = new_area_cgg/2;
6897  sBarley->m_areaPercent = new_area_sbarley;
6898 
6899  }
6900 
6901 }//end of check CattleRotation for almass crops
virtual void decreaseCrops(vector< CropSort >cropsToDecrease, double &howMuchToDecrease)
Decreases area of cropsToDecrease by howMuchToDecrease.
Definition: farm.cpp:7454
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
double m_totalFUgrown
Fodder grown, i.e. obtained from growing fodder crops. [fodder units].
Definition: farm.h:2097
CropOptimised * findCropByName_almass(string crop_name)
Returns a pointer to almass crop whose name is specified as the argument (ALMaSS crops mode)...
Definition: farm.cpp:7293
vector< CropSort > m_variableCrops
Vector of structs containing pointers to crops which are not fixed.
Definition: farm.h:2042
double Get_FUKey(int i)
Definition: farm.h:561
double m_areaPercent
Area of a crop in percent of a farm&#39;s total area [%].
Definition: farm.h:1552
double m_resp
Response - yield of a crop per ha [hkg/ha].
Definition: farm.h:1522
double m_totalFUt
Fodder from trade (has to be purchased). [fodder units].
Definition: farm.h:2095
double m_totalArea
Total area of a farm. A sum of initial crop areas (if in bedriftsmodel, i.e. original farm optimizati...
Definition: farm.h:2081
vector< CropSort > m_variableCrops2
Vector of structs containing pointers to crops which are not fixed and: in case of the winter rotatio...
Definition: farm.h:2047
double m_totalLoss
Summary value of the yield loss due to the limited use of herbicides and fung- and insecticides [%]...
Definition: farm.h:1540
A class for storing all parameters and results of crop optimisation.
Definition: farm.h:1491
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void OptimisingCattleFarm::checkRestrictions ( )
protectedvirtual

Checks if the restrictions are fulfilled and corrects crops' areas if necessary.

Includes additionally the function dealing with the cattle rotation restricton.

Reimplemented from OptimisingFarm.

Definition at line 5965 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, OptimisingFarm::checkRestrictions(), and CfgBool::value().

5965  {
5969 
5970  //3rd restriction: cattle crops
5973  }
5974  else{
5976  }
5977 
5978 }
void checkCattleRotation_almass()
Checks if the cattle restriction is fulfilled - in the ALMaSS crops mode.
Definition: farm.cpp:6827
CfgBool cfg_OptimiseBedriftsmodelCrops("OPTIMISE_BEDRIFTSMODEL_CROPS", CFG_CUSTOM, false)
If set to true, the original farm optimisation model&#39;s crop set is used in the farmer decision making...
virtual void checkRestrictions()
Checks if the restrictions are fulfilled and corrects crops&#39; areas if necessary.
Definition: farm.cpp:5933
bool value(void)
Definition: configurator.h:123
void checkCattleRotation()
Checks if the cattle restriction is fulfilled - in the Bedriftsmodel (original farm optimization mode...
Definition: farm.cpp:6576
void OptimisingCattleFarm::preventCashCrops ( )
protectedvirtual

Prevents small cattle farms from growing cash crops and maize silage.

Prevents cattle farms on sandy soils with area < 15 ha from growing cash crops. For cattle farms on sandy soils larger than 15 ha and with the worse soil subtype - it prevents cash crops in 90% of cases. Farms above 15 ha with a good soil subtype are allowed to grow cash crops. Additionally, the function prevents cattle farms with area < 30 ha from growing maize silage.

Reimplemented from OptimisingFarm.

Definition at line 5227 of file farm.cpp.

References OptimisingFarm::findCropByName_almass(), CropOptimised::m_rotationMax, OptimisingFarm::m_soilSubType, OptimisingFarm::m_soilType, OptimisingFarm::m_totalArea_original, and tos_Sand.

5227  {
5228 
5233  CropOptimised *ms = findCropByName_almass ("MaizeSilage");
5234  if(m_totalArea_original < 30){ //cattle farms with area < 30 ha do not have maize silage!
5235  ms->m_rotationMax = 0;
5236  }
5237 
5238  CropOptimised *wwheat = findCropByName_almass ("WinterWheat");
5239  CropOptimised *wrye = findCropByName_almass ("WinterRye");
5240  CropOptimised *srape = findCropByName_almass ("SpringRape");
5241  CropOptimised *wrape = findCropByName_almass ("WinterRape");
5242  CropOptimised *fpeas = findCropByName_almass ("FieldPeas");
5243  CropOptimised *potatoes = findCropByName_almass ("Potatoes");
5244  CropOptimised *potind = findCropByName_almass ("PotatoesIndustry");
5245  CropOptimised *seedg1 = findCropByName_almass ("SeedGrass1");
5246  CropOptimised *seedg2 = findCropByName_almass ("SeedGrass2");
5247 
5249 
5250  wwheat->m_rotationMax = 0;
5251  wrye->m_rotationMax = 0;
5252  srape->m_rotationMax = 0;
5253  wrape->m_rotationMax = 0;
5254  fpeas->m_rotationMax = 0;
5255  potatoes->m_rotationMax = 0;
5256  potind->m_rotationMax = 0;
5257  seedg1->m_rotationMax = 0;
5258  seedg2->m_rotationMax = 0;
5259 
5260  cash_crops_allowed=false;
5261  }
5262  else if(m_soilType==tos_Sand && m_totalArea_original >= 15 && m_soilSubType == 0){ //v. small prob. of having cash crops
5263 
5264  //see: http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution
5265  std::random_device rd;
5266  std::mt19937 gen(rd());
5267  distribution_type2 dis(0, 1);
5268  double random_no = dis(gen);
5269 
5270  if(random_no > 0.1){ //so in 90% of cases
5271  wwheat->m_rotationMax = 0;
5272  wrye->m_rotationMax = 0;
5273  srape->m_rotationMax = 0;
5274  wrape->m_rotationMax = 0;
5275  fpeas->m_rotationMax = 0;
5276  potatoes->m_rotationMax = 0;
5277  potind->m_rotationMax = 0;
5278  seedg1->m_rotationMax = 0;
5279  seedg2->m_rotationMax = 0;
5280 
5281  cash_crops_allowed=false;
5282  }
5283  }
5284  //else nothing - allow cash crops
5285 
5286 }
CropOptimised * findCropByName_almass(string crop_name)
Returns a pointer to almass crop whose name is specified as the argument (ALMaSS crops mode)...
Definition: farm.cpp:7293
boost::random::uniform_int_distribution distribution_type2
Definition: farm.h:233
double m_totalArea_original
Total area of a farm as in bedriftsmodel, i.e. original farm optimization model. [ha].
Definition: farm.h:2083
int m_soilSubType
Farm&#39;s soil subtype. Defined only for cattle farms on sandy soil (0-bad, 1-good, 2-undefined).
Definition: farm.h:2075
bool cash_crops_allowed
Sets to true if cash crops are allowed. True by default.
Definition: farm.h:2254
A class for storing all parameters and results of crop optimisation.
Definition: farm.h:1491
double m_rotationMax
Maximum area in percent of farm&#39;s arable area for a given crop (depends on a farm size...
Definition: farm.h:1507
TTypesOfSoils m_soilType
Farm&#39;s soil type (sandy, clay, other).
Definition: farm.h:2069
void OptimisingCattleFarm::setCattleCropsAtMin ( )
protected

Decreases area of cattle crops to their min. required area.

In Bedriftsmodel crop mode, it decreases area of the two cattle crops (Grass Seed, Clover Grass) to their minimum required area (RotationMin).

Definition at line 6550 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, DataForOptimisation::Get_fodder(), DataForOptimisation::Get_FUKey(), OptimisingFarm::m_farmType, Farm::m_OurManager, OptimisingFarm::m_totalArea, OptimisingFarm::m_totalFUgrown, OptimisingFarm::m_totalFUt, FarmManager::pm_data, toc_Foobar, tov_Undefined, and CfgBool::value().

6550  {
6553  for(int i=0; i<(int)m_cattleCrops.size(); i++){ //just go through all 2 of them:)
6554  double area = m_cattleCrops[i].crop->m_areaPercent;
6555  double areaBefore = area;
6556  double rotationMin = m_cattleCrops[i].crop->m_rotationMin;
6557  area = rotationMin; //set all at min
6558  m_cattleCrops[i].crop->m_areaPercent = area;
6559 
6560  if(areaBefore > area){
6561  int index = (cfg_OptimiseBedriftsmodelCrops.value())? toc_Foobar*m_farmType + m_cattleCrops[i].crop->m_cropType : tov_Undefined*m_farmType + m_cattleCrops[i].crop->m_cropType_almass;
6562  bool fodder = m_OurManager->pm_data->Get_fodder(index);
6563  if(fodder){
6564  double resp = m_cattleCrops[i].crop->m_resp;
6565  double loss = m_cattleCrops[i].crop->m_totalLoss;
6566  double FUKey = m_OurManager->pm_data->Get_FUKey(index);
6567  double FUha = resp * (1-loss/100) * FUKey; //[ha * hkg/ha * FU/hkg = FU]
6568  double changeFU = (areaBefore - area) * m_totalArea/100 * FUha; //positive number
6569  m_totalFUt += changeFU; //so you buy more
6570  m_totalFUgrown -= changeFU; //and grow less:)
6571  }
6572  }
6573  }
6574 }
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
double m_totalFUgrown
Fodder grown, i.e. obtained from growing fodder crops. [fodder units].
Definition: farm.h:2097
double Get_FUKey(int i)
Definition: farm.h:561
double m_totalFUt
Fodder from trade (has to be purchased). [fodder units].
Definition: farm.h:2095
double m_totalArea
Total area of a farm. A sum of initial crop areas (if in bedriftsmodel, i.e. original farm optimizati...
Definition: farm.h:2081
bool Get_fodder(int i)
Definition: farm.h:559
CfgBool cfg_OptimiseBedriftsmodelCrops("OPTIMISE_BEDRIFTSMODEL_CROPS", CFG_CUSTOM, false)
If set to true, the original farm optimisation model&#39;s crop set is used in the farmer decision making...
bool value(void)
Definition: configurator.h:123
vector< CropSort > m_cattleCrops
Vector of crops used in checkCattleRotation.
Definition: farm.h:2308
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733

Member Data Documentation

vector<CropSort> OptimisingCattleFarm::m_cattleCrops
protected

Vector of crops used in checkCattleRotation.

Definition at line 2308 of file farm.h.

vector<CropSort> OptimisingCattleFarm::m_cattleCrops_almass
protected

Vector of crops used in checkCattleRotation_almass.

Definition at line 2314 of file farm.h.


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