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

Subclass of the OptimisingFarm. Either pig or cattle farm. More...

#include <farm.h>

Inheritance diagram for AnimalFarm:
OptimisingFarm Farm OptimisingCattleFarm OptimisingPigFarm

Public Member Functions

 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 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...
 
virtual void preventCashCrops ()
 Prevents small cattle farms from growing cash crops and maize silage. 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...
 
virtual void checkRestrictions ()
 Checks if the restrictions are fulfilled and corrects crops' areas if necessary. 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

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 OptimisingFarm. Either pig or cattle farm.

Definition at line 2232 of file farm.h.

Constructor & Destructor Documentation

AnimalFarm::AnimalFarm ( FarmManager a_myfarmmanager,
int  a_No 
)

Definition at line 4793 of file farm.cpp.

References cash_crops_allowed, and m_fakeCrop.

4793  : OptimisingFarm(a_fred, a_No)
4794 {
4795  m_fakeCrop = new CropOptimised(); //("FakeCrop", 0)
4796  cash_crops_allowed = true;
4797 }
bool cash_crops_allowed
Sets to true if cash crops are allowed. True by default.
Definition: farm.h:2254
CropOptimised * m_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 det...
Definition: farm.h:2235
A class for storing all parameters and results of crop optimisation.
Definition: farm.h:1491
OptimisingFarm(FarmManager *a_myfarmmanager, int a_No)
The constructor.
Definition: farm.cpp:4676
virtual AnimalFarm::~AnimalFarm ( )
inlinevirtual

Definition at line 2235 of file farm.h.

2235 {};

Member Function Documentation

void AnimalFarm::checkWinterCrops ( )
protectedvirtual

Animal farm version of the checkWinterCrops() function (accounts for fodder changes).

Function for animal farms checking if restriction on maximum winter crops area is fulfilled. Works in the same way as the NonAnimalFarm version, but additionally accounts for fodder changes. In Bedriftsmodel crop mode, both for cattle and pig farms two of the winter crops, WBarley and WCerealSil, are fodder crops. In the ALMaSS crop mode, WCerealSil does not exist (is aggregated to another crop) and is thus excluded from the restriction's condition.

Reimplemented from OptimisingFarm.

Definition at line 6455 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, OptimisingFarm::decreaseCrops(), OptimisingFarm::findCropByName(), OptimisingFarm::findCropByName_almass(), DataForOptimisation::Get_winterMax(), OptimisingFarm::increaseCrops(), OptimisingFarm::m_almass_no, CropOptimised::m_areaPercent, OptimisingFarm::m_farmType, Farm::m_OurManager, OptimisingFarm::m_variableCrops, OptimisingFarm::m_variableCrops2, OptimisingFarm::m_winterCrops, FarmManager::pm_data, OptimisingFarm::sortCrops(), and CfgBool::value().

6455  {
6456 
6462  CropOptimised *wBarley;
6463  CropOptimised *wWheat;
6464  CropOptimised *wRye;
6465  CropOptimised *wRape;
6466  CropOptimised *wCerealSil = NULL; // To prevent the annoying warning
6467 
6469  wBarley = findCropByName("WBarley");
6470  wWheat = findCropByName("WWheat");
6471  wRye = findCropByName("WRye");
6472  wRape = findCropByName("WRape"); //should not be decreased - might cause violation of winterRotation restriction
6473  wCerealSil = findCropByName("WCerealSil");
6474  }
6475  else{
6476  wBarley = findCropByName_almass("WinterBarley");
6477  wWheat = findCropByName_almass("WinterWheat");
6478  wRye = findCropByName_almass("WinterRye");
6479  wRape = findCropByName_almass("WinterRape"); //should not be decreased - might cause violation of winterRotation restriction
6480  }
6481 
6482  double areaWBarley = wBarley->m_areaPercent;
6483  double areaWWheat = wWheat->m_areaPercent;
6484  double areaWRye = wRye->m_areaPercent;
6485  double areaWRape = wRape->m_areaPercent;
6486  double areaWCerealSil = 0;
6487 
6489  areaWCerealSil = wCerealSil->m_areaPercent;
6490  }
6491 
6492  double sum = areaWBarley + areaWWheat + areaWRye + areaWRape + areaWCerealSil;
6493 
6494  int winterMax = m_OurManager->pm_data->Get_winterMax(m_farmType);
6495  if(sum > winterMax){
6496  double diff = sum - winterMax;
6497  double diffBefore = diff;
6498 
6499  m_variableCrops2 = m_variableCrops; //initiate the new list and remove all winter crops:
6501  for(int s=(int)m_variableCrops2.size()-1; s>=0; s--){
6502  if(m_variableCrops2[s].crop==wBarley || m_variableCrops2[s].crop==wWheat || m_variableCrops2[s].crop==wRye || m_variableCrops2[s].crop==wRape || m_variableCrops2[s].crop==wCerealSil){
6503  m_variableCrops2.erase(m_variableCrops2.begin() + s);
6504  }
6505  }
6506  }
6507  else{
6508  for(int s=(int)m_variableCrops2.size()-1; s>=0; s--){
6509  if(m_variableCrops2[s].crop==wBarley || m_variableCrops2[s].crop==wWheat || m_variableCrops2[s].crop==wRye || m_variableCrops2[s].crop==wRape){
6510  m_variableCrops2.erase(m_variableCrops2.begin() + s);
6511  }
6512  }
6513  }
6514 
6515  //assign keys for sorting - for fodder crops these will be Savings!
6516  CropSort cs1 = {0., wBarley}; //an object with a key for sorting and a pointer to crop
6517  CropSort cs2 = {0., wWheat};
6518  CropSort cs3 = {0., wRye};//CropSort cs4 = {wRape->pullVariable<double>("GM"), wRape};
6519 
6520  m_winterCrops.clear();
6521  m_winterCrops.push_back(cs1);
6522  m_winterCrops.push_back(cs2);
6523  m_winterCrops.push_back(cs3);
6524 
6526  CropSort cs5 = {0., wCerealSil};
6527  m_winterCrops.push_back(cs5);
6528  }
6529 
6530  sortCrops(m_winterCrops, "GM_Savings");
6531 
6532  //decrease area of one or more winter crops by diff
6534 
6535  if(diff>0){ //loop stopped by the other condition: impossible to cut more
6536  //violation of the restriction; do not exit, just print a warning
6537  ofstream ofile("Restrictions.txt",ios::app);
6538  ofile << m_almass_no << '\t' << "winter crops restriction broken, Animal farm. Diff is: " << diff << endl;
6539  ofile.close();
6540  }
6541 
6542  //assign the area cut from winter crops to one or more variable crops (that haven't reached the max yet)
6543  double toIncrease = diffBefore - diff;
6544  increaseCrops(m_variableCrops2, toIncrease);
6545 
6546  }//else nothing!:) it's ok
6547 
6548 }//end of checkWinterCropsAnimal
vector< CropSort > m_winterCrops
Vector of structs containing pointers to winter crops.
Definition: farm.h:2055
virtual void decreaseCrops(vector< CropSort >cropsToDecrease, double &howMuchToDecrease)
Decreases area of cropsToDecrease by howMuchToDecrease.
Definition: farm.cpp:7454
int Get_winterMax(int i)
Definition: farm.h:530
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
virtual void increaseCrops(vector< CropSort >cropsToIncrease, double &howMuchToIncrease)
Increases area of cropsToIncrease by howMuchToIncrease.
Definition: farm.cpp:7397
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
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 m_areaPercent
Area of a crop in percent of a farm&#39;s total area [%].
Definition: farm.h:1552
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
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
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 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 AnimalFarm::checkWinterRotation1 ( )
protectedvirtual

Animal farm version of the OptimisingFarm::checkWinterRotation1() function (accounts for fodder changes).

Function checks if the restriction on rotation: area(WWheat) - (area(WRape) + area(SRape) + area(FieldPeas) + area(Oats)) <=0, is fulfilled. If not, it corrects crops areas excluding the fixed crop (FieldPeas). In case area of a fodder crop is changed, the value of OptimisingFarm::m_totalFUt is updated.

Reimplemented from OptimisingFarm.

Definition at line 6159 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, OptimisingFarm::decreaseCrops(), OptimisingFarm::findCropByName(), OptimisingFarm::findCropByName_almass(), DataForOptimisation::Get_fodder(), DataForOptimisation::Get_FUKey(), OptimisingFarm::increaseCrops(), OptimisingFarm::m_almass_no, CropOptimised::m_areaPercent, OptimisingFarm::m_farmType, CropOptimised::m_GM, Farm::m_OurManager, OptimisingFarm::m_rotationCrops, CropOptimised::m_rotationMin, OptimisingFarm::m_totalArea, OptimisingFarm::m_totalFUgrown, OptimisingFarm::m_totalFUt, OptimisingFarm::m_variableCrops, OptimisingFarm::m_variableCrops2, FarmManager::pm_data, OptimisingFarm::sortCrops(), toc_Foobar, tov_Undefined, and CfgBool::value().

6159  {
6160 
6165  CropOptimised *wWheat;
6166  CropOptimised *wRape;
6167  CropOptimised *sRape;
6168  CropOptimised *oats;
6169  CropOptimised *peas;
6170 
6172  wWheat = findCropByName("WWheat");
6173  wRape = findCropByName("WRape");
6174  sRape = findCropByName("SRape");
6175  oats = findCropByName("Oats");//fodder
6176  peas = findCropByName("Peas"); //fixed
6177  }
6178  else{
6179  wWheat = findCropByName_almass("WinterWheat");
6180  wRape = findCropByName_almass("WinterRape");
6181  sRape = findCropByName_almass("SpringRape");
6182  oats = findCropByName_almass("Oats");//fodder
6183  peas = findCropByName_almass("FieldPeas"); //fixed
6184  }
6185 
6186  double areaWWheat = wWheat->m_areaPercent;
6187  double areaWRape = wRape->m_areaPercent;
6188  double areaSRape = sRape->m_areaPercent;
6189  double areaOats = oats->m_areaPercent;
6190  double areaPeas = peas->m_areaPercent;
6191 
6192  double diff = areaWWheat - (areaWRape + areaSRape + areaOats + areaPeas); //difference;
6193  if (diff > 0){ //restriction is not fulfilled
6194  CropSort cs1 = {0., wRape}; //an object with a key for sorting and a pointer to crop
6195  CropSort cs2 = {0., sRape};
6196  CropSort cs3 = {0., oats};
6197  m_rotationCrops.clear();
6198  m_rotationCrops.push_back(cs1);
6199  m_rotationCrops.push_back(cs2);
6200  m_rotationCrops.push_back(cs3);
6201 
6202  sortCrops(m_rotationCrops, "GM_Savings"); //sorting the rotation crops wrt GM
6203 
6204 
6205  m_variableCrops2 = m_variableCrops; //initiate the new list and remove all 'winter rotation' crops:
6206  for(int s=(int)m_variableCrops2.size()-1; s>=0; s--){
6207  if(m_variableCrops2[s].crop==wWheat || m_variableCrops2[s].crop==wRape || m_variableCrops2[s].crop==sRape || m_variableCrops2[s].crop==oats){
6208  m_variableCrops2.erase(m_variableCrops2.begin() + s);
6209  }
6210  }
6211 
6212  double GM_WWheat = wWheat->m_GM;
6213  double areaMin = wWheat->m_rotationMin;
6214 
6215  for(int i=0; i<(int)m_rotationCrops.size() && diff!=0; i++){
6216  double areaRC = m_rotationCrops[i].crop->m_areaPercent;
6217  double rotationMaxRC = m_rotationCrops[i].crop->m_rotationMax;
6218  double areaBeforeRC = areaRC;
6219  if(areaRC < rotationMaxRC){
6220  double GM_RC = m_rotationCrops[i].crop->m_GM_Savings;
6221  bool stopInnerLoop = false;
6222 
6223  for(int j=0; j<(int)m_variableCrops2.size() && stopInnerLoop==false; j++){
6224 
6225  double GM_var = m_variableCrops2[j].crop->m_GM_Savings;
6226 
6227  if(GM_RC + GM_WWheat < 2 * GM_var){
6228  //add variable
6229  double areaVC = m_variableCrops2[j].crop->m_areaPercent;
6230  double rotationMaxVC = m_variableCrops2[j].crop->m_rotationMax;
6231  double areaBefore = areaVC;
6232  if(areaWWheat - areaMin >= diff){
6233  if(rotationMaxVC - areaVC >= diff){
6234  areaVC += diff;
6235  areaWWheat -= diff;
6236  diff = 0; //finished
6237  stopInnerLoop = true;
6238  }
6239  else{
6240  areaWWheat -= rotationMaxVC - areaVC;
6241  diff -= (rotationMaxVC - areaVC);
6242  areaVC = rotationMaxVC;
6243  }
6244  }
6245  else{
6246  if(rotationMaxVC - areaVC >= areaWWheat - areaMin){
6247  areaVC += (areaWWheat - areaMin);
6248  diff -= (areaWWheat - areaMin);
6249  areaWWheat = areaMin; //now you can only add rot crops! so stop the inner loop
6250  stopInnerLoop=true;
6251  }
6252  else{
6253  areaWWheat -= rotationMaxVC - areaVC;
6254  diff -= (rotationMaxVC - areaVC);
6255  areaVC = rotationMaxVC;
6256  }
6257  }
6258  m_variableCrops2[j].crop->m_areaPercent = areaVC;
6259  //this just in an animal version, add if - checking if area has changed
6260  if(areaVC > areaBefore){
6261  int index = (cfg_OptimiseBedriftsmodelCrops.value())? toc_Foobar*m_farmType + m_variableCrops2[j].crop->m_cropType : tov_Undefined*m_farmType + m_variableCrops2[j].crop->m_cropType_almass;
6262  bool fodder = m_OurManager->pm_data->Get_fodder(index);
6263  if(fodder){ //this is a fodder crop - so you need to buy less fodder - totalFUt
6264  double resp = m_variableCrops2[j].crop->m_resp;
6265  double loss = m_variableCrops2[j].crop->m_totalLoss;
6266  double FUKey = m_OurManager->pm_data->Get_FUKey(index);
6267  double FUha = resp * (1-loss/100) * FUKey; //[ha * hkg/ha * FU/hkg = FU]
6268  double changeFU = (areaVC - areaBefore) * m_totalArea/100 * FUha; //positive
6269  m_totalFUt -= changeFU;
6270  m_totalFUgrown+=changeFU;
6271  }
6272  }
6273  }
6274  else{
6275  //add rotational
6276 
6277  if(areaWWheat - areaMin >= diff/2){
6278  if(rotationMaxRC - areaRC >= diff/2){
6279  areaRC += diff/2;
6280  areaWWheat -= diff/2;
6281  diff = 0; //finito
6282  stopInnerLoop = true;
6283  }
6284  else{
6285  areaWWheat -= rotationMaxRC - areaRC;
6286  diff -= 2 * (rotationMaxRC - areaRC);
6287  areaRC = rotationMaxRC;
6288  stopInnerLoop = true; //take next rotation crop
6289  }
6290  }
6291  else{
6292  if(rotationMaxRC - areaRC >= areaWWheat - areaMin){
6293  areaRC += areaWWheat - areaMin;
6294  diff -= 2 * (areaWWheat - areaMin);
6295  areaWWheat = areaMin; //now you can only add rot crops! so stop the inner loop:
6296  stopInnerLoop = true;
6297  }
6298  else{
6299  areaWWheat -= rotationMaxRC - areaRC;
6300  diff -= 2 * (rotationMaxRC - areaRC);
6301  areaRC = rotationMaxRC;
6302  stopInnerLoop = true; //take the next rotation crop
6303  }
6304  }
6305  }
6306  }//inner for-loop
6307 
6308  m_rotationCrops[i].crop->m_areaPercent = areaRC;
6309  //this just in an animal version, add if - checking if area has changed
6310  if(areaRC>areaBeforeRC){
6311  int index = (cfg_OptimiseBedriftsmodelCrops.value())? toc_Foobar*m_farmType + m_rotationCrops[i].crop->m_cropType : tov_Undefined*m_farmType + m_rotationCrops[i].crop->m_cropType_almass;
6312  bool fodder = m_OurManager->pm_data->Get_fodder(index);
6313  if(fodder){ //this is a fodder crop - so you need to buy less fodder - totalFUt
6314  double resp = m_rotationCrops[i].crop->m_resp;
6315  double loss = m_rotationCrops[i].crop->m_totalLoss;
6316  double FUKey = m_OurManager->pm_data->Get_FUKey(index);
6317  double FUha = resp * (1-loss/100) * FUKey; //[ha * hkg/ha * FU/hkg = FU]
6318  double changeFU = (areaRC - areaBeforeRC) * m_totalArea/100 * FUha; //positive
6319  m_totalFUt -= changeFU;
6320  m_totalFUgrown += changeFU;
6321  }
6322  }
6323  }//if rot crop<rotmax//else - take the next rot crop, i++
6324  }//outer for
6325 
6326  //now the diff can be positive in two cases:
6327 
6328  //1. wwheat area is at zero - need to increase rotation crops - if possible
6329  if(areaWWheat==areaMin && diff>0){
6330  double diff1 = diff;
6332  if(diff1==0) {decreaseCrops(m_variableCrops2, diff);} //do it only if we actually
6333  //managed to diff (=diff1) to the rotation crops,so diff1=0; if it's (0, diff)-then
6334  //we added smth, but not enough and restriction can't be fulfilled...- then...
6335  else{
6336  double toCut = diff-diff1;
6338  diff = diff1; //restriction will be broken by diff1
6339  ofstream ofile("Restrictions.txt",ios::app);
6340  ofile << m_almass_no << '\t' << "winter rotation1 restriction broken. Animal farm. WWheat area at 0. Diff is: " << diff << endl;
6341  ofile.close();
6342  }
6343  }
6344 
6345  //2. it was always more profitable to grow rotation crops, but they were not
6346  //enough (maybe at max from the beginning) - increase variable crops, cut wwheat
6347 
6348  if(diff>0 && areaWWheat-areaMin >= diff){
6349  areaWWheat -= diff;
6351  }
6352 
6353  wWheat->m_areaPercent = areaWWheat;
6354 
6355  }//if
6356 
6357 }//end of the function
double m_rotationMin
Minimum area in percent of farm&#39;s arable area for a given crop (depends on a farm size...
Definition: farm.h:1509
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
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
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
vector< CropSort > m_rotationCrops
Vector of structs containing pointers to (winter) rotation crops.
Definition: farm.h:2053
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_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_GM
Value of gross margin for a crop (m_income_ha - m_costs_ha) [DKK/ha].
Definition: farm.h:1546
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
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 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 AnimalFarm::correctFodderDemand ( int  a_foobar)
protected

Determines how much fodder is produced from fixed crops and min. areas of variable crops.

Function determining how much fodder is produced from fixed crops and minimial areas of variable crops. Updates the variable holding the value of the total fodder demand for a farm, m_totalFUdemand. Updates a variable holding the value of the fodder that has to be obtained from own production.

Definition at line 7011 of file farm.cpp.

References cfg_Min_fodder_prod_cattle, cfg_Min_fodder_prod_pig, cfg_OptimiseBedriftsmodelCrops, DataForOptimisation::Get_FUKey(), OptimisingFarm::m_farmType, OptimisingFarm::m_fixedCrops, Farm::m_OurManager, OptimisingFarm::m_totalArea, OptimisingFarm::m_totalFUdemand, OptimisingFarm::m_totalFUgrown, OptimisingFarm::m_variableCrops, FarmManager::pm_data, toof_Pig, CfgFloat::value(), and CfgBool::value().

7011  {
7016  m_totalFUgrown=0; //initialize
7017 
7018  double min_fodder = (m_farmType == toof_Pig) ? cfg_Min_fodder_prod_pig.value() : cfg_Min_fodder_prod_cattle.value(); //there are only two types of animal farms
7019  m_totalFodderToProduce = (min_fodder/100)*m_totalFUdemand; //[FU]
7020 
7021  double fodderFromFixed=0;
7022  for (int i=0; i<(int)m_fixedCrops.size(); i++){
7023  double area_percent = m_fixedCrops[i]->m_areaPercent;
7024  if(area_percent!=0){
7025  double area = area_percent/100* m_totalArea;
7026  double resp = m_fixedCrops[i]->m_resp;
7027  double loss = m_fixedCrops[i]->m_totalLoss;
7028 
7029  int index = (cfg_OptimiseBedriftsmodelCrops.value())? a_foobar*m_farmType + m_fixedCrops[i]->m_cropType : a_foobar*m_farmType + m_fixedCrops[i]->m_cropType_almass;
7030  double FUKey = m_OurManager->pm_data->Get_FUKey(index);//if it is not a fodder crop, key=0
7031  double FU = area*resp*(1-loss/100)*FUKey; //[ha * hkg/ha * FU/hkg = FU]
7032  fodderFromFixed += FU;//0 will be added in case of non-fodder crops
7033  m_totalFUgrown += FU;
7034  }
7035  }
7036  double fodderFromMinAreas=0;
7037  for (int i=0; i<(int)m_variableCrops.size(); i++){
7038  double areaMinPercent = m_variableCrops[i].crop->m_rotationMin;
7039  if(areaMinPercent!=0){ //150713
7040  double area = areaMinPercent/100*m_totalArea; //min area in ha
7041  double resp = m_variableCrops[i].crop->m_resp;
7042  double loss = m_variableCrops[i].crop->m_totalLoss;
7043 
7044  int index = (cfg_OptimiseBedriftsmodelCrops.value())? a_foobar*m_farmType + m_variableCrops[i].crop->m_cropType : a_foobar*m_farmType + m_variableCrops[i].crop->m_cropType_almass;
7045  double FUKey = m_OurManager->pm_data->Get_FUKey(index);//if it is not a fodder crop, key=0
7046  double FU = area*resp*(1-loss/100)*FUKey; //[ha * hkg/ha * FU/hkg = FU]
7047  fodderFromMinAreas += FU;
7048  m_totalFUgrown += FU;
7049  }
7050  }
7051  //this much fodder HAS to be obtained from self-production IF the requirment
7052  //on min fodder production holds; might be negative!
7053 
7054  m_fodderToProduce = m_totalFodderToProduce - (fodderFromFixed + fodderFromMinAreas);
7056 
7057  //decrease the fodder demand by the amount obtained from growing fixed crops and from
7058  //min areas of variable crops; could be also negative now;
7059  m_totalFUdemand -= (fodderFromFixed + fodderFromMinAreas);
7060 
7061 }
vector< CropOptimised * > m_fixedCrops
Vector of pointers to fixed crops.
Definition: farm.h:2051
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
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 value(void)
Definition: configurator.h:107
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
CfgFloat cfg_Min_fodder_prod_pig("MIN_FODDER_PROD_PIG", CFG_CUSTOM, 20)
A parameter setting the minimum proportion of fodder demand that has to be supplied from own fodder p...
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
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
double m_fodderToProduce
Fodder that has to be produced to fulfill the min. fodder production restriction at the end of a year...
Definition: farm.h:2250
double m_fodderToProduceBefore
Fodder that has to be produced to fulfill the min. fodder production restriction at the beginning of ...
Definition: farm.h:2252
CfgFloat cfg_Min_fodder_prod_cattle("MIN_FODDER_PROD_CATTLE", CFG_CUSTOM, 35)
A parameter setting the minimum proportion of fodder demand that has to be supplied from own fodder p...
Definition: farm.h:228
double m_totalFodderToProduce
Fodder that has to be produced by a farm to fulfill the min. fodder production restriction. [fodder units].
Definition: farm.h:2248
double m_totalFUdemand
Farm&#39;s total demand for fodder (it is covered by growing fodder crops and/or purchasing fodder and th...
Definition: farm.h:2093
void AnimalFarm::createCropsLists ( int  a_foobar)
protectedvirtual

Creates lists of crops.

Reimplemented from OptimisingFarm.

Definition at line 5097 of file farm.cpp.

References OptimisingFarm::createVariableCrops().

5097  {
5099  createFodderCrops(a_foobar);
5100 }
void createFodderCrops(int a_foobar)
Creates a list of pointers to all fodder crops.
Definition: farm.cpp:5119
void createVariableCrops(int a_foobar)
Creates a list of pointers to all variable crops included in the optimisation and a list of pointers ...
Definition: farm.cpp:5102
void AnimalFarm::createFodderCrops ( int  a_foobar)
protected

Creates a list of pointers to all fodder crops.

Creates a vector of pointers to variable fodder crops (those fixed excluded!).

Definition at line 5119 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, DataForOptimisation::Get_fixed(), DataForOptimisation::Get_fodder(), OptimisingFarm::m_crops, OptimisingFarm::m_farmType, Farm::m_OurManager, FarmManager::pm_data, and CfgBool::value().

5119  {
5122  int n = (int)m_crops.size();
5123  for (int i=0; i < n; ++i) {
5124  int crop_type=(cfg_OptimiseBedriftsmodelCrops.value())? (int)m_crops[i]->m_cropType : (int)m_crops[i]->m_cropType_almass;
5125  int index = a_foobar*m_farmType + crop_type;
5126  if(m_OurManager->pm_data->Get_fodder(index)){ //if the crop is a fodder crop...
5127  if(!(m_OurManager->pm_data->Get_fixed(index))){ //check if it is not fixed and attach it to the list
5128  CropSort cs={0., m_crops[i]};
5129  m_fodderCrops.push_back(cs);
5130  }
5131  }
5132  }
5133 }
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
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
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
vector< CropSort > m_fodderCrops
List of pointers to variable (non-fixed) fodder crops.
Definition: farm.h:2243
bool Get_fixed(int i)
Definition: farm.h:554
void AnimalFarm::decreaseCrops ( vector< CropSort cropsToDecrease,
double &  howMuchToDecrease 
)
protectedvirtual

Decreases area of cropsToDecrease by howMuchToDecrease.

Function decreases area of one or more crops from the list given as a first argument.The total area subtracted from the crops in the list is equal to the value of the second argument. In case an area of a fodder crop is decreased, the m_totalFUgrown is decreased and the totalFUt is increased by the amount of fodder corresponding to the removed area of a given fodder crop.

Reimplemented from OptimisingFarm.

Definition at line 7454 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().

7454  {
7459  for(int j=(int)cropsToDecrease.size()-1; howMuchToDecrease>0 && j>=0; j--){ //start with the worst
7460  double areaCrop = cropsToDecrease[j].crop->m_areaPercent;
7461  double areaBefore = areaCrop;
7462  double rotMinCrop = cropsToDecrease[j].crop->m_rotationMin;
7463  if(areaCrop - howMuchToDecrease >= rotMinCrop){
7464  areaCrop -= howMuchToDecrease;
7465  howMuchToDecrease = 0; //finito
7466  }
7467  else{
7468  howMuchToDecrease -= areaCrop - rotMinCrop;
7469  areaCrop = rotMinCrop;
7470  }
7471  cropsToDecrease[j].crop->m_areaPercent = areaCrop;
7472  cropsToDecrease[j].crop->m_areaVariable = areaCrop - rotMinCrop;
7473 
7474  if(areaCrop < areaBefore){
7475  int index = (cfg_OptimiseBedriftsmodelCrops.value())? toc_Foobar*m_farmType + cropsToDecrease[j].crop->m_cropType : tov_Undefined*m_farmType + cropsToDecrease[j].crop->m_cropType_almass;
7476  bool fodder = m_OurManager->pm_data->Get_fodder(index);
7477  if(fodder){ //this is a fodder crop - so you need to buy more fodder (totalFUt)
7478  double resp = cropsToDecrease[j].crop->m_resp;
7479  double loss = cropsToDecrease[j].crop->m_totalLoss;
7480  double FUKey = m_OurManager->pm_data->Get_FUKey(index);
7481  double FUha = resp * (1-loss/100) * FUKey; //[ha * hkg/ha * FU/hkg = FU]
7482  double changeFU = (areaBefore - areaCrop) * m_totalArea/100 * FUha; //positive number
7483  m_totalFUt += changeFU;
7484  m_totalFUgrown -= changeFU;
7485  }
7486  }
7487  }
7488 }
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
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void AnimalFarm::determineAreas ( int  a_foobar)
protectedvirtual

Determines areas of variable crops.

Animal farm version of the determineAreas function. In case of some farms (i.e. cattle farms) the sum of maximum allowed areas of non-fodder crops does not reach 100%, therefore it is necessary to introduce a virtual crop (AnimalFarm::m_fakeCrop)to 'fill' the area til 100%. This virtual crop is substituted by fodder crops in AnimalFarm::determineFodderAreas function.

Reimplemented from OptimisingFarm.

Definition at line 5896 of file farm.cpp.

References OptimisingFarm::determineAreas(), OptimisingFarm::m_assigned, OptimisingFarm::m_grownVariableCrops, OptimisingFarm::m_variableCrops, OptimisingFarm::randomizeCropList(), and OptimisingFarm::sortCrops().

5896  {
5902 
5903 /*If after this loop area assigned is < 100%, this means that the sum of the maximum allowed areas of non-fodder crops doesn't reach 100%;
5904 in such case introduce a fake crop to fill up the space till 100% (temporarily - until the determineFodderAreas function is called).*/
5905 
5906  m_fakeCropTest=false;
5907  if(m_assigned<100){ //use virtual 'fake crop'
5908  m_fakeCropTest = true;
5909  m_grownVariableCrops.push_back(m_fakeCrop); //append at the end (it is - it must be - the least profitable crop); this list is used in the determineFodderAreas function
5910  double areaP = 100-m_assigned;
5911  m_fakeCrop->m_GM = -1000000;
5912  m_fakeCrop->m_rotationMax = 100;
5913  m_fakeCrop->m_rotationMin = 0;
5914  m_fakeCrop->m_areaPercent = areaP;
5915  m_fakeCrop->m_areaVariable = areaP;
5916  m_assigned += areaP;
5917  }
5918 
5919  sortCrops(m_fodderCrops, "Savings"); //order fodder crops from the highest to the lowest savings resulting from growing a fodder crop - in relation to purchased fodder
5920  randomizeCropList(m_fodderCrops, "Savings"); //shuffles elements of the list with equal Savings
5921 
5922  sortCrops(m_variableCrops, "GM_Savings"); //has to be done before restrictions, but only for animal farms.
5923  randomizeCropList(m_variableCrops, "GM_Savings"); //shuffles elements of the list with equal GM_Savings. Fodder crops have their savings saved under GM_Savings, non-fodder - GM.
5924 
5925  correctFodderDemand(a_foobar); //correct demand for min areas and fixed crops
5926  determineFodderAreas(a_foobar);
5927 }
double m_rotationMin
Minimum area in percent of farm&#39;s arable area for a given crop (depends on a farm size...
Definition: farm.h:1509
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 p...
Definition: farm.cpp:7334
vector< CropSort > m_variableCrops
Vector of structs containing pointers to crops which are not fixed.
Definition: farm.h:2042
void determineFodderAreas(int a_foobar)
Determines areas of fodder crops and corrects areas of non-fodder crops.
Definition: farm.cpp:7142
bool m_fakeCropTest
Set to true if the fake crop is present after determineAreas function.
Definition: farm.h:2241
double m_areaPercent
Area of a crop in percent of a farm&#39;s total area [%].
Definition: farm.h:1552
double m_areaVariable
Area of a crop that can be changed when checking for restrictions (=m_areaPercent - m_rotationMin) [%...
Definition: farm.h:1554
double m_GM
Value of gross margin for a crop (m_income_ha - m_costs_ha) [DKK/ha].
Definition: farm.h:1546
virtual void determineAreas(int a_foobar)
Determines areas of variable crops.
Definition: farm.cpp:5827
vector< CropOptimised * > m_grownVariableCrops
Vector of pointers to variable crops that are grown on area larger than areaMin (after determineAreas...
Definition: farm.h:2049
CropOptimised * m_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 det...
Definition: farm.h:2235
double m_assigned
Variable holding a value of area already reserved for certain crops at a farm. [0-100%].
Definition: farm.h:2099
vector< CropSort > m_fodderCrops
List of pointers to variable (non-fixed) fodder crops.
Definition: farm.h:2243
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
void correctFodderDemand(int a_foobar)
Determines how much fodder is produced from fixed crops and min. areas of variable crops...
Definition: farm.cpp:7011
void AnimalFarm::determineFodderAreas ( int  a_foobar)
protected

Determines areas of fodder crops and corrects areas of non-fodder crops.

First, it calls a function determining areas for fodder that has to be grown to fulfill the condition on min. requirement of own fodder production.

Next, the function chooses the most profitable alternative of covering the remaining fodder demand: purchasing fodder, growing fodder crops, or a mix of these two. In case any fodder crops are grown (above their minimum area), one or more of the variable crops' areas has to be corrected (decreased).

The general structure of the part of the function determining whether to grow fodder, buy it or mix the two: The outer for-loop goes through fodder crops until the total fodder demand is zero – and it starts with the crop with highest savings (the best one). At the beginning it checks if the fodder crop has reached its max rotation area. The inner for-loop goes through all non-fodder variable crops that after they were assigned area had an area above area minimum (there’s no point in checking other crops – their areas cannot be decreased). It starts with the variable crop with the lowest GM (the worst one) and the condition in the loop is a Boolean value which turns to true once a current fodder crop reached its area max. Then the outer loop takes the next best fodder crop.

In some cases (happens when the non-fodder crops are assigned areas according to the rules from the Bedriftsmodel - i.e. using the maximum rotations) even when the m_totalFUdemand is covered in 100% by fodder crops, there is still a virtual (non-fodder) crop present at a farm (m_fakeCrop). In such case this virtual crop has to be substituted by fodder crops and the total fodder production is higher than the total fodder demand (m_totalFUdemand).

Definition at line 7142 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, DataForOptimisation::Get_FUKey(), OptimisingFarm::increaseCrops(), OptimisingFarm::m_farmType, OptimisingFarm::m_grownVariableCrops, Farm::m_OurManager, OptimisingFarm::m_totalArea, OptimisingFarm::m_totalFUdemand, OptimisingFarm::m_totalFUgrown, OptimisingFarm::m_totalFUt, FarmManager::pm_data, and CfgBool::value().

7142  {
7143 
7165 //1. assigning area to fodder crops in order to cover the min fodder production
7166  if(!cash_crops_allowed) determineMinFodder(a_foobar);
7167 
7168 //2. now the choice - produce or purchase fodder
7169 
7170  m_totalFUt=0;
7171 
7172 
7173  //go through fodder crops - start with the one with max savings. Check if it reached its max area (could have happened in the previous step)
7174 
7175 for(int p=0; m_totalFUdemand>0 && p<(int)m_fodderCrops.size(); p++){ //outer for loop - fodder crops;
7176 
7177  double rotationMax = m_fodderCrops[p].crop->m_rotationMax;
7178  double areaFodder = m_fodderCrops[p].crop->m_areaPercent;
7179  if(areaFodder < rotationMax){ //if not -> go to the next fodder crop
7180  double savings = m_fodderCrops[p].crop->m_savings;
7181  bool assigningFinished = false; //changed to true when a fodder crop reaches rotationMax
7182 
7183  int v = (int)m_grownVariableCrops.size()-1;
7184  double minGM = 1000000; //set it high so that if there are no grown var crops - we go directly to the fodder trade code (as savings are not > minGM)
7185  do{ //inner loop; normal crops; starts with the crop with the lowest GM;
7186  if(v>=0){
7187  minGM = m_grownVariableCrops[v]->m_GM;
7188  }
7189  if(savings > minGM){ //compare savings to GM of the worst 'available' normal crop - which is currently planted and have areaVariable>0
7190  double areaVariable = m_grownVariableCrops[v]->m_areaVariable;
7191  int index = (cfg_OptimiseBedriftsmodelCrops.value())? a_foobar*m_farmType + m_fodderCrops[p].crop->m_cropType : a_foobar*m_farmType + m_fodderCrops[p].crop->m_cropType_almass;
7192  double FUKey = m_OurManager->pm_data->Get_FUKey(index);//if it is not a fodder crop, key=0
7193  double resp = m_fodderCrops[p].crop->m_resp;
7194  double loss = m_fodderCrops[p].crop->m_totalLoss;
7195  double FUha = resp*(1-loss/100)*FUKey;
7196  double haNeeded = m_totalFUdemand/FUha;
7197  double percNeeded = haNeeded*100/m_totalArea;
7198 
7199  if(percNeeded <= rotationMax - areaFodder){//you can plant as much as need of fodder crop, but check if there is enough space in the normal crop
7200  if(percNeeded <= areaVariable){//if so, just plant as much as you need of this one fodder crop and cut the normal crop by percNeeded
7201  areaFodder += percNeeded; //increase the area (not just assign!)
7202  m_totalFUdemand = 0; //finish outer loop
7203  m_totalFUgrown += percNeeded*FUha*m_totalArea/100;
7204  areaVariable -= percNeeded;
7205  assigningFinished = true; //finish inner loop
7206  }
7207  else{//you can plant fodder crop on an area of a normal crop and then check with the next normal crop
7208  areaFodder += areaVariable; //increase by the whole 'available' area of a normal crop
7209  m_totalFUdemand -= FUha*areaVariable*m_totalArea/100; //update fodder demand
7210  m_totalFUgrown += areaVariable*FUha*m_totalArea/100;
7211  areaVariable = 0;
7212  }
7213  }
7214  else{//this fodder crop will not cover all the needs; will have to check the next one
7215  if(rotationMax - areaFodder <= areaVariable){//if so, just plant as much as you need of this one fodder crop and cut the normal crop by...
7216  areaVariable -= rotationMax-areaFodder;
7217  m_totalFUgrown += (rotationMax-areaFodder)*FUha*m_totalArea/100;
7218  m_totalFUdemand -= FUha*(rotationMax-areaFodder)*m_totalArea/100;
7219  areaFodder = rotationMax; //max
7220  assigningFinished = true;
7221  //finish inner loop-you have to take the next fodder crop
7222  }
7223  else{//you can plant fodder crop on an area of a normal crop and then check with the next normal crop
7224  areaFodder += areaVariable; //increase by the whole 'available' area of a normal crop
7225  m_totalFUdemand -= FUha*areaVariable*m_totalArea/100;
7226  m_totalFUgrown += areaVariable*FUha*m_totalArea/100;
7227  areaVariable = 0;
7228  //whole replaced by a fodder crop
7229  }
7230  }
7231  double areaMin = m_grownVariableCrops[v]->m_rotationMin;
7232  double areaPer = areaMin + areaVariable;
7233  m_grownVariableCrops[v]->m_areaPercent = areaPer;
7234  m_grownVariableCrops[v]->m_areaVariable = areaVariable;
7235 
7236  }
7237  else{//buy all the remaining fodder demand
7238  m_totalFUt = m_totalFUdemand; //demand is already updated for fodder from fixed crops and min areas
7239  m_totalFUdemand = 0; //finish outer loop
7240  assigningFinished = true; //finish inner loop
7241  }
7242  v--;
7243  }while (assigningFinished==false && v>=0);//inner loop (normal crops)
7244 
7245  m_fodderCrops[p].crop->m_areaPercent = areaFodder;//update fodder crop - after the inner loop
7246 
7247  if(assigningFinished==false){ //loop was stopped by the condition->no more space on normal crops available
7248  //there's no more space on normal crops-have to buy the remaining totalFUdemand
7250  }
7251  }
7252 }//outer for-loop (fodder crops)
7253 
7254 
7255 if(m_totalFUdemand > 0){ //added 30.01 - for some farms the condition 'if(areaFodder<rotationMax)' is never fulfilled, so the inner loop will never run
7257  m_totalFUdemand = 0;
7258 }
7259 
7260 if(m_fakeCropTest==true){ //only if it was used in determineAreas - check if it is >0
7261  //check if the fake crop is still there - if so, substitute it with fodder crops
7262  int s = (int)m_grownVariableCrops.size()-1;
7263  double areaFakeCrop = m_grownVariableCrops[s]->m_areaPercent;
7264  if(areaFakeCrop > 0){
7265  increaseCrops(m_fodderCrops, areaFakeCrop);
7266  m_grownVariableCrops[s]->m_areaPercent = areaFakeCrop; //sets fake crop's area at 0.
7267  }
7268  //remove the fake crop from the grownVariable crops vector
7269  m_grownVariableCrops.erase(m_grownVariableCrops.begin() + s);
7270 }
7271 
7272 }// end of determineFodderAreas
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 determineMinFodder(int a_foobar)
Covers the min. required fodder production for animal farms.
Definition: farm.cpp:7064
double Get_FUKey(int i)
Definition: farm.h:561
bool m_fakeCropTest
Set to true if the fake crop is present after determineAreas function.
Definition: farm.h:2241
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< CropOptimised * > m_grownVariableCrops
Vector of pointers to variable crops that are grown on area larger than areaMin (after determineAreas...
Definition: farm.h:2049
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
bool cash_crops_allowed
Sets to true if cash crops are allowed. True by default.
Definition: farm.h:2254
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
vector< CropSort > m_fodderCrops
List of pointers to variable (non-fixed) fodder crops.
Definition: farm.h:2243
double m_totalFUdemand
Farm&#39;s total demand for fodder (it is covered by growing fodder crops and/or purchasing fodder and th...
Definition: farm.h:2093
void AnimalFarm::determineMinFodder ( int  a_foobar)
protected

Covers the min. required fodder production for animal farms.

Function assigning area to fodder crops in order to cover the min fodder production if it is not covered by the fodder from fixed crops and min. areas of variable crops.

Definition at line 7064 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, OptimisingFarm::decreaseCrops(), g_msg, DataForOptimisation::Get_FUKey(), OptimisingFarm::m_almass_no, OptimisingFarm::m_farmType, OptimisingFarm::m_grownVariableCrops, Farm::m_OurManager, OptimisingFarm::m_totalArea, OptimisingFarm::m_totalFUdemand, OptimisingFarm::m_totalFUgrown, FarmManager::pm_data, CfgBool::value(), MapErrorMsg::Warn(), and WARN_BUG.

7064  {
7067  double areaAssignedToFodder=0; //holds the value of area that has to be grown to cover the min fodder production requirement
7068  if(m_fodderToProduce > 0){
7069  double available=0; //area of normal (non-fodder) crops available to substitute with fodder crops
7070  for(int i=0; i<(int)m_grownVariableCrops.size(); i++){
7071  double areaVariableCrop = m_grownVariableCrops[i]->m_areaVariable;
7072  available += areaVariableCrop;
7073  }
7074 
7075  for(int i=0; available>0 && i<(int)m_fodderCrops.size() && m_fodderToProduce > 0 ; i++){// if so, more has to be produced (than it is already-from min areas and fixed crops)
7076  int index = (cfg_OptimiseBedriftsmodelCrops.value())? a_foobar*m_farmType + + m_fodderCrops[i].crop->m_cropType : a_foobar*m_farmType + + m_fodderCrops[i].crop->m_cropType_almass;
7077  double rotationMax = m_fodderCrops[i].crop->m_rotationMax;
7078  double area = m_fodderCrops[i].crop->m_areaPercent; //fodder crop's area
7079  double areaBefore = area; //this is positive if areaMin>0, so save it
7080  double FUKey = m_OurManager->pm_data->Get_FUKey(index); //if it is not a fodder crop, key=0; number of FU per hkg of a crop
7081  double resp = m_fodderCrops[i].crop->m_resp;
7082  double loss = m_fodderCrops[i].crop->m_totalLoss;
7083  double FUha = resp * (1-loss/100) * FUKey;
7084  double haNeeded = m_fodderToProduce/FUha;
7085  double percNeeded = haNeeded*100/m_totalArea;
7086  if(percNeeded <= rotationMax - area){ //area might be positive! (min area)
7087  if(percNeeded <= available){
7088  area += percNeeded; //the end, fodderToProduce will be 0.
7089  available -= percNeeded;
7090  }
7091  else{
7092  area+=available; //so we can't grow any more fodder - no space left!
7093  available=0;
7094  }
7095  }
7096  else{
7097  if(rotationMax-area >= available){
7098  area += available;
7099  available=0; //no space left
7100  }
7101  else{
7102  available -= rotationMax-area;
7103  area = rotationMax;
7104  }
7105  }
7106  m_fodderCrops[i].crop->m_areaPercent = area;
7107  double Funits = FUha * (area-areaBefore) * m_totalArea/100;
7108  m_fodderToProduce -= Funits; //update fodderToProduce; in 1st case - it's now = 0.
7109  m_totalFUdemand -= Funits; //update the total demand as well!
7110  m_totalFUgrown += Funits; //update the amount of grown fodder units
7111  areaAssignedToFodder += (area-areaBefore);
7112 
7113  }
7114  if(m_fodderToProduce>0.1){
7115  //restriction broken! impossible to produce the min amount of fodder - send a message, but don't stop.
7116  char index[ 20 ];
7117  sprintf( index, "%d", m_almass_no);
7118  g_msg->Warn( WARN_BUG, "AnimalFarm::determineMinFodder(): impossible to cover the min. fodder prod., farm no: ", index );
7119  //exit( 1 );
7120  }
7121  //decreasing area of variable crops that has just been assigned to fodder crops
7122  //need to create a vector of type CropSort
7123  vector<CropSort>grownVarCrops_key;
7124  for(int g=0; g < (int)m_grownVariableCrops.size(); g++){
7125  CropSort gc = {0., m_grownVariableCrops[g]};
7126  grownVarCrops_key.push_back(gc);
7127  }
7128 
7129  OptimisingFarm::decreaseCrops(grownVarCrops_key, areaAssignedToFodder); //m_grownVariableCrops does not contain fodder crops-call optimising farms version. there might be here a fake crop; here use grownVarCrops_key - need CropSort type vector to use decreaseCrops;
7130  if(areaAssignedToFodder>0){
7131  //there is not enough space to grow fodder to cover the min required.
7132  char index[ 20 ];
7133  sprintf( index, "%d", m_almass_no);
7134  g_msg->Warn( WARN_BUG, "AnimalFarm::determineMinFodder(): not enough space to grow the min. fodder, farm no.: ", index );
7135  //exit( 1 );
7136 
7137  }
7138  }
7139 } //determineMinFodder
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_totalArea
Total area of a farm. A sum of initial crop areas (if in bedriftsmodel, i.e. original farm optimizati...
Definition: farm.h:2081
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
vector< CropOptimised * > m_grownVariableCrops
Vector of pointers to variable crops that are grown on area larger than areaMin (after determineAreas...
Definition: farm.h:2049
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
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
double m_fodderToProduce
Fodder that has to be produced to fulfill the min. fodder production restriction at the end of a year...
Definition: farm.h:2250
virtual void decreaseCrops(vector< CropSort >cropsToDecrease, double &howMuchToDecrease)
Decreases area of a crops by a specified number.
Definition: farm.cpp:7435
vector< CropSort > m_fodderCrops
List of pointers to variable (non-fixed) fodder crops.
Definition: farm.h:2243
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
int m_almass_no
Farm&#39;s almass number.
Definition: farm.h:2077
double m_totalFUdemand
Farm&#39;s total demand for fodder (it is covered by growing fodder crops and/or purchasing fodder and th...
Definition: farm.h:2093
void AnimalFarm::findFodderCropSavings ( )
protected

Determines the savings resulting from growing a fodder crop relative to purchasing fodder.

void AnimalFarm::increaseCrops ( vector< CropSort cropsToIncrease,
double &  howMuchToIncrease 
)
protectedvirtual

Increases area of cropsToIncrease by howMuchToIncrease.

Function increases area of one or more crops from the list given as a first argument.The total area added to the crops in the list is equal to the value of the second argument. In case an area of a fodder crop is increased, the m_totalFUgrown is increased and the m_totalFUt is decreased by the amount of fodder corresponding to the added area of a given fodder crop.

Reimplemented from OptimisingFarm.

Definition at line 7397 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().

7397  {
7402  for(int i=0; howMuchToIncrease>0 && i<(int)cropsToIncrease.size(); i++){
7403  double area = cropsToIncrease[i].crop->m_areaPercent;
7404  double areaBefore = area;
7405  double rotationMax = cropsToIncrease[i].crop->m_rotationMax;
7406  double rotMinCrop = cropsToIncrease[i].crop->m_rotationMin;
7407  if(area + howMuchToIncrease <= rotationMax){
7408  area += howMuchToIncrease; //finito
7409  howMuchToIncrease = 0;
7410  }
7411  else{
7412  howMuchToIncrease -= rotationMax-area;
7413  area = rotationMax;
7414  }
7415  cropsToIncrease[i].crop->m_areaPercent = area;
7416  cropsToIncrease[i].crop->m_areaVariable = area - rotMinCrop;
7417 
7418  //checking if area has changed
7419  if(area > areaBefore){
7420  int index = (cfg_OptimiseBedriftsmodelCrops.value())? toc_Foobar*m_farmType + cropsToIncrease[i].crop->m_cropType : tov_Undefined*m_farmType + cropsToIncrease[i].crop->m_cropType_almass;
7421  bool fodder = m_OurManager->pm_data->Get_fodder(index);
7422  if(fodder){ //this is a fodder crop - so you need to buy less fodder (totalFUt)
7423  double resp = cropsToIncrease[i].crop->m_resp;
7424  double loss = cropsToIncrease[i].crop->m_totalLoss;
7425  double FUKey = m_OurManager->pm_data->Get_FUKey(index);
7426  double FUha = resp * (1-loss/100) * FUKey; //[ha * hkg/ha * FU/hkg = FU]
7427  double changeFU = (area-areaBefore) * m_totalArea/100 * FUha; //positive
7428  m_totalFUt -= changeFU;
7429  m_totalFUgrown += changeFU;
7430  }
7431  }
7432  }
7433 }
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
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

bool AnimalFarm::cash_crops_allowed
protected

Sets to true if cash crops are allowed. True by default.

Definition at line 2254 of file farm.h.

Referenced by AnimalFarm().

CropOptimised* AnimalFarm::m_fakeCrop
protected

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.

Definition at line 2235 of file farm.h.

Referenced by AnimalFarm().

bool AnimalFarm::m_fakeCropTest
protected

Set to true if the fake crop is present after determineAreas function.

Definition at line 2241 of file farm.h.

vector<CropSort> AnimalFarm::m_fodderCrops
protected

List of pointers to variable (non-fixed) fodder crops.

Definition at line 2243 of file farm.h.

double AnimalFarm::m_fodderToProduce
protected

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].

Definition at line 2250 of file farm.h.

double AnimalFarm::m_fodderToProduceBefore
protected

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].

Definition at line 2252 of file farm.h.

double AnimalFarm::m_totalFodderToProduce
protected

Fodder that has to be produced by a farm to fulfill the min. fodder production restriction. [fodder units].

Definition at line 2248 of file farm.h.


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