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

A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or other decision startegies. More...

#include <farm.h>

Inheritance diagram for OptimisingFarm:
Farm AnimalFarm NonAnimalFarm OptimisingCattleFarm OptimisingPigFarm OptimisingOtherFarm OptimisingPlantFarm

Classes

struct  CropSort
 Struct used for sorting crops. More...
 
struct  MakeRotation
 Struct used only in Bedriftsmodel crop type mode for creating m_rotation vector. Bool member used for marking the element of a vector as already assigned a TTypesOfVegetation crop type. More...
 
struct  reverseSort
 Struct redefining operator < - used for sorting crops. More...
 

Public Member Functions

 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 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...
 
virtual void createCropsLists (int a_foobar)
 Creates lists of crops. 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...
 
virtual void determineAreas (int a_foobar)
 Determines areas of variable crops. 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...
 
virtual void checkWinterRotation1 ()
 Checks if the restriction on a winter rotation is fulfilled. More...
 
virtual void checkWinterCrops ()
 Checks if the restriction on a max. share of winter crops is fulfilled. 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...
 
virtual void increaseCrops (vector< CropSort >cropsToIncrease, double &howMuchToIncrease)
 Increases area of crops by a specified number. More...
 
virtual void decreaseCrops (vector< CropSort >cropsToDecrease, double &howMuchToDecrease)
 Decreases area of a crops by a specified number. 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

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

A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or other decision startegies.

Definition at line 1885 of file farm.h.

Constructor & Destructor Documentation

OptimisingFarm::OptimisingFarm ( FarmManager a_myfarmmanager,
int  a_No 
)

The constructor.

Definition at line 4676 of file farm.cpp.

References animals_no, force_deliberation, Initialize(), m_actual_aggregated_yield, m_actual_costs, m_actual_income, m_actual_profit, m_almass_no, m_animals_numbers, m_decision_mode_counters, m_exp_costs, m_exp_income, m_exp_profit, Farm::m_farmtype, m_main_goal, Farm::m_OurManager, m_previously_imitated_neighbour, tof_OptimisingFarm, and tofg_profit.

4676  : Farm(a_myfarmmanager)
4677 {
4678 
4679 
4680  m_farmtype = tof_OptimisingFarm; //this is almass farm type (and not the optimising farm type - see OptimisingFarm::Initialize)
4681  m_almass_no = a_No;
4682  force_deliberation = false;
4684 
4685  //assign goals - DEFAULT values. Later FarmManager assigns main goals again.
4687  //m_pest_goal = tofg_profit;
4688  //m_fert_goal = tofg_profit;
4689 
4690  //initialize the actual and expected values
4691  m_actual_profit=0;
4692  m_actual_income=0;
4693  m_actual_costs=0;
4695  m_exp_profit=0;
4696  m_exp_income=0;
4697  m_exp_costs=0;
4699 
4700  //initialize the dec. mode counters
4701  m_decision_mode_counters.resize(4);
4703 
4704  m_animals_numbers.resize(0);
4705  animals_no = 0;
4706 
4707 }
vector< int > m_decision_mode_counters
Vector with counters for each decision mode. 0 - imitation, 1 - social comparison, 2 - repeat, 3 - deliberation.
Definition: farm.h:1971
TTypeOfFarmerGoal m_main_goal
Farmer&#39;s main goal (determined by a farmer&#39;s type) .
Definition: farm.h:1960
double m_exp_income
An expected farm&#39;s income at a farm in a given year.
Definition: farm.h:1981
double m_actual_profit
An actual profit realised at a farm in a given year.
Definition: farm.h:1975
double m_actual_aggregated_yield
Actual aggregated yield at a farm in a given year.
Definition: farm.h:1988
double m_actual_costs
Actual costs at a farm in a given year.
Definition: farm.h:1983
TTypesOfFarm m_farmtype
Definition: farm.h:842
double m_actual_income
An actual income at a farm in a given year.
Definition: farm.h:1979
double m_exp_costs
Expected costs at a farm in a given year.
Definition: farm.h:1985
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
void Initialize(FarmManager *a_pfm)
Assigns to each farm its farm type, farm size, farm&#39;s real ID number, and soil type. It creates livestock and crops.
Definition: farm.cpp:4710
bool force_deliberation
If set to true, a farm must use deliberation as a decision strategy.
Definition: farm.h:2009
vector< double > m_animals_numbers
Vector for storing numbers of animals at a farm in previous years (3).
Definition: farm.h:2007
OptimisingFarm * m_previously_imitated_neighbour
The neighbouring farmer whose crops might be copied in imitation and social comparison decision modes...
Definition: farm.h:2004
double m_exp_profit
An expected farm&#39;s profit for a given year.
Definition: farm.h:1977
int animals_no
Holds the number of animals in a farm at a particular day in a year (depends on a species)...
Definition: farm.h:2011
Farm(FarmManager *a_manager)
Farm constructor - creates an instance of each possible crop type.
Definition: farm.cpp:862
int m_almass_no
Farm&#39;s almass number.
Definition: farm.h:2077
virtual OptimisingFarm::~OptimisingFarm ( )
inlinevirtual

Definition at line 1890 of file farm.h.

1890 { ; }

Member Function Documentation

void OptimisingFarm::ActualProfit ( )

Function that determines actual crop yields and profit in a given year.

The function calculates actual yields, income, costs, profits etc. for a given farm in a previous year by accounting for crops grown at its fields. Determines farmer's need satisfaction level (m_need_satisfaction_level) which depends on farmer's actual results relative to the expected ones; the values compared depend on a farmer type, profit maximizer and environmentalist look at profit, yield maximizer looks at aggregated yield. The function also accounts for the pesticide and fertilizer usage in order to obtain aggregate results. The function is used only in ALMaSS crop set mode.

Definition at line 8329 of file farm.cpp.

References FarmManager::Add_to_cropTotals(), animals_no, CropActualValues::area, CropActualValues::biomass_at_harvest, cfg_AnimalsThreshold, cfg_MaizeEnergy, cfg_Min_need_satisfaction1, cfg_Min_need_satisfaction2, cfg_OnlyDeliberation, cfg_Price_Nt, cfg_PriceChangeThreshold, VegElement::Clean_CropDataStorage(), crop_parameter(), findCropByName_almass(), force_deliberation, g_date, g_msg, DataForOptimisation::Get_beta1(), DataForOptimisation::Get_beta2(), DataForOptimisation::Get_biomass_factor(), VegElement::Get_CropDataStorage(), FarmManager::Get_crops_summary_BIs_tov(), DataForOptimisation::Get_cropTypes_almass(), DataForOptimisation::Get_cropTypes_almass_size(), DataForOptimisation::Get_fodder(), DataForOptimisation::Get_noCrops(), DataForOptimisation::Get_sellingPrice(), DataForOptimisation::Get_sellingPrice_lastyr(), VegElement::Get_taken(), Farm::GetArea(), FarmManager::GetDD(), Calendar::GetYearNumber(), CropActualValues::harvested, m_actual_aggregated_yield, m_actual_costs, m_actual_income, m_actual_profit, m_almass_no, m_animals_numbers, CropOptimised::m_costs_ha, CropOptimised::m_cropType_almass, m_exp_aggregated_yield, m_exp_costs, m_exp_income, m_exp_profit, m_farmType, Farm::m_fields, CropOptimised::m_grooming, CropOptimised::m_hoeing, m_main_goal, CropOptimised::m_n, m_need_satisfaction_level, CropOptimised::m_nt, CropOptimised::m_optimalN, Farm::m_OurManager, m_previous_aggregated_yields, m_previous_costs, m_previous_incomes, m_previous_profits, m_previous_satisfaction_levels, CropOptimised::m_resp, CropOptimised::m_rotationMax, m_soilType, CropOptimised::m_totalLoss, CropOptimised::m_weeding, CropActualValues::missed_fi_app, CropActualValues::missed_herb_app, CropActualValues::no_fi_app, CropActualValues::no_herb_app, FarmManager::pm_data, FarmManager::Set_crops_fertilizer(), FarmManager::Set_crops_fertilizer_trade(), FarmManager::Set_crops_summary_BIs(), FarmManager::Set_crops_summary_BIs_fi(), FarmManager::Set_crops_summary_BIs_herb(), FarmManager::Set_cropTotals_cattle_sum(), FarmManager::Set_cropTotals_other_sum(), FarmManager::Set_cropTotals_pig_sum(), FarmManager::Set_cropTotals_plant_sum(), FarmManager::Set_cropTotals_sum(), CropActualValues::taken, tofg_environment, tofg_profit, tofg_yield, toof_Cattle, toof_Other, toof_Pig, toof_Plant, tos_Foobar, tov_CloverGrassGrazed1, tov_CloverGrassGrazed2, tov_FodderBeet, tov_FodderGrass, tov_Maize, tov_OrchardCrop, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_Potatoes, tov_PotatoesIndustry, tov_SeedGrass1, tov_SeedGrass2, tov_SpringBarleySilage, CropActualValues::tov_type, tov_Undefined, tov_YoungForest, CfgFloat::value(), CfgBool::value(), MapErrorMsg::Warn(), and WARN_BUG.

Referenced by FarmManager::ActualProfit().

8329  {
8337  vector<TTypesOfVegetation> veg_type;
8338  //vector<double>profits; //profit from each field
8339  //profits.resize(m_fields.size());
8340 
8341  double priceNt = cfg_Price_Nt.value();
8342 
8343  //for energy maize impacts on wildlife
8344  bool emaize=false;
8345 
8346  //exp. agg. yield - for now it is not necessary to do this every year since the fields size is constant, but later it might change!
8347  m_exp_aggregated_yield = (double)m_fields.size(); //cause each field is expected to give 100% = 1. Except the fields with a crop with exp yield = 0.
8348 
8349  //go through all farm's field:
8350  for(int i=0; i<(int)m_fields.size(); i++){
8351 
8352  CropActualValues crop_data;
8353  TTypesOfVegetation crop;
8354  double biomass=0; double area=0; double yield_loss_pest=0; double no_herb_app=0; double no_fi_app=0;
8355  double unit_loss_herb=0; double unit_loss_fi=0; //to determine or take from field's data
8356  double yield_ha=0; double income_ha=0; double income=0; double costs_ha=0; double costs=0; double profit_ha=0; double profit=0; //to determine
8357  double yield_exp=0; double yield_ratio=0; double income_exp=0; double costs_exp=0; double profit_exp=0; //to account for - it was already calculated per crop in the determine GM function
8358  double sellingPrice=0; double priceHerb=0; double priceFi=0; double priceLM=0; double priceH=0; double priceW=0; double priceG=0; double subsidy=0; //economic data - need to be given as input;
8359  double no_missed_herb_app, no_missed_fi_app = 0; //no_missed - how many applications of herb/fi were missed
8360  double fert_applied=0; double fert_opt=0; double fert_trade=0; double beta1=0; double beta2=0; double alfaH=0; double alfaFI=0;
8361  double yield_factor = 0; //this serves both as biomass-to-yield factor and day degrees-to-yield factor - they are saved in one input table (a single crop has just one of these factors!)
8362  VegElement * pf = dynamic_cast<VegElement*>(m_fields[i]);
8363 
8364  int cropDataStorage_index=-1; //initialize
8365 
8366  if(pf->Get_taken(1)){ //there is a crop at position one - so account for this crop; otherwise go to position 0
8367  crop_data = pf->Get_CropDataStorage(1);
8368  cropDataStorage_index = 1;
8369  }
8370  else{
8371  crop_data = pf->Get_CropDataStorage(0);
8372  cropDataStorage_index = 0;
8373  if(crop_data.taken==false){//error
8374  g_msg->Warn( WARN_BUG, "OptimisingFarm::ActualProfit(): There is no crop data in the fields m_CropDataStorage", "" );
8375  exit( 1 );
8376  }
8377  }
8378 
8379  crop = crop_data.tov_type;
8380 
8381  //for energy maize impacts on wildlife
8382  if (crop==tov_Maize) emaize = true;
8383  //
8384 
8385  bool do_accounting = true;
8386  if(cropDataStorage_index==0){ //could be this crop was not harvested yet
8387  bool harvested = crop_data.harvested;
8390  && !harvested){
8391  //this is a crop that shoud be harvested, but so far it wasn't - so do not account for this crop yet! - just skip this field in accounting
8392  do_accounting = false;
8393  }
8394  }
8395 
8396  if(do_accounting){
8397  area = crop_data.area * 0.0001; //change the units from sq. meters to ha!
8398 
8399  if(crop==tov_SeedGrass1 || crop==tov_SeedGrass2){ //alfaherb is more than 100! - so problem with negative yield
8400  double betaH = crop_parameter(crop, "BetaHerb");
8401  alfaFI = crop_parameter(crop, "AlfaFi");
8402  unit_loss_herb = betaH/100/2;
8403  unit_loss_fi = alfaFI/100;
8404  }
8405  else{
8406  alfaH = crop_parameter(crop, "AlfaHerb");
8407  alfaFI = crop_parameter(crop, "AlfaFi");
8408  unit_loss_herb = alfaH/100; //yield loss per unit of herb application, = max yield loss/optBI = betaH/optBI = alfa. (and /100).
8409  unit_loss_fi = alfaFI/100; //yield loss per unit of fung-insecticide application
8410  }
8411 
8412  //draw random numbers to modify the pest related yield loss
8413  //method from: http://stackoverflow.com/questions/9651024/using-stdtr1normal-distribution-in-qt
8414  std::random_device rd;
8415  std::normal_distribution<double> dist(1, 0.2);
8416  std::mt19937 engine(rd());
8417  double r_number_1 = dist(engine);
8418  double r_number_2 = dist(engine);
8419 
8420 
8421  //determine the pest related yield loss
8422  no_missed_herb_app = crop_data.missed_herb_app;
8423  no_missed_fi_app = crop_data.missed_fi_app;
8424  yield_loss_pest = no_missed_herb_app * unit_loss_herb * r_number_1 + no_missed_fi_app * unit_loss_fi * r_number_2; //total yield loss due to missed pesticide applications
8425 
8426  //determine the yield
8427  biomass = crop_data.biomass_at_harvest;
8428  yield_factor = m_OurManager->pm_data->Get_biomass_factor(tov_Undefined * m_soilType + crop); //crop is tov - integer
8429 
8430  fert_applied = findCropByName_almass (crop)->m_n;
8431  fert_opt = findCropByName_almass (crop)->m_optimalN;
8432  fert_trade = findCropByName_almass (crop)->m_nt;
8433 
8434  int index = tov_Undefined * m_soilType + crop;
8435  beta1=m_OurManager->pm_data->Get_beta1(index);
8436  beta2=m_OurManager->pm_data->Get_beta2(index);
8437 
8438  double dd=m_OurManager->GetDD();
8439 
8440  yield_ha = (biomass==-1)? dd : biomass; //if biomass=-1 this crop is not harvested - use daydegress to estimate the yield
8441  yield_ha *= yield_factor; //multiply by the factor to convert biomass to yield - works both for harvested and not harvested crops.
8442  if(fert_opt!=0){
8443  yield_ha -= (1 - fert_applied/fert_opt) * (beta1 * fert_opt + beta2 * fert_opt*fert_opt); //subtract the amount which depends on the applied ferilizer - if the applied=optimal, then amount subtracted=0. The expression in brackets - with betas - corresponds to the max yield loss-when fert=0.
8444  }
8445  yield_ha *= (1-yield_loss_pest); //finally account for the yield loss due to pests
8446 
8447  //get other numbers for economic calculations
8448  sellingPrice = m_OurManager->pm_data->Get_sellingPrice(tov_Undefined*tos_Foobar*m_farmType + tov_Undefined*m_soilType + crop); //always tov_Undefined because this funtion is called ONLY in almass crop mode!
8449  priceFi = crop_parameter(crop, "PriceFi");
8450  priceHerb = crop_parameter(crop, "PriceHerb");
8451  priceG = crop_parameter(crop, "PriceG");
8452  priceH = crop_parameter(crop, "PriceH");
8453  priceW = crop_parameter(crop, "PriceW");
8454  priceLM = crop_parameter(crop, "PriceLM");
8455  subsidy =crop_parameter(crop, "Subsidy");
8456 
8457  double grooming = findCropByName_almass (crop)->m_grooming;
8458  double hoeing = findCropByName_almass (crop)->m_hoeing;
8459  double weeding = findCropByName_almass (crop)->m_weeding;
8460 
8461  no_herb_app = crop_data.no_herb_app;
8462  no_fi_app = crop_data.no_fi_app;
8463 
8464  //special case for potatoes and fodder beet
8465  if(crop==tov_Potatoes || crop==tov_PotatoesIndustry){
8466  no_herb_app = 1.41; //need to be consistent with numbers in the fix BI function!
8467  no_fi_app = 9.28;
8468  }
8469  if(crop==tov_FodderBeet){
8470  no_herb_app = 2.28; //need to be consistent with numbers in the fix BI function!
8471  }
8472 
8473  //saving the amount of pesticides and fertilizer
8474  if(g_date->GetYearNumber()>9){ //do it for the first time in year 10 ->only then we account for new dec.- modes
8475  for(int i=0; i<m_OurManager->pm_data->Get_noCrops(); i++){
8476  if(m_OurManager->Get_crops_summary_BIs_tov(i) == crop){
8477  m_OurManager->Set_crops_summary_BIs_herb(i, no_herb_app * area);
8478  m_OurManager->Set_crops_summary_BIs_fi(i, no_fi_app * area);
8479  m_OurManager->Set_crops_summary_BIs(i, (no_fi_app+no_herb_app) * area);
8480  m_OurManager->Set_crops_fertilizer(i, fert_applied * area);
8481  m_OurManager->Set_crops_fertilizer_trade(i, fert_trade * area);
8482  break;
8483  }
8484  }
8485  }
8486 
8487 
8488  //GET THE ACTUAL FIGURES:
8489  //1. determine the actual income from this crop: use selling price also for fodder crops! they do not add to income, just diminish the costs of fodder...hm
8490  income_ha = yield_ha * sellingPrice + subsidy;
8491  income = income_ha * area; //total income from this crop
8492 
8493  //2. account for the costs incurred for this crop
8494  costs_ha = no_herb_app*priceHerb + no_fi_app*priceFi + grooming*priceG + hoeing*priceH + weeding*priceW + fert_trade*priceNt+ priceLM;
8495  costs = costs_ha * area;
8496 
8497  //3. determine the actual profit
8498  profit_ha = income_ha - costs_ha;
8499  profit = profit_ha * area;
8500 
8501  //4. determine what part of the expected yield you actually got from this crop - but do this by ha! here there are only crops that were grown this year - because we go through the list of fields
8502  yield_exp = findCropByName_almass (crop)->m_resp;
8503  if(yield_exp!=0){
8504  yield_ratio = yield_ha/yield_exp; // must be min. 0, can be > than 1.
8505  }
8506  else{
8507  m_exp_aggregated_yield -=1; //this crop wasn't expected to yield anything, so exclude it from the sum of expected yields
8508  }
8509 
8510  //add actual figures for this crop to the totals at a farm this year
8511  m_actual_income += income;
8512  m_actual_costs += costs;
8513  m_actual_profit += profit;
8514  m_actual_aggregated_yield += yield_ratio;
8515 
8516 
8517  //add expected figures for this crop to the totals at a farm this year
8518  //get the expected values! use the actual area - otherwise a comparison doesn't make sense!
8519 
8520  //to determine the expected income use last year's price
8521  double resp = findCropByName_almass (crop)->m_resp;
8522  double totalLoss = findCropByName_almass (crop)->m_totalLoss;
8523  double sellingPrice_lastyr = m_OurManager->pm_data->Get_sellingPrice_lastyr(tov_Undefined*tos_Foobar*m_farmType + tov_Undefined*m_soilType + crop); //always tov_Undefined because this funtion is called ONLY in almass crop mode!
8524 
8526  bool fodder = m_OurManager->pm_data->Get_fodder(index1);
8527  if (fodder) income_exp = subsidy;
8528  else income_exp = (sellingPrice_lastyr*resp*(1-totalLoss/100)+subsidy)*area;
8529 
8530  costs_exp = findCropByName_almass (crop)->m_costs_ha *area;
8531  profit_exp = income_exp - costs_exp;
8532 
8533  m_exp_income += income_exp; //add income expected from this crop to the total expected income
8534  m_exp_costs += costs_exp;
8535  m_exp_profit += profit_exp;
8536 
8537  //clean data in this field's struct: remove the data that you just accounted for
8538  pf->Clean_CropDataStorage(cropDataStorage_index);
8539  }
8540  else{//there was no accounting done, print the crop and year in which this happened
8541  #ifdef _DEBUG
8542  g_msg->Warn("OptimisingFarm::ActualProfit(): There was no accounting for tov: ", crop);
8543  //g_msg->Warn("Farm Number: ",GetFarmNumber());
8544  g_msg->Warn("Year Number: ",g_date->GetYearNumber());
8545  #endif
8546  }
8547 
8548  //send the info on this field's crop for the landscape total crop areas accounting
8549  //first find the right index in m_cropTotals:
8550  int index_for_croptotals=0;
8552  for(int k = 0; k<size; k++){
8554  if(crop_type == crop){
8555  index_for_croptotals = k;
8556  break;
8557  }
8558  }
8559  //then add the area of this field to the right element of m_cropTotals; change the units from sq meters to ha.
8560  m_OurManager->Add_to_cropTotals(index_for_croptotals, m_fields[i]->GetArea() * 0.0001); //yearly totals
8561  if(g_date->GetYearNumber()>20){ //do it for the first time in year 10 ->only then we account for new dec.- modes//for wildlife runs - only since year 20 when emaize appears, but here in year 20 we only account for year 19...that's why it has to be '>20'
8562  m_OurManager->Set_cropTotals_sum(index_for_croptotals, m_fields[i]->GetArea() * 0.0001);
8563  if(m_farmType == toof_Plant){
8564  m_OurManager->Set_cropTotals_plant_sum(index_for_croptotals, m_fields[i]->GetArea() * 0.0001);
8565  }
8566  else if(m_farmType == toof_Pig){
8567  m_OurManager->Set_cropTotals_pig_sum(index_for_croptotals, m_fields[i]->GetArea() * 0.0001);
8568  }
8569  else if(m_farmType == toof_Cattle){
8570  m_OurManager->Set_cropTotals_cattle_sum(index_for_croptotals, m_fields[i]->GetArea() * 0.0001);
8571  }
8572  else if(m_farmType == toof_Other){
8573  m_OurManager->Set_cropTotals_other_sum(index_for_croptotals, m_fields[i]->GetArea() * 0.0001);
8574  }
8575  }
8576 
8577  //then add also to farm type specific crop totals
8578 
8579 
8580 
8581  }//for: going through m_fields
8582 
8583 
8584  //print the expected and actual values
8585  ofstream ofile ("Economic_figures.txt", ios::app);
8586  ofile << "farm_no: " << m_almass_no << '\t' << "year_no " << g_date->GetYearNumber() << endl;
8587  ofile << "Expected: " << '\t' <<"Income " << m_exp_income << "\tCosts "<< m_exp_costs << "\tProfit " << m_exp_profit<< "\tAgg.yield " << m_exp_aggregated_yield;
8588  ofile << endl;
8589  ofile << "Actual: " << '\t' << "Income " << m_actual_income << "\tCosts "<< m_actual_costs << "\tProfit " << m_actual_profit<< "\tAgg.yield " << m_actual_aggregated_yield;
8590  ofile << endl <<endl;
8591  ofile.close();
8592 
8593 
8594  //save the economic figures for this year (or rather past - we account for things happen in the year before the current March 1st, xxxx)
8597  m_previous_costs.push_back(m_actual_costs);
8598  m_previous_aggregated_yields.push_back(m_actual_aggregated_yield);
8599 
8600 
8601  double min_need_satisfaction1 = cfg_Min_need_satisfaction1.value();
8602  double min_need_satisfaction2 = cfg_Min_need_satisfaction2.value();
8603  if(cfg_OnlyDeliberation.value()){ //then everybody deliberates (and: min cert is set to 0 when config var OnlyDeliberation is set to true)
8604  min_need_satisfaction1 = 100;
8605  min_need_satisfaction2 = 100;
8606  }
8607 
8609  if(m_exp_profit>0){
8610  if(m_actual_profit >= min_need_satisfaction1*m_exp_profit){
8612  }
8613  else{
8615  }
8616  }
8617  else if(m_exp_profit<0){
8618  if(m_actual_profit >= (2 - min_need_satisfaction1) * m_exp_profit){ //e.g. EP=-1000, AP=-1100 -> ok for MNS<=0.9.
8620  }
8621  else{
8623  }
8624  }
8625  else{ //exp profit = 0
8626  m_need_satisfaction_level = (m_actual_profit >0)? 1 : 0; //need to deal with this case - not very likely to happen
8627  }
8628  }
8629  else if (m_main_goal == tofg_yield){
8630  m_need_satisfaction_level = (m_actual_aggregated_yield >= m_exp_aggregated_yield * min_need_satisfaction2)? 1 : 0 ;
8631  }
8632 
8633  m_previous_satisfaction_levels.push_back(m_need_satisfaction_level); //add it to the list of satisfaction levels from last 5 years
8634  if(m_previous_satisfaction_levels.size()>5){ // it's been more than 5 years since the first accoutning, so...
8635  m_previous_satisfaction_levels.erase(m_previous_satisfaction_levels.begin()); //remove the first element: satisfaction level 6 years ago
8636  }
8637 
8638  //for energy maize impact on wildlife - January 2014
8639  if(cfg_MaizeEnergy.value()){
8640  double threshold = cfg_AnimalsThreshold.value();
8641  double sum = 0;
8642  for(int i=0; i<m_animals_numbers.size(); i++){
8643  sum += m_animals_numbers[i];
8644  }
8645  double avrg_animals_no = 0;
8646  if(m_animals_numbers.size()>0){
8647  avrg_animals_no = sum/m_animals_numbers.size();
8648  }
8649 
8650  if(emaize && animals_no < threshold * avrg_animals_no && m_animals_numbers.size()>2){ //three conditions: 1. you actually have grown energy maize
8651  // 2. the animal numbers have decreased below the acceptable level 3. you have data on animal numbers from min. 3 years
8652  //then set the rotation max. for energy maize to zero and force deliberation to stop growing energy maize
8653  CropOptimised *em = findCropByName_almass ("Maize");
8654  em->m_rotationMax = 0;
8655  force_deliberation = true;
8656  }
8657  m_animals_numbers.push_back(animals_no);
8658  if(m_animals_numbers.size() > 3){ //have data for more than 3 years now
8659  m_animals_numbers.erase(m_animals_numbers.begin()); //remove the oldest data - first element
8660  }
8661 
8662  //force optimisation when energy maize price changed by more than a given %
8665  if(abs(EMPrice_current - EMPrice_lastyr) > EMPrice_lastyr * cfg_PriceChangeThreshold.value()){
8666  force_deliberation = true;
8667  }
8668  }
8669  //
8670 
8671  //and restart the actual and expected values - for next year
8672  m_exp_income = 0;
8673  m_exp_costs = 0;
8674  m_exp_profit = 0;
8675  //exp agg yield is determined at the begininng of this function;
8676  m_actual_income = 0;
8677  m_actual_costs = 0;
8678  m_actual_profit = 0;
8679  m_actual_aggregated_yield = 0;
8680 
8681 }
vector< double > m_previous_satisfaction_levels
Vector of satisfaction levels in five previous years.
Definition: farm.h:2002
CfgBool cfg_OnlyDeliberation("ONLY_DELIBERATION", CFG_CUSTOM, true)
If set to yes, the only decision mode/startegy the farmers can use is deliberation (i...
double crop_parameter(int index, string par_name)
Reads in crop parameters that do NOT vary with any farm level parameters.
Definition: farm.cpp:7279
vector< LE * > m_fields
Definition: farm.h:839
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
vector< double > m_previous_incomes
Vector of incomes from previous years.
Definition: farm.h:1996
double Get_sellingPrice_lastyr(int i)
Definition: farm.h:566
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
void Set_crops_summary_BIs(int i, double BI)
Definition: farm.h:1713
TTypeOfFarmerGoal m_main_goal
Farmer&#39;s main goal (determined by a farmer&#39;s type) .
Definition: farm.h:1960
double m_exp_income
An expected farm&#39;s income at a farm in a given year.
Definition: farm.h:1981
double m_actual_profit
An actual profit realised at a farm in a given year.
Definition: farm.h:1975
double m_costs_ha
Costs of growing 1 ha of a crop. Include costs of labour and machine (constant), pesticides (herbicid...
Definition: farm.h:1542
int GetYearNumber(void)
Definition: calendar.h:68
void Set_crops_summary_BIs_fi(int i, double BIfi)
Definition: farm.h:1712
CfgBool cfg_MaizeEnergy("MAIZE_ENERGY", CFG_CUSTOM, false)
If set to true, the energy maize crop is included in the simulation.
TTypesOfVegetation
double m_actual_aggregated_yield
Actual aggregated yield at a farm in a given year.
Definition: farm.h:1988
double value(void)
Definition: configurator.h:107
double m_resp
Response - yield of a crop per ha [hkg/ha].
Definition: farm.h:1522
double m_actual_costs
Actual costs at a farm in a given year.
Definition: farm.h:1983
double m_grooming
Value of mechanical weed control for a crop - grooming [DKK/ha].
Definition: farm.h:1530
double m_totalLoss
Summary value of the yield loss due to the limited use of herbicides and fung- and insecticides [%]...
Definition: farm.h:1540
double m_exp_aggregated_yield
Expected aggregated yield at a farm in a given year.
Definition: farm.h:1991
double Get_sellingPrice(int i)
Definition: farm.h:564
CfgFloat cfg_PriceChangeThreshold("PRICE_CHANGE_THRESHOLD", CFG_CUSTOM, 0.2)
This parameter specifies the relative difference in energy maize price which causes a farmer to delib...
double m_nt
Amount of purchased (and applied) fertilizer per ha of a crop [kg N/ha].
Definition: farm.h:1515
bool Get_fodder(int i)
Definition: farm.h:559
CropActualValues Get_CropDataStorage(int index)
Definition: elements.h:592
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
bool value(void)
Definition: configurator.h:123
CfgFloat cfg_AnimalsThreshold("ANIMALS_THRESHOLD", CFG_CUSTOM, 0)
This parameter specifies the proportion of average number of animals on a farm for previous 3 years...
CfgFloat cfg_Min_need_satisfaction1("MIN_NEED_SATISFACTION_ONE", CFG_CUSTOM, 100)
A parameter setting the minimum satisfaction level for profit.
vector< double > m_previous_profits
Vector of profits from previous years.
Definition: farm.h:1994
double m_actual_income
An actual income at a farm in a given year.
Definition: farm.h:1979
double m_exp_costs
Expected costs at a farm in a given year.
Definition: farm.h:1985
TTypesOfVegetation m_cropType_almass
Type/name of a crop (ALMaSS crops).
Definition: farm.h:1503
double Get_beta2(int i)
Definition: farm.h:545
vector< double > m_previous_costs
Vector of costs from previous years.
Definition: farm.h:1998
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
double Get_biomass_factor(int i)
Definition: farm.h:576
double m_n
Total amount of fertilizer applied per ha of a crop [kg N/ha].
Definition: farm.h:1513
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void Set_cropTotals_plant_sum(int i, double crop_area)
Definition: farm.h:1715
int GetArea(void)
Returns the area of arable fields owned by that farm.
Definition: farm.cpp:1045
bool Get_taken(int index)
Definition: elements.h:567
class Calendar * g_date
Definition: calendar.cpp:38
void Set_cropTotals_other_sum(int i, double crop_area)
Definition: farm.h:1718
double m_optimalN
Optimal amount of fertilizer per ha of a crop supposing ferilizer price equals zero [kg N/ha]...
Definition: farm.h:1517
TTypesOfVegetation Get_cropTypes_almass(int i)
Definition: farm.h:579
void Set_crops_fertilizer(int i, double fert)
Definition: farm.h:1720
bool force_deliberation
If set to true, a farm must use deliberation as a decision strategy.
Definition: farm.h:2009
vector< double > m_animals_numbers
Vector for storing numbers of animals at a farm in previous years (3).
Definition: farm.h:2007
double m_hoeing
Value of mechanical weed control for a crop - hoeing [DKK/ha].
Definition: farm.h:1532
double GetDD(void)
Returnes day degrees for the period March 1st - November 1st. Used for determining yields of crops th...
Definition: farm.h:1692
CfgFloat cfg_Price_Nt("PRICE_NT", CFG_CUSTOM, 1.93)
Price of fertilizer. [DKK/kg].
void Set_cropTotals_sum(int i, double crop_area)
Definition: farm.h:1714
Definition: farm.h:228
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
double biomass_at_harvest
Definition: elements.h:477
double m_exp_profit
An expected farm&#39;s profit for a given year.
Definition: farm.h:1977
vector< double > m_previous_aggregated_yields
Vector of aggregated yields from previous years.
Definition: farm.h:2000
int Get_cropTypes_almass_size()
Definition: farm.h:580
void Add_to_cropTotals(int i, double value)
Definition: farm.h:1695
int animals_no
Holds the number of animals in a farm at a particular day in a year (depends on a species)...
Definition: farm.h:2011
double m_need_satisfaction_level
Farmer&#39;s actual satisfaction level.
Definition: farm.h:1967
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
int m_almass_no
Farm&#39;s almass number.
Definition: farm.h:2077
double m_weeding
Value of mechanical weed control for a crop - manual weeding [DKK/ha].
Definition: farm.h:1534
void Set_cropTotals_pig_sum(int i, double crop_area)
Definition: farm.h:1716
TTypesOfVegetation Get_crops_summary_BIs_tov(int i)
Definition: farm.h:1710
int Get_noCrops()
Definition: farm.h:585
void Set_crops_summary_BIs_herb(int i, double BIherb)
Definition: farm.h:1711
double Get_beta1(int i)
Definition: farm.h:543
Struct for storing actual data on crop type, area of a field it is grown in, biomass at harvest...
Definition: elements.h:474
CfgFloat cfg_Min_need_satisfaction2("MIN_NEED_SATISFACTION_TWO", CFG_CUSTOM, 100)
A parameter setting the minimum satisfaction level for yield.
void Set_cropTotals_cattle_sum(int i, double crop_area)
Definition: farm.h:1717
TTypesOfVegetation tov_type
Definition: elements.h:476
TTypesOfSoils m_soilType
Farm&#39;s soil type (sandy, clay, other).
Definition: farm.h:2069
void Set_crops_fertilizer_trade(int i, double fert_trade)
Definition: farm.h:1721
void Clean_CropDataStorage(int index)
Definition: elements.cpp:1751
void OptimisingFarm::assignFixed ( )
protected

Adds areas of fixed crops to the variable m_assigned. For each fixed crop it saves its area under variable CropOptimised::m_areaPercent.

Function assigning to fixed crops their initial areas as percentages of a farm's total area. It determines the share of a farm (%) reserved for fixed crops - excluded from the optimisation - and saves it in a variable m_assigned.

Definition at line 5798 of file farm.cpp.

References cfg_UseBedriftsmodelFarmAreas, m_area_scaling_factor, m_assigned, m_fixedCrops, m_totalArea, and CfgBool::value().

Referenced by OptimiseFarm().

5798  {
5799 
5803  m_assigned = 0;
5804  for (int i=0; i<(int)m_fixedCrops.size(); i++){//take only crops that are fixed
5805  double area = m_fixedCrops[i]->m_initialArea;
5806 
5807  if(!cfg_UseBedriftsmodelFarmAreas.value()){ //almass farm areas are in use, so scale the fixed crop area
5808  area *= m_area_scaling_factor;
5809  }
5810 
5811  double areaPercent= area/m_totalArea*100;
5812  m_fixedCrops[i]->m_areaPercent = areaPercent; //assign initial area in % for fixed crops
5813  m_assigned += areaPercent;//add areaPercent of a fixed crop to assigned
5814  }//now assigned is a number <0, 100> - excluded from the optimisation
5815 }
CfgBool cfg_UseBedriftsmodelFarmAreas("USE_BEDRIFTSMODEL_FARM_AREAS", CFG_CUSTOM, false)
If set to true, the farm areas from the original farm optimisation model are used in the optimisation...
vector< CropOptimised * > m_fixedCrops
Vector of pointers to fixed crops.
Definition: farm.h:2051
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 value(void)
Definition: configurator.h:123
double m_assigned
Variable holding a value of area already reserved for certain crops at a farm. [0-100%].
Definition: farm.h:2099
double m_area_scaling_factor
Factor used to scale areas of fixed crops and livestock numbers. Used to adjust these values to the f...
Definition: farm.h:2085
void OptimisingFarm::Check_if_area_100 ( )
protected

Checks if the sum of crops' areaPercent is 100%.

Determines the sum of all crops' CropOptimised::m_areaPercent. If the sum is not equal to 100, it issues a warning in a "Check_if_area_is_100%.txt" file.

Definition at line 7583 of file farm.cpp.

References m_almass_no, and m_crops.

Referenced by OptimiseFarm().

7583  {
7586  double area_to_check = 0.0;
7587  for(int i=0; i<(int)m_crops.size(); i++) {
7588  area_to_check += m_crops[i]->m_areaPercent;
7589  }
7590 
7591  if(area_to_check > 100.0001 || area_to_check < 99.999){ //issue a warning
7592  ofstream ofile("Check_if_area_is_100%.txt",ios::app);
7593  ofile << m_almass_no << '\t' << "Farms area is not equal to 100%. The sum of crops areaPercent is: " << area_to_check << endl;
7594  ofile.close();
7595  }
7596 }
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
int m_almass_no
Farm&#39;s almass number.
Definition: farm.h:2077
void OptimisingFarm::Check_SG_and_CGG ( )
protected

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

Definition at line 5400 of file farm.cpp.

References findCropByName_almass(), CropOptimised::m_areaPercent, CropOptimised::m_areaVariable, and CropOptimised::m_rotationMin.

Referenced by checkRestrictions().

5400  {
5401 
5402  CropOptimised *CGG1 = findCropByName_almass("CloverGrassGrazed1");
5403  CropOptimised *CGG2 = findCropByName_almass("CloverGrassGrazed2");
5404  CropOptimised *GS1 = findCropByName_almass("SeedGrass1");
5405  CropOptimised *GS2 = findCropByName_almass("SeedGrass2");
5406 
5407  double CGG1area = CGG1->m_areaPercent;
5408  double CGG2area = CGG2->m_areaPercent;
5409  double GS1area = GS1->m_areaPercent;
5410  double GS2area = GS2->m_areaPercent;
5411  if(CGG1area!= CGG2area){ //even if this is a cattle farm - where CGG are fodder - it won't have any effect here since the areas are zero or at min, so there won't be any change.
5412  double area_sum = CGG1area + CGG2area;
5413  double CGG1min = CGG1->m_rotationMin; double CGG2min = CGG2->m_rotationMin;
5414  CGG1->m_areaPercent = area_sum/2; CGG2->m_areaPercent = area_sum/2;
5415  CGG1->m_areaVariable = area_sum/2 - CGG1min; CGG2->m_areaVariable = area_sum/2 - CGG2min;
5416  }
5417  if(GS1area!=GS2area){
5418  double area_sum = GS1area + GS2area;
5419  double GS1min = GS1->m_rotationMin; double GS2min = GS2->m_rotationMin;
5420  GS1->m_areaPercent = area_sum/2; GS2->m_areaPercent = area_sum/2;
5421  GS1->m_areaVariable = area_sum/2 - GS1min; GS2->m_areaVariable = area_sum/2 - GS2min;
5422  }
5423 }
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
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
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
A class for storing all parameters and results of crop optimisation.
Definition: farm.h:1491
void OptimisingFarm::checkRestrictions ( )
protectedvirtual

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

Function checking if restrictions concerning crop rotations are fulfilled. If not, it corrects the crop areas in order to fulfill the restrictions. It starts with checking the restriction on winter crops rotation. Then it checks restriction on max winter crops' area. Finally, for cattle farms it checks the restriction on crop rotation.

The order of checking the first two restrictions does matter: in case the first restriction is not fullfilled, the first function always decreases winter wheat's area and only in a particular case increases area of winter rape. Thus, the total area of winter crops (->second restriction) most likely is decreased or, otherwise - unchanged by the function dealing with the first restriction. The second restriction, on max area of winter crops, does not allow to decrease area of winter rape; this, in certain cases, might result in suboptimal final result, but ensures that the first restriction is not violated. In the third restriction (only in the version for cattle farms) in the Bedriftsmodel crop mode, winter wheat is removed from the list of crops which is used to fill up the gap after decreasing some of the restriction crops.

In the ALMaSS crops mode the third restriction (for cattle farms) is implemented in a simplified version, i.e. it is limited to changing only areas of crops that form the restriction. Additionally, in the ALMaSS crops mode there is a function which ensures that areas of both CloverGrassGrazed1 and CloverGrassGrazed2 as well as SeedGrass1 and SeedGrass2 are equal (since '1' and '2' are the same crops, but with different management in the first and next year they are grown).

Reimplemented in OptimisingCattleFarm, and OptimisingPigFarm.

Definition at line 5933 of file farm.cpp.

References cfg_Areas_Based_on_Distribution, cfg_OptimiseBedriftsmodelCrops, Check_SG_and_CGG(), NonAnimalFarm::checkWinterCrops(), NonAnimalFarm::checkWinterRotation1(), and CfgBool::value().

Referenced by OptimisingPigFarm::checkRestrictions(), OptimisingCattleFarm::checkRestrictions(), and OptimiseFarm().

5933  {
5952  //1st restriction: winter rotation
5953  if(!cfg_Areas_Based_on_Distribution.value()){ //if this is true, skip this restriction
5955  }
5956 
5957  //2nd restriction: max share of winter crops area
5958  checkWinterCrops();
5959 
5960  if (!cfg_OptimiseBedriftsmodelCrops.value()){ //just for almass crop mode: make sure cgg1 and cgg2, sgg1 and sgg2 - have equal areas. added 26.03.13 -function since 110613
5961  Check_SG_and_CGG();
5962  }
5963 }
void Check_SG_and_CGG()
Modifies areas of SeedGrass1 and SeedGrass2, CloverGrassGrazed1 and CloverGrassGrazed2 to be even...
Definition: farm.cpp:5400
CfgBool cfg_Areas_Based_on_Distribution("AREAS_BASED_ON_DISTRIBUTION", CFG_CUSTOM, false)
If set to true, crops are assigned area based on their gross margin proportion in the total GM for al...
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
virtual void checkWinterRotation1()
Checks if the restriction on a winter rotation is fulfilled.
Definition: farm.h:2187
virtual void checkWinterCrops()
Checks if the restriction on a max. share of winter crops is fulfilled.
Definition: farm.h:2189
virtual void OptimisingFarm::checkWinterCrops ( )
inlineprotectedvirtual

Checks if the restriction on a max. share of winter crops is fulfilled.

Reimplemented in NonAnimalFarm, and AnimalFarm.

Definition at line 2189 of file farm.h.

2189 {};
virtual void OptimisingFarm::checkWinterRotation1 ( )
inlineprotectedvirtual

Checks if the restriction on a winter rotation is fulfilled.

Reimplemented in NonAnimalFarm, and AnimalFarm.

Definition at line 2187 of file farm.h.

2187 {};
void OptimisingFarm::ChooseDecisionMode ( )

Function determines which decision mode to use. The choice depends on the values of need satisfaction and uncertainty.

In the first year the function is called (8), it calls Find_neighbour_to_imitate. Every year it determines a farmer's certainty level. Depending on farmer's satisfaction and certainty levels it picks a decision mode: imitation if a farmer is uncertain, but satisfied; social comparison if a farmer is uncertain and not satisfied; repetition if a farmer is certain and satisifed; or deliberation if a farmer is certain, but not satisifed.

Definition at line 5001 of file farm.cpp.

References cfg_Min_certainty, cfg_OnlyDeliberation, Find_neighbour_to_imitate(), force_deliberation, g_date, Get_actual_aggregated_yield(), Get_actual_profit(), Get_rotational_crops_visible(), Calendar::GetYearNumber(), m_certainty_level, m_decision_mode_counters, m_main_goal, m_need_satisfaction_level, m_previous_satisfaction_levels, m_previously_imitated_neighbour, m_rotational_crops, m_rotational_crops_copy, m_totalFUdemand, m_totalFUdemandBefore, m_totalFUgrown, Make_almass_crops_vector(), Make_rotational_crops(), OptimiseFarm(), tofg_environment, tofg_profit, tofg_yield, tov_Undefined, CfgFloat::value(), and CfgBool::value().

Referenced by FarmManager::ChooseDecisionMode_for_farms().

5001  {
5006  //pick a farmer to copy (imitation startegy)/ or compare with and possibly copy (social comparison strategy) if this is the first time this function is called: year 8
5007  if(g_date->GetYearNumber() == 8){
5009  }
5010 
5011  //1. get the values of parameters
5012  double min_certainty = cfg_Min_certainty.value();
5013  if(cfg_OnlyDeliberation.value()) min_certainty = 0;
5014 
5015  //2. determine the satisfaction level: already done in the ActualProfit()
5016 
5017  //3. determine the certainty level
5018  double sum_of_sat_levels=0;
5019  for(int i=0; i<5; i++){
5020  sum_of_sat_levels += m_previous_satisfaction_levels[i];
5021  }
5022  m_certainty_level = sum_of_sat_levels/5.0; // i.e. take 5 years into account
5023 
5024  //4. choose the decision mode
5025  //'if' for forcing deliberation:
5026  if(force_deliberation){ //do the same as when deliberation is chosen normally
5028  m_totalFUdemand=m_totalFUdemandBefore; //restart the fodder demand to the original value
5029  m_totalFUgrown = 0; //restart
5031  Make_almass_crops_vector(); //makes m_crops_almass
5032  Make_rotational_crops(); //makes new m_rotational_crops - based on m_crops_almass
5034  force_deliberation=false;
5035  }
5036  else{
5037  if(m_certainty_level < min_certainty){
5038  if(m_need_satisfaction_level == 1 ){ //IMITATION (high sat., low cert.)
5040  //now imitate:
5042  m_rotational_crops_copy = m_rotational_crops; //m_rotational_crops_copy is used for finding a crop for a given field - in Match_crop_to_field function.
5043  } //imitation over
5044 
5045  else{ //SOCIAL COMPARISON - similar to imitation, but includes comparison (low sat., low cert.)
5047  //compare yourself to the neighbour: this depends on your goal
5048  bool imitate=false;
5049  if(m_main_goal == tofg_profit){
5050  if(m_actual_profit < m_previously_imitated_neighbour->Get_actual_profit()){
5051  imitate=true;
5052  }
5053  }
5054  else if (m_main_goal == tofg_yield){
5055  if(m_actual_aggregated_yield < m_previously_imitated_neighbour->Get_actual_aggregated_yield()){
5056  imitate=true;
5057  }
5058  }
5059  else if (m_main_goal == tofg_environment) {
5060  if(m_actual_aggregated_yield < m_previously_imitated_neighbour->Get_actual_aggregated_yield() && m_actual_profit < m_previously_imitated_neighbour->Get_actual_profit()){//compare both
5061  imitate=true;
5062  }
5063  }
5064 
5065  if(imitate){
5067  }
5068  //else: just continue
5069  m_rotational_crops_copy = m_rotational_crops; //this happens for both cases - imitate or not
5070  } //social comparison over
5071  } //high uncertainty
5072 
5073  else{ //low uncertainty (= high certainty)
5074  int value_for_satisfaction = 1; //1 for a simulation with not only deliberation
5075  if(cfg_OnlyDeliberation.value()) value_for_satisfaction = 10; //10 - then everybody deliberates
5076  if(m_need_satisfaction_level == value_for_satisfaction){ //REPETITION (high sat., high cert.)
5078  //continue with the same set of crops - see line after else!
5079  }
5080  else{ //DELIBERATION - i.e. optimise to make a new m_rotational_crops (low sat., high cert.)
5082  m_totalFUdemand=m_totalFUdemandBefore; //restart the fodder demand to the original value
5083  m_totalFUgrown = 0; //restart
5085  Make_almass_crops_vector(); //makes m_crops_almass
5086  Make_rotational_crops(); //makes new m_rotational_crops - based on m_crops_almass
5087  }
5088  m_rotational_crops_copy = m_rotational_crops; //do this for both cases
5089  }
5090  }
5091 }
vector< double > m_previous_satisfaction_levels
Vector of satisfaction levels in five previous years.
Definition: farm.h:2002
void Make_rotational_crops()
Creates a vector m_rotational_crops using the results of optimisation.
Definition: farm.cpp:7808
CfgBool cfg_OnlyDeliberation("ONLY_DELIBERATION", CFG_CUSTOM, true)
If set to yes, the only decision mode/startegy the farmers can use is deliberation (i...
CfgFloat cfg_Min_certainty("MIN_CERTAINTY", CFG_CUSTOM, 0)
A parameter setting the minimum certainty level.
double m_totalFUgrown
Fodder grown, i.e. obtained from growing fodder crops. [fodder units].
Definition: farm.h:2097
vector< int > m_decision_mode_counters
Vector with counters for each decision mode. 0 - imitation, 1 - social comparison, 2 - repeat, 3 - deliberation.
Definition: farm.h:1971
OptimisingFarm * Find_neighbour_to_imitate()
Picks randomly a farmer to imitate/compare with. It chooses among neighbouring farmers with similar f...
Definition: farm.cpp:4903
TTypeOfFarmerGoal m_main_goal
Farmer&#39;s main goal (determined by a farmer&#39;s type) .
Definition: farm.h:1960
int GetYearNumber(void)
Definition: calendar.h:68
double Get_actual_profit()
Definition: farm.h:1910
double value(void)
Definition: configurator.h:107
vector< AlmassCrop > m_rotational_crops_copy
A copy of m_rotational_crops used when matching crops to fields.
Definition: farm.h:2061
double m_totalFUdemandBefore
Farm&#39;s total demand for fodder. [fodder units]
Definition: farm.h:2091
void Make_almass_crops_vector()
Creates a vector storing crops with positive area. Used in ALMaSS crop mode.
Definition: farm.cpp:7792
bool value(void)
Definition: configurator.h:123
vector< AlmassCrop > m_rotational_crops
Vector of structs with almass type crops with positive areas in % (result of optimisation): includes ...
Definition: farm.h:2059
double m_certainty_level
Farmer&#39;s certainty level.
Definition: farm.h:1969
class Calendar * g_date
Definition: calendar.cpp:38
vector< AlmassCrop > Get_rotational_crops_visible()
Definition: farm.h:1909
double Get_actual_aggregated_yield()
Definition: farm.h:1911
bool force_deliberation
If set to true, a farm must use deliberation as a decision strategy.
Definition: farm.h:2009
void OptimiseFarm(int a_foobar)
Carries out the whole farm optimisation.
Definition: farm.cpp:5288
OptimisingFarm * m_previously_imitated_neighbour
The neighbouring farmer whose crops might be copied in imitation and social comparison decision modes...
Definition: farm.h:2004
double m_need_satisfaction_level
Farmer&#39;s actual satisfaction level.
Definition: farm.h:1967
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 OptimisingFarm::createCropsLists ( int  a_foobar)
protectedvirtual

Creates lists of crops.

Reimplemented in AnimalFarm.

Definition at line 5093 of file farm.cpp.

References createVariableCrops().

Referenced by Init().

5093  {
5094  createVariableCrops(a_foobar);
5095 }
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 OptimisingFarm::createVariableCrops ( int  a_foobar)
protected

Creates a list of pointers to all variable crops included in the optimisation and a list of pointers to fixed crops.

Creates two vectors: vector of pointers to fixed crops and a vector of structs containing variable crops.

Definition at line 5102 of file farm.cpp.

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

Referenced by createCropsLists(), and AnimalFarm::createCropsLists().

5102  {
5105  int n = (int)m_crops.size();
5106  for (int i=0; i < n; ++i) {
5107  int crop_type=(cfg_OptimiseBedriftsmodelCrops.value())? (int)m_crops[i]->m_cropType : (int)m_crops[i]->m_cropType_almass;
5108  int index=a_foobar*m_farmType + crop_type;
5109  if (m_OurManager->pm_data->Get_fixed(index)){ //if the crop is fixed, attach it to the list fixedCrops
5110  m_fixedCrops.push_back(m_crops[i]);
5111  }
5112  else{
5113  CropSort cs = {0., m_crops[i]}; //an object with a key and a pointer to crop
5114  m_variableCrops.push_back(cs);
5115  }
5116  }
5117 }
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
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
vector< CropSort > m_variableCrops
Vector of structs containing pointers to crops which are not fixed.
Definition: farm.h:2042
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
bool Get_fixed(int i)
Definition: farm.h:554
double OptimisingFarm::crop_parameter ( int  index,
string  par_name 
)
protected

Reads in crop parameters that do NOT vary with any farm level parameters.

Definition at line 7279 of file farm.cpp.

References DataForOptimisation::Get_cropParameter(), Farm::m_OurManager, FarmManager::pm_data, top_Foobar, and FarmManager::TranslateParametersCodes().

Referenced by ActualProfit(), findBIs(), findGrossMargin(), findMWeedControl(), and findYieldLoss().

7279  {
7280  double par_value;
7282  return par_value;
7283 }
TTypesOfParameters TranslateParametersCodes(string &str)
Definition: farm.cpp:3910
double Get_cropParameter(int i)
Definition: farm.h:538
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void OptimisingFarm::decreaseCrops ( vector< CropSort cropsToDecrease,
double &  howMuchToDecrease 
)
protectedvirtual

Decreases area of a crops by a specified number.

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.

Reimplemented in AnimalFarm.

Definition at line 7435 of file farm.cpp.

Referenced by OptimisingPigFarm::check_WRape_WBarley(), OptimisingCattleFarm::checkCattleRotation(), OptimisingCattleFarm::checkCattleRotation_almass(), AnimalFarm::checkWinterCrops(), NonAnimalFarm::checkWinterCrops(), AnimalFarm::checkWinterRotation1(), NonAnimalFarm::checkWinterRotation1(), and AnimalFarm::determineMinFodder().

7435  {
7438  for(int j=(int)cropsToDecrease.size()-1; howMuchToDecrease>0 && j>=0; j--){ //start with the worst
7439  double areaCrop = cropsToDecrease[j].crop->m_areaPercent;
7440  double rotMinCrop = cropsToDecrease[j].crop->m_rotationMin;
7441  if(areaCrop - howMuchToDecrease >= rotMinCrop){
7442  areaCrop -= howMuchToDecrease;
7443  howMuchToDecrease = 0; //finito
7444  }
7445  else{
7446  howMuchToDecrease -= areaCrop - rotMinCrop;
7447  areaCrop = rotMinCrop;
7448  }
7449  cropsToDecrease[j].crop->m_areaPercent = areaCrop;
7450  cropsToDecrease[j].crop->m_areaVariable = areaCrop - rotMinCrop;
7451  }
7452 }
void OptimisingFarm::determineAreas ( int  a_foobar)
protectedvirtual

Determines areas of variable crops.

Function determining areas of all not fixed, non-fodder crops at a farm as percentages of a farm's total area. It goes through a list of variable crops sorted from the highest to the lowest Gross Margin (i.e., most to least profitable) and assigns a maximal allowed area for each non-fodder crop - until the remaining farm's area is equal to or lower than a maximal allowed area for a given crop. In such case it assigns the remaining area to this crop. All remaining crops are assigned areas equal to zero (above their minimal required areas).

If the cfg_Areas_Based_on_Distribution variable is set to true, the area is assigned on the basis og each crop's GM proportion in the summary GM based on crops with a positive GM.

Reimplemented in AnimalFarm.

Definition at line 5827 of file farm.cpp.

References cfg_Areas_Based_on_Distribution, cfg_OptimiseBedriftsmodelCrops, DataForOptimisation::Get_fodder(), m_assigned, m_farmType, m_grownVariableCrops, Farm::m_OurManager, m_variableCrops, FarmManager::pm_data, and CfgBool::value().

Referenced by AnimalFarm::determineAreas(), and OptimiseFarm().

5827  {
5836  m_grownVariableCrops.clear();
5837 
5838  for(int i=0; i<(int)m_variableCrops.size(); i++){
5839  double areaPercent=0;
5840  double minArea=m_variableCrops[i].crop->m_rotationMin;
5841 
5842  int index1 = (cfg_OptimiseBedriftsmodelCrops.value())? a_foobar*m_farmType + m_variableCrops[i].crop->m_cropType : a_foobar*m_farmType + m_variableCrops[i].crop->m_cropType_almass;
5843 
5844  //next two lines necessary for animal farms' function version
5845  bool fodder = m_OurManager->pm_data->Get_fodder(index1);
5846  if (!fodder){ //this should be checked for animal farms, for other and plant - will always be false
5847  if (m_assigned<100){ //check if there is any area left at a farm
5848  double rotationMax = m_variableCrops[i].crop->m_rotationMax; //same as in else
5849 
5850  if(cfg_Areas_Based_on_Distribution.value()){ //added 170713
5851 
5852  double GMsum = 0;
5853  for(int k=i; k<(int)m_variableCrops.size(); k++){ //do it for each crop (calculate prob) to avoid getting area without any crop. Start with the current crop (k=i), i.e. exclude the crops that are already assigned area.
5854  if(m_variableCrops[k].crop->m_GM > 0 && m_variableCrops[k].crop->m_rotationMax>0){ //make sure you dont include crops that have rot max set to zero! then the area won't sum up to 100%
5855  GMsum += pow (m_variableCrops[k].crop->m_GM, 1);
5856  }
5857  }
5858  double base_prob = 0;
5859  if(m_variableCrops[i].crop->m_GM > 0){
5860  base_prob = pow(m_variableCrops[i].crop->m_GM, 1)/GMsum;
5861  }
5862  else base_prob = 0;
5863 
5864  //draw a random number
5865  std::random_device rd;
5866  distribution_type3 dis(-1.0, 1.0);
5867  std::mt19937 engine(rd());
5868  double random_number = dis(engine);
5869  if(base_prob == 1) random_number = 0; // this is the last crop on the list - don't manipulate the area
5870  double area_1 = base_prob * (1 + 0.2 * random_number) * (100 - m_assigned); //take only a percent of the remaining area!
5871  areaPercent = ( area_1 <= rotationMax)? area_1 : rotationMax;
5872  if (areaPercent > 100 - m_assigned) areaPercent = 100 - m_assigned; //added 280813
5873 
5874  }
5875  else{ //standard area assignment
5876  areaPercent = (rotationMax-minArea <= 100-m_assigned)? rotationMax : (100 - m_assigned+minArea); //check if the remaining area (100-assigned) is enough to assign max allowed area for a crop (max-min, which was already assigned, if not - assign the remaining area+min area
5877  }
5878 
5879  m_assigned += areaPercent - minArea; //add the assigned area (final area percent minus minimum; minimum was assigned before) to the total assigned area
5880  if(areaPercent>minArea){m_grownVariableCrops.push_back(m_variableCrops[i].crop);} //this might not be used for other than animal farms...but maybe - it would be nice to have such a list anyway
5881 
5882  }//m_assigned < 100
5883 
5884  else {areaPercent = minArea;}
5885 
5886  m_variableCrops[i].crop->m_areaPercent = areaPercent;
5887  double areaVar=areaPercent-minArea;
5888  m_variableCrops[i].crop->m_areaVariable = areaVar; //save the value of the area that can be changed! For farms other than animal this maybe could be used just in restrictions functions...
5889  }
5890  else{ //it is a fodder crop, so just save its min area under areaPercent
5891  m_variableCrops[i].crop->m_areaPercent = minArea;
5892  }
5893  }
5894 }
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
vector< CropSort > m_variableCrops
Vector of structs containing pointers to crops which are not fixed.
Definition: farm.h:2042
CfgBool cfg_Areas_Based_on_Distribution("AREAS_BASED_ON_DISTRIBUTION", CFG_CUSTOM, false)
If set to true, crops are assigned area based on their gross margin proportion in the total GM for al...
bool Get_fodder(int i)
Definition: farm.h:559
boost::random::uniform_real_distribution< double > distribution_type3
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
double m_assigned
Variable holding a value of area already reserved for certain crops at a farm. [0-100%].
Definition: farm.h:2099
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void OptimisingFarm::determineAreas_ha ( vector< CropOptimised * >  crops)
protected

Determines areas of crops in ha.

Determines areas of crops in ha: CropOptimised::m_area_ha = CropOptimised::m_areaPercent/100 * m_totalArea.

Definition at line 7490 of file farm.cpp.

References m_totalArea.

Referenced by OptimiseFarm().

7490  { //area in ha
7493  for(int i=0; i<(int)allCrops.size(); i++){
7494  double areaPercent = allCrops[i]->m_areaPercent;
7495  double area_ha = (areaPercent==0) ? 0 : (areaPercent/100 * m_totalArea);
7496  allCrops[i]->m_area_ha = area_ha;
7497  }
7498 }
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
void OptimisingFarm::FarmLevelCalculation ( )
protected

Calls functions determining farm level values before the initial optimisation.

Calls functions determining farm level values before the initial optimisation (i.e.: amount of animal fertilizer (total - m_totalNanim, and per ha - m_Nanim), farm's area - m_totalArea, and fodder demand - m_totalFUdemand).

Definition at line 5136 of file farm.cpp.

References cfg_Areas_Based_on_Distribution, NonAnimalFarm::findFodderDemand(), findNanim(), findTotalArea(), findTotalNanim(), preventCashCrops(), and CfgBool::value().

Referenced by Init().

5136  {
5137 
5138  findTotalArea();
5139  findTotalNanim();
5140  findNanim();
5141  findFodderDemand(); //this function cannot be called in the constructor!
5143  preventCashCrops();
5144  }
5145 }
virtual void preventCashCrops()
Prevents small cattle farms from growing cash crops and maize silage.
Definition: farm.h:2150
CfgBool cfg_Areas_Based_on_Distribution("AREAS_BASED_ON_DISTRIBUTION", CFG_CUSTOM, false)
If set to true, crops are assigned area based on their gross margin proportion in the total GM for al...
virtual void findFodderDemand()
Determines farm&#39;s total demand for fodder (m_totalFUdemand).
Definition: farm.cpp:5193
bool value(void)
Definition: configurator.h:123
void findNanim()
Determines amount of animal fertilizer per ha (m_Nanim) at a farm.
Definition: farm.cpp:5188
void findTotalNanim()
Determines total animal fertilizer (m_totalNanim) available at a farm.
Definition: farm.cpp:5166
void findTotalArea()
Determines m_totalArea of a farm.
Definition: farm.cpp:5147
OptimisingFarm * OptimisingFarm::Find_neighbour_to_imitate ( )

Picks randomly a farmer to imitate/compare with. It chooses among neighbouring farmers with similar farms.

Chooses a farmer for imitation and social comparison decision making modes. For business (>10 ha) farms it chooses a farmer with the same farm type and soil type. For private (<10 ha) farms it chooses a farmer with the same soil type.

Definition at line 4903 of file farm.cpp.

References g_msg, Get_farmSize(), Get_soilType(), m_almass_no, m_farmSize, m_farmType, m_neighbours, m_previously_imitated_neighbour, m_rotational_crops_visible, m_soilType, tofs_Private, tos_Clay, MapErrorMsg::Warn(), and WARN_BUG.

Referenced by ChooseDecisionMode().

4903  {
4904 
4908  int no_farmers = (int)m_neighbours.size();
4909 
4910  if(no_farmers!=0){ //if the list is empty - no neighbours
4911  bool ok=false;
4912  vector<OptimisingFarm*>neighbours_copy = m_neighbours;
4913  for(int a=0; ok==false && neighbours_copy.size()>0; a++){
4914  srand ((unsigned)time(NULL)); //warning?
4915  int neighbour = rand() % (no_farmers-a); //returns a random int number from the range: <0, no_farmers-1-a> - need to subtract those remved from the list-there is 'a' removed neighbours
4916  m_previously_imitated_neighbour = neighbours_copy[neighbour];
4917  if(m_farmSize==tofs_Private){ //then look just at the soil type
4918  if(m_soilType!=tos_Clay){ //private with sand or other soil
4921  ok=true; //found somebody to imitate
4922  }
4923  else{
4924  neighbours_copy.erase(neighbours_copy.begin() + neighbour);
4925  }
4926  }
4927  else{ //private with clay
4930  ok=true; //found somebody to imitate
4931  }
4932  else{
4933  neighbours_copy.erase(neighbours_copy.begin() + neighbour);
4934  }
4935  }
4936  }
4937  else if(m_soilType!=tos_Clay){ //business farm with sand or other soil
4940  ok=true; //found somebody to imitate
4941  }
4942  else{
4943  neighbours_copy.erase(neighbours_copy.begin() + neighbour);
4944  }
4945  }
4946  else{ //business farm with clay soil
4949  ok=true; //found somebody to imitate
4950  }
4951  else{
4952  neighbours_copy.erase(neighbours_copy.begin() + neighbour);
4953  }
4954  }
4955 
4956  }
4957  if(ok==true){ //found a neighbouring farmer to imitate
4959  }
4960  else{ //try to find a neighbour with at least the same farm type
4961  neighbours_copy = m_neighbours; //first restart the neighbours copy!
4962  for(int a=0; ok==false && neighbours_copy.size()>0; a++){ //040713 - do not accept a farm with empty rot crops
4963  srand ((unsigned)time(NULL)); //warning?
4964  int neighbour = rand() % (no_farmers-a); //returns a random int number from the range: <0, no_farmers-1-a> - need to subtract those remved from the list-there is 'a' removed neighbours
4965  m_previously_imitated_neighbour = neighbours_copy[neighbour];
4967  ok=true;
4968  }
4969  else{
4970  neighbours_copy.erase(neighbours_copy.begin() + neighbour);
4971  }
4972  }
4973  if(ok==true){
4975  }
4976  else{
4977  m_previously_imitated_neighbour = this; //no neighbour that fits - copy yourself
4978  #ifdef _DEBUG
4979  char errornum[ 20 ];
4980  sprintf( errornum, "%d", m_almass_no );
4981  g_msg->Warn( WARN_BUG, "No farm with a matching farm type to imitate: ", errornum );
4982  #endif
4984  }
4985  }
4986  }
4987 
4988 
4989  else{ //no neighboring farmers //just set yourself
4992  }
4993 }
TTypesOfFarmSize Get_farmSize(void)
Definition: farm.h:1893
Definition: farm.h:235
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
TTypesOfFarmSize m_farmSize
Scale of the farm - business (size above 10 ha) or private (size below 10 ha).
Definition: farm.h:2071
TTypesOfSoils Get_soilType(void)
Definition: farm.h:1892
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
vector< OptimisingFarm * > m_neighbours
Vector of pointers to the farms considered neighbours (fulfilling the neighbourship condition) of a g...
Definition: farm.h:1965
OptimisingFarm * m_previously_imitated_neighbour
The neighbouring farmer whose crops might be copied in imitation and social comparison decision modes...
Definition: farm.h:2004
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
vector< AlmassCrop > m_rotational_crops_visible
Stores a copy of m_rotational_crops from a previous year and is accessible to farmers who want to cop...
Definition: farm.h:2063
TTypesOfSoils m_soilType
Farm&#39;s soil type (sandy, clay, other).
Definition: farm.h:2069
void OptimisingFarm::findBIs ( CropOptimised a_crop,
double  benefit 
)
protected

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.

Function determining the optimal 'behandling indeks' (treatment frequency index) for herbicides (CropOptimised::m_BIHerb), fungicides and insecticides (CropOptimised::m_BIFi), and a summary BI per ha (CropOptimised::m_BIHerb). For each crop there is a specified amount of herbicides, fungicides and insecticides for which the yield loss is equal to zero. The farmer can choose between this value and not using pesticide at all (since yield and profit are linear functions of pesticide usage). However, when a given crop is actually grown, farmer might not apply pesticide if there is no pest problem (even though he originally planned to apply pesticides), or might apply more than he planned to if there is an excess pest problem. Therefore, there is a variation in the actual pesticide usage between farmers.

Definition at line 5570 of file farm.cpp.

References cfg_Env_pest_multiplier, cfg_OptimiseBedriftsmodelCrops, crop_parameter(), CropOptimised::m_BI, CropOptimised::m_BIFi, CropOptimised::m_BIHerb, CropOptimised::m_cropType, CropOptimised::m_cropType_almass, m_main_goal, CropOptimised::m_resp, tofg_environment, tofg_profit, tofg_yield, CfgFloat::value(), and CfgBool::value().

Referenced by optimizeCrops().

5570  {
5576  int index = (cfg_OptimiseBedriftsmodelCrops.value())? (int)a_crop->m_cropType : (int)a_crop->m_cropType_almass;
5577 
5578  double alfaFi = crop_parameter(index, "AlfaFi");
5579  double alfaHerb = crop_parameter(index, "AlfaHerb");
5580  double alfaG = crop_parameter(index, "AlfaG");
5581  double alfaH = crop_parameter(index, "AlfaH");
5582  double alfaW = crop_parameter(index, "AlfaW");
5583  double betaFi = crop_parameter(index, "BetaFi");
5584  double betaHerb = crop_parameter(index, "BetaHerb");
5585 
5586  double priceFi = crop_parameter(index, "PriceFi");
5587  double priceHerb = crop_parameter(index, "PriceHerb");
5588  double priceG = crop_parameter(index, "PriceG");
5589  double priceH = crop_parameter(index, "PriceH");
5590  double priceW = crop_parameter(index, "PriceW");
5591 
5592  double resp1=a_crop->m_resp;
5593 
5594  if(alfaHerb>0){//make sure it is not zero!it is for Fodder beet
5595  double BIHerbMax = betaHerb/alfaHerb;
5596  double gainHerb = 0;
5597  double BIHerb = 0;
5598 
5599  if(m_main_goal == tofg_profit){
5600  gainHerb = benefit*resp1*alfaHerb/100 + priceG*alfaG + priceH*alfaH + priceW*alfaW;
5601  BIHerb = (gainHerb>priceHerb)? BIHerbMax : 0;
5602  a_crop->m_BIHerb = BIHerb;
5603  }
5604  else if (m_main_goal == tofg_yield){
5605  a_crop->m_BIHerb = BIHerbMax; //12.12.12
5606  }
5607  else if (m_main_goal == tofg_environment){
5608  gainHerb = benefit*resp1*alfaHerb/100 + priceG*alfaG + priceH*alfaH + priceW*alfaW;
5609  BIHerb = (gainHerb> (priceHerb * cfg_Env_pest_multiplier.value()))? BIHerbMax : 0;
5610  a_crop->m_BIHerb = BIHerb;
5611  }
5612  }
5613  else a_crop->m_BIHerb = 0; //BI for fodder beet in the original model (Bedriftsmodel)
5614 
5615  if(alfaFi>0){
5616  double BIFiMax = betaFi/alfaFi;
5617  double gainFi = 0;
5618  double BIFi = 0;
5619  if(m_main_goal == tofg_profit){
5620  gainFi = benefit*resp1*alfaFi/100;
5621  BIFi = (gainFi > priceFi) ? BIFiMax : 0;
5622  a_crop->m_BIFi = BIFi;
5623  }
5624  else if (m_main_goal == tofg_yield){
5625  a_crop->m_BIFi = BIFiMax;
5626  }
5627  else if (m_main_goal == tofg_environment){
5628  gainFi = benefit*resp1*alfaFi/100;
5629  if (gainFi > (priceFi * cfg_Env_pest_multiplier.value())){
5630  BIFi = BIFiMax;
5631  }
5632  else{
5633  BIFi = 0;
5634  }
5635  a_crop->m_BIFi = BIFi;
5636  }
5637  }
5638  else a_crop->m_BIFi = 0;
5639 
5640  double BIFi = a_crop->m_BIFi;
5641  double BIHerb = a_crop->m_BIHerb;
5642  double BI = BIFi+BIHerb;
5643  a_crop->m_BI = BI;
5644 }
double crop_parameter(int index, string par_name)
Reads in crop parameters that do NOT vary with any farm level parameters.
Definition: farm.cpp:7279
TTypeOfFarmerGoal m_main_goal
Farmer&#39;s main goal (determined by a farmer&#39;s type) .
Definition: farm.h:1960
double m_BIFi
Value of BI for fung- and insecticides [BI/ha].
Definition: farm.h:1526
double value(void)
Definition: configurator.h:107
double m_resp
Response - yield of a crop per ha [hkg/ha].
Definition: farm.h:1522
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
TTypesOfVegetation m_cropType_almass
Type/name of a crop (ALMaSS crops).
Definition: farm.h:1503
CfgFloat cfg_Env_pest_multiplier("ENV_PEST_MULTIPLIER", CFG_CUSTOM, 1.25)
A parameter of the environmentalist farmer type: increases the chance that environmentalist does not ...
double m_BI
Summary value of BI for herbicides and fung- and insecticides [BI/ha].
Definition: farm.h:1528
double m_BIHerb
Value of BI for herbicides [BI/ha].
Definition: farm.h:1524
TTypesOfCrops m_cropType
Type/name of a crop (original farm optimization model crop types).
Definition: farm.h:1501
CropOptimised * OptimisingFarm::findCropByName ( string  crop_name)
protected

Returns a pointer to a crop whose name is specified as the argument (bedriftsmodel, i.e. original farm optimization model, crops mode).

Definition at line 7285 of file farm.cpp.

References g_msg, m_crops, Farm::m_OurManager, FarmManager::TranslateCropsCodes(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by OptimisingCattleFarm::checkCattleRotation(), AnimalFarm::checkWinterCrops(), NonAnimalFarm::checkWinterCrops(), AnimalFarm::checkWinterRotation1(), NonAnimalFarm::checkWinterRotation1(), fixBI(), and Make_rotations().

7285  {
7286  for(int c=0; c< (int)m_crops.size(); c++){
7287  if(m_crops[c]->m_cropType==m_OurManager->TranslateCropsCodes(crop_name)) return m_crops[c];
7288  }
7289  g_msg->Warn( WARN_FILE, "OptimisingFarm::findCropByName():" "Unknown Code Identificator", crop_name.c_str() );
7290  exit(0);
7291 }
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
TTypesOfCrops TranslateCropsCodes(string &str)
Definition: farm.cpp:3861
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
CropOptimised * OptimisingFarm::findCropByName_almass ( string  crop_name)
protected

Returns a pointer to almass crop whose name is specified as the argument (ALMaSS crops mode).

Definition at line 7293 of file farm.cpp.

References g_msg, m_crops, Farm::m_OurManager, FarmManager::TranslateCropCodes(), MapErrorMsg::Warn(), and WARN_FILE.

Referenced by ActualProfit(), Check_SG_and_CGG(), OptimisingPigFarm::check_WRape_WBarley(), OptimisingCattleFarm::checkCattleRotation_almass(), AnimalFarm::checkWinterCrops(), NonAnimalFarm::checkWinterCrops(), AnimalFarm::checkWinterRotation1(), NonAnimalFarm::checkWinterRotation1(), fixBI(), Make_rotations(), OptimisingCattleFarm::preventCashCrops(), Spraying_fungins(), and Spraying_herbicides().

7293  {
7294  for(int c=0; c< (int)m_crops.size(); c++){
7295  if(m_crops[c]->m_cropType_almass == m_OurManager->TranslateCropCodes(crop_name)) return m_crops[c];
7296  }
7297  g_msg->Warn( WARN_FILE, "OptimisingFarm::findCropByName_almass():" "Unknown Code Identificator", crop_name.c_str() );
7298  exit(0);
7299 }
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
TTypesOfVegetation TranslateCropCodes(std::string &str)
Definition: farm.cpp:1435
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
CropOptimised * OptimisingFarm::findCropByName_almass ( TTypesOfVegetation  a_tov_type)
protected

Returns a pointer to almass crop whose tov type is specified as the argument.

Definition at line 7301 of file farm.cpp.

References g_msg, m_crops, MapErrorMsg::Warn(), and WARN_BUG.

7301  {
7302  for(int c=0; c< (int)m_crops.size(); c++){
7303  if(m_crops[c]->m_cropType_almass == a_tov_type) return m_crops[c];
7304  }
7305  char error_num[ 20 ];
7306  sprintf( error_num, "%d", a_tov_type);
7307  g_msg->Warn( WARN_BUG, "OptimisingFarm::findCropByName_almass():" "Unknown Code Identificator", error_num );
7308  exit(0);
7309 }
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
void OptimisingFarm::findFertilizer ( CropOptimised a_crop,
int  a_foobar,
double  benefit 
)
protected

Determines the optimal amounts of: total fertilizer (CropOptimised::m_n) and purchased fertilizer (CropOptimised::m_nt) for a given crop at a farm.

Function determining the optimal amounts of: total fertilizer (CropOptimised::m_n) and purchased fertilizer (CropOptimised::m_nt) per ha of a crop at a given farm. [kg/ha]

Definition at line 5429 of file farm.cpp.

References cfg_Env_fert_multiplier, cfg_OptimiseBedriftsmodelCrops, cfg_Price_Nt, DataForOptimisation::Get_beta1(), DataForOptimisation::Get_beta2(), DataForOptimisation::Get_Nnorm(), CropOptimised::m_cropType, CropOptimised::m_cropType_almass, m_main_goal, CropOptimised::m_n, m_Nanim, CropOptimised::m_nt, CropOptimised::m_optimalN, Farm::m_OurManager, m_soilType, FarmManager::pm_data, tofg_environment, tofg_profit, tofg_yield, CfgFloat::value(), and CfgBool::value().

Referenced by optimizeCrops().

5429  {
5430 
5434  int index = (cfg_OptimiseBedriftsmodelCrops.value())? a_foobar * m_soilType + a_crop->m_cropType : a_foobar * m_soilType + a_crop->m_cropType_almass;
5435 
5436  double beta1=m_OurManager->pm_data->Get_beta1(index);
5437  double beta2=m_OurManager->pm_data->Get_beta2(index);
5438  double nNorm=m_OurManager->pm_data->Get_Nnorm(index);
5439  double priceNt=cfg_Price_Nt.value();
5440 
5441  if(!beta2==0){
5442  a_crop->m_optimalN = -(beta1/beta2)*0.5; //01.03.12 save the optimal free fertilizer
5443  }
5444  else{ //if beta2 is =0, beta1 is also =0 -> so optimum is at 0.
5445  a_crop->m_optimalN = 0;
5446  }
5447 
5448  if(m_main_goal == tofg_profit){
5449 
5450  if(!beta2==0){ //beta2 is not 0
5451  double n1=-(beta1/beta2)*0.5; //optimal fertilizer supposing it's for free
5452  if(m_Nanim >= n1){ //there is more than you need, so check the norm:
5453  if (n1<nNorm){
5454  a_crop->m_n = n1; //apply optimal amount
5455  }
5456  else {
5457  a_crop->m_n = nNorm; //apply max allowed amount
5458  }
5459  a_crop->m_nt = 0; //don't buy fertilizer
5460  }
5461  else { //the optimal amount is larger than Nanim
5462  double nt1= 0.5*(priceNt/(benefit*beta2) - beta1/beta2) - m_Nanim; //optimal fertilizer Nt
5463  if (nt1>0){
5464  double n2=nt1+m_Nanim; //optimal total N
5465  if (n2<nNorm){
5466  a_crop->m_nt = nt1;
5467  a_crop->m_n = n2;
5468  }
5469  else {
5470  double p=nNorm-m_Nanim;
5471  if(p>=0){a_crop->m_nt = p;} //buy the diff between what you have (Nanim) and what is the max allowed
5472  else{a_crop->m_nt = 0;}// your Nanim is higher than the norm!
5473  a_crop->m_n = nNorm; //total amount is the max allowed, Nanim+(nNorm-Nanim)=nNorm
5474  }
5475  }
5476  else { //it doesn't pay off to buy fertilizer, so just use Nanim
5477  if(m_Nanim<=nNorm){a_crop->m_n = m_Nanim;} //apply fertilizer
5478  else {a_crop->m_n = nNorm;}
5479  a_crop->m_nt = 0;
5480  }
5481  }
5482  }
5483  else{ //beta2=0, so don't apply fertilizer, but in this model - apply Nanim if there is any
5484  if(m_Nanim<=nNorm){a_crop->m_n = m_Nanim;} //apply fertilizer
5485  else {a_crop->m_n = nNorm;}
5486  a_crop->m_nt = 0;
5487  }
5488 
5489  }
5490 
5491  else if (m_main_goal == tofg_yield) { //modified profit optimization algorithm
5492  if(!beta2==0){ //beta2 is not 0
5493  double n1=-(beta1/beta2)*0.5; //optimal fertilizer supposing it's for free
5494  if(m_Nanim >= n1){ //there is more than you need, so check the norm:
5495  if (n1<nNorm){
5496  a_crop->m_n = n1; //apply optimal amount
5497  }
5498  else {
5499  a_crop->m_n = nNorm; //apply max allowed amount
5500  }
5501  a_crop->m_nt = 0; //don't buy fertilizer
5502  }
5503  else { //the optimal amount is larger than Nanim
5504  if(n1>=nNorm){
5505  if(m_Nanim > nNorm){a_crop->m_nt = 0;}
5506  else{a_crop->m_nt = nNorm - m_Nanim;}//buy the diff between what you have (Nanim) and what is the max allowed
5507  a_crop->m_n = nNorm; //total amount is the max allowed
5508  }
5509  else{
5510  a_crop->m_nt = n1 - m_Nanim;
5511  a_crop->m_n = n1;
5512  }
5513  }
5514  }
5515  else{ //beta2=0, so don't apply fertilizer, but in this model - apply Nanim if there is any
5516  if(m_Nanim<=nNorm){a_crop->m_n = m_Nanim;} //apply fertilizer
5517  else {a_crop->m_n = nNorm;}
5518  a_crop->m_nt = 0;
5519  }
5520 
5521  }
5522  else if (m_main_goal == tofg_environment) { //apply less than a norm: the code copied from yield max - the only change is in calculation of n1 - mulitplied by 0.8.
5523  if(!beta2==0){ //beta2 is not 0
5524  double n1=-(beta1/beta2)*0.5 * cfg_Env_fert_multiplier.value(); //optimal fertilizer supposing it's for free; multiplier - to make this type use less fertilizer
5525  if(m_Nanim >= n1){ //there is more than you need, so check the norm:
5526  if (n1<nNorm){
5527  a_crop->m_n = n1; //apply optimal amount
5528  }
5529  else {
5530  a_crop->m_n = nNorm; //apply max allowed amount
5531  }
5532  a_crop->m_nt = 0; //don't buy fertilizer
5533  }
5534  else { //the optimal amount is larger than Nanim
5535  if(n1>=nNorm){
5536  if(m_Nanim > nNorm){a_crop->m_nt = 0;}
5537  else{a_crop->m_nt = nNorm - m_Nanim;}//buy the diff between what you have (Nanim) and what is the max allowed
5538  a_crop->m_n = nNorm; //total amount is the max allowed
5539  }
5540  else{
5541  a_crop->m_nt = n1 - m_Nanim;
5542  a_crop->m_n = n1;
5543  }
5544  }
5545  }
5546  else{ //beta2=0, so don't apply fertilizer, but in this model - apply Nanim if there is any
5547  if(m_Nanim<=nNorm){a_crop->m_n = m_Nanim;} //apply fertilizer
5548  else {a_crop->m_n = nNorm;}
5549  a_crop->m_nt = 0;
5550  }
5551  }
5552 }
TTypeOfFarmerGoal m_main_goal
Farmer&#39;s main goal (determined by a farmer&#39;s type) .
Definition: farm.h:1960
double m_Nanim
Amount of animal fertilizer available at a farm per hectar. [kg/ha].
Definition: farm.h:2089
double value(void)
Definition: configurator.h:107
CfgFloat cfg_Env_fert_multiplier("ENV_FERT_MULTIPLIER", CFG_CUSTOM, 0.8)
A parameter of the environmentalist farmer type: reduces environmentalist&#39;s use of fertiliser...
double Get_Nnorm(int i)
Definition: farm.h:547
double m_nt
Amount of purchased (and applied) fertilizer per ha of a crop [kg N/ha].
Definition: farm.h:1515
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
TTypesOfVegetation m_cropType_almass
Type/name of a crop (ALMaSS crops).
Definition: farm.h:1503
double Get_beta2(int i)
Definition: farm.h:545
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
double m_n
Total amount of fertilizer applied per ha of a crop [kg N/ha].
Definition: farm.h:1513
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
double m_optimalN
Optimal amount of fertilizer per ha of a crop supposing ferilizer price equals zero [kg N/ha]...
Definition: farm.h:1517
CfgFloat cfg_Price_Nt("PRICE_NT", CFG_CUSTOM, 1.93)
Price of fertilizer. [DKK/kg].
TTypesOfCrops m_cropType
Type/name of a crop (original farm optimization model crop types).
Definition: farm.h:1501
double Get_beta1(int i)
Definition: farm.h:543
TTypesOfSoils m_soilType
Farm&#39;s soil type (sandy, clay, other).
Definition: farm.h:2069
void OptimisingFarm::findFodderDemand ( )
protectedvirtual

Determines farm's total demand for fodder (m_totalFUdemand).

Function determining farm's demand for fodder. Sums fodder needed for all types of livestock.

Reimplemented in NonAnimalFarm.

Definition at line 5193 of file farm.cpp.

References cfg_UseBedriftsmodelFarmAreas, DataForOptimisation::Get_livestockParameter(), m_area_scaling_factor, m_livestock, Farm::m_OurManager, m_totalFUdemand, m_totalFUdemandBefore, FarmManager::pm_data, tolp_Foobar, FarmManager::TranslateLivestockParametersCodes(), and CfgBool::value().

Referenced by NonAnimalFarm::findFodderDemand().

5193  {
5196  m_totalFUdemand=0;
5197  for(int i=0; i< (int) m_livestock.size(); i++){
5198  string str_FUuKey="FUuKey";
5199  TTypesOfAnimals index=m_livestock[i]->m_animalType;
5200  double FUuKey=m_OurManager->pm_data->Get_livestockParameter(tolp_Foobar*index + m_OurManager->TranslateLivestockParametersCodes(str_FUuKey)); //number of fodder units needed per one animal per year
5201  double number = m_livestock[i]->m_number;
5202 
5203  if(!cfg_UseBedriftsmodelFarmAreas.value()){ //almass farm areas - need to scale the livestock numbers; we don't even have to take integer...
5204  number *= m_area_scaling_factor;
5205  }
5206 
5207  if(number>0){
5208  double FUdemand=FUuKey*number;
5209  m_livestock[i]->m_FUdemand = FUdemand;
5210  m_totalFUdemand+=FUdemand;
5211  }
5212  }
5213  m_totalFUdemandBefore=m_totalFUdemand; //just to know afterwards the total demand
5214 }
CfgBool cfg_UseBedriftsmodelFarmAreas("USE_BEDRIFTSMODEL_FARM_AREAS", CFG_CUSTOM, false)
If set to true, the farm areas from the original farm optimisation model are used in the optimisation...
double m_totalFUdemandBefore
Farm&#39;s total demand for fodder. [fodder units]
Definition: farm.h:2091
double Get_livestockParameter(int i)
Definition: farm.h:534
bool value(void)
Definition: configurator.h:123
vector< Livestock * > m_livestock
Vector of pointers to animals belonging to a farm.
Definition: farm.h:2038
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
TTypesOfAnimals
Definition: farm.h:245
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
double m_area_scaling_factor
Factor used to scale areas of fixed crops and livestock numbers. Used to adjust these values to the f...
Definition: farm.h:2085
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
TTypesOfLivestockParameters TranslateLivestockParametersCodes(string &str)
Definition: farm.cpp:3937
void OptimisingFarm::findGrossMargin ( CropOptimised a_crop,
int  a_foobar,
double  benefit 
)
protected

Determines the gross margin (CropOptimised::m_GM) for a given crop at a farm.

Function determining gross margin (CropOptimised::m_GM, i.e. profit per ha for a given crop; it might be positive only for non-fodder crops) and savings (CropOptimised::m_savings, savings from growing a fodder crop per ha, it equals zero for all non-fodder crops). [DKK]

Definition at line 5748 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, cfg_Price_Nt, crop_parameter(), DataForOptimisation::Get_fodder(), CropOptimised::m_BIFi, CropOptimised::m_BIHerb, CropOptimised::m_costs_ha, CropOptimised::m_cropType, CropOptimised::m_cropType_almass, m_farmType, CropOptimised::m_GM, CropOptimised::m_GM_Savings, CropOptimised::m_grooming, CropOptimised::m_hoeing, CropOptimised::m_income_ha, CropOptimised::m_nt, Farm::m_OurManager, CropOptimised::m_resp, CropOptimised::m_savings, CropOptimised::m_totalLoss, CropOptimised::m_weeding, FarmManager::pm_data, CfgFloat::value(), and CfgBool::value().

Referenced by optimizeCrops().

5748  {
5752  int index = (cfg_OptimiseBedriftsmodelCrops.value())? (int) a_crop->m_cropType : (int) a_crop->m_cropType_almass;
5753 
5754  double priceFi = crop_parameter(index, "PriceFi");
5755  double priceHerb =crop_parameter(index, "PriceHerb");
5756  double priceG =crop_parameter(index, "PriceG");
5757  double priceH =crop_parameter(index, "PriceH");
5758  double priceW =crop_parameter(index, "PriceW");
5759  double priceLM =crop_parameter(index, "PriceLM");
5760  double subsidy =crop_parameter(index, "Subsidy");
5761 
5762  double resp = a_crop->m_resp;
5763  double BIHerb = a_crop->m_BIHerb;
5764  double BIFi = a_crop->m_BIFi;
5765  double grooming = a_crop->m_grooming;
5766  double hoeing = a_crop->m_hoeing;
5767  double weeding = a_crop->m_weeding;
5768  double totalLoss = a_crop->m_totalLoss;
5769  double nt = a_crop->m_nt;
5770  double priceNt = cfg_Price_Nt.value();
5771 
5772  double income_ha = benefit*resp*(1-totalLoss/100)+subsidy;
5773  double costs_ha = BIHerb*priceHerb + BIFi*priceFi + grooming*priceG + hoeing*priceH + weeding*priceW + nt*priceNt + priceLM;
5774  double profit = income_ha - costs_ha;
5775 
5776  a_crop->m_costs_ha = costs_ha;
5777  a_crop->m_GM_Savings = profit;
5778 
5779  //29.02.12
5780  int index1 = (cfg_OptimiseBedriftsmodelCrops.value())? a_foobar * m_farmType + a_crop->m_cropType : a_foobar * m_farmType + a_crop->m_cropType_almass;
5781  bool fodder = m_OurManager->pm_data->Get_fodder(index1);
5782  if (fodder){
5783  a_crop->m_income_ha = subsidy; //because fodder crops can't be sold
5784  a_crop->m_GM = subsidy-costs_ha; //because fodder crops can't be sold
5785  a_crop->m_savings = profit;
5786  }
5787  else{
5788  a_crop->m_income_ha = income_ha;
5789  a_crop->m_GM = profit;
5790  a_crop->m_savings = 0; //this is not a fodder crop!
5791  }
5792 }
double crop_parameter(int index, string par_name)
Reads in crop parameters that do NOT vary with any farm level parameters.
Definition: farm.cpp:7279
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
double m_income_ha
Value of income per ha of a crop. Includes value of sales and subsidy [DKK/ha].
Definition: farm.h:1544
double m_costs_ha
Costs of growing 1 ha of a crop. Include costs of labour and machine (constant), pesticides (herbicid...
Definition: farm.h:1542
double m_BIFi
Value of BI for fung- and insecticides [BI/ha].
Definition: farm.h:1526
double value(void)
Definition: configurator.h:107
double m_resp
Response - yield of a crop per ha [hkg/ha].
Definition: farm.h:1522
double m_grooming
Value of mechanical weed control for a crop - grooming [DKK/ha].
Definition: farm.h:1530
double m_GM
Value of gross margin for a crop (m_income_ha - m_costs_ha) [DKK/ha].
Definition: farm.h:1546
double m_totalLoss
Summary value of the yield loss due to the limited use of herbicides and fung- and insecticides [%]...
Definition: farm.h:1540
double m_nt
Amount of purchased (and applied) fertilizer per ha of a crop [kg N/ha].
Definition: farm.h:1515
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
TTypesOfVegetation m_cropType_almass
Type/name of a crop (ALMaSS crops).
Definition: farm.h:1503
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
double m_savings
Value of savings resulting from growing a fodder crop and not purchasing amount of fodder correspondi...
Definition: farm.h:1548
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_hoeing
Value of mechanical weed control for a crop - hoeing [DKK/ha].
Definition: farm.h:1532
CfgFloat cfg_Price_Nt("PRICE_NT", CFG_CUSTOM, 1.93)
Price of fertilizer. [DKK/kg].
double m_BIHerb
Value of BI for herbicides [BI/ha].
Definition: farm.h:1524
TTypesOfCrops m_cropType
Type/name of a crop (original farm optimization model crop types).
Definition: farm.h:1501
double m_weeding
Value of mechanical weed control for a crop - manual weeding [DKK/ha].
Definition: farm.h:1534
void OptimisingFarm::findMWeedControl ( CropOptimised a_crop)
protected

Determines the optimal mechanical weed control means (CropOptimised::m_grooming, CropOptimised::m_hoeing, CropOptimised::m_weeding) for a given crop at a farm.

Function determining optimal values of mechanical weed control means: grooming (CropOptimised::m_grooming), hoeing (CropOptimised::m_hoeing) and weeding (CropOptimised::m_weeding). All of them are functions of treatment frequency index (behandling indeks) for herbicides (CropOptimised::m_BIHerb).

Definition at line 5676 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, crop_parameter(), CropOptimised::m_BI, CropOptimised::m_BIFi, CropOptimised::m_BIHerb, CropOptimised::m_cropType, CropOptimised::m_cropType_almass, CropOptimised::m_grooming, CropOptimised::m_hoeing, CropOptimised::m_weeding, and CfgBool::value().

Referenced by optimizeCrops().

5676  {
5680  int index = (cfg_OptimiseBedriftsmodelCrops.value())? (int) a_crop->m_cropType : (int) a_crop->m_cropType_almass;
5681 
5682  double betaG = crop_parameter(index, "BetaG");
5683  double betaH = crop_parameter(index, "BetaH");
5684  double betaW = crop_parameter(index, "BetaW");
5685  double alfaG = crop_parameter(index, "AlfaG");
5686  double alfaH = crop_parameter(index, "AlfaH");
5687  double alfaW = crop_parameter(index, "AlfaW");
5688  double BIHerb = a_crop->m_BIHerb;
5689 
5690  double grooming, hoeing, weeding =0;
5691  double g = betaG - BIHerb*alfaG;
5692  double h = betaH - BIHerb*alfaH;
5693  double w = betaW - BIHerb*alfaW;
5694  double BIHerbCorr = BIHerb;
5695 
5696  if(g <= 0){
5697  grooming=0;
5698  if(alfaG!=0) BIHerbCorr=betaG/alfaG;
5699  }
5700  else{grooming=g;}
5701  if(h <= 0){
5702  hoeing=0;
5703  if(betaH/alfaH < BIHerbCorr) BIHerbCorr=betaH/alfaH;
5704  }
5705  else{hoeing=h;}
5706  if(w <= 0){
5707  weeding=0;
5708  if(betaW/alfaW < BIHerbCorr) BIHerbCorr = betaW/alfaW;
5709  }
5710  else{weeding=w;}
5711 
5712 
5713  a_crop->m_grooming = grooming;
5714  a_crop->m_hoeing = hoeing;
5715  a_crop->m_weeding = weeding;
5716  if(BIHerbCorr < BIHerb){
5717  a_crop->m_BIHerb = BIHerbCorr;
5718  a_crop->m_BI = a_crop->m_BIHerb + a_crop->m_BIFi;
5719  }
5720 
5721 }
double crop_parameter(int index, string par_name)
Reads in crop parameters that do NOT vary with any farm level parameters.
Definition: farm.cpp:7279
double m_BIFi
Value of BI for fung- and insecticides [BI/ha].
Definition: farm.h:1526
double m_grooming
Value of mechanical weed control for a crop - grooming [DKK/ha].
Definition: farm.h:1530
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
TTypesOfVegetation m_cropType_almass
Type/name of a crop (ALMaSS crops).
Definition: farm.h:1503
double m_hoeing
Value of mechanical weed control for a crop - hoeing [DKK/ha].
Definition: farm.h:1532
double m_BI
Summary value of BI for herbicides and fung- and insecticides [BI/ha].
Definition: farm.h:1528
double m_BIHerb
Value of BI for herbicides [BI/ha].
Definition: farm.h:1524
TTypesOfCrops m_cropType
Type/name of a crop (original farm optimization model crop types).
Definition: farm.h:1501
double m_weeding
Value of mechanical weed control for a crop - manual weeding [DKK/ha].
Definition: farm.h:1534
void OptimisingFarm::findNanim ( )
protected

Determines amount of animal fertilizer per ha (m_Nanim) at a farm.

Determines m_Nanim - amount of animal fertilizer per ha for a farm.

Definition at line 5188 of file farm.cpp.

References m_Nanim, m_totalArea, and m_totalNanim.

Referenced by FarmLevelCalculation().

5188  {
5191  }
double m_Nanim
Amount of animal fertilizer available at a farm per hectar. [kg/ha].
Definition: farm.h:2089
double m_totalNanim
Total animal fertilizer at a farm. A sum of Livestock::m_NanimUsable (from all types of livestock)...
Definition: farm.h:2087
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
void OptimisingFarm::findResponse ( CropOptimised a_crop,
int  a_foobar 
)
protected

Determines the response (CropOptimised::m_resp) of a crop at a farm.

Function determining the response of a crop (yield per ha), CropOptimised::m_resp. It is a function of a total fertilizer (CropOptimised::m_n) applied for a crop at a given farm. [hkg/ha]

Definition at line 5554 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, DataForOptimisation::Get_alfa(), DataForOptimisation::Get_beta1(), DataForOptimisation::Get_beta2(), CropOptimised::m_cropType, CropOptimised::m_cropType_almass, CropOptimised::m_n, Farm::m_OurManager, CropOptimised::m_resp, m_soilType, FarmManager::pm_data, and CfgBool::value().

Referenced by optimizeCrops().

5554  {
5555 
5559  int index = (cfg_OptimiseBedriftsmodelCrops.value())? a_foobar * m_soilType + a_crop->m_cropType : a_foobar * m_soilType + a_crop->m_cropType_almass;
5560 
5561  double beta1=m_OurManager->pm_data->Get_beta1(index);
5562  double beta2=m_OurManager->pm_data->Get_beta2(index);
5563  double alfa=m_OurManager->pm_data->Get_alfa(index);
5564 
5565  double ntotal=a_crop->m_n;
5566  double resp1=alfa + beta1*ntotal + beta2*pow(ntotal,2);
5567  a_crop->m_resp = resp1;
5568 }
double m_resp
Response - yield of a crop per ha [hkg/ha].
Definition: farm.h:1522
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
TTypesOfVegetation m_cropType_almass
Type/name of a crop (ALMaSS crops).
Definition: farm.h:1503
double Get_beta2(int i)
Definition: farm.h:545
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
double m_n
Total amount of fertilizer applied per ha of a crop [kg N/ha].
Definition: farm.h:1513
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
TTypesOfCrops m_cropType
Type/name of a crop (original farm optimization model crop types).
Definition: farm.h:1501
double Get_beta1(int i)
Definition: farm.h:543
double Get_alfa(int i)
Definition: farm.h:541
TTypesOfSoils m_soilType
Farm&#39;s soil type (sandy, clay, other).
Definition: farm.h:2069
void OptimisingFarm::findTotalArea ( )
protected

Determines m_totalArea of a farm.

Function determining farm's total area. Depending on which area is to be used it either sums initial crop areas on a farm (to get area equal to area used in Bedriftsmodel) or deteremines area based on farm's fields size.

Definition at line 5147 of file farm.cpp.

References cfg_UseBedriftsmodelFarmAreas, Farm::GetAreaDouble(), m_area_scaling_factor, m_crops, m_totalArea, m_totalArea_original, and CfgBool::value().

Referenced by FarmLevelCalculation().

5147  {
5152  m_totalArea=0.;
5153  for (int i=0; i< (int) m_crops.size(); i++) {
5154  m_totalArea+=m_crops[i]->m_initialArea;
5155  }
5157 
5158  if(!cfg_UseBedriftsmodelFarmAreas.value()){ //almass farm areas used: just sum the fields area
5159  double area_copy = m_totalArea; //ha
5160  m_totalArea = GetAreaDouble()/10000; //change from sq m to ha
5161  m_area_scaling_factor = m_totalArea/area_copy;
5162  }
5163  //otherwise do nothing: total area = sum of initial crop areas (see the for loop)
5164 }
CfgBool cfg_UseBedriftsmodelFarmAreas("USE_BEDRIFTSMODEL_FARM_AREAS", CFG_CUSTOM, false)
If set to true, the farm areas from the original farm optimisation model are used in the optimisation...
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
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
double m_totalArea_original
Total area of a farm as in bedriftsmodel, i.e. original farm optimization model. [ha].
Definition: farm.h:2083
bool value(void)
Definition: configurator.h:123
double m_area_scaling_factor
Factor used to scale areas of fixed crops and livestock numbers. Used to adjust these values to the f...
Definition: farm.h:2085
double GetAreaDouble(void)
Returns the area of arable fields owned by that farm.
Definition: farm.cpp:1064
void OptimisingFarm::findTotalNanim ( )
protected

Determines total animal fertilizer (m_totalNanim) available at a farm.

Function determining farm's total animal fertilizer. Sums usable fertilizer from all types of livestock.

Definition at line 5166 of file farm.cpp.

References cfg_UseBedriftsmodelFarmAreas, DataForOptimisation::Get_livestockParameter(), m_area_scaling_factor, m_livestock, Farm::m_OurManager, m_totalNanim, FarmManager::pm_data, tolp_Foobar, FarmManager::TranslateLivestockParametersCodes(), and CfgBool::value().

Referenced by FarmLevelCalculation().

5166  {
5169  m_totalNanim = 0;
5170  for (int i=0; i< (int) m_livestock.size(); i++){
5171  string str_AUKey="AUKey";
5172  string str_Nusable="Nusable";
5173  TTypesOfAnimals index=m_livestock[i]->m_animalType;
5174  double AUKey = m_OurManager->pm_data->Get_livestockParameter(tolp_Foobar*index + m_OurManager->TranslateLivestockParametersCodes(str_AUKey)); //Number of animal units (AU, DE-dyreenheder) -> hkg N per year
5175  double Nusable = m_OurManager->pm_data->Get_livestockParameter(tolp_Foobar*index + m_OurManager->TranslateLivestockParametersCodes(str_Nusable)); // [%] Usable fertilizer from livestock
5176  double number = m_livestock[i]->m_number;
5177 
5178  if(!cfg_UseBedriftsmodelFarmAreas.value()){ //almass farm areas - need to scale the livestock numbers; we don't even have to take integer...
5179  number *= m_area_scaling_factor;
5180  }
5181 
5182  double NanimUsable = number*AUKey*Nusable*100; // [1*hkg/yr*1*100 = kg/yr] Usable fertilizer from livestock
5183  m_livestock[i]->m_NanimUsable = NanimUsable;
5184  m_totalNanim += NanimUsable;
5185  }
5186 }
CfgBool cfg_UseBedriftsmodelFarmAreas("USE_BEDRIFTSMODEL_FARM_AREAS", CFG_CUSTOM, false)
If set to true, the farm areas from the original farm optimisation model are used in the optimisation...
double m_totalNanim
Total animal fertilizer at a farm. A sum of Livestock::m_NanimUsable (from all types of livestock)...
Definition: farm.h:2087
double Get_livestockParameter(int i)
Definition: farm.h:534
bool value(void)
Definition: configurator.h:123
vector< Livestock * > m_livestock
Vector of pointers to animals belonging to a farm.
Definition: farm.h:2038
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
TTypesOfAnimals
Definition: farm.h:245
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
double m_area_scaling_factor
Factor used to scale areas of fixed crops and livestock numbers. Used to adjust these values to the f...
Definition: farm.h:2085
TTypesOfLivestockParameters TranslateLivestockParametersCodes(string &str)
Definition: farm.cpp:3937
void OptimisingFarm::findYieldLoss ( CropOptimised a_crop)
protected

Determines the yield losses (CropOptimised::m_lossHerb, CropOptimised::m_lossFi, CropOptimised::m_totalLoss) for a given crop at a farm.

Function determining yield losses resulting from not using maximal amount of herbicides (CropOptimised::m_lossHerb), fungicides and insecticides (CropOptimised::m_lossFi) and a total yield loss, which is a sum of m_lossHerb and m_lossFi (CropOptimised::m_totalLoss). Losses are expressed as percentages of yield (take values from 0 to 100).

Definition at line 5723 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, crop_parameter(), CropOptimised::m_BIFi, CropOptimised::m_BIHerb, CropOptimised::m_cropType, CropOptimised::m_cropType_almass, CropOptimised::m_lossFi, CropOptimised::m_lossHerb, CropOptimised::m_totalLoss, and CfgBool::value().

Referenced by optimizeCrops().

5723  {
5728  int index = (cfg_OptimiseBedriftsmodelCrops.value())? (int) a_crop->m_cropType : (int) a_crop->m_cropType_almass;
5729 
5730  double alfaFi = crop_parameter(index, "AlfaFi");
5731  double alfaHerb = crop_parameter(index, "AlfaHerb");
5732  double betaFi = crop_parameter(index, "BetaFi");
5733  double betaHerb = crop_parameter(index, "BetaHerb");
5734 
5735  double BIHerb=a_crop->m_BIHerb;
5736  double BIFi=a_crop->m_BIFi;
5737 
5738  double lossHerb = betaHerb - alfaHerb*BIHerb;
5739  a_crop->m_lossHerb = lossHerb;
5740 
5741  double lossFi = betaFi - alfaFi*BIFi;
5742  a_crop->m_lossFi = lossFi;
5743 
5744  double totalLoss = lossHerb + lossFi;// [%]
5745  a_crop->m_totalLoss = totalLoss;
5746 }
double crop_parameter(int index, string par_name)
Reads in crop parameters that do NOT vary with any farm level parameters.
Definition: farm.cpp:7279
double m_BIFi
Value of BI for fung- and insecticides [BI/ha].
Definition: farm.h:1526
double m_lossFi
Value of the yield loss due to the limited use of fung- and insecticides [%].
Definition: farm.h:1538
double m_totalLoss
Summary value of the yield loss due to the limited use of herbicides and fung- and insecticides [%]...
Definition: farm.h:1540
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
TTypesOfVegetation m_cropType_almass
Type/name of a crop (ALMaSS crops).
Definition: farm.h:1503
double m_lossHerb
Value of the yield loss due to the limited use of herbicides [%].
Definition: farm.h:1536
double m_BIHerb
Value of BI for herbicides [BI/ha].
Definition: farm.h:1524
TTypesOfCrops m_cropType
Type/name of a crop (original farm optimization model crop types).
Definition: farm.h:1501
void OptimisingFarm::fixBI ( )
protected

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

Definition at line 5646 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, findCropByName(), findCropByName_almass(), CropOptimised::m_BI, CropOptimised::m_BIFi, CropOptimised::m_BIHerb, and CfgBool::value().

Referenced by optimizeCrops().

5646  {
5647 
5648  if(cfg_OptimiseBedriftsmodelCrops.value()){ //b. crops
5649  CropOptimised *fodderBeet = findCropByName ("FodderBeet");
5650  CropOptimised *sugarBeet = findCropByName ("SugarBeet");
5651  CropOptimised *potato = findCropByName ("Potato");
5652  CropOptimised *potatoFood = findCropByName ("PotatoFood");
5653 
5654  fodderBeet->m_BIHerb = 2.28; //seems it's constant - in the results of Bedriftsmodel, but herbicide parameters are = zero!
5655  sugarBeet->m_BIHerb = 2.28;
5656  fodderBeet->m_BI = fodderBeet->m_BIFi + fodderBeet->m_BIHerb;
5657  sugarBeet->m_BI = sugarBeet->m_BIFi + sugarBeet->m_BIHerb;
5658 
5659  //potatoes - everything fixed
5660  potato->m_BIHerb = 1.41; potato->m_BIFi = 9.28; potato->m_BI = 10.69;
5661  potatoFood->m_BIHerb = 1.41; potatoFood->m_BIFi = 9.28; potatoFood->m_BI = 10.69;
5662  }
5663  else{ //almass crops
5664  CropOptimised *FodderBeet = findCropByName_almass ("FodderBeet");
5665  CropOptimised *PotatoesIndustry = findCropByName_almass ("PotatoesIndustry");
5666  CropOptimised *Potatoes = findCropByName_almass ("Potatoes");
5667 
5668  FodderBeet->m_BIHerb = 2.28; //the values have to be now like in the bedriftsmodel //modified probability
5669  FodderBeet->m_BI = FodderBeet->m_BIHerb + FodderBeet->m_BIFi;
5670  PotatoesIndustry->m_BIHerb = 1.41; PotatoesIndustry->m_BIFi = 9.28; PotatoesIndustry->m_BI = 10.69;
5671  Potatoes->m_BIHerb = 1.41; Potatoes->m_BIFi = 9.28; Potatoes->m_BI = 10.69;
5672  }
5673 
5674 }
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
double m_BIFi
Value of BI for fung- and insecticides [BI/ha].
Definition: farm.h:1526
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
double m_BI
Summary value of BI for herbicides and fung- and insecticides [BI/ha].
Definition: farm.h:1528
double m_BIHerb
Value of BI for herbicides [BI/ha].
Definition: farm.h:1524
bool OptimisingFarm::FungicideTreat ( LE a_field,
double  ,
int  a_days 
)
protectedvirtual

Carries out fungicide application. Saves information on each application for a given crop.

Reimplemented from Farm.

Definition at line 928 of file farmfuncs.cpp.

References VegElement::Add_no_fi_app(), DO_IT_PROB, EL_TRAMLINE_DECAYTIME, fungicide_treat, g_weather, LE::GetSignal(), Weather::GetWind(), LE_SIG_NO_FUNGICIDE, Weather::Raining(), LE::SetLastTreatment(), LE::SetTramlinesDecay(), LE::Trace(), and CfgBool::value().

929 {
930 
931  if (0 >= a_days)
932  {
933  if ( ( ! a_field->GetSignal() & LE_SIG_NO_FUNGICIDE )) {
934  a_field->Trace( fungicide_treat );
935  a_field->SetLastTreatment( fungicide_treat );
937 
939  Field * pf = dynamic_cast<Field*>(a_field);
940  pf->Add_no_fi_app();
941  }
942  }
943  return true;
944  }
945  else if ( (g_weather->GetWind()<4.5) && (!g_weather->Raining()) && DoIt(DO_IT_PROB)) {
946  if ( ! (a_field->GetSignal() & LE_SIG_NO_FUNGICIDE) ) {
947  a_field->Trace( fungicide_treat );
948  a_field->SetLastTreatment( fungicide_treat );
950 
952  Field * pf = dynamic_cast<Field*>(a_field);
953  pf->Add_no_fi_app();
954  }
955  }
956  return true;
957  }
958  return false;
959 }
#define LE_SIG_NO_FUNGICIDE
Definition: elements.h:40
bool DoIt(int a_probability)
Return chance out of 100.
Definition: farm.cpp:610
void SetTramlinesDecay(int a_decaytime_days)
Definition: elements.h:304
void Add_no_fi_app()
Definition: elements.h:579
double GetWind(long a_date)
Definition: weather.h:425
#define DO_IT_PROB
Definition: farmfuncs.cpp:58
class Weather * g_weather
Definition: weather.cpp:41
bool value(void)
Definition: configurator.h:123
bool Raining(void)
Definition: weather.h:432
CfgBool cfg_OptimiseBedriftsmodelCrops
If set to true, the original farm optimisation model&#39;s crop set is used in the farmer decision making...
void SetLastTreatment(int a_treatment)
Definition: elements.cpp:472
LE_Signal GetSignal(void)
Definition: elements.h:107
#define EL_TRAMLINE_DECAYTIME
Definition: elements.h:55
void Trace(int a_value)
Definition: elements.cpp:459
double OptimisingFarm::Get_actual_aggregated_yield ( )
inline

Definition at line 1911 of file farm.h.

Referenced by ChooseDecisionMode().

1911 {return m_actual_aggregated_yield;};
double m_actual_aggregated_yield
Actual aggregated yield at a farm in a given year.
Definition: farm.h:1988
double OptimisingFarm::Get_actual_profit ( )
inline

Definition at line 1910 of file farm.h.

Referenced by ChooseDecisionMode().

1910 {return m_actual_profit;};
double m_actual_profit
An actual profit realised at a farm in a given year.
Definition: farm.h:1975
int OptimisingFarm::Get_almass_no ( void  )
inline
CropOptimised* OptimisingFarm::Get_crop ( int  i)
inline

Definition at line 1897 of file farm.h.

Referenced by FarmManager::CropDistribution(), and FarmManager::PrintOutput().

1897 {return m_crops[i];}
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
int OptimisingFarm::Get_cropsSize ( void  )
inline

Definition at line 1898 of file farm.h.

Referenced by FarmManager::CropDistribution(), and FarmManager::PrintOutput().

1898 {return (int)m_crops.size();}
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
int OptimisingFarm::Get_decision_mode_counters ( int  index)
inline

Definition at line 1917 of file farm.h.

Referenced by FarmManager::PrintDecModes_counts().

1917 {return m_decision_mode_counters[index];};
vector< int > m_decision_mode_counters
Vector with counters for each decision mode. 0 - imitation, 1 - social comparison, 2 - repeat, 3 - deliberation.
Definition: farm.h:1971
int OptimisingFarm::Get_farmRealID ( void  )
inline

Definition at line 1894 of file farm.h.

1894 {return m_farmRealID;}
int m_farmRealID
Farm&#39;s real ID number.
Definition: farm.h:2073
TTypesOfFarmSize OptimisingFarm::Get_farmSize ( void  )
inline

Definition at line 1893 of file farm.h.

Referenced by Find_neighbour_to_imitate().

1893 {return m_farmSize;}
TTypesOfFarmSize m_farmSize
Scale of the farm - business (size above 10 ha) or private (size below 10 ha).
Definition: farm.h:2071
TTypesOfOptFarms OptimisingFarm::Get_farmType ( void  )
inline

Definition at line 1891 of file farm.h.

Referenced by FarmManager::Save_diff_farm_types_areas().

1891 {return m_farmType;}
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
TTypeOfFarmerGoal OptimisingFarm::Get_main_goal ( )
inline

Definition at line 1915 of file farm.h.

Referenced by FarmManager::FarmManagement().

1915 {return m_main_goal;};
TTypeOfFarmerGoal m_main_goal
Farmer&#39;s main goal (determined by a farmer&#39;s type) .
Definition: farm.h:1960
OptimisingFarm* OptimisingFarm::Get_Neighbour ( int  i)
inline

Definition at line 1907 of file farm.h.

Referenced by FarmManager::PrintNeighbours().

1907 {return m_neighbours[i];};
vector< OptimisingFarm * > m_neighbours
Vector of pointers to the farms considered neighbours (fulfilling the neighbourship condition) of a g...
Definition: farm.h:1965
int OptimisingFarm::Get_NeighboursSize ( void  )
inline

Definition at line 1906 of file farm.h.

Referenced by FarmManager::PrintNeighbours().

1906 {return (int)m_neighbours.size();};
vector< OptimisingFarm * > m_neighbours
Vector of pointers to the farms considered neighbours (fulfilling the neighbourship condition) of a g...
Definition: farm.h:1965
vector<AlmassCrop> OptimisingFarm::Get_rotational_crops ( )
inline

Definition at line 1908 of file farm.h.

1908 {return m_rotational_crops;};
vector< AlmassCrop > m_rotational_crops
Vector of structs with almass type crops with positive areas in % (result of optimisation): includes ...
Definition: farm.h:2059
vector<AlmassCrop> OptimisingFarm::Get_rotational_crops_visible ( )
inline

Definition at line 1909 of file farm.h.

Referenced by ChooseDecisionMode().

1909 {return m_rotational_crops_visible;};
vector< AlmassCrop > m_rotational_crops_visible
Stores a copy of m_rotational_crops from a previous year and is accessible to farmers who want to cop...
Definition: farm.h:2063
int OptimisingFarm::Get_soilSubType ( void  )
inline

Definition at line 1895 of file farm.h.

1895 {return m_soilSubType;}
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
TTypesOfSoils OptimisingFarm::Get_soilType ( void  )
inline

Definition at line 1892 of file farm.h.

Referenced by Find_neighbour_to_imitate().

1892 {return m_soilType;}
TTypesOfSoils m_soilType
Farm&#39;s soil type (sandy, clay, other).
Definition: farm.h:2069
int OptimisingFarm::GetFarmCentroidX ( )
inline

Definition at line 1912 of file farm.h.

Referenced by FarmManager::FindNeighbours().

1912 { return m_farm_centroidx; }
int m_farm_centroidx
Farm&#39;s centroid, value x. Equal to the average of the x centroid values of all farm&#39;s fields...
Definition: farm.h:861
int OptimisingFarm::GetFarmCentroidY ( )
inline

Definition at line 1913 of file farm.h.

Referenced by FarmManager::FindNeighbours().

1913 { return m_farm_centroidy; }
int m_farm_centroidy
Farm&#39;s centroid, value y. Equal to the average of the y centroid values of all farm&#39;s fields...
Definition: farm.h:863
void OptimisingFarm::HandleEvents ( void  )
protectedvirtual

If there are events to carry out do this, and perhaps start a new crop.

Call the management plan for the current crop and it this return done=true starts the next management.

Sets the new index to the rotation.

Save the new veg type as the LE vegetation type

Reimplemented from Farm.

Definition at line 755 of file farm.cpp.

References LE::BumpRunNum(), cfg_OptimiseBedriftsmodelCrops, VegElement::Clean_CropDataStorage(), Calendar::Date(), g_date, g_farm_fixed_crop_enable, g_farm_fixed_crop_type, g_letype, g_msg, VegElement::Get_CropDataStorage(), VegElement::Get_taken(), LE::GetArea(), LE::GetRotIndex(), LE::GetRunNum(), LE::GetVegType(), LowPriPair< ELEMTYPE >::m_element, FarmEvent::m_field, LowPriPair< ELEMTYPE >::m_pri, PROG_START, LE::ResetTrace(), VegElement::Set_area_in_crop_data(), VegElement::Set_CropDataStorage(), VegElement::Set_taken(), VegElement::Set_tov_type(), LE::SetMgtLoopDetectDate(), LE::SetRotIndex(), LE::SetVegStore(), LE::SetVegType(), tov_Undefined, LE_TypeClass::TranslateVegTypes(), CfgInt::value(), CfgBool::value(), MapErrorMsg::Warn(), and WARN_FILE.

755  {
756  if ( m_queue.Empty() )
757  return;
758 
760  FarmEvent * ev = pair.m_element;
761  while ( pair.m_pri <= g_date->Date() ) {
762  m_queue.Pop();
763 
764  if ( LeSwitch( ev ) ) {
765  // This crop management plan has terminated.
766 
767  // First check for an infinite loop in the rotation scheme,
768  // ie. a scenario where all crops decide not to run given
769  // the date.
771 
772  // Outdate any remaining events for this field.
773  ev->m_field->BumpRunNum();
774 
775  // Crop treatment done, select and initiate new crop if in rotation.
776  TTypesOfVegetation new_veg = ev->m_field->GetVegType();
777 
778  if ( ev->m_field->GetRotIndex() >= 0 ) {
779  int new_index = GetNextCropIndex( ev->m_field->GetRotIndex() );
780  new_veg = m_rotation[ new_index ];
781  // Running in fixed crop mode?
784  }
785  /*
786  if ( g_farm_test_crop.value() ) {
787  new_veg = g_letype->TranslateVegTypes( g_farm_test_crop_type.value() );
788  }
789  */
790  ev->m_field->SetRotIndex( new_index );
791  ev->m_field->SetVegType( new_veg, tov_Undefined );
792  // ***CJT*** Testing removal 3/2/2015 ev->m_field->ForceGrowthTest();
793  }
794 
795 
796  //------------05.03.12 AM - tell a field the crop has changed - here the OptimisingFarm part---------------------------------------
797  if(!cfg_OptimiseBedriftsmodelCrops.value()){ //don't do this if you simulate the bedriftsmodel (original farm optimization model) crops
798  //switch the previous crop (if it is still there) to position 1 in an array m_CropDataStorage; put a new crop at position 0
799  VegElement * pf = dynamic_cast<VegElement*>(ev->m_field);
800  if(pf->Get_taken(0)){ //there is a crop at position 0 - so need to copy it to position 1 and clear all values at position 0
801  if(pf->Get_taken(1)){ //problem - we have 3rd crop when two previous crops were not calculated yet - it shouldn't happen!
802  char error_num[ 20 ];
803  sprintf( error_num, "%d", new_veg );
804  g_msg->Warn( WARN_FILE, "Farm::HandleEvents(): there is 3rd crop starting when 2 previous were not calculated yet, the 3rd crop is", error_num );
805  exit( 1 );
806  }
807  pf->Set_CropDataStorage(1, pf->Get_CropDataStorage(0)); //copy the content of a struct at position 0 of the m_CropDataStorage array to position 1
808  pf->Set_taken(true, 1); //mark the struct at position 1 as taken by a crop
809  pf->Clean_CropDataStorage(0); //clear struct at position 0
810 
811  }
812  //now save the new crop at position zero - whether there was a crop here or not
813  pf->Clean_CropDataStorage(0); //clear struct at position 0 //do it cause the previous crop's operations could have been saved here - if there was some time between accoutning and start of this new crop
814  pf->Set_taken(true, 0); // the new crop is at position 0
815  pf->Set_tov_type(new_veg, 0); //save the tov_type of a new crop
816  pf->Set_area_in_crop_data(pf->GetArea());
817  }
818  //---------------------end 05.03.13----------------------------------------------------------------
819 
820 
821  // Reset the event list for this field.
822  ev->m_field->ResetTrace();
823  // Reset event timeout counter.
824  ev->m_field->SetVegStore( 0 );
825 
826  // The next bit simply determines the start date of the next crop in
827  // the rotation and passes this to the start crop event.
828  // The crop is responsible for raising an error if the next crop is
829  // not possible or otherwise handling the problem
830 
831  // 19/5-2003: Note: This code was moved out into a dedicated
832  // method of the Farm class, GetNextCropStartDate(), as precisely
833  // the same piece of code needs to be run during initialization of
834  // farm management.
835  TTypesOfVegetation l_tov = new_veg;
836  int l_nextcropstartdate = GetNextCropStartDate( ev->m_field, l_tov );
837 
838  // Create 'start' event for today and put it on the queue.
839  AddNewEvent( new_veg, g_date->Date(), ev->m_field, PROG_START, ev->m_field->GetRunNum(),
840  false, l_nextcropstartdate, false, l_tov );
841 
842  // Set starting date for rotation mgmt loop detection.
844  }
845 
846  delete ev;
847 
848  if ( m_queue.Empty() )
849  return;
850  pair = m_queue.Bottom();
851  ev = pair.m_element;
852  }
853 }
#define PROG_START
Definition: farm.h:76
long Date(void)
Definition: calendar.h:57
int GetNextCropStartDate(LE *a_field, TTypesOfVegetation &a_curr_veg)
Returns the start date of the next crop in the rotation.
Definition: farm.cpp:666
virtual void SetVegType(TTypesOfVegetation, TTypesOfVegetation)
Definition: elements.h:164
bool LeSwitch(FarmEvent *ev)
Call do function for any crop with an outstanding event. Signal if the crop has terminated.
Definition: farm.cpp:331
void Set_tov_type(TTypesOfVegetation a_tov_type, int index)
Definition: elements.h:568
CfgBool g_farm_fixed_crop_enable("FARM_FIXED_CROP_ENABLE", CFG_CUSTOM, false)
void SetRotIndex(int a_index)
Definition: elements.h:301
void Pop()
Definition: lowqueue.h:124
TTypesOfVegetation
virtual int GetNextCropIndex(int a_rot_index)
Returns the next crop in the rotation.
Definition: farm.cpp:1141
vector< TTypesOfVegetation > m_rotation
Definition: farm.h:840
void BumpRunNum(void)
Definition: elements.h:118
virtual TTypesOfVegetation GetVegType(void)
Definition: elements.h:125
class LE_TypeClass * g_letype
Definition: elements.cpp:265
CropActualValues Get_CropDataStorage(int index)
Definition: elements.h:592
LE * m_field
Definition: farm.h:400
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
void Set_area_in_crop_data(double a_area)
Definition: elements.h:570
CfgInt g_farm_fixed_crop_type("FARM_FIXED_CROP_TYPE", CFG_CUSTOM, 22)
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 struct to hold the information required to trigger a farm event.
Definition: farm.h:391
LowPriority< FarmEvent * > m_queue
Definition: farm.h:838
void Set_CropDataStorage(int index, CropActualValues a_struct)
Definition: elements.h:591
bool Empty(void)
Definition: lowqueue.h:129
TTypesOfVegetation TranslateVegTypes(int VegReference)
Definition: elements.cpp:2692
int GetRotIndex(void)
Definition: elements.h:303
void AddNewEvent(TTypesOfVegetation a_event, long a_date, LE *a_field, int a_todo, long a_num, bool a_lock, int a_start, bool a_first_year, TTypesOfVegetation a_crop)
Adds an event to the event queue for a farm.
Definition: farm.cpp:599
bool Get_taken(int index)
Definition: elements.h:567
class Calendar * g_date
Definition: calendar.cpp:38
ELEMTYPE m_element
Definition: lowqueue.h:88
void Set_taken(bool a_taken, int index)
Definition: elements.h:566
void ResetTrace(void)
Definition: elements.cpp:463
int value(void)
Definition: configurator.h:92
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
void SetVegStore(int a_veg)
Definition: elements.h:127
void SetMgtLoopDetectDate(long a_num)
Definition: elements.h:120
double GetArea(void)
Definition: elements.h:196
long m_pri
Definition: lowqueue.h:89
long GetRunNum(void)
Definition: elements.h:117
LowPriPair< ELEMTYPE > Bottom(void)
Definition: lowqueue.h:134
Used in event handling.
Definition: lowqueue.h:83
void CheckRotationManagementLoop(FarmEvent *ev)
Definition: farm.cpp:641
void Clean_CropDataStorage(int index)
Definition: elements.cpp:1751
bool OptimisingFarm::Harvest ( LE a_field,
double  a_user,
int  a_days 
)
virtual

OptimisingFarm's virtual version of Farm::Harvest(). Saves information on biomass of a crop at harvest.

Reimplemented from Farm.

Definition at line 1487 of file farmfuncs.cpp.

References Calendar::Date(), DO_IT_PROB, EL_TRAMLINE_DECAYTIME, g_date, g_weather, LE::GetInsectPop(), Weather::GetRainPeriod(), LE::GetUnsprayedMarginPolyRef(), LE::GetVegBiomass(), VegElement::GetVegType(), harvest, harvest1, LE::InsectMortality(), LE::RecalculateBugsNStuff(), LE::ResetDigestability(), VegElement::Set_biomass_at_harvest(), VegElement::Set_harvested(), LE::SetGrowthPhase(), LE::SetInsectPop(), LE::SetLastTreatment(), LE::SetTramlinesDecay(), Landscape::SupplyLEPointer(), tov_Potatoes, tov_PotatoesIndustry, LE::Trace(), and CfgBool::value().

1488 {
1489 
1490  //5 days good weather before
1491  if ( (0 >= a_days) ||
1492  ((g_weather->GetRainPeriod(g_date->Date(),5)<0.1) && DoIt(DO_IT_PROB)))
1493  {
1494 
1495  //05.03.13 need to get the info on biomass
1497  Field * pf = dynamic_cast<Field*>(a_field); //ok????? - maybe should be VegElement instead of field!
1498  if(pf->GetVegType()!=tov_Potatoes && pf->GetVegType()!=tov_PotatoesIndustry){ //do not save biomass for potatoes!
1499  double biomass_at_harvest = a_field->GetVegBiomass();
1500  pf->Set_biomass_at_harvest(biomass_at_harvest, 0); //sets the biomass of a current crop; the current crop is at the index 0
1501  pf->Set_harvested(); //mark this crop as harvested
1502  }
1503  }
1504  //05.03.13 end
1505 
1506  a_field->Trace( harvest );
1507  a_field->SetLastTreatment( harvest );
1508  a_field->SetGrowthPhase( harvest1 );
1509  // Here we have to do a little skip to avoid too low insect populations after harvest, but a correct veg biomass
1510  a_field->InsectMortality( 0.4 );
1511  double insects=a_field->GetInsectPop();
1512  a_field->RecalculateBugsNStuff();
1513  a_field->SetInsectPop(insects);
1515  a_field->ResetDigestability();
1516  int pref=a_field->GetUnsprayedMarginPolyRef();
1517  if (pref!=-1){
1518  // Must have an unsprayed margin so need to pass the information on to it
1519  LE* um=g_landscape_p->SupplyLEPointer(pref);
1521  um->SetGrowthPhase( harvest1 );
1522  um->InsectMortality( 0.4 );
1524  um->ResetDigestability();
1525  um->RecalculateBugsNStuff();
1526  }
1527  return true;
1528  }
1529  return false;
1530 }
long Date(void)
Definition: calendar.h:57
LE * SupplyLEPointer(int a_polyref)
Definition: landscape.h:1020
int GetUnsprayedMarginPolyRef(void)
Definition: elements.h:313
bool DoIt(int a_probability)
Return chance out of 100.
Definition: farm.cpp:610
virtual void SetInsectPop(double)
Definition: elements.h:157
void SetTramlinesDecay(int a_decaytime_days)
Definition: elements.h:304
#define DO_IT_PROB
Definition: farmfuncs.cpp:58
Definition: elements.h:81
class Weather * g_weather
Definition: weather.cpp:41
virtual TTypesOfVegetation GetVegType(void)
Definition: elements.h:509
bool value(void)
Definition: configurator.h:123
virtual double GetVegBiomass(void)
Definition: elements.h:154
virtual void ResetDigestability()
sets growth record to zero in descendent classes
Definition: elements.h:370
void Set_biomass_at_harvest(double a_biomass, int index)
Definition: elements.h:571
CfgBool cfg_OptimiseBedriftsmodelCrops
If set to true, the original farm optimisation model&#39;s crop set is used in the farmer decision making...
virtual void InsectMortality(double)
Definition: elements.h:159
class Calendar * g_date
Definition: calendar.cpp:38
void SetLastTreatment(int a_treatment)
Definition: elements.cpp:472
Landscape * g_landscape_p
Definition: Landscape.cpp:238
virtual void SetGrowthPhase(int)
Definition: elements.h:170
virtual void RecalculateBugsNStuff(void)
Definition: elements.h:132
double GetRainPeriod(long a_date, unsigned int a_period)
Definition: weather.cpp:278
#define EL_TRAMLINE_DECAYTIME
Definition: elements.h:55
void Set_harvested()
Definition: elements.h:573
virtual double GetInsectPop(void)
Definition: elements.h:156
void Trace(int a_value)
Definition: elements.cpp:459
bool OptimisingFarm::HerbicideTreat ( LE a_field,
double  ,
int  a_days 
)
protectedvirtual

Carries out herbicide application. Saves information on each application for a given crop.

Reimplemented from Farm.

Definition at line 821 of file farmfuncs.cpp.

References VegElement::Add_no_herb_app(), DO_IT_PROB, EL_HERBICIDE_DELAYTIME, EL_TRAMLINE_DECAYTIME, g_weather, LE::GetSignal(), Weather::GetWind(), herbicide_treat, l_farm_herbicide_kills, LE_SIG_NO_HERBICIDE, Weather::Raining(), LE::ReduceWeedBiomass(), LE::SetHerbicideDelay(), LE::SetLastTreatment(), LE::SetTramlinesDecay(), LE::Trace(), and CfgBool::value().

822 {
823 
824  if (0 >= a_days) // Must do this
825  {
826  if (((a_field->GetSignal() & LE_SIG_NO_HERBICIDE)==0 ))
827  {
828  a_field->Trace( herbicide_treat );
829  a_field->SetLastTreatment( herbicide_treat );
830  if ( l_farm_herbicide_kills.value()) {
831  a_field->ReduceWeedBiomass( 0.05 );
832  }
835 
836 
838  Field * pf = dynamic_cast<Field*>(a_field);
839  pf->Add_no_herb_app();
840  }
841 
842  }
843  return true;
844  }
845  else if ((g_weather->GetWind()<4.5) && (!g_weather->Raining()) && DoIt(DO_IT_PROB))
846  {
847  if ( !(a_field->GetSignal() & LE_SIG_NO_HERBICIDE) )
848  {
849  a_field->Trace( herbicide_treat );
850  a_field->SetLastTreatment( herbicide_treat );
851  if ( l_farm_herbicide_kills.value()) {
852  a_field->ReduceWeedBiomass( 0.05 );
853  }
856 
858  Field * pf = dynamic_cast<Field*>(a_field);
859  pf->Add_no_herb_app();
860  }
861  }
862  return true;
863  }
864  return false;
865 }
bool DoIt(int a_probability)
Return chance out of 100.
Definition: farm.cpp:610
void SetTramlinesDecay(int a_decaytime_days)
Definition: elements.h:304
#define LE_SIG_NO_HERBICIDE
Definition: elements.h:45
double GetWind(long a_date)
Definition: weather.h:425
#define DO_IT_PROB
Definition: farmfuncs.cpp:58
class Weather * g_weather
Definition: weather.cpp:41
void Add_no_herb_app()
Definition: elements.h:576
bool value(void)
Definition: configurator.h:123
bool Raining(void)
Definition: weather.h:432
#define EL_HERBICIDE_DELAYTIME
Definition: elements.h:58
CfgBool cfg_OptimiseBedriftsmodelCrops
If set to true, the original farm optimisation model&#39;s crop set is used in the farmer decision making...
static CfgBool l_farm_herbicide_kills("FARM_PESTICIDE_KILLS", CFG_CUSTOM, true)
void SetLastTreatment(int a_treatment)
Definition: elements.cpp:472
LE_Signal GetSignal(void)
Definition: elements.h:107
#define EL_TRAMLINE_DECAYTIME
Definition: elements.h:55
void SetHerbicideDelay(int a_decaytime_days)
Definition: elements.h:306
virtual void ReduceWeedBiomass(double)
Definition: elements.h:160
void Trace(int a_value)
Definition: elements.cpp:459
void OptimisingFarm::increaseCrops ( vector< CropSort cropsToIncrease,
double &  howMuchToIncrease 
)
protectedvirtual

Increases area of crops by a specified number.

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.

Reimplemented in AnimalFarm.

Definition at line 7377 of file farm.cpp.

Referenced by OptimisingPigFarm::check_WRape_WBarley(), OptimisingCattleFarm::checkCattleRotation(), AnimalFarm::checkWinterCrops(), NonAnimalFarm::checkWinterCrops(), AnimalFarm::checkWinterRotation1(), NonAnimalFarm::checkWinterRotation1(), and AnimalFarm::determineFodderAreas().

7377  {
7380  for(int i=0; howMuchToIncrease>0 && i<(int)cropsToIncrease.size(); i++){
7381  double area = cropsToIncrease[i].crop->m_areaPercent;
7382  double rotationMax = cropsToIncrease[i].crop->m_rotationMax;
7383  double rotMinCrop = cropsToIncrease[i].crop->m_rotationMin;
7384  if(area + howMuchToIncrease <= rotationMax){
7385  area += howMuchToIncrease; //finito
7386  howMuchToIncrease = 0;
7387  }
7388  else{
7389  howMuchToIncrease -= rotationMax-area;
7390  area = rotationMax;
7391  }
7392  cropsToIncrease[i].crop->m_areaPercent = area;
7393  cropsToIncrease[i].crop->m_areaVariable = area - rotMinCrop;
7394  }
7395 }
void OptimisingFarm::Init ( ofstream *  ap_output_file)

Function carrying out the initial calculations at a farm level (including the initial optimisation).

Definition at line 4817 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, createCropsLists(), FarmLevelCalculation(), m_crops_almass, Farm::m_PermCrops, Farm::m_rotation, Make_almass_crops_vector(), Make_rotational_crops(), Make_rotations(), OptimiseFarm(), Print_FarmVariables(), Print_rotations(), toc_Foobar, tov_OrchardCrop, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_PermanentSetaside, tov_SpringBarley, tov_Undefined, tov_YoungForest, Translate_crops_to_almass(), and CfgBool::value().

Referenced by FarmManager::InitFarms().

4817  {
4818 
4819  int foobar = (cfg_OptimiseBedriftsmodelCrops.value())? (int)toc_Foobar : (int)tov_Undefined;
4820 
4821  FarmLevelCalculation(); //could stay in the constructor, but for clarity should be here
4822  createCropsLists(foobar);
4823  OptimiseFarm(foobar);
4824  Print_FarmVariables(ap_output_file);
4825 
4828  Make_rotations();
4829  }
4830  else{ //need to create almass crop vector and do all the things that are done otherwise in Make_rotations
4833  m_rotation.push_back(tov_SpringBarley); //put there one crop for the hidden year - m_rotation is used to initialize
4834 
4835  //deal with perm crops (copied from make rotations):
4836  int area_perm = 0; //sum of areas of permanent crops
4837  int no_perm=0;
4838  for(int i = 0; i < (int)m_crops_almass.size(); i++){
4839  TTypesOfVegetation tov = m_crops_almass[i].Tov;
4840 
4842  tov==tov_PermanentGrassLowYield || tov==tov_YoungForest || tov==tov_OrchardCrop) { //|| tov==tov_Orchard
4843  int pct = (int)(m_crops_almass[i].Number + 0.5); //round a double to int
4844  PermCropData pcd = {tov, pct};
4845  m_PermCrops.push_back(pcd);
4846  no_perm++;
4847  area_perm += pct;
4848  }
4849  }
4850  }
4852  Print_rotations(ap_output_file);
4853  }
4854 
4855 }
void Print_FarmVariables(ofstream *ap_output_file)
Prints farm-level variables to a text file (one file for all farms).
Definition: farm.cpp:7568
void Make_rotational_crops()
Creates a vector m_rotational_crops using the results of optimisation.
Definition: farm.cpp:7808
void Print_rotations(ofstream *ap_output_file)
Prints the content of a farm&#39;s m_rotation. Not used in ALMaSS crop mode.
Definition: farm.cpp:7912
vector< AlmassCrop > m_crops_almass
Vector of structs with almass type crops with positive areas in % (result of optimisation).
Definition: farm.h:2057
void Make_rotations()
Creates m_rotation. Not used in ALMaSS crop mode.
Definition: farm.cpp:7926
void FarmLevelCalculation()
Calls functions determining farm level values before the initial optimisation.
Definition: farm.cpp:5136
TTypesOfVegetation
void Make_almass_crops_vector()
Creates a vector storing crops with positive area. Used in ALMaSS crop mode.
Definition: farm.cpp:7792
vector< TTypesOfVegetation > m_rotation
Definition: farm.h:840
virtual void createCropsLists(int a_foobar)
Creates lists of crops.
Definition: farm.cpp:5093
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< PermCropData > m_PermCrops
Definition: farm.h:841
Used for storing permanent crop data for the farm rotation.
Definition: farm.h:376
void OptimiseFarm(int a_foobar)
Carries out the whole farm optimisation.
Definition: farm.cpp:5288
void Translate_crops_to_almass()
Translates crops from Bedriftsmodel (original farm optimization model) to Almass crops. Used in Bedriftsmodel crop mode.
Definition: farm.cpp:7598
void OptimisingFarm::Initialize ( FarmManager a_pfm)
protected

Assigns to each farm its farm type, farm size, farm's real ID number, and soil type. It creates livestock and crops.

Definition at line 4710 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, g_msg, DataForOptimisation::Get_cropArea(), DataForOptimisation::Get_cropAreasSize(), DataForOptimisation::Get_cropTypes(), DataForOptimisation::Get_cropTypes_almass(), DataForOptimisation::Get_livestockNumber(), DataForOptimisation::Get_livestockNumbersSize(), DataForOptimisation::Get_livestockTypes(), DataForOptimisation::Get_noCrops(), DataForOptimisation::Get_rotationMax(), DataForOptimisation::Get_rotationMin(), m_almass_no, DataForOptimisation::m_farm_data, m_farmRealID, m_farmSize, m_farmType, Farm::m_OurManager, CropOptimised::m_rotationMax, CropOptimised::m_rotationMin, m_soilSubType, m_soilType, FarmManager::pm_data, Set_Crop(), Set_Livestock(), toa_Foobar, toc_Foobar, tofs_Foobar, tos_Foobar, tov_Undefined, CfgBool::value(), MapErrorMsg::Warn(), and WARN_BUG.

Referenced by OptimisingFarm().

4710  {
4711 
4712  //assign to each farm: farm type, farm size, real ID and soil type + soil subtype
4713  int size=(int)a_pfm->pm_data->m_farm_data.size();
4714  for(int i=0; i<size; i++){
4715  if(m_almass_no==a_pfm->pm_data->m_farm_data[i]->md_almass_no){
4716  m_farmType=a_pfm->pm_data->m_farm_data[i]->md_farmType;
4717  m_farmSize=a_pfm->pm_data->m_farm_data[i]->md_farmSize;
4718  m_farmRealID=a_pfm->pm_data->m_farm_data[i]->md_farmRealID;
4719  m_soilType=a_pfm->pm_data->m_farm_data[i]->md_soilType;
4720  m_soilSubType=a_pfm->pm_data->m_farm_data[i]->md_soilSubType;
4721  }
4722  }
4723 
4724  //create livestock
4725  for(int i=0; i<toa_Foobar; i++){
4726  int index=-1;
4727  int size=a_pfm->pm_data->Get_livestockNumbersSize();
4728  int j;
4729  for(j=0; j<size; j += (toa_Foobar+1)){
4730  if((a_pfm->pm_data->Get_livestockNumber(j))==m_almass_no){
4731  index=j;
4732  }
4733  }
4734  //test for index!!
4735  if(index==-1){
4736  g_msg->Warn( WARN_BUG, "Farm's almass_no doesn't match any of the numbers within the livestock numbers vector", "" );
4737  exit(0);
4738  }
4739  int index2 = index + 1 + i;
4740  int number = a_pfm->pm_data->Get_livestockNumber(index2);
4741  if (number!=0){
4742  Livestock * p_lvs;
4743  TTypesOfAnimals livestock_type = a_pfm->pm_data->Get_livestockTypes(i);
4744  p_lvs = new Livestock(livestock_type, number);
4745  Set_Livestock(p_lvs);
4746  }
4747  }
4748 
4749  //create crops
4750  int no_crops = (cfg_OptimiseBedriftsmodelCrops.value())? toc_Foobar : a_pfm->pm_data->Get_noCrops(); //bedriftsmodel crops/almass crops
4751 
4752  for(int i=0; i<no_crops; i++){ //crop areas vector contains only the crops that are used, not all tov types!
4753  int index=-1;
4754  int size=a_pfm->pm_data->Get_cropAreasSize();
4755  int j;
4756  for(j=0; j<size; j+=(no_crops+1)){ //+1 becuase in the vector we store also farm numbers
4757  if((a_pfm->pm_data->Get_cropArea(j))==m_almass_no){
4758  index=j;
4759  break;
4760  }
4761  }
4762  //test for index!!
4763  if(index==-1){
4764  g_msg->Warn( WARN_BUG, "Farm's almass_no doesn't match any of the numbers within the crop areas vector", "" );
4765  exit(0);
4766  }
4767  int index2= index + 1 + i;
4768  double area=a_pfm->pm_data->Get_cropArea(index2);
4769 
4770  int foobar = (cfg_OptimiseBedriftsmodelCrops.value())? (int)toc_Foobar : (int)tov_Undefined; //bedriftsmodel crops/almass crops
4771 
4772  CropOptimised *p_crop;
4773  int index3 = -1;
4775  TTypesOfCrops crop_type = a_pfm->pm_data->Get_cropTypes(i);
4776  p_crop = new CropOptimised(crop_type, area);
4777  index3 = foobar*tofs_Foobar*tos_Foobar*m_farmType + foobar*tofs_Foobar*m_soilType + foobar*m_farmSize + crop_type; //crop_type is TTypesOfCrops
4778  }
4779  else{
4780  TTypesOfVegetation crop_type = a_pfm->pm_data->Get_cropTypes_almass(i);
4781  p_crop = new CropOptimised(crop_type, area);
4782  index3 = foobar*tofs_Foobar*tos_Foobar*m_farmType + foobar*tofs_Foobar*m_soilType + foobar*m_farmSize + crop_type; //crop_type is TTypesOfVegetation
4783  }
4784  //added 01.05: save the rot max ad min
4785  p_crop->m_rotationMax = m_OurManager->pm_data->Get_rotationMax(index3);
4786  p_crop->m_rotationMin = m_OurManager->pm_data->Get_rotationMin(index3);
4787 
4788  //add crop to the list of crops
4789  Set_Crop(p_crop);
4790  }
4791 }
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 Set_Crop(CropOptimised *p_crop)
Definition: farm.h:1900
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
TTypesOfFarmSize m_farmSize
Scale of the farm - business (size above 10 ha) or private (size below 10 ha).
Definition: farm.h:2071
A class for storing livestock parameters and variables for optimising farms.
Definition: farm.h:1474
TTypesOfAnimals Get_livestockTypes(int i)
Definition: farm.h:514
double Get_cropArea(int index)
Definition: farm.h:523
TTypesOfVegetation
void Set_Livestock(Livestock *p_lvs)
Definition: farm.h:1899
int Get_livestockNumber(int index)
Definition: farm.h:521
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
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
double Get_rotationMax(int i)
Definition: farm.h:569
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
int m_farmRealID
Farm&#39;s real ID number.
Definition: farm.h:2073
TTypesOfCrops Get_cropTypes(int i)
Definition: farm.h:516
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
TTypesOfAnimals
Definition: farm.h:245
TTypesOfCrops
Definition: farm.h:269
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
int Get_livestockNumbersSize()
Definition: farm.h:522
TTypesOfVegetation Get_cropTypes_almass(int i)
Definition: farm.h:579
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
int Get_cropAreasSize()
Definition: farm.h:524
vector< FarmData * > m_farm_data
Definition: farm.h:601
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
int m_almass_no
Farm&#39;s almass number.
Definition: farm.h:2077
int Get_noCrops()
Definition: farm.h:585
double Get_rotationMin(int i)
Definition: farm.h:571
TTypesOfSoils m_soilType
Farm&#39;s soil type (sandy, clay, other).
Definition: farm.h:2069
void OptimisingFarm::InitiateManagement ( void  )
protectedvirtual

Kicks off the farm's management.

It assignes permanent crops (if there are any) to fields. In case there are no rotational crops it checks if there are any fields that haven't been assigned any permanent crop. In case there are, it assignes to a field a first permanent crop from the list of this farm's permanent crops.

Reimplemented from Farm.

Definition at line 4647 of file farm.cpp.

References Farm::AssignPermanentCrop(), Farm::InitiateManagement(), Farm::m_fields, Farm::m_PermCrops, and tov_Undefined.

4647  {
4648 
4653  // First we need to assign the permanent crops if any.
4654  if (m_PermCrops.size()>0) {
4655  // We have something to do
4656  for (int i=0; i<(int)m_PermCrops.size(); i++) {
4658  }
4659 
4660  //check if in case there are no rotational crops - all fields have been assigned a perm crop
4661  if(m_area_rot ==0) { //so there's need to check
4662  for(int i=0; i<(int)m_fields.size(); i++){
4663  if(m_fields[i]->GetRotIndex() != -4){ //there is a field that is not assigned a perm crop!
4664  m_fields[i]->SetRotIndex(-4);
4665  TTypesOfVegetation tov = m_PermCrops[0].Tov; //just take the first perm crop?
4666  m_fields[i]->SetVegType(tov, tov_Undefined); //need a tov of one of the assigned perm crops
4667  }
4668  }
4669  }
4670 
4671  }
4672 
4674 }
void AssignPermanentCrop(TTypesOfVegetation tov, int pct)
Used to assign a permanent crop to an otherwise rotational field polygon.
Definition: farm.cpp:1973
vector< LE * > m_fields
Definition: farm.h:839
virtual void InitiateManagement(void)
Kicks off the farm&#39;s management.
Definition: farm.cpp:1227
double m_area_rot
Area assigned to rotational crops. [ha].
Definition: farm.h:2123
TTypesOfVegetation
vector< PermCropData > m_PermCrops
Definition: farm.h:841
bool OptimisingFarm::InsecticideTreat ( LE a_field,
double  ,
int  a_days 
)
protectedvirtual

Carries out insecticide application. Saves information on each application for a given crop.

Reimplemented from Farm.

Definition at line 1006 of file farmfuncs.cpp.

References VegElement::Add_no_fi_app(), DO_IT_PROB, EL_TRAMLINE_DECAYTIME, g_weather, LE::GetSignal(), Weather::GetWind(), LE::Insecticide(), insecticide_treat, l_farm_insecticide_kills, LE_SIG_NO_INSECTICIDE, Weather::Raining(), LE::SetLastTreatment(), LE::SetTramlinesDecay(), LE::Trace(), and CfgBool::value().

1007 {
1008 
1009  if (0 >= a_days)
1010  {
1011  if (( ! (a_field->GetSignal() & LE_SIG_NO_INSECTICIDE) ))
1012  {
1013  // **CJT** Turn this code on to use the pesticide engine with insecticides
1014  // g_pest->DailyQueueAdd( a_field, l_pest_insecticide_amount.value());
1015  //
1016  a_field->Trace( insecticide_treat );
1017  a_field->SetLastTreatment( insecticide_treat );
1019  a_field->Insecticide( 0.36 );
1020  }
1022 
1024  Field * pf = dynamic_cast<Field*>(a_field);
1025  pf->Add_no_fi_app();
1026  }
1027 
1028  }
1029  return true;
1030  }
1031  else if ( (g_weather->GetWind()<4.5) && (!g_weather->Raining()) && DoIt(DO_IT_PROB))
1032  {
1033  if ( ! (a_field->GetSignal() & LE_SIG_NO_INSECTICIDE )) {
1034  // **CJT** Turn this code on to use the pesticide engine with insecticides
1035  // g_pest->DailyQueueAdd( a_field, l_pest_insecticide_amount.value());
1036  //
1037  a_field->Trace( insecticide_treat );
1038  a_field->SetLastTreatment( insecticide_treat );
1040  a_field->Insecticide( 0.36 );
1041  }
1043 
1045  Field * pf = dynamic_cast<Field*>(a_field);
1046  pf->Add_no_fi_app();
1047  }
1048  }
1049 
1050  return true;
1051  }
1052  return false;
1053 }
static CfgBool l_farm_insecticide_kills("FARM_INSECTICIDE_KILLS", CFG_CUSTOM, true)
bool DoIt(int a_probability)
Return chance out of 100.
Definition: farm.cpp:610
void SetTramlinesDecay(int a_decaytime_days)
Definition: elements.h:304
void Add_no_fi_app()
Definition: elements.h:579
double GetWind(long a_date)
Definition: weather.h:425
#define DO_IT_PROB
Definition: farmfuncs.cpp:58
class Weather * g_weather
Definition: weather.cpp:41
bool value(void)
Definition: configurator.h:123
bool Raining(void)
Definition: weather.h:432
CfgBool cfg_OptimiseBedriftsmodelCrops
If set to true, the original farm optimisation model&#39;s crop set is used in the farmer decision making...
void SetLastTreatment(int a_treatment)
Definition: elements.cpp:472
LE_Signal GetSignal(void)
Definition: elements.h:107
virtual void Insecticide(double)
Definition: elements.h:158
#define EL_TRAMLINE_DECAYTIME
Definition: elements.h:55
void Trace(int a_value)
Definition: elements.cpp:459
#define LE_SIG_NO_INSECTICIDE
Definition: elements.h:41
void OptimisingFarm::Make_almass_crops_vector ( )
protected

Creates a vector storing crops with positive area. Used in ALMaSS crop mode.

The function goes throught the list of all crops and attach them to the m_crops_almass vector if the area resulting from optimisation is larger than zero.

Definition at line 7792 of file farm.cpp.

References m_crops, and m_crops_almass.

Referenced by ChooseDecisionMode(), and Init().

7792  {
7796  m_crops_almass.clear();
7797 
7798  for(int i = 0; i < (int)m_crops.size(); i++){
7799  if(m_crops[i]->m_areaPercent > 0){
7800  TTypesOfVegetation tov = m_crops[i]->m_cropType_almass;
7801  AlmassCrop crop = { m_crops[i]->m_areaPercent, tov};
7802  m_crops_almass.push_back(crop);
7803  }
7804  }
7805 
7806 }
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
vector< AlmassCrop > m_crops_almass
Vector of structs with almass type crops with positive areas in % (result of optimisation).
Definition: farm.h:2057
TTypesOfVegetation
Struct for storing ALMaSS crop type (TTypesOfVegetation) with a corresponding value (mainly crop area...
Definition: farm.h:496
void OptimisingFarm::Make_rotational_crops ( )
protected

Creates a vector m_rotational_crops using the results of optimisation.

Definition at line 7808 of file farm.cpp.

References m_area_rot, m_crops_almass, m_rotational_crops, tov_CloverGrassGrazed1, tov_CloverGrassGrazed2, tov_OrchardCrop, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_PermanentSetaside, tov_SeedGrass1, tov_SeedGrass2, tov_SpringBarley, and tov_YoungForest.

Referenced by ChooseDecisionMode(), and Init().

7808  {
7809 
7810  //first deal with the probelmatic crops:CGG1 + CGG2 and SB, and SG1 + SG2
7811  double area_cgg=0;
7812  for(int i = 0; i < (int)m_crops_almass.size(); i++){
7813  if(m_crops_almass[i].Tov == tov_CloverGrassGrazed1){
7814  bool cg2=false;
7815  for(int j = 0; j < (int)m_crops_almass.size(); j++){
7816  if(m_crops_almass[j].Tov == tov_CloverGrassGrazed2){
7817  double pct = (m_crops_almass[i].Number + m_crops_almass[j].Number)/2; //take average
7818  m_crops_almass[i].Number = pct;
7819  m_crops_almass[j].Number = pct;
7820  area_cgg = pct;
7821  cg2=true;
7822  }
7823  }
7824  if(!cg2){ //there is cgg1 but not cgg2
7825  double pct = (m_crops_almass[i].Number)/2; //divide cgg1 area by two and save it in cgg1 and create cgg2
7826  m_crops_almass[i].Number = pct;
7827  area_cgg = pct;
7828  AlmassCrop cgg2 = {pct, tov_CloverGrassGrazed2};
7829  m_crops_almass.push_back(cgg2);
7830  }
7831  break;
7832  }
7833  }
7834 
7835  //cgg and sb
7836  bool sb=false;
7837  double new_area = area_cgg; //initialize with the current area of cgg - maybe it won't change
7838  for(int i = 0; i < (int)m_crops_almass.size(); i++){
7839  if(m_crops_almass[i].Tov == tov_SpringBarley){
7840  sb=true;
7841  double area_sb = m_crops_almass[i].Number;
7842  if(area_sb < area_cgg){ //problem
7843  new_area = (area_sb + 2*area_cgg)/3;
7844  m_crops_almass[i].Number = new_area;
7845  }
7846  break;
7847  }
7848  }
7849  if(!sb){ //there wasn't spring barley - need to add
7850  new_area = area_cgg*2/3;
7851  if(new_area >0){ //otherwise do not add sbarley
7852  AlmassCrop sb = {new_area, tov_SpringBarley};
7853  m_crops_almass.push_back(sb);
7854  }
7855  }
7856  //now find both cgg and change their areas
7857  for(int j = 0; j < (int)m_crops_almass.size(); j++){
7858  if(m_crops_almass[j].Tov == tov_CloverGrassGrazed1){
7859  m_crops_almass[j].Number = new_area;
7860  }
7861  if(m_crops_almass[j].Tov == tov_CloverGrassGrazed2){
7862  m_crops_almass[j].Number = new_area;
7863  }
7864  }
7865 
7866 
7867 
7868  //sg1 and sg2
7869  for(int i = 0; i < (int)m_crops_almass.size(); i++){
7870  if(m_crops_almass[i].Tov == tov_SeedGrass1){
7871  bool sg2=false;
7872  for(int j = 0; j < (int)m_crops_almass.size(); j++){
7873  if(m_crops_almass[j].Tov == tov_SeedGrass2){
7874  double pct = (m_crops_almass[i].Number + m_crops_almass[j].Number)/2; //take average
7875  m_crops_almass[i].Number = pct;
7876  m_crops_almass[j].Number = pct;
7877  sg2=true;
7878  }
7879  }
7880  if(!sg2){ //there is cgg1 but not cgg2
7881  double pct = (m_crops_almass[i].Number)/2; //divide cgg1 area by two and save it in cgg1 and create cgg2
7882  m_crops_almass[i].Number = pct;
7883  AlmassCrop sg2 = {pct, tov_SeedGrass2};
7884  m_crops_almass.push_back(sg2);
7885  }
7886  break;
7887  }
7888  }
7889 
7890  //first clear the current m_rotational_crops
7891  m_rotational_crops.clear();
7892 
7893  //then add rotational crops from the list of all crops - both rotational and permanent
7894  m_area_rot = 0;//sum of areas of rotational crops - need it for checking if there is any field without perm crops in case there are no rot. crops
7895  for(int i = 0; i < (int)m_crops_almass.size(); i++){
7896  TTypesOfVegetation tov = m_crops_almass[i].Tov;
7897 
7900  //do nothing - just need rotational crops
7901  }
7902  else {
7903  double pct = m_crops_almass[i].Number;
7904  if(pct<0.5) pct+=0.5; //thanks to that such crop won't disappear! (won't have area=0 after rounding)
7905  AlmassCrop pcd = {pct, tov};
7906  m_rotational_crops.push_back(pcd);
7907  m_area_rot += pct;
7908  }
7909  }
7910 }
vector< AlmassCrop > m_crops_almass
Vector of structs with almass type crops with positive areas in % (result of optimisation).
Definition: farm.h:2057
double m_area_rot
Area assigned to rotational crops. [ha].
Definition: farm.h:2123
TTypesOfVegetation
Struct for storing ALMaSS crop type (TTypesOfVegetation) with a corresponding value (mainly crop area...
Definition: farm.h:496
vector< AlmassCrop > m_rotational_crops
Vector of structs with almass type crops with positive areas in % (result of optimisation): includes ...
Definition: farm.h:2059
void OptimisingFarm::Make_rotations ( )
protected

Creates m_rotation. Not used in ALMaSS crop mode.

Used in the Bedriftsmodel crop mode. The function provides the functionality of the UserDefinedFarm's constructor:

  • it assigns true or false to the variable Farm::m_stockfarmer
  • creates a vector of permanent crops
  • creates a vector of rotational crops, m_rotation vector (size equal 100 or 0 in case there are only permanent crops) with a number of crop ocurrences corresponding to the optimised crop areas in percent of the total farm area.

Definition at line 7926 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, findCropByName(), findCropByName_almass(), g_msg, FarmManager::Get_lookup_table(), m_area_rot, CropOptimised::m_areaPercent, m_crops_almass, m_farmType, Farm::m_OurManager, Farm::m_PermCrops, Farm::m_rotation, m_rotational_crops, Farm::m_stockfarmer, toof_Cattle, toof_Pig, OptimisingFarm::MakeRotation::Tov, tov_CloverGrassGrazed1, tov_CloverGrassGrazed2, tov_FieldPeas, tov_FieldPeasSilage, tov_FodderBeet, tov_MaizeSilage, tov_OrchardCrop, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_PermanentSetaside, tov_Potatoes, tov_SeedGrass1, tov_SeedGrass2, tov_Setaside, tov_SpringBarley, tov_SpringRape, tov_Undefined, tov_WinterBarley, tov_WinterRape, tov_WinterWheat, tov_YoungForest, CfgBool::value(), MapErrorMsg::Warn(), and WARN_BUG.

Referenced by Init().

7926  {
7934  //1. STOCK FARM
7936  else m_stockfarmer = false;
7937 
7938  //2. INTENSITY - skip
7939 
7940  //3. PERMANENT vs ROTATIONAL CROPS
7941  //sort them and put into two vectors: m_PermCrops (member of Farm class, type: struct PermCropData) + local vector rotational_crops (type: struct AlmassCrop)
7942 
7943  int no_perm = 0;
7944  int no_rotational = 0;
7945  int area_perm = 0; //sum of areas of permanent crops
7946  m_area_rot = 0; //sum of areas of rotational crops
7947 
7948  for(int i = 0; i < (int)m_crops_almass.size(); i++){
7949  TTypesOfVegetation tov = m_crops_almass[i].Tov;
7950 
7953  int pct = (int)(m_crops_almass[i].Number + 0.5); //round a double to int
7954  PermCropData pcd = {tov, pct};
7955  m_PermCrops.push_back(pcd);
7956  no_perm++;
7957  area_perm += pct;
7958  }
7959  else {
7960  double pct = m_crops_almass[i].Number;
7961  if(pct<0.5) pct+=0.5; //thanks to that such crop won't disappear! (won't have area=0 after rounding)
7962  AlmassCrop pcd = {pct, tov};
7963  m_rotational_crops.push_back(pcd);
7964  no_rotational++;
7965  m_area_rot += pct;
7966  }
7967  }
7968 
7969  //4. ROTATIONAL CROPS
7970 
7971  //first check if there are any rotational crops!
7972  if(m_rotational_crops.size()!=0){
7973 
7974  m_rotation.resize(100);
7975  vector<TTypesOfVegetation>all_crops; //vector the has a right proportion of each crop tov type
7976  vector<MakeRotation>rotation;
7977  rotation.resize(100);
7978 
7979  //scale the rotational crop areas to account for the area that is reserved for permanent crops
7980  //and
7981  //save scaled areas of SBarley and CGG1 to make a check in the next step
7982  int area_rot_int = (int)(m_area_rot + 0.5); //area in percent of rot crops - as an integer
7983  int SBarley_area=0;
7984  int CGG1_area=0;
7985 
7986  for(int i=0; i<(int)m_rotational_crops.size(); i++){
7987  double area = m_rotational_crops[i].Number;
7988  int area_scaled = (int)(100 * area / area_rot_int + 0.5);
7989  m_rotational_crops[i].Number = area_scaled;
7990  if(m_rotational_crops[i].Tov == tov_CloverGrassGrazed1) CGG1_area = (int) m_rotational_crops[i].Number; //scaled area
7991  if(m_rotational_crops[i].Tov == tov_SpringBarley) SBarley_area = (int) m_rotational_crops[i].Number; //(this is scaled area)
7992  }
7993 
7994  //check if we have enough spring barley for CGG1 and CGG2 (area CGG1 = area CGG2); if not - change the areas so that
7995  //SBarley = CGG1 = CGG2 area.
7996  if(SBarley_area < CGG1_area){ //problem
7997  if(SBarley_area == 0){ //there's no sbarley! - need to create
7998  AlmassCrop sbarley = {0, tov_SpringBarley};
7999  m_rotational_crops.push_back(sbarley); //add sbarley
8000  }
8001  int new_area = (int)((CGG1_area * 2 + SBarley_area)/3 + 0.5); //= (CGG1 + CGG2 + SBarley)/3 ->and take integer
8002  for(int i=0; i<(int)m_rotational_crops.size(); i++){
8005  m_rotational_crops[i].Number = new_area;
8006  }
8007  }
8008  }
8009 
8010 
8011  //fill the all_crops vector with tov types -> in the right proportions
8012  for(int i = 0; i<(int)m_rotational_crops.size(); i++){
8013  int area = (int) m_rotational_crops[i].Number; //conversion to int - OK! - this is already int after the previous for loop
8014  for(int j = 0; j<area; j++){
8015  all_crops.push_back(m_rotational_crops[i].Tov);
8016  }
8017  }//now the size of all_crops might NOT be 100! - so check and make it to be 100?
8018 
8019  //sort the all_crops vector and rearrange it so that the probability of two crops that cannot follow each other is minimised
8020  //so - the order of the for loops below matter!!!
8021  vector<TTypesOfVegetation>all_crops_helper; //vector helper
8022 
8023  for(int i = (int)all_crops.size()-1; i>=0; i--){
8024  if(all_crops[i] == tov_SpringBarley) {
8025  all_crops_helper.push_back(all_crops[i]);
8026  all_crops.erase(all_crops.begin() + i);
8027  }
8028  }
8029 
8030  for(int i = (int)all_crops.size()-1; i>=0; i--){
8031  if(all_crops[i] == tov_CloverGrassGrazed1) {
8032  all_crops_helper.push_back(all_crops[i]);
8033  all_crops.erase(all_crops.begin() + i);
8034  }
8035  }
8036  for(int i = (int)all_crops.size()-1; i>=0; i--){
8037  if(all_crops[i] == tov_CloverGrassGrazed2) {
8038  all_crops_helper.push_back(all_crops[i]);
8039  all_crops.erase(all_crops.begin() + i);
8040  }
8041  }
8042  for(int i = (int)all_crops.size()-1; i>=0; i--){
8043  if(all_crops[i] == tov_FodderBeet) {
8044  all_crops_helper.push_back(all_crops[i]);
8045  all_crops.erase(all_crops.begin() + i);
8046  }
8047  }
8048  for(int i = (int)all_crops.size()-1; i>=0; i--){
8049  if(all_crops[i] == tov_WinterRape) {
8050  all_crops_helper.push_back(all_crops[i]);
8051  all_crops.erase(all_crops.begin() + i);
8052  }
8053  }
8054  for(int i = (int)all_crops.size()-1; i>=0; i--){
8055  if(all_crops[i] == tov_SpringRape) {
8056  all_crops_helper.push_back(all_crops[i]);
8057  all_crops.erase(all_crops.begin() + i);
8058  }
8059  }
8060  for(int i = (int)all_crops.size()-1; i>=0; i--){
8061  if(all_crops[i] == tov_Potatoes) {
8062  all_crops_helper.push_back(all_crops[i]);
8063  all_crops.erase(all_crops.begin() + i);
8064  }
8065  }
8066  for(int i = (int)all_crops.size()-1; i>=0; i--){
8067  if(all_crops[i] == tov_SeedGrass1) {
8068  all_crops_helper.push_back(all_crops[i]);
8069  all_crops.erase(all_crops.begin() + i);
8070  }
8071  }
8072  for(int i = 0; i<(int)all_crops.size(); i++){
8073  if(all_crops[i] == tov_SeedGrass2) {
8074  all_crops_helper.push_back(all_crops[i]);
8075  all_crops.erase(all_crops.begin() + i);
8076  }
8077  }
8078  for(int i = (int)all_crops.size()-1; i>=0; i--){
8079  if(all_crops[i] == tov_FieldPeas) {
8080  all_crops_helper.push_back(all_crops[i]);
8081  all_crops.erase(all_crops.begin() + i);
8082  }
8083  }
8084  for(int i = (int)all_crops.size()-1; i>=0; i--){
8085  if(all_crops[i] == tov_FieldPeasSilage) {
8086  all_crops_helper.push_back(all_crops[i]);
8087  all_crops.erase(all_crops.begin() + i);
8088  }
8089  }
8090  for(int i = (int)all_crops.size()-1; i>=0; i--){
8091  if(all_crops[i] == tov_WinterBarley) {
8092  all_crops_helper.push_back(all_crops[i]);
8093  all_crops.erase(all_crops.begin() + i);
8094  }
8095  }
8096  for(int i = (int)all_crops.size()-1; i>=0; i--){
8097  if(all_crops[i] == tov_WinterWheat) {
8098  all_crops_helper.push_back(all_crops[i]);
8099  all_crops.erase(all_crops.begin() + i);
8100  }
8101  }
8102  for(int i = (int)all_crops.size()-1; i>=0; i--){
8103  if(all_crops[i] == tov_Setaside) {
8104  all_crops_helper.push_back(all_crops[i]);
8105  all_crops.erase(all_crops.begin() + i);
8106  }
8107  }
8108 
8109  for(int i = (int)all_crops.size()-1; i>=0; i--){
8110  if(all_crops[i] == tov_MaizeSilage) {
8111  all_crops_helper.push_back(all_crops[i]);
8112  all_crops.erase(all_crops.begin() + i);
8113  }
8114  }
8115 
8116  //now place the other - remaining crops (in the all_crops vector) in further positions of the helper vector
8117  for(int i = 0; i<(int)all_crops.size(); i++){
8118  all_crops_helper.push_back(all_crops[i]);
8119  }
8120 
8121  //check if the size is 100 - correct if not
8122  if(all_crops_helper.size()!=100){
8123  if(all_crops_helper.size()>100){
8124  for(int i = (int)all_crops_helper.size(); i>100; i--){
8125  all_crops_helper.erase(all_crops_helper.end()-1); //just remove the last element
8126  }
8127  }
8128  else{ //<100
8129  for(int i = (int)all_crops_helper.size(); i<100; i++){
8130  if(all_crops_helper[i-2] != tov_CloverGrassGrazed2) all_crops_helper.push_back(all_crops_helper[i-2]); //this way I duplicate the ending (max 2/4 last elements)
8131  else all_crops_helper.push_back(tov_SpringBarley); //add spring barley
8132  }
8133  }
8134  }
8135 
8136  //copy the helper to all_crops
8137  all_crops = all_crops_helper;
8138 
8139 
8140  //fill the rotation vector with tov_Undefined
8141  for(int i = 0; i<(int)rotation.size(); i++){
8142  rotation[i].Tov = tov_Undefined;
8143  }
8144 
8145 
8146  // go through all_crops - should be 100...
8147 
8148  for(int i = 0; i < (int)all_crops.size(); i++){
8149 
8150  //find a place for the tov in the rotation vector:
8151  bool test=false;
8152  int count=0;
8153  TTypesOfVegetation crop_index = all_crops[i]; //current crop (tov) you want to place in a vector
8154 
8155  int step=no_rotational;
8156  int p=0;
8157 
8158  for(int j = p; count<101 && test==false; j=j+step){
8159  double sb_area = (cfg_OptimiseBedriftsmodelCrops.value())? findCropByName ("SBarley")->m_areaPercent : findCropByName_almass ("SpringBarley")->m_areaPercent;
8160  if (crop_index == tov_SpringBarley && sb_area > (100/step)) step = (int)(100/sb_area + 0.5);
8161  if(j>=100) {//without this we would always start out in the same position
8162  if (crop_index == tov_SpringBarley) {p+=3; j=p;} //special case - sbarley, cgg1 and cgg2; has to be 3 - doesn't work with 4
8163  else j=++p;
8164  }
8165 
8166  if(!(rotation[j].taken)){ //not taken - so check if it is allowed here - lookup
8167 
8168  TTypesOfVegetation crop_before, crop_after;
8169 
8170  crop_before = (j==0) ? rotation[99].Tov : rotation[j-1].Tov;
8171  crop_after = (j==99) ? rotation[0].Tov : rotation[j+1].Tov;
8172 
8173  int lookup_before = m_OurManager->Get_lookup_table(crop_before * (tov_Undefined+1) + crop_index); //check with a preceeding crop; tov_undef+1 - because this tov_undef is included in the lookup table
8174  int lookup_after = m_OurManager->Get_lookup_table(crop_index * (tov_Undefined+1) + crop_after); //check with a following crop
8175 
8176  if(lookup_before==-1 || lookup_after==-1){ //issue a warning: wrong index...
8177  char index[ 20 ];
8178  sprintf( index, "%d", crop_index);
8179  g_msg->Warn( WARN_BUG, "OptimisingFarm::Make_rotations(): Error (possibly caused by a new tov type that is not incuded in the crops_lookup table) in reading the lookup table; tov type that should not appear: ", index );
8180  exit( 1 );
8181  }
8182 
8183  if(lookup_before==1 && lookup_after==1){
8184  rotation[j].Tov = all_crops[i]; //same as crop_index
8185  rotation[j].taken = true;
8186  test=true;
8187  }
8188  else count++; //did not succeed in placing the crop, so increase the count
8189  }
8190  else{
8191  count++; //did not succeed in placing the crop, so increase the count
8192  }
8193 
8194  } //inner for loop: searching for a place for a given crop
8195 
8196  if(test==false){ //there is no place that does not break the lookup table rules
8197 
8198  //so try to go through the whole rotation and find a place where the current crop fits
8199 
8200  for(int r=0; r<(int)rotation.size() && test==false; r++){
8201 
8202  TTypesOfVegetation crop_before, crop_after;
8203 
8204  crop_before = rotation[r].Tov;
8205  crop_after = (r==99) ? rotation[0].Tov : rotation[r+1].Tov;
8206  int lookup_before = m_OurManager->Get_lookup_table(crop_before * (tov_Undefined+1) + crop_index); //check with a preceeding crop; tov_undef+1 - because this tov_undef is included in the lookup table
8207  int lookup_after = m_OurManager->Get_lookup_table(crop_index * (tov_Undefined+1) + crop_after); //check with a following crop
8208 
8209  if(lookup_before==1 && lookup_after==1){
8210  MakeRotation crop = {true, all_crops[i]};
8211  rotation.insert(rotation.begin() + r+1, crop); //->insert before element r+1
8212  test=true;
8213 
8214  //need to remove 1 element of the rotation! as 1 additional was just inserted
8215  //but this might cause troubles: two already placed elements might become incompatible...
8216 
8217  for(int p=(int)rotation.size()-1; p>=0; p--){//start at the end - more efficient, as here should be empty elements
8218  if(rotation[p].Tov == tov_Undefined){
8219  rotation.erase(rotation.begin() + p);
8220  //check if the 'new neighbours' can be next to each other
8221  crop_before = (p==0) ? rotation[99].Tov : rotation[p-1].Tov;
8222  crop_after = (p==100) ? rotation[0].Tov : rotation[p].Tov; //100 because the index is p
8223  int crop_after_position = (p==100) ? 0 : p;
8224 
8225  int lookup_before = m_OurManager->Get_lookup_table(crop_before * (tov_Undefined+1) + crop_after); //check with a preceeding crop; tov_undef+1 - because this tov_undef is included in the lookup table
8226 
8227  TTypesOfVegetation crop_before1, crop_after1, crop_before2;
8228  crop_before2=tov_Undefined; //for the begininng
8229  int crop_before2_position;
8230  int count2=0;
8231 
8232  while(lookup_before!=1){ //need to move somewhere the crop_after
8233 
8234  //check if there is no correct rotation possible
8235  if(count2>100){ //problem: impossible to make a rotation
8236  //so switch some crop...to Spring Barley
8237  TTypesOfVegetation problem_crop = rotation[crop_before2_position].Tov;
8238  rotation[crop_before2_position].Tov = tov_SpringBarley;
8239  //issue a message
8240  char index[ 20 ];
8241  sprintf( index, "%d", problem_crop);
8242  g_msg->Warn( WARN_BUG, "OptimisingFarm::Make_rotations(): The following crop was changed to spring barley: ", index );
8243  break; //break the if
8244  }
8245 
8246  crop_index = crop_after; //now crop_after is searching for a place
8247  bool test2=false;
8248  for(int t=0; t<(int)rotation.size() && test2==false; t++){
8249  crop_before1 = rotation[t].Tov;
8250  crop_after1 = (t==99) ? rotation[0].Tov : rotation[t+1].Tov;
8251  int lookup_before1 = m_OurManager->Get_lookup_table(crop_before1 * (tov_Undefined+1) + crop_index); //check with a preceeding crop; tov_undef+1 - because this tov_undef is included in the lookup table
8252  int lookup_after1 = m_OurManager->Get_lookup_table(crop_index * (tov_Undefined+1) + crop_after1); //check with a following crop
8253 
8254  if(lookup_before1==1 && lookup_after1==1){
8255  //check for indefinite loop
8256 
8257  bool skip=true;
8258  for(int s=crop_after_position; s!=t+1; s++){ //check locations between;
8259  if(s==100) s=0;
8260  TTypesOfVegetation crop = rotation[s].Tov;
8261  int lookup = m_OurManager->Get_lookup_table(crop_before2 * (tov_Undefined+1) + crop);
8262  if( lookup == 1){
8263  skip = false;
8264  break; //there is a different crop that the one that we removed (crop_index) - so there shouldnt be an infinite loop
8265  }
8266  }
8267 
8268  if(!skip){
8269 
8270  MakeRotation crop = {true, crop_index};
8271  rotation.insert(rotation.begin() + t+1, crop);
8272  //now the crop to be removed can be at the same or changed position, depending on where we inserted the crop
8273 
8274  if(t+1 > crop_after_position){ //OK
8275  rotation.erase(rotation.begin() + crop_after_position); //remove the crop that was just placed in a new position-from the old one
8276  crop_before2 = (crop_after_position==0) ? rotation[99].Tov : rotation[crop_after_position-1].Tov;
8277  crop_before2_position = (crop_after_position==0) ? 99 : crop_after_position-1;
8278  crop_after = (crop_after_position==99) ? rotation[0].Tov : rotation[crop_after_position].Tov;
8279  crop_after_position = (crop_after_position==99) ? 0 : crop_after_position;
8280  lookup_before = m_OurManager->Get_lookup_table(crop_before2 * (tov_Undefined+1) + crop_after);
8281  }
8282  else{
8283  rotation.erase(rotation.begin() + crop_after_position + 1); //can be 99+1 -ok, now the size is 101
8284  crop_before2 = (crop_after_position==0) ? rotation[99].Tov : rotation[crop_after_position].Tov;
8285  crop_before2_position = (crop_after_position==0) ? 99 : crop_after_position;
8286  crop_after = (crop_after_position==99) ? rotation[0].Tov : rotation[crop_after_position+1].Tov;
8287  crop_after_position = (crop_after_position==99) ? 0 : crop_after_position+1;
8288  lookup_before = m_OurManager->Get_lookup_table(crop_before2 * (tov_Undefined+1) + crop_after);
8289  }
8290  test2=true;
8291  }
8292 
8293  }
8294 
8295  }
8296  count2++;
8297  } //while
8298 
8299  break; //break the for (index p) loop, need to remove just one element
8300  }//undefined removed
8301  }//for:searching for an undef element to remove
8302  }//if:found a place to put an element that doesnt fit in any empty space left
8303  }//for: searching for a place for a problematic crop
8304 
8305  if(test==false){ //we have a problem
8306  char index[ 20 ];
8307  sprintf( index, "%d", crop_index);
8308  //sprintf( index, "%d", m_almass_no);
8309  g_msg->Warn( WARN_BUG, "OptimisingFarm::Make_rotations(): The following tov type cannot be assigned a place in the rotation: ", index );
8310  exit( 1 );
8311  }
8312 
8313  }//there's no empty space that fits for the current crop
8314  }//outer for loop: searcin for an empty spae for a current crop
8315 
8316 
8317  //copy the tovs from rotation vector to the m_rotation vector
8318  for(int i=0; i<100; i++){
8319  m_rotation[i] = rotation[i].Tov;
8320  }
8321 
8322  }//if there are any rotational crops
8323 
8324 else{ //no rotational crops
8325  m_rotation.resize(0);
8326  }
8327 }
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
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< AlmassCrop > m_crops_almass
Vector of structs with almass type crops with positive areas in % (result of optimisation).
Definition: farm.h:2057
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
double m_area_rot
Area assigned to rotational crops. [ha].
Definition: farm.h:2123
TTypesOfVegetation
double m_areaPercent
Area of a crop in percent of a farm&#39;s total area [%].
Definition: farm.h:1552
Struct for storing ALMaSS crop type (TTypesOfVegetation) with a corresponding value (mainly crop area...
Definition: farm.h:496
vector< TTypesOfVegetation > m_rotation
Definition: farm.h:840
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
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< AlmassCrop > m_rotational_crops
Vector of structs with almass type crops with positive areas in % (result of optimisation): includes ...
Definition: farm.h:2059
bool m_stockfarmer
Definition: farm.h:845
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
vector< PermCropData > m_PermCrops
Definition: farm.h:841
Used for storing permanent crop data for the farm rotation.
Definition: farm.h:376
Definition: farm.h:228
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
int Get_lookup_table(int index)
Definition: farm.h:1736
void OptimisingFarm::Match_crop_to_field ( LE a_field)

Finds a crop to be grown on a given field next year.

The function chooses a crop to grow in a given filed after the management plan of the current crop is finished.

  1. Creates a probability distribution of choosing rotational crops based on their planned areas (as percentages of a farm's area).
  2. Draws a number from the distribution and identifies which crop the number refers to.
  3. Checks if the crop is allowed to follow the current crop in a field, and if the difference between the field's area and crop's planned area is within acceptable range (to avoid growing too much of a given crop). If either of the conditions is not fulfilled, point 2 is repeated until a crop fulfilling both conditions is chosen. If this procedure fails in choosing a crop 20 times, the 2nd condition is released and the search is continued.
  4. If there is no crop fulfilling even just the 1st condition, the farm vector m_rotational_crops_copy is restarted, so that it includes all rotational crops a farmer wants to plant this year, including those that might have already been planted on other field this year.
  5. If there is still no crop that can follow a current crop, spring barley is grown (this situation happens when in the rotation there are only crops that can follow one specific crop, e.g. CloverGrassGrazed1 can follow only SpringBarley and CloverGrassGrazed2 can only follow CloverGrassGrazed1).
  6. When a crop to be grown is found, the function switches the rotation index to point to the crop placed in m_rotation before the chosen crop.

Definition at line 8684 of file farm.cpp.

References cfg_Areas_Based_on_Distribution, g_msg, FarmManager::Get_lookup_table(), LE::GetArea(), Farm::GetArea(), LE::GetVegType(), m_almass_no, Farm::m_fields, Farm::m_OurManager, Farm::m_rotation, m_rotational_crops, m_rotational_crops_copy, LE::SetRotIndex(), tov_CloverGrassGrazed1, tov_CloverGrassGrazed2, tov_OrchardCrop, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_PermanentSetaside, tov_SeedGrass1, tov_SeedGrass2, tov_SpringBarley, tov_SpringRape, tov_Undefined, tov_WinterRape, tov_YoungForest, CfgBool::value(), MapErrorMsg::Warn(), WARN_BUG, and WARN_FILE.

Referenced by Crop::ChooseNextCrop().

8684  {
8685 
8701  double field_size_pct = a_field->GetArea()/GetArea() * 100; //convert field size to pct of total arable farm area (a_rotational_crops will contain values of areas in %)
8702  TTypesOfVegetation current_crop =a_field->GetVegType();
8703  TTypesOfVegetation crop_to_grow = tov_Undefined;
8704 
8705  if(current_crop==tov_PermanentGrassGrazed || current_crop==tov_PermanentGrassTussocky || current_crop==tov_PermanentSetaside ||
8706  current_crop==tov_PermanentGrassLowYield || current_crop==tov_YoungForest || current_crop==tov_OrchardCrop) {
8707 
8708  crop_to_grow = current_crop; //and do not switch rot index - has to stay as it is to mark the field as perm
8709  }
8710  else{
8711 
8712  if((int)m_rotational_crops_copy.size()==0 ){ // in the 1st year it is empty since the choose dec. mode was not called yet!
8713  m_rotational_crops_copy = m_rotational_crops; //restart the copy - it is empty and we still need crops
8714  //debug
8715  if((int)m_rotational_crops_copy.size()==0){ //should not happen!
8716  char index[ 20 ];
8717  sprintf( index, "%d", m_almass_no);
8718  g_msg->Warn( WARN_BUG, "OptimisingFarm::Match_crop_to_field(): rot crops vector is empty! Farm no: ", index );
8719  exit( 1 );
8720  }
8721  }
8722 
8723  if (current_crop==tov_SeedGrass1){
8724  bool sg2=false;
8725  for(int i=0; i< (int)m_rotational_crops_copy.size(); i++){
8727  if(crop==tov_SeedGrass2) sg2 = true;
8728  }
8729  if (!sg2){ //there is no seedgrass2 in the list of crops. Otherwise just go to the normal procedure of choosing crop
8730  crop_to_grow = tov_SeedGrass2;
8731  }
8732  }
8733  if (current_crop==tov_CloverGrassGrazed1){
8734  bool cgg2=false;
8735  for(int i=0; i< (int)m_rotational_crops_copy.size(); i++){
8737  if(crop==tov_CloverGrassGrazed2) cgg2 = true;
8738  }
8739  if (!cgg2){ //there is no tov_CloverGrassGrazed2 in the list of crops. Otherwise just go to the normal procedure of choosing crop
8740  crop_to_grow = tov_CloverGrassGrazed2;
8741  }
8742  }
8743 
8744  if (current_crop!=tov_SpringBarley){
8745  bool other_crop_than_cgg = false;
8746  for(int i=0; i< (int)m_rotational_crops_copy.size(); i++){
8749  other_crop_than_cgg = true;
8750  break;
8751  }
8752  }
8753  if (!other_crop_than_cgg){ //there is no other tov than CGG1 or CGG2 in the list of crops. So need to grow smth which will fit - SB.
8754  crop_to_grow = tov_SpringBarley;
8755  }
8756  }
8757 
8758  bool Sb_inserted=false;
8759  if(crop_to_grow==tov_Undefined){ //if not, it is already CGG2 or SG
8760 
8761  //create the vector with numbers
8762  vector<int>probability_line;
8763  probability_line.push_back(0); //add the first element
8764  for(int i=0; i< (int)m_rotational_crops_copy.size(); i++){
8765  if(m_rotational_crops_copy[i].Number<0.5) m_rotational_crops_copy[i].Number += 0.5; //just in case - to avoid having crops that disappeear
8766  int area = (int)(m_rotational_crops_copy[i].Number + 0.5); //change to integer
8767  probability_line.push_back(area + (int)probability_line[probability_line.size() - 1]); //add a number equal to the sum of the current last element and this crop's area
8768  }
8769 
8770  //pick an index of a crop
8771  //see: http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution
8772  std::random_device rd;
8773  std::mt19937 gen(rd());
8774  int last_number = probability_line[(int)probability_line.size() - 1]; //the last number
8775  distribution_type2 dis(0, last_number - 1);
8776  double crop_index = 0;
8777 
8778  double diff = 0;
8779  int index_j = 0;
8780  bool crop_found = false;
8781  for(int c = 0; !crop_found; c++){
8782  crop_index = dis(gen); //int from a range 0 - sum of crop areas in percent - only crops that haven't been grown yet - on their 'full' i.e. planned area
8783  //which crop is it?
8784  for(int j=0; j < (int)probability_line.size(); j++){
8785  if(j==(int)probability_line.size()-1) { //unless j=0 smth's wrong: we didnt find this index
8786  if(j==0){ //there are no crops left - prob. line contains just one element - 0.why?
8787  char index[ 20 ];
8788  sprintf( index, "%d", (int) crop_index);
8789  g_msg->Warn( WARN_BUG, "OptimisingFarm::Match_crop_to_field(): no crops left, index drawn is ", index );
8790  exit( 1 );
8791  }
8792  else{
8793  char index[ 20 ];
8794  sprintf( index, "%d", (int) crop_index);
8795  g_msg->Warn( WARN_BUG, "OptimisingFarm::Match_crop_to_field(): index not found in the prob. line", index );
8796  exit( 1 );
8797  }
8798  }
8799  if(crop_index >= probability_line[j] && crop_index < probability_line[j+1]) {
8800  if(j >= (int)m_rotational_crops_copy.size()) { //problem
8801  char index[ 20 ];
8802  sprintf( index, "%d", j);
8803  g_msg->Warn( WARN_BUG, "OptimisingFarm::Match_crop_to_field(): index out of a range", index );
8804  exit( 1 );
8805  }
8806  crop_to_grow = m_rotational_crops_copy[j].Tov;
8807  index_j = j;
8808  break; //got the crop type
8809  }
8810 
8811  }
8812  //make a check
8813  int lookup_before = m_OurManager->Get_lookup_table(current_crop * (tov_Undefined+1) + crop_to_grow); //check with a preceeding crop; tov_undef+1 - because this tov_undef is included in the lookup table
8814  if(lookup_before==-1){ //issue a warning: wrong index...
8815  char index[ 20 ];
8816  sprintf( index, "%d", current_crop);
8817  g_msg->Warn( WARN_BUG, "OptimisingFarm::Match_crop_to_field(): Error (possibly caused by a new tov type that is not incuded in the crops_lookup table) in reading the lookup table; tov type that should not appear: ", index );
8818  exit( 1 );
8819  }
8820  if(lookup_before==1){ //if so, make another check - but not if we tried already 20 times - then release this constraint
8821 
8822  bool WRape_grown = false;
8823  if(cfg_Areas_Based_on_Distribution.value()){ //then another check: spring rape cannot be grown if the farm grows winter rape within 1000 m (www.landbrugsinfo.dk)
8824  if(crop_to_grow == tov_SpringRape){
8825  for(int w=0; w<(int)m_fields.size(); w++){
8826  if(m_fields[w]->GetVegType() == tov_WinterRape) WRape_grown = true;
8827  }
8828  }
8829  }
8830 
8831  if(c<20){
8832  diff = field_size_pct - m_rotational_crops_copy[index_j].Number;
8833  if(diff <= 20 && !WRape_grown){ //diff in size smaller than 20 percent points - ok. Plus there is no winter rape around in case the chosen crop is SRape
8834  crop_found=true;
8835  break; //break the for - this crop is OK
8836  }
8837  }
8838  else{
8839  diff = field_size_pct - m_rotational_crops_copy[index_j].Number;
8840  if(!WRape_grown){
8841  crop_found=true; //this crop must be accepted
8842  break;
8843  }
8844  }
8845  }
8846  if(c==1000 && !crop_found){ //seems there's no crop that can follow the current one, so restart the crops instead and continue the search!
8847  m_rotational_crops_copy = m_rotational_crops; //restart - that's not enough - need a new prob line
8848  probability_line.clear();
8849  probability_line.push_back(0); //add the first element
8850  for(int i=0; i< (int)m_rotational_crops_copy.size(); i++){
8851  if(m_rotational_crops_copy[i].Number<0.5) m_rotational_crops_copy[i].Number += 0.5; //necessary to avoid having crop disappeeared
8852  int area = (int)(m_rotational_crops_copy[i].Number + 0.5); //change to integer
8853  probability_line.push_back(area + (int)probability_line[probability_line.size() - 1]); //add a number equal to the sum of the current last element and this crop's area
8854  }
8855 
8856  last_number = probability_line[(int)probability_line.size() - 1]; //the last number
8857  distribution_type2 dis(0, last_number - 1);
8858  }
8859  if(c>1500){ //seems there's no crop that can follow the current one - issue a warning; but now do this only after restarting
8860  #ifdef _DEBUG
8861  char index[ 20 ];
8862  sprintf( index, "%d", current_crop);
8863  g_msg->Warn( WARN_BUG, "OptimisingFarm::Match_crop_to_field(): There is no crop that can follow the current crop. Sbarley will be grown. The current crop is: ", index );
8864  #endif
8865  crop_to_grow=tov_SpringBarley;
8866  Sb_inserted=true;
8867  break;
8868  //exit( 1 );
8869  }
8870  }
8871 
8872  //crop found, so update the vector of crops
8873  if(!Sb_inserted){
8874  if(diff < 0){ //crop area should be larger than this field's area
8875  m_rotational_crops_copy[index_j].Number -= field_size_pct;
8876  }
8877  else{
8878  if(m_rotational_crops_copy.size() <1){ //smth is wrong
8879  char index[ 20 ];
8880  sprintf( index, "%d", current_crop);
8881  g_msg->Warn( WARN_BUG, "OptimisingFarm::Match_crop_to_field(): m_rotational_crops_copy is empty, the crop chosen is: ", index );
8882  exit( 1 );
8883  }
8884  m_rotational_crops_copy.erase(m_rotational_crops_copy.begin() + index_j);
8885  }
8886  }
8887  }
8888 
8889  //switch the rotational index:
8890 
8891  //1. find the chosen crop in the m_rotation
8892  int position_in_mrotation=-1;
8893  int size=(int)m_rotation.size();
8894 
8895  for(int c=0; c< (int)m_rotation.size(); c++){
8896  if(m_rotation[c] == crop_to_grow){
8897  position_in_mrotation=c;
8898  break;
8899  }
8900  }
8901 
8902  if(position_in_mrotation==-1){
8903  char error_num[ 20 ];
8904  sprintf( error_num, "%d", crop_to_grow );
8905  g_msg->Warn( WARN_FILE, "OptimisingFarm::Match_crop_to_field(): ""Unknown vegetation type:", error_num );
8906  exit( 1 );
8907  }
8908  //2. switch the rot index to a crop just before the chosen one
8909  if(position_in_mrotation!=0){
8910  a_field->SetRotIndex(position_in_mrotation-1);
8911  }
8912  else{
8913  a_field->SetRotIndex(size-1);
8914  }
8915  }//current crop is a rotational crop
8916 }
vector< LE * > m_fields
Definition: farm.h:839
void SetRotIndex(int a_index)
Definition: elements.h:301
CfgBool cfg_Areas_Based_on_Distribution("AREAS_BASED_ON_DISTRIBUTION", CFG_CUSTOM, false)
If set to true, crops are assigned area based on their gross margin proportion in the total GM for al...
boost::random::uniform_int_distribution distribution_type2
TTypesOfVegetation
vector< AlmassCrop > m_rotational_crops_copy
A copy of m_rotational_crops used when matching crops to fields.
Definition: farm.h:2061
vector< TTypesOfVegetation > m_rotation
Definition: farm.h:840
virtual TTypesOfVegetation GetVegType(void)
Definition: elements.h:125
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
bool value(void)
Definition: configurator.h:123
vector< AlmassCrop > m_rotational_crops
Vector of structs with almass type crops with positive areas in % (result of optimisation): includes ...
Definition: farm.h:2059
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
int GetArea(void)
Returns the area of arable fields owned by that farm.
Definition: farm.cpp:1045
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
double GetArea(void)
Definition: elements.h:196
int m_almass_no
Farm&#39;s almass number.
Definition: farm.h:2077
int Get_lookup_table(int index)
Definition: farm.h:1736
void OptimisingFarm::OptimiseFarm ( int  a_foobar)
protected

Carries out the whole farm optimisation.

Definition at line 5288 of file farm.cpp.

References assignFixed(), cfg_Price_FU, Check_if_area_100(), checkRestrictions(), determineAreas(), determineAreas_ha(), m_crops, m_farmSize, m_totalBI, m_totalBIFi, m_totalBIHerb, m_totalCosts, m_totalFUt, m_totalGrooming, m_totalHoeing, m_totalIncome, m_totalN, m_totalNt, m_totalProfit, m_totalWeeding, m_variableCrops, optimizeCrops(), randomizeCropList(), sortCrops(), sumMinAreas(), tocv_BI, tocv_BIFi, tocv_BIHerb, tocv_Costs, tocv_GM, tocv_Grooming, tocv_Hoeing, tocv_Income, tocv_N, tocv_Nt, tocv_Weeding, tofs_Business, total(), and CfgFloat::value().

Referenced by ChooseDecisionMode(), and Init().

5288  {
5289 
5290  optimizeCrops(a_foobar);
5291  sortCrops(m_variableCrops, "GM" );//ORDER OPTIMISED CROPS WRT HIGHEST GM
5292  randomizeCropList(m_variableCrops, "GM"); //shuffles elements of the list with equal GMs
5293  assignFixed();
5294  sumMinAreas();
5295  determineAreas(a_foobar);
5296 
5297  if(m_farmSize == tofs_Business){
5299  }
5300 
5302 
5304 
5306  m_totalNt=total(tocv_Nt); //total amount of Nt at a farm - summed for all crops
5316  else m_totalProfit = total(tocv_GM);
5317 }
void sumMinAreas()
Adds minimum required areas of variable crops to the variable m_assigned.
Definition: farm.cpp:5817
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
Definition: farm.h:352
double m_totalBIHerb
Total amount of herbicides which is planned to be applied at a farm. Expressed as a Treatment frequen...
Definition: farm.h:2105
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
vector< CropSort > m_variableCrops
Vector of structs containing pointers to crops which are not fixed.
Definition: farm.h:2042
CfgFloat cfg_Price_FU("PRICE_FU", CFG_CUSTOM, 1.157)
Price of a fodder unit. [DKK/FU].
TTypesOfFarmSize m_farmSize
Scale of the farm - business (size above 10 ha) or private (size below 10 ha).
Definition: farm.h:2071
double total(TTypesOfCropVariables variable_name)
Function for determining total values per farm after initial optimisation.
Definition: farm.cpp:7500
Definition: farm.h:348
void Check_if_area_100()
Checks if the sum of crops&#39; areaPercent is 100%.
Definition: farm.cpp:7583
void assignFixed()
Adds areas of fixed crops to the variable m_assigned. For each fixed crop it saves its area under var...
Definition: farm.cpp:5798
double value(void)
Definition: configurator.h:107
double m_totalWeeding
Total manual weeding planned at a farm.
Definition: farm.h:2115
double m_totalFUt
Fodder from trade (has to be purchased). [fodder units].
Definition: farm.h:2095
void determineAreas_ha(vector< CropOptimised * >crops)
Determines areas of crops in ha.
Definition: farm.cpp:7490
Definition: farm.h:349
double m_totalCosts
Planned total costs of growing crops at a farm. [DKK].
Definition: farm.h:2117
virtual void determineAreas(int a_foobar)
Determines areas of variable crops.
Definition: farm.cpp:5827
virtual void checkRestrictions()
Checks if the restrictions are fulfilled and corrects crops&#39; areas if necessary.
Definition: farm.cpp:5933
double m_totalBIFi
Total amount of fung- and insecticides which is planned to be applied at a farm. Expressed as a Treat...
Definition: farm.h:2107
double m_totalProfit
Planned total profit (= income - costs) at a farm. In case of animal farms costs of purchased fodder ...
Definition: farm.h:2121
void optimizeCrops(int a_foobar)
Carries out crop optimisation at a farm.
Definition: farm.cpp:5319
Definition: farm.h:360
double m_totalGrooming
Total grooming planned at a farm.
Definition: farm.h:2111
double m_totalNt
Total amount of fertilizer purchased at a farm. [kg].
Definition: farm.h:2103
double m_totalIncome
Planned total income from growing crops at a farm. [DKK].
Definition: farm.h:2119
double m_totalHoeing
Total hoeing planned at a farm.
Definition: farm.h:2113
void sortCrops(vector< CropSort > &cropsToSort, string sortingKey)
Sorts structs of type CropSort.
Definition: farm.cpp:7311
double m_totalBI
Total amount of pesticides (sum of m_totalBIHerb and m_totalBIFi) which is planned to be applied at a...
Definition: farm.h:2109
double m_totalN
Total amount of fertilizer used at a farm. [kg].
Definition: farm.h:2101
void OptimisingFarm::optimizeCrops ( int  a_foobar)
protected

Carries out crop optimisation at a farm.

Function carrying out the optimisation of each crop for a given farm. It contains functions determining the optimal amounts (per ha) of fertilizer (animal and purchased), pesticides and mechanical weed control as well as functions finding response (yield per ha), yield loss and gross margin (profitability) of each crop.

Definition at line 5319 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, cfg_Price_FU, cfg_Price_Oats, cfg_Price_SBarley, cfg_Price_SRape, cfg_Price_Triticale, cfg_Price_WBarley, cfg_Price_WRape, cfg_Price_WWheat, cfg_Sensitivity_analysis, findBIs(), findFertilizer(), findGrossMargin(), findMWeedControl(), findResponse(), findYieldLoss(), fixBI(), DataForOptimisation::Get_fodder(), DataForOptimisation::Get_FUKey(), DataForOptimisation::Get_sellingPrice(), CropOptimised::m_benefit, m_crops, m_farmType, Farm::m_OurManager, m_soilType, FarmManager::pm_data, toc_Oats, toc_WWheat, toof_Cattle, toof_Pig, tos_Foobar, tov_Oats, tov_SpringBarley, tov_SpringRape, tov_Triticale, tov_WinterBarley, tov_WinterRape, tov_WinterWheat, CfgFloat::value(), and CfgBool::value().

Referenced by OptimiseFarm().

5319  {
5320 
5324  for (int i=0; i< (int) m_crops.size(); i++){
5325 
5326  //1. define the benefit; for non-fodder crops it is simply a selling price ;
5327  double benefit;
5328  int crop_type=(cfg_OptimiseBedriftsmodelCrops.value())? (int)m_crops[i]->m_cropType : (int)m_crops[i]->m_cropType_almass;
5329  int index = a_foobar*m_farmType + crop_type;
5330  bool fodder = m_OurManager->pm_data->Get_fodder(index);
5331  if(fodder){
5332  double FUKey = m_OurManager->pm_data->Get_FUKey(index);
5333  benefit = FUKey * cfg_Price_FU.value();
5334  }
5335  else {benefit = m_OurManager->pm_data->Get_sellingPrice(a_foobar*tos_Foobar*m_farmType + a_foobar*m_soilType + crop_type);}
5336 
5337  CropOptimised * crop = m_crops[i]; //define a pointer which is passed in the functions below
5338 
5339  crop->m_benefit = benefit; //added 090114
5340 
5341  //for SA: modify the prices of crops included in the analysis
5342  if(cfg_Sensitivity_analysis.value()){ //modify the prices only if this is a sensitivity analysis/calibration run
5344  if(crop_type==toc_Oats){
5345  if(m_farmType != toof_Pig && m_farmType != toof_Cattle){//don't modify for these farms - for them the price is zero for this crop - becasue it is a fodder crop!
5346  benefit = cfg_Price_Oats.value();
5347  }
5348  }
5349  else if(crop_type==toc_WWheat){ //not fodder
5350  benefit = cfg_Price_WWheat.value();
5351  }
5352  }
5353  else{//almass crop set
5354  if(crop_type==tov_SpringBarley){ //fodder for cattle and pig farms: price is zero if crop is a fodder crop. so changing price will affect only non-animal farms.
5355  if(m_farmType != toof_Pig && m_farmType != toof_Cattle){//don't modify for these farms - for them the price is zero for this crop - becasue it is a fodder crop!
5356  benefit = cfg_Price_SBarley.value();
5357  }
5358  }
5359  else if(crop_type==tov_Oats){ //f for c and p
5360  if(m_farmType != toof_Pig && m_farmType != toof_Cattle){//don't modify for these farms - for them the price is zero for this crop - becasue it is a fodder crop!
5361  benefit = cfg_Price_Oats.value();
5362  }
5363  }
5364  else if(crop_type==tov_WinterBarley){ //f for c and p
5365  if(m_farmType != toof_Pig && m_farmType != toof_Cattle){//don't modify for these farms - for them the price is zero for this crop - becasue it is a fodder crop!
5366  benefit = cfg_Price_WBarley.value();
5367  }
5368  }
5369  else if(crop_type==tov_WinterWheat){ //not fodder
5370  benefit = cfg_Price_WWheat.value();
5371  }
5372  else if(crop_type==tov_Triticale){
5373  if(m_farmType != toof_Cattle){//don't modify for these farms - for them the price is zero for this crop - becasue it is a fodder crop!
5374  benefit = cfg_Price_Triticale.value();
5375  }
5376  }
5377  else if(crop_type==tov_WinterRape){ //not fodder
5378  benefit = cfg_Price_WRape.value();
5379  }
5380  else if(crop_type==tov_SpringRape){ //not fodder
5381  benefit = cfg_Price_SRape.value();
5382  }
5383  }
5384  }
5385 
5386 
5387  //2. optimize the crop
5388  findFertilizer(crop, a_foobar, benefit);
5389  findResponse(crop, a_foobar);
5390  findBIs(crop, benefit);
5391  fixBI(); //added 22.03.13
5392  findMWeedControl(crop);
5393  findYieldLoss(crop);
5394  findGrossMargin(crop, a_foobar, benefit);
5395 
5396  }
5397 }
void findFertilizer(CropOptimised *a_crop, int a_foobar, double benefit)
Determines the optimal amounts of: total fertilizer (CropOptimised::m_n) and purchased fertilizer (Cr...
Definition: farm.cpp:5429
CfgFloat cfg_Price_SBarley("PRICE_SBARLEY", CFG_CUSTOM, 83)
TTypesOfOptFarms m_farmType
Farm&#39;s type (cattle, pig, plant, other).
Definition: farm.h:2067
void findBIs(CropOptimised *a_crop, double benefit)
Determines the optimal Treatment frequency indices (behandling index, BI in Danish) (CropOptimised::m...
Definition: farm.cpp:5570
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
CfgFloat cfg_Price_FU("PRICE_FU", CFG_CUSTOM, 1.157)
Price of a fodder unit. [DKK/FU].
double Get_FUKey(int i)
Definition: farm.h:561
CfgFloat cfg_Price_WWheat("PRICE_WWHEAT", CFG_CUSTOM, 94)
double value(void)
Definition: configurator.h:107
CfgFloat cfg_Price_Oats("PRICE_OATS", CFG_CUSTOM, 75)
double Get_sellingPrice(int i)
Definition: farm.h:564
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
void findGrossMargin(CropOptimised *a_crop, int a_foobar, double benefit)
Determines the gross margin (CropOptimised::m_GM) for a given crop at a farm.
Definition: farm.cpp:5748
void fixBI()
Sets values of Treatment frequency indices (BI) for crops with fixed amount of pesticides (CropOptimi...
Definition: farm.cpp:5646
CfgFloat cfg_Price_SRape("PRICE_SRAPE", CFG_CUSTOM, 163)
A class for storing all parameters and results of crop optimisation.
Definition: farm.h:1491
void findResponse(CropOptimised *a_crop, int a_foobar)
Determines the response (CropOptimised::m_resp) of a crop at a farm.
Definition: farm.cpp:5554
FarmManager * m_OurManager
Pointer to the FarmManager.
Definition: farm.h:837
void findYieldLoss(CropOptimised *a_crop)
Determines the yield losses (CropOptimised::m_lossHerb, CropOptimised::m_lossFi, CropOptimised::m_tot...
Definition: farm.cpp:5723
CfgFloat cfg_Price_Triticale("PRICE_TRITICALE", CFG_CUSTOM, 80)
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void findMWeedControl(CropOptimised *a_crop)
Determines the optimal mechanical weed control means (CropOptimised::m_grooming, CropOptimised::m_hoe...
Definition: farm.cpp:5676
CfgFloat cfg_Price_WBarley("PRICE_WBARLEY", CFG_CUSTOM, 93)
Definition: farm.h:228
Definition: farm.h:271
CfgFloat cfg_Price_WRape("PRICE_WRAPE", CFG_CUSTOM, 163)
CfgBool cfg_Sensitivity_analysis("SENSITIVITY_ANALYSIS", CFG_CUSTOM, false)
TTypesOfSoils m_soilType
Farm&#39;s soil type (sandy, clay, other).
Definition: farm.h:2069
double m_benefit
A value of selling price for non-fodder crops or a value of fodder units obtained from a hkg of a fod...
Definition: farm.h:1520
virtual void OptimisingFarm::preventCashCrops ( )
inlineprotectedvirtual

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

Reimplemented in OptimisingCattleFarm.

Definition at line 2150 of file farm.h.

Referenced by FarmLevelCalculation().

2150 {};
void OptimisingFarm::Print_FarmVariables ( ofstream *  ap_output_file)
protected

Prints farm-level variables to a text file (one file for all farms).

Prints farm level variables into one file (FarmVariables.txt).

Definition at line 7568 of file farm.cpp.

References m_almass_no, m_main_goal, m_Nanim, m_totalArea, m_totalBI, m_totalBIFi, m_totalBIHerb, m_totalCosts, m_totalFUdemand, m_totalFUdemandBefore, m_totalFUgrown, m_totalFUt, m_totalGrooming, m_totalHoeing, m_totalIncome, m_totalN, m_totalNanim, m_totalNt, m_totalProfit, and m_totalWeeding.

Referenced by Init().

7568  {
7571  //print the almass farm number
7572  (*ap_output_file) << m_almass_no << '\t';
7573 
7574  //print the values
7575  (*ap_output_file) << m_main_goal << '\t' << m_totalArea << '\t' << m_totalIncome<<'\t'<< m_totalCosts <<'\t'<< m_totalProfit <<'\t';
7576  (*ap_output_file) << m_totalFUdemand <<'\t' << m_totalFUdemandBefore << '\t' << m_totalFUt <<'\t'<< m_totalFUgrown << '\t';
7577  (*ap_output_file) << m_Nanim <<'\t'<< m_totalNanim <<'\t'<< m_totalNt <<'\t'<< m_totalN <<'\t';
7578  (*ap_output_file) << m_totalBI <<'\t'<< m_totalBIHerb <<'\t'<< m_totalBIFi <<'\t';
7579  (*ap_output_file) << m_totalGrooming <<'\t'<< m_totalHoeing <<'\t'<< m_totalWeeding <<'\t';
7580  (*ap_output_file) << endl;
7581 }
double m_totalFUgrown
Fodder grown, i.e. obtained from growing fodder crops. [fodder units].
Definition: farm.h:2097
double m_totalBIHerb
Total amount of herbicides which is planned to be applied at a farm. Expressed as a Treatment frequen...
Definition: farm.h:2105
TTypeOfFarmerGoal m_main_goal
Farmer&#39;s main goal (determined by a farmer&#39;s type) .
Definition: farm.h:1960
double m_Nanim
Amount of animal fertilizer available at a farm per hectar. [kg/ha].
Definition: farm.h:2089
double m_totalNanim
Total animal fertilizer at a farm. A sum of Livestock::m_NanimUsable (from all types of livestock)...
Definition: farm.h:2087
double m_totalWeeding
Total manual weeding planned at a farm.
Definition: farm.h:2115
double m_totalFUdemandBefore
Farm&#39;s total demand for fodder. [fodder units]
Definition: farm.h:2091
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
double m_totalCosts
Planned total costs of growing crops at a farm. [DKK].
Definition: farm.h:2117
double m_totalBIFi
Total amount of fung- and insecticides which is planned to be applied at a farm. Expressed as a Treat...
Definition: farm.h:2107
double m_totalProfit
Planned total profit (= income - costs) at a farm. In case of animal farms costs of purchased fodder ...
Definition: farm.h:2121
double m_totalGrooming
Total grooming planned at a farm.
Definition: farm.h:2111
double m_totalNt
Total amount of fertilizer purchased at a farm. [kg].
Definition: farm.h:2103
double m_totalIncome
Planned total income from growing crops at a farm. [DKK].
Definition: farm.h:2119
double m_totalHoeing
Total hoeing planned at a farm.
Definition: farm.h:2113
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
double m_totalBI
Total amount of pesticides (sum of m_totalBIHerb and m_totalBIFi) which is planned to be applied at a...
Definition: farm.h:2109
double m_totalN
Total amount of fertilizer used at a farm. [kg].
Definition: farm.h:2101
void OptimisingFarm::Print_rotations ( ofstream *  ap_output_file)
protected

Prints the content of a farm's m_rotation. Not used in ALMaSS crop mode.

Prints the content of m_rotation vector into the FarmVariables text file.

Definition at line 7912 of file farm.cpp.

References Farm::m_rotation.

Referenced by Init().

7912  {
7915  //print the almass farm number
7916  //(*ap_output_file) << m_almass_no << '\t';
7917 
7918  //print the content of the m_rotation vector
7919  for(int i=0; i<(int)m_rotation.size(); i++){
7920  TTypesOfVegetation crop = m_rotation[i];
7921  (*ap_output_file) << i << '\t' << crop << endl;
7922  }
7923  (*ap_output_file) << endl;
7924 }
TTypesOfVegetation
vector< TTypesOfVegetation > m_rotation
Definition: farm.h:840
double OptimisingFarm::Prob_multiplier ( )
virtual

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.

Reimplemented from Farm.

Definition at line 4895 of file farm.cpp.

References cfg_Yield_max_pest_prob_multiplier, m_main_goal, tofg_yield, and CfgFloat::value().

4895  {
4896 
4897  if(m_main_goal==tofg_yield){ // || m_pest_goal == tofg_yield){ //in case we give farmers different goals - include also the pest_goal
4899  }
4900  else return 1; //for other farmer types
4901 }
TTypeOfFarmerGoal m_main_goal
Farmer&#39;s main goal (determined by a farmer&#39;s type) .
Definition: farm.h:1960
CfgFloat cfg_Yield_max_pest_prob_multiplier("YIELD_MAX_PEST_PROB_MULITPLIER", CFG_CUSTOM, 1.5)
A parameter of the yield maximizer farmer type: it increases the chance of necessity of carrying out ...
double value(void)
Definition: configurator.h:107
void OptimisingFarm::randomizeCropList ( vector< CropSort > &  listToRandomize,
string  key 
)
protected

Swaps randomly elements of the list holding same values of the key (according to which the list was previosuly sorted).

Function randomly swaps elements of a sorted vector holding equal values of the key used for sorting. Uses a vector to carry out shuffling.

Definition at line 7334 of file farm.cpp.

References g_msg, MapErrorMsg::Warn(), and WARN_FILE.

Referenced by AnimalFarm::determineAreas(), and OptimiseFarm().

7334  {
7337  std::vector<CropSort>helper; //to store and shuffle elements with an equal value of a key
7338  helper.push_back(listToRandomize[0]); //save the first element of the list in the helper list
7339 
7340  for(int i=1; i<(int)listToRandomize.size(); i++){
7341  double key_current, key_previous;
7342  if(key=="GM"){
7343  key_current=listToRandomize[i].crop->m_GM;
7344  key_previous=listToRandomize[i-1].crop->m_GM;
7345  }
7346  else if (key=="Savings"){
7347  key_current=listToRandomize[i].crop->m_savings;
7348  key_previous=listToRandomize[i-1].crop->m_savings;
7349  }
7350  else if(key=="GM_Savings"){
7351  key_current=listToRandomize[i].crop->m_GM_Savings;
7352  key_previous=listToRandomize[i-1].crop->m_GM_Savings;
7353  }
7354  else{
7355  key_current=key_previous=0;
7356  g_msg->Warn( WARN_FILE, "OptimisingFarm::randomizeCropList():" "Unknown sorting key identificator", key.c_str() );
7357  exit(0);
7358  }
7359 
7360  if(key_current==key_previous){
7361  helper.push_back(listToRandomize[i]);
7362  }
7363  else{
7364  std::random_shuffle(helper.begin(), helper.end());
7365  //insert the elements of the vector - back to the original list
7366  //assign the elements of the vector in the reverse order (that's easier then the
7367  //normal order). The last element of the list has index = i-1.
7368  for(int j=(int)helper.size()-1; j>=0; j--){
7369  listToRandomize[i-1-j]=helper[j];
7370  }
7371  helper.clear(); //remove the elements...
7372  helper.push_back(listToRandomize[i]); //and 'start' a new vector with the current element
7373  }
7374  }
7375 }
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
void OptimisingFarm::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.

Definition at line 4995 of file farm.cpp.

References m_rotational_crops, and m_rotational_crops_visible.

Referenced by FarmManager::Save_last_years_crops_for_farms().

4995  {
4996 
4998 
4999 }
vector< AlmassCrop > m_rotational_crops
Vector of structs with almass type crops with positive areas in % (result of optimisation): includes ...
Definition: farm.h:2059
vector< AlmassCrop > m_rotational_crops_visible
Stores a copy of m_rotational_crops from a previous year and is accessible to farmers who want to cop...
Definition: farm.h:2063
void OptimisingFarm::Set_animals_no ( int  a_number)
inline

Definition at line 1916 of file farm.h.

Referenced by FarmManager::FarmManagement().

1916 {animals_no = a_number;};
int animals_no
Holds the number of animals in a farm at a particular day in a year (depends on a species)...
Definition: farm.h:2011
void OptimisingFarm::Set_Crop ( CropOptimised p_crop)
inline

Definition at line 1900 of file farm.h.

Referenced by Initialize().

1900 {m_crops.push_back(p_crop);};
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
void OptimisingFarm::Set_Livestock ( Livestock p_lvs)
inline

Definition at line 1899 of file farm.h.

Referenced by Initialize().

1899 {m_livestock.push_back(p_lvs);};
vector< Livestock * > m_livestock
Vector of pointers to animals belonging to a farm.
Definition: farm.h:2038
void OptimisingFarm::Set_main_goal ( TTypeOfFarmerGoal  a_goal)
inline

Definition at line 1914 of file farm.h.

1914 {m_main_goal = a_goal;};
TTypeOfFarmerGoal m_main_goal
Farmer&#39;s main goal (determined by a farmer&#39;s type) .
Definition: farm.h:1960
void OptimisingFarm::Set_Neighbour ( OptimisingFarm farm)
inline

Definition at line 1905 of file farm.h.

Referenced by FarmManager::FindNeighbours().

1905 {m_neighbours.push_back(farm);};
vector< OptimisingFarm * > m_neighbours
Vector of pointers to the farms considered neighbours (fulfilling the neighbourship condition) of a g...
Definition: farm.h:1965
void OptimisingFarm::setRotationCropsAtMax ( )
protected

Increases area of winter rotation crops to their max. allowed area.

void OptimisingFarm::sortCrops ( vector< CropSort > &  cropsToSort,
string  sortingKey 
)
protected

Sorts structs of type CropSort.

Function for sorting crops using sortingKey as a criterion for sorting. First argument is a vector of structs containing a pointer to a crop and a key.

Definition at line 7311 of file farm.cpp.

Referenced by OptimisingCattleFarm::checkCattleRotation(), AnimalFarm::checkWinterCrops(), NonAnimalFarm::checkWinterCrops(), AnimalFarm::checkWinterRotation1(), NonAnimalFarm::checkWinterRotation1(), AnimalFarm::determineAreas(), and OptimiseFarm().

7311  {
7315  if(sortKey=="GM"){
7316  for (int i=0; i<(int)cropsToSort.size(); i++){//define the key to sorting
7317  cropsToSort[i].key = cropsToSort[i].crop->m_GM;
7318  }
7319  }
7320  else if (sortKey=="Savings"){
7321  for (int i=0; i<(int)cropsToSort.size(); i++){//define the key to sorting
7322  cropsToSort[i].key = cropsToSort[i].crop->m_savings;
7323  }
7324  }
7325  else {
7326  for (int i=0; i<(int)cropsToSort.size(); i++){//define the key to sorting
7327  cropsToSort[i].key = cropsToSort[i].crop->m_GM_Savings;
7328  }
7329  }
7330 
7331  sort(cropsToSort.begin(), cropsToSort.end(), reverseSort());
7332 }
bool OptimisingFarm::Spraying_fungins ( TTypesOfVegetation  a_tov_type)
virtual

Returns true if a farmer decided to treat a given crop with fung- and insecticides.

Reimplemented from Farm.

Definition at line 4883 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, findCropByName_almass(), CropOptimised::m_BIFi, and CfgBool::value().

4883  {
4884 
4886  return true;
4887  }
4888  else{
4889  double BIfi = findCropByName_almass (a_tov_type)->m_BIFi;
4890  if (BIfi > 0) return true;
4891  else return false;
4892  }
4893 }
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
double m_BIFi
Value of BI for fung- and insecticides [BI/ha].
Definition: farm.h:1526
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 OptimisingFarm::Spraying_herbicides ( TTypesOfVegetation  a_tov_type)
virtual

Returns true if a farmer decided to treat a given crop with herbicides.

Reimplemented from Farm.

Definition at line 4871 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, findCropByName_almass(), CropOptimised::m_BIHerb, and CfgBool::value().

4871  {
4872 
4874  return true;
4875  }
4876  else{
4877  double BIherb = findCropByName_almass (a_tov_type)->m_BIHerb;
4878  if (BIherb > 0) return true;
4879  else return false;
4880  }
4881 }
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
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
double m_BIHerb
Value of BI for herbicides [BI/ha].
Definition: farm.h:1524
void OptimisingFarm::sumMinAreas ( )
protected

Adds minimum required areas of variable crops to the variable m_assigned.

The function adds the minimum required areas of variable crops to the variable m_assigned (which holds a share of the farm area excluded from the optimisation).

Definition at line 5817 of file farm.cpp.

References m_assigned, and m_variableCrops.

Referenced by OptimiseFarm().

5817  {
5821  for(int i=0; i<(int)m_variableCrops.size(); i++){
5822  double rotationMin = m_variableCrops[i].crop->m_rotationMin;
5823  m_assigned+=rotationMin; //the min area added to the area already assigned
5824  }
5825 }
vector< CropSort > m_variableCrops
Vector of structs containing pointers to crops which are not fixed.
Definition: farm.h:2042
double m_assigned
Variable holding a value of area already reserved for certain crops at a farm. [0-100%].
Definition: farm.h:2099
double OptimisingFarm::total ( TTypesOfCropVariables  variable_name)
protected

Function for determining total values per farm after initial optimisation.

Function for determining total values of crop variables per farm. Goes through the list of all crops. If an area of a crop is positive, it adds the area of this crop (in ha) multiplied by the value of a variable (per ha) to the total value per farm.

Definition at line 7500 of file farm.cpp.

References g_msg, m_crops, tocv_AreaHa, tocv_AreaPercent, tocv_BI, tocv_BIFi, tocv_BIHerb, tocv_Costs, tocv_GM, tocv_Grooming, tocv_Hoeing, tocv_Income, tocv_N, tocv_Nt, tocv_Response, tocv_Savings, tocv_TotalLoss, tocv_Weeding, MapErrorMsg::Warn(), and WARN_BUG.

Referenced by OptimiseFarm().

7500  {
7504  double totalAmount = 0;
7505  for (int i=0; i<(int)m_crops.size(); i++){
7506  double area_ha = m_crops[i]->m_area_ha;
7507  if(!area_ha==0){ //otherwise don't change totalAmount
7508  double value_per_ha;
7509  switch (a_var){
7510  case tocv_AreaPercent:
7511  value_per_ha = m_crops[i] ->m_areaPercent;
7512  break;
7513  case tocv_AreaHa:
7514  value_per_ha = m_crops[i] ->m_area_ha;
7515  break;
7516  case tocv_N:
7517  value_per_ha = m_crops[i] ->m_n;
7518  break;
7519  case tocv_Nt:
7520  value_per_ha = m_crops[i] ->m_nt;
7521  break;
7522  case tocv_BIHerb:
7523  value_per_ha = m_crops[i] ->m_BIHerb;
7524  break;
7525  case tocv_BIFi:
7526  value_per_ha = m_crops[i] ->m_BIFi;
7527  break;
7528  case tocv_BI:
7529  value_per_ha = m_crops[i] ->m_BI;
7530  break;
7531  case tocv_Grooming:
7532  value_per_ha = m_crops[i] ->m_grooming;
7533  break;
7534  case tocv_Hoeing:
7535  value_per_ha = m_crops[i] ->m_hoeing;
7536  break;
7537  case tocv_Weeding:
7538  value_per_ha = m_crops[i] ->m_weeding;
7539  break;
7540  case tocv_TotalLoss:
7541  value_per_ha = m_crops[i] ->m_totalLoss;
7542  break;
7543  case tocv_Response:
7544  value_per_ha = m_crops[i] ->m_resp;
7545  break;
7546  case tocv_Income:
7547  value_per_ha = m_crops[i] ->m_income_ha;
7548  break;
7549  case tocv_Costs:
7550  value_per_ha = m_crops[i] ->m_costs_ha;
7551  break;
7552  case tocv_GM:
7553  value_per_ha = m_crops[i] ->m_GM;
7554  break;
7555  case tocv_Savings:
7556  value_per_ha = m_crops[i] ->m_savings;
7557  break;
7558  default:
7559  g_msg->Warn( WARN_BUG, "OptimisingFarm::total(): ""Unknown crop variable type! ", "" );
7560  exit( 1 );
7561  }
7562  totalAmount += value_per_ha * area_ha; //each crop's/(field's) optimal values per ha multiplied by acreage of a crop
7563  }
7564  }
7565  return totalAmount;
7566  }
Definition: farm.h:352
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
Definition: farm.h:348
Definition: farm.h:349
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
Definition: farm.h:360
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
void OptimisingFarm::Translate_crops_to_almass ( )
protected

Translates crops from Bedriftsmodel (original farm optimization model) to Almass crops. Used in Bedriftsmodel crop mode.

The function takes a vector m_crops as an input. It goes through all crops; for those with a positive areaPercent, it finds an equivalent in almass crops. The output is a vector of structs AlmassCrop (with 2 members: area in percent and tov, type of vegetation).

Definition at line 7598 of file farm.cpp.

References g_msg, m_crops, m_crops_almass, tov_Carrots, tov_CloverGrassGrazed1, tov_CloverGrassGrazed2, tov_FieldPeas, tov_FieldPeasSilage, tov_FodderBeet, tov_FodderGrass, tov_MaizeSilage, tov_Oats, tov_OrchardCrop, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_PermanentSetaside, tov_Potatoes, tov_PotatoesIndustry, tov_SeedGrass1, tov_SeedGrass2, tov_Setaside, tov_SpringBarley, tov_SpringBarleySilage, tov_SpringRape, tov_Triticale, tov_WinterBarley, tov_WinterRape, tov_WinterRye, tov_WinterWheat, tov_YoungForest, MapErrorMsg::Warn(), and WARN_BUG.

Referenced by Init().

7598  {
7603  for(int i = 0; i < (int)m_crops.size(); i++){
7604  if(m_crops[i]->m_areaPercent > 0){
7605  TTypesOfCrops toc = m_crops[i]->m_cropType; //Bedriftsmodel crop type
7606  TTypesOfVegetation tov;
7607 
7608  switch (toc) {
7609  case 0: //toc_SBarley
7610  tov = tov_SpringBarley;
7611  break;
7612  case 1: //toc_Oats
7613  tov = tov_Oats;
7614  break;
7615  case 2: //toc_OSCrops
7616  tov = tov_SpringBarley; //spring wheat - no code for this crop
7617  break;
7618  case 3: //toc_WBarley
7619  tov = tov_WinterBarley;
7620  break;
7621  case 4: //toc_WWheat
7622  tov = tov_WinterWheat;
7623  break;
7624  case 5: //toc_WRye
7625  tov = tov_WinterRye;
7626  break;
7627  case 6: //toc_Triticale
7628  tov = tov_Triticale;
7629  break;
7630  case 7: //toc_SRape
7631  tov = tov_SpringRape;
7632  break;
7633  case 8: //toc_WRape
7634  tov = tov_WinterRape;
7635  break;
7636  case 9: //toc_OOilseed
7637  tov = tov_WinterRape;
7638  break;
7639  case 10: //toc_Peas
7640  tov = tov_FieldPeas;
7641  break;
7642  case 11: //toc_OLSeed
7643  tov = tov_FieldPeas;
7644  break;
7645  case 12: //toc_GrassSeed //TRANSLATES TO TWO ALMASS CROPS
7646  tov = tov_SeedGrass1; //this translates to both tov_SeedGrass1 and tov_SeedGrass2; thus sg2 has to be considered in the rotation vector after the sg1; both get area percent = half of the original crop area percent
7647  break;
7648  case 13: //toc_Potato
7649  tov = tov_PotatoesIndustry;
7650  break;
7651  case 14: //toc_PotatoFood
7652  tov = tov_Potatoes;
7653  break;
7654  case 15: //toc_SugarBeet
7655  tov = tov_FodderBeet;
7656  break;
7657  case 16: //toc_GrassClover //TRANSLATES TO TWO ALMASS CROPS
7658  tov = tov_CloverGrassGrazed1; // also tov_CloverGrassGrazed2; need to first aggregate with CloverGrz and then divide the sum by two!
7659  break;
7660  case 17: //toc_OLSeedCut
7661  tov = tov_FieldPeasSilage;
7662  break;
7663  case 18: //toc_SCerealSil
7664  tov = tov_SpringBarleySilage; //undersown
7665  break;
7666  case 19: //toc_PeasSil
7667  tov = tov_FieldPeasSilage;
7668  break;
7669  case 20: //toc_MaizeSil
7670  tov = tov_MaizeSilage; //
7671  break;
7672  case 21: //toc_WCerealSil
7673  tov = tov_SpringBarleySilage;
7674  break;
7675  case 22: //toc_SCerealG
7676  tov = tov_SpringBarleySilage;
7677  break;
7678  case 23: //toc_PerGrassLow
7680  break;
7681  case 24: //toc_PerGrassNorm
7683  break;
7684  case 25: //toc_GrassEnv1
7685  tov = tov_PermanentGrassTussocky; // is aggregated with GrassEnv2
7686  break;
7687  case 26: //toc_GrassEnv2
7688  tov = tov_PermanentGrassTussocky; // is aggregated with GrassEnv1
7689  break;
7690  case 27: //toc_GrassRot
7691  tov = tov_FodderGrass;
7692  break;
7693  case 28: //toc_Setaside
7694  tov = tov_Setaside;
7695  break;
7696  case 29: //toc_Uncult
7697  tov = tov_PermanentSetaside;
7698  break;
7699  case 30: //toc_OUncult
7700  tov = tov_PermanentSetaside;
7701  break;
7702  case 31: //toc_FodderBeet
7703  tov = tov_FodderBeet;
7704  break;
7705  case 32: //toc_CloverGrz //TRANSLATES TO TWO ALMASS CROPS
7706  tov = tov_CloverGrassGrazed1; // also tov_CloverGrassGrazed2; need to first aggregate with GrassClover and then divide the sum by two!
7707  break;
7708  case 33: //toc_Veg
7709  tov = tov_Carrots;
7710  break;
7711  case 34: //toc_Fruit
7712  tov = tov_OrchardCrop;
7713  break;
7714  case 35: //toc_FruitTree
7715  tov = tov_OrchardCrop;
7716  break;
7717  case 36: //toc_OSpecCrops
7718  tov = tov_Carrots; // could be also smth else
7719  break;
7720  case 37: //toc_ChrisTree
7721  tov = tov_YoungForest;
7722  break;
7723  case 38: //toc_EnergyFor
7724  tov = tov_YoungForest; // ideally should be willow
7725  break;
7726  case 39: //toc_Other
7727  tov = tov_Carrots; // this also could be smth else
7728  break;
7729  default:
7730  g_msg->Warn( WARN_BUG, "OptimisingFarm::Translate_crops_to_almass(): ""Unknown crop type! ", "" );
7731  exit( 1 );
7732  }
7733 
7734  //try not separating fixed from variables crops
7735  AlmassCrop crop = { m_crops[i]->m_areaPercent, tov};
7736  m_crops_almass.push_back(crop);
7737 
7738  } //if
7739  }//for
7740 
7741  //aggregate the almass crops that are in >1 position in the m_crops vector - so that they are listed only once
7742 
7743  vector<AlmassCrop>crops_almass_aggregated;
7744  int size = (int)m_crops_almass.size();
7745 
7746  for(int i = 0; i < size; i++){
7747  TTypesOfVegetation tov1 = m_crops_almass[i].Tov;
7748  double summaryArea = m_crops_almass[i].Number; //initialize
7749  bool skip = false;
7750 
7751  for(int p = 0; p < i; p++){ //check if this tov was already aggregated (so check elements of the vector before this one)
7752  if(m_crops_almass[p].Tov == tov1){ //this tov is already aggregated, so skip i element
7753  skip = true;
7754  }
7755  }
7756  if (!skip){
7757  for(int j = i+1; j < size; j++){ // start comparing with the crop following the one at position i
7758  if(m_crops_almass[j].Tov == tov1){
7759  summaryArea += m_crops_almass[j].Number; //add area to the summary area
7760  }
7761  }
7762  AlmassCrop crop = {summaryArea, m_crops_almass[i].Tov, };
7763  crops_almass_aggregated.push_back(crop);
7764  }
7765  }
7766  m_crops_almass = crops_almass_aggregated; //save the aggregated crops in m_crops_almass vector
7767 
7768 
7769  //now deal with the crops that translate to more than one almass crop, i.e.:
7770  //1) GrassClover + CloverGrz = CGG1 + CGG2
7771  //2) GrassSeed = SG1 + SG2
7772 
7773 
7774  for(int i = 0; i < (int)m_crops_almass.size(); i++){
7775  if(m_crops_almass[i].Tov == tov_CloverGrassGrazed1){
7776  double pct = (m_crops_almass[i].Number)/2; //have to divide the area between CGG1 and CGG2
7777  m_crops_almass[i].Number = pct;
7778  AlmassCrop cgg2 = {pct, tov_CloverGrassGrazed2};
7779  m_crops_almass.push_back(cgg2);
7780  }
7781  if(m_crops_almass[i].Tov == tov_SeedGrass1){
7782  double pct = (m_crops_almass[i].Number)/2; //have to divide the area between SG1 and SG2
7783  m_crops_almass[i].Number = pct;
7784  AlmassCrop sg2 = {pct, tov_SeedGrass2};
7785  m_crops_almass.push_back(sg2);
7786  }
7787  }
7788 
7789 }
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
Definition: farm.h:2040
vector< AlmassCrop > m_crops_almass
Vector of structs with almass type crops with positive areas in % (result of optimisation).
Definition: farm.h:2057
TTypesOfVegetation
Struct for storing ALMaSS crop type (TTypesOfVegetation) with a corresponding value (mainly crop area...
Definition: farm.h:496
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
TTypesOfCrops
Definition: farm.h:269
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56

Member Data Documentation

int OptimisingFarm::animals_no
protected

Holds the number of animals in a farm at a particular day in a year (depends on a species).

Definition at line 2011 of file farm.h.

Referenced by ActualProfit(), and OptimisingFarm().

bool OptimisingFarm::force_deliberation
protected

If set to true, a farm must use deliberation as a decision strategy.

Definition at line 2009 of file farm.h.

Referenced by ActualProfit(), ChooseDecisionMode(), and OptimisingFarm().

double OptimisingFarm::m_actual_aggregated_yield
protected

Actual aggregated yield at a farm in a given year.

Sum of yield ratios (actual to expected yield) from all grown crops.

Definition at line 1988 of file farm.h.

Referenced by ActualProfit(), and OptimisingFarm().

double OptimisingFarm::m_actual_costs
protected

Actual costs at a farm in a given year.

Definition at line 1983 of file farm.h.

Referenced by ActualProfit(), and OptimisingFarm().

double OptimisingFarm::m_actual_income
protected

An actual income at a farm in a given year.

Definition at line 1979 of file farm.h.

Referenced by ActualProfit(), and OptimisingFarm().

double OptimisingFarm::m_actual_profit
protected

An actual profit realised at a farm in a given year.

Definition at line 1975 of file farm.h.

Referenced by ActualProfit(), and OptimisingFarm().

int OptimisingFarm::m_almass_no
protected
vector<double> OptimisingFarm::m_animals_numbers
protected

Vector for storing numbers of animals at a farm in previous years (3).

Definition at line 2007 of file farm.h.

Referenced by ActualProfit(), and OptimisingFarm().

double OptimisingFarm::m_area_rot
protected

Area assigned to rotational crops. [ha].

Definition at line 2123 of file farm.h.

Referenced by Make_rotational_crops(), and Make_rotations().

double OptimisingFarm::m_area_scaling_factor
protected

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.

Definition at line 2085 of file farm.h.

Referenced by assignFixed(), findFodderDemand(), findTotalArea(), and findTotalNanim().

double OptimisingFarm::m_assigned
protected

Variable holding a value of area already reserved for certain crops at a farm. [0-100%].

Definition at line 2099 of file farm.h.

Referenced by assignFixed(), determineAreas(), AnimalFarm::determineAreas(), and sumMinAreas().

double OptimisingFarm::m_certainty_level
protected

Farmer's certainty level.

Definition at line 1969 of file farm.h.

Referenced by ChooseDecisionMode().

vector<CropOptimised*> OptimisingFarm::m_crops
protected
vector<AlmassCrop> OptimisingFarm::m_crops_almass
protected

Vector of structs with almass type crops with positive areas in % (result of optimisation).

Definition at line 2057 of file farm.h.

Referenced by Init(), Make_almass_crops_vector(), Make_rotational_crops(), Make_rotations(), and Translate_crops_to_almass().

vector<int> OptimisingFarm::m_decision_mode_counters
protected

Vector with counters for each decision mode. 0 - imitation, 1 - social comparison, 2 - repeat, 3 - deliberation.

Definition at line 1971 of file farm.h.

Referenced by ChooseDecisionMode(), and OptimisingFarm().

double OptimisingFarm::m_exp_aggregated_yield
protected

Expected aggregated yield at a farm in a given year.

Equal to a number of fields with crops with positive CropOptimised::m_resp values.

Definition at line 1991 of file farm.h.

Referenced by ActualProfit().

double OptimisingFarm::m_exp_costs
protected

Expected costs at a farm in a given year.

Definition at line 1985 of file farm.h.

Referenced by ActualProfit(), and OptimisingFarm().

double OptimisingFarm::m_exp_income
protected

An expected farm's income at a farm in a given year.

Definition at line 1981 of file farm.h.

Referenced by ActualProfit(), and OptimisingFarm().

double OptimisingFarm::m_exp_profit
protected

An expected farm's profit for a given year.

Definition at line 1977 of file farm.h.

Referenced by ActualProfit(), and OptimisingFarm().

int OptimisingFarm::m_farmRealID
protected

Farm's real ID number.

Definition at line 2073 of file farm.h.

Referenced by Initialize().

TTypesOfFarmSize OptimisingFarm::m_farmSize
protected

Scale of the farm - business (size above 10 ha) or private (size below 10 ha).

Definition at line 2071 of file farm.h.

Referenced by Find_neighbour_to_imitate(), Initialize(), and OptimiseFarm().

TTypesOfOptFarms OptimisingFarm::m_farmType
protected
vector<CropOptimised*> OptimisingFarm::m_fixedCrops
protected

Vector of pointers to fixed crops.

Definition at line 2051 of file farm.h.

Referenced by assignFixed(), AnimalFarm::correctFodderDemand(), and createVariableCrops().

vector<CropOptimised*> OptimisingFarm::m_grownVariableCrops
protected

Vector of pointers to variable crops that are grown on area larger than areaMin (after determineAreas function was called).

Definition at line 2049 of file farm.h.

Referenced by determineAreas(), AnimalFarm::determineAreas(), AnimalFarm::determineFodderAreas(), and AnimalFarm::determineMinFodder().

vector<Livestock*> OptimisingFarm::m_livestock
protected

Vector of pointers to animals belonging to a farm.

Definition at line 2038 of file farm.h.

Referenced by findFodderDemand(), and findTotalNanim().

TTypeOfFarmerGoal OptimisingFarm::m_main_goal
protected

Farmer's main goal (determined by a farmer's type) .

Definition at line 1960 of file farm.h.

Referenced by ActualProfit(), ChooseDecisionMode(), findBIs(), findFertilizer(), OptimisingFarm(), Print_FarmVariables(), and Prob_multiplier().

double OptimisingFarm::m_Nanim
protected

Amount of animal fertilizer available at a farm per hectar. [kg/ha].

Definition at line 2089 of file farm.h.

Referenced by findFertilizer(), findNanim(), and Print_FarmVariables().

double OptimisingFarm::m_need_satisfaction_level
protected

Farmer's actual satisfaction level.

Definition at line 1967 of file farm.h.

Referenced by ActualProfit(), and ChooseDecisionMode().

vector<OptimisingFarm*> OptimisingFarm::m_neighbours
protected

Vector of pointers to the farms considered neighbours (fulfilling the neighbourship condition) of a given farm.

Definition at line 1965 of file farm.h.

Referenced by Find_neighbour_to_imitate().

vector<double> OptimisingFarm::m_previous_aggregated_yields
protected

Vector of aggregated yields from previous years.

Definition at line 2000 of file farm.h.

Referenced by ActualProfit().

vector<double> OptimisingFarm::m_previous_costs
protected

Vector of costs from previous years.

Definition at line 1998 of file farm.h.

Referenced by ActualProfit().

vector<double> OptimisingFarm::m_previous_incomes
protected

Vector of incomes from previous years.

Definition at line 1996 of file farm.h.

Referenced by ActualProfit().

vector<double> OptimisingFarm::m_previous_profits
protected

Vector of profits from previous years.

Definition at line 1994 of file farm.h.

Referenced by ActualProfit().

vector<double> OptimisingFarm::m_previous_satisfaction_levels
protected

Vector of satisfaction levels in five previous years.

Definition at line 2002 of file farm.h.

Referenced by ActualProfit(), and ChooseDecisionMode().

OptimisingFarm* OptimisingFarm::m_previously_imitated_neighbour
protected

The neighbouring farmer whose crops might be copied in imitation and social comparison decision modes.

Definition at line 2004 of file farm.h.

Referenced by ChooseDecisionMode(), Find_neighbour_to_imitate(), and OptimisingFarm().

vector<AlmassCrop> OptimisingFarm::m_rotational_crops
protected

Vector of structs with almass type crops with positive areas in % (result of optimisation): includes only rotational crops.

Definition at line 2059 of file farm.h.

Referenced by ChooseDecisionMode(), Make_rotational_crops(), Make_rotations(), Match_crop_to_field(), and Save_last_years_crops().

vector<AlmassCrop> OptimisingFarm::m_rotational_crops_copy
protected

A copy of m_rotational_crops used when matching crops to fields.

Definition at line 2061 of file farm.h.

Referenced by ChooseDecisionMode(), and Match_crop_to_field().

vector<AlmassCrop> OptimisingFarm::m_rotational_crops_visible
protected

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

Definition at line 2063 of file farm.h.

Referenced by Find_neighbour_to_imitate(), and Save_last_years_crops().

vector<CropSort> OptimisingFarm::m_rotationCrops
protected

Vector of structs containing pointers to (winter) rotation crops.

Definition at line 2053 of file farm.h.

Referenced by AnimalFarm::checkWinterRotation1(), and NonAnimalFarm::checkWinterRotation1().

int OptimisingFarm::m_soilSubType
protected

Farm's soil subtype. Defined only for cattle farms on sandy soil (0-bad, 1-good, 2-undefined).

Definition at line 2075 of file farm.h.

Referenced by Initialize(), and OptimisingCattleFarm::preventCashCrops().

TTypesOfSoils OptimisingFarm::m_soilType
protected

Farm's soil type (sandy, clay, other).

Definition at line 2069 of file farm.h.

Referenced by ActualProfit(), Find_neighbour_to_imitate(), findFertilizer(), findResponse(), Initialize(), optimizeCrops(), and OptimisingCattleFarm::preventCashCrops().

double OptimisingFarm::m_totalArea
protected
double OptimisingFarm::m_totalArea_original
protected

Total area of a farm as in bedriftsmodel, i.e. original farm optimization model. [ha].

Definition at line 2083 of file farm.h.

Referenced by findTotalArea(), and OptimisingCattleFarm::preventCashCrops().

double OptimisingFarm::m_totalBI
protected

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

Definition at line 2109 of file farm.h.

Referenced by OptimiseFarm(), and Print_FarmVariables().

double OptimisingFarm::m_totalBIFi
protected

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

Definition at line 2107 of file farm.h.

Referenced by OptimiseFarm(), and Print_FarmVariables().

double OptimisingFarm::m_totalBIHerb
protected

Total amount of herbicides which is planned to be applied at a farm. Expressed as a Treatment frequency index (behandling indeks, BI in Danish).

Definition at line 2105 of file farm.h.

Referenced by OptimiseFarm(), and Print_FarmVariables().

double OptimisingFarm::m_totalCosts
protected

Planned total costs of growing crops at a farm. [DKK].

Definition at line 2117 of file farm.h.

Referenced by OptimiseFarm(), and Print_FarmVariables().

double OptimisingFarm::m_totalFUdemand
protected

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]

Definition at line 2093 of file farm.h.

Referenced by ChooseDecisionMode(), AnimalFarm::correctFodderDemand(), AnimalFarm::determineFodderAreas(), AnimalFarm::determineMinFodder(), findFodderDemand(), NonAnimalFarm::findFodderDemand(), and Print_FarmVariables().

double OptimisingFarm::m_totalFUdemandBefore
protected

Farm's total demand for fodder. [fodder units]

Definition at line 2091 of file farm.h.

Referenced by ChooseDecisionMode(), findFodderDemand(), and Print_FarmVariables().

double OptimisingFarm::m_totalFUgrown
protected
double OptimisingFarm::m_totalFUt
protected
double OptimisingFarm::m_totalGrooming
protected

Total grooming planned at a farm.

Definition at line 2111 of file farm.h.

Referenced by OptimiseFarm(), and Print_FarmVariables().

double OptimisingFarm::m_totalHoeing
protected

Total hoeing planned at a farm.

Definition at line 2113 of file farm.h.

Referenced by OptimiseFarm(), and Print_FarmVariables().

double OptimisingFarm::m_totalIncome
protected

Planned total income from growing crops at a farm. [DKK].

Definition at line 2119 of file farm.h.

Referenced by OptimiseFarm(), and Print_FarmVariables().

double OptimisingFarm::m_totalN
protected

Total amount of fertilizer used at a farm. [kg].

Definition at line 2101 of file farm.h.

Referenced by OptimiseFarm(), and Print_FarmVariables().

double OptimisingFarm::m_totalNanim
protected

Total animal fertilizer at a farm. A sum of Livestock::m_NanimUsable (from all types of livestock). [kg].

Definition at line 2087 of file farm.h.

Referenced by findNanim(), findTotalNanim(), and Print_FarmVariables().

double OptimisingFarm::m_totalNt
protected

Total amount of fertilizer purchased at a farm. [kg].

Definition at line 2103 of file farm.h.

Referenced by OptimiseFarm(), and Print_FarmVariables().

double OptimisingFarm::m_totalProfit
protected

Planned total profit (= income - costs) at a farm. In case of animal farms costs of purchased fodder is subtracted from the profit. [DKK].

Definition at line 2121 of file farm.h.

Referenced by OptimiseFarm(), and Print_FarmVariables().

double OptimisingFarm::m_totalWeeding
protected

Total manual weeding planned at a farm.

Definition at line 2115 of file farm.h.

Referenced by OptimiseFarm(), and Print_FarmVariables().

vector<CropSort> OptimisingFarm::m_variableCrops
protected
vector<CropSort> OptimisingFarm::m_variableCrops2
protected

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.

Definition at line 2047 of file farm.h.

Referenced by OptimisingPigFarm::check_WRape_WBarley(), OptimisingCattleFarm::checkCattleRotation(), OptimisingCattleFarm::checkCattleRotation_almass(), AnimalFarm::checkWinterCrops(), NonAnimalFarm::checkWinterCrops(), AnimalFarm::checkWinterRotation1(), and NonAnimalFarm::checkWinterRotation1().

vector<CropSort> OptimisingFarm::m_winterCrops
protected

Vector of structs containing pointers to winter crops.

Definition at line 2055 of file farm.h.

Referenced by AnimalFarm::checkWinterCrops(), and NonAnimalFarm::checkWinterCrops().


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