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

The Farm Manager class. More...

#include <farm.h>

Classes

struct  PesticideData
 Struct used for storing data on pesticide usage throughout the whole simulation (one instance, m_crops_summary_BIs). More...
 

Public Member Functions

 FarmManager ()
 Farm manager constructor. More...
 
 ~FarmManager ()
 Farm manager destructor. More...
 
void FarmManagement ()
 Runs the daily farm management for each farm, but also calculates annual spilled grain and maize. More...
 
void InitiateManagement (void)
 
void AddField (int a_OwnerIndex, LE *a_newland, int a_Owner)
 
void RemoveField (int a_OwnerIndex, LE *a_field)
 
int ConnectFarm (int a_owner)
 
TTypesOfVegetation TranslateCropCodes (std::string &str)
 
void DumpFarmAreas ()
 
void DumpFarmrefs ()
 dumps the farmrefs file to a standard named file More...
 
void InitFarms ()
 Calls OptimisingFarm::Init for all optimising farms. More...
 
void Save_diff_farm_types_areas ()
 Calculates and saves total areas of all optimising farms and specific farm types. More...
 
int GetFarmTotalSize (int a_farmref)
 Returns the total farm area from the farm ref num. More...
 
int GetFarmArableSize (int a_farmref)
 Returns the arable area from the farm ref num. More...
 
TTypesOfFarm GetFarmType (int a_farmref)
 Returns the farm type from the farm ref num. More...
 
int GetFarmNoFields (int a_farmref)
 Returns the number of fields owned by a from the farm ref num. More...
 
APoint GetFarmValidCoords (int a_farmref)
 Returns the number of fields owned by a from the farm ref num. More...
 
int GetFarmNoOpenFields (int a_farmref, int a_openness)
 Returns the number of fields with openness more than a_openness. More...
 
int GetFarmAreaOpenFields (int a_farmref, int a_openness)
 Returns the area of fields with openness more than a_openness. More...
 
FarmGetFarmPtr (int a_owner)
 Returns the pointer to a farm with a specific number. More...
 
FarmGetFarmPtrIndex (int a_index)
 Returns the pointer to a farm with a specific index. More...
 
int GetRandomFarmRefnum ()
 Returns a random farm reference number. More...
 
void CalcCentroids ()
 calculate all farm centroids More...
 
bool InIllegalList (int a_farm_ref, vector< int > *a_farmlist)
 Checks a list to see if a farm matches the illegal list of references. More...
 
void AddToIllegalList (int a_farm_ref, vector< int > *a_farmlist)
 Add to a list if a farm is not already among the illegal list of references. More...
 
int FindClosestFarm (HunterInfo a_hinfo, vector< int > *a_farmlist)
 Finds the closest farm to this co-ordinate. More...
 
int FindClosestFarmOpenness (HunterInfo a_hinfo, vector< int > *a_farmlist, int a_openness)
 Finds the closest farm to this co-ordinate but uses a probability distribtution for acceptance. More...
 
int FindClosestFarmOpennessProb (HunterInfo a_hinfo, vector< int > *a_farmlist, int a_openness)
 Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness. More...
 
int FindClosestFarmOpennessProbSmallIsBest (HunterInfo a_hinfo, vector< int > *a_farmlist, int a_openness, vector< int > *a_farmsizelist)
 Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness and another based on farm size. More...
 
int FindClosestFarmOpennessProbNearRoostIsBest (HunterInfo a_hinfo, vector< int > *a_farmlist, int a_openness, vector< APoint > *a_farmsizelist)
 Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness and another based on farm size. More...
 
int FindFarmWithRandom (vector< int > *a_farmlist)
 Finds a farm openness more than a value not on the list. More...
 
int FindFarmWithOpenness (vector< int > *a_farmlist, int a_openness)
 Finds a farm openness more than a value not on the list. More...
 
int FindOpennessFarm (int a_openness)
 Finds a random farm with at least one field with openness above a_openness. More...
 
bool CheckOpenness (int a_openness, int a_ref)
 Check if a farm has at least one field with openness above a_openness. More...
 
APoint GetFarmCentroid (int a_farmref)
 Gets the farm centroid as an APoint. More...
 
bool IsDuplicateRef (int a_ref, HunterInfo *a_hinfo)
 Checks if we already have this ref. More...
 
double GetSpilledGrain ()
 Returns the average amount of spilled grain in KJ/m2 this year. More...
 
double GetSpilledMaize ()
 Returns the average amount of spilled maize in KJ/m2 this year. More...
 
void SetSpilledGrain (bool a_spilledgrain)
 Set m_SpilledGrain which is the flag for either 2013 (true) or 2014 (false) spilled grain distributions. More...
 
void FindNeighbours ()
 Finds all OptimisingFarms' neighbours and saves them in the farm's OptimisingFarm::m_neighbours vector. More...
 
double GetDD (void)
 Returnes day degrees for the period March 1st - November 1st. Used for determining yields of crops that are not harvested. More...
 
void SetDD (double a_dd)
 
double Get_cropTotals (int i)
 
void Add_to_cropTotals (int i, double value)
 
void Set_cropTotals (int i, double value)
 
int Get_cropTotals_size ()
 
void ActualProfit ()
 Calls OptimisingFarm::ActualProfit for all optimising farms. More...
 
void ChooseDecisionMode_for_farms ()
 Calls OptimisingFarm::ChooseDecisionMode for all optimising farms. More...
 
void Save_last_years_crops_for_farms ()
 Calls OptimisingFarm::Save_last_years_crops for all optimising farms. More...
 
void PrintDecModes_counts ()
 For each OptimizingFarm it prints the number of times each of the decision modes was used within a single simulation. See also OptimisingFarm::m_decision_mode_counters. More...
 
void PrintFinalResults ()
 At the end of a simulation it prints results on crop distribution, pesticide and fertilizer usage. More...
 
void Switch_rotation ()
 Switches OptimisingFarms Farm::m_rotation to the list of all possible rotational crops. More...
 
TTypesOfVegetation Get_crops_summary_BIs_tov (int i)
 
void Set_crops_summary_BIs_herb (int i, double BIherb)
 
void Set_crops_summary_BIs_fi (int i, double BIfi)
 
void Set_crops_summary_BIs (int i, double BI)
 
void Set_cropTotals_sum (int i, double crop_area)
 
void Set_cropTotals_plant_sum (int i, double crop_area)
 
void Set_cropTotals_pig_sum (int i, double crop_area)
 
void Set_cropTotals_cattle_sum (int i, double crop_area)
 
void Set_cropTotals_other_sum (int i, double crop_area)
 
void Set_crops_fertilizer (int i, double fert)
 
void Set_crops_fertilizer_trade (int i, double fert_trade)
 
TTypesOfOptFarms TranslateFarmCodes (string &str)
 
TTypesOfSoils TranslateSoilCodes (string &str)
 
TTypesOfFarmSize TranslateFarmSizeCodes (string &str)
 
TTypesOfAnimals TranslateAnimalsCodes (string &str)
 
TTypesOfCrops TranslateCropsCodes (string &str)
 
TTypesOfParameters TranslateParametersCodes (string &str)
 
TTypesOfLivestockParameters TranslateLivestockParametersCodes (string &str)
 
TTypesOfCropVariables TranslateCropVariablesCodes (string &str)
 
int Get_lookup_table (int index)
 
int GetFarmNoLookup (int a_ref)
 Get a farm reference from the lookup table. More...
 
int GetFarmTypeLookup (int a_ref)
 Get a farm type from the lookup table. More...
 
bool GetIsRenumbered ()
 Returns the flag for renumbering. More...
 
int GetRenumberedFarmRef (int a_farmref)
 Returns the farm ref index for a farmref. More...
 
int GetNoFarms ()
 

Public Attributes

DataForOptimisationpm_data
 Pointer to the DataForOptimisation. More...
 
ofstream * pm_output_file
 

Protected Member Functions

void CreateFarms (const char *a_farmfile)
 
void ReadFarmsData ()
 Reads farm level parameters and saves them in a vector DataForOptimisation::m_farm_data. More...
 
void ReadLivestockNumbers ()
 Reads the data on livestock numbers and saves them in a vector DataForOptimisation::m_livestockNumbers. More...
 
void ReadInitialCropAreas ()
 Reads the data on farms' initial crop distributions and saves them in a vector DataForOptimisation::m_cropAreas. More...
 
void ReadFarmsData_perFarmType ()
 Reads the data on farms' parameters that vary with a farm type and saves them in a vector of a DataForOptimisation class. More...
 
void ReadLivestockData ()
 Reads the data on livestock parameters (do not vary with farm variables) and saves them in a vector DataForOptimisation::m_livestockParameters. More...
 
void ReadCropsData ()
 Reads the data on crops' parameters that do not vary with farm variables and saves them in a vector DataForOptimisation::m_cropParameters. More...
 
void ReadCropsData_perSoilType ()
 Reads the data on crops' parameters that vary with a soil type (alfa, beta1, beta2, Nnorm) and saves them in vectors of the DataForOptimisation class. More...
 
void ReadCropsData_perFarmType ()
 Reads the data on crops' parameters that vary with a farm type (fixed, fodder, FUKey) and saves them in vectors of the DataForOptimisation class. More...
 
void ReadCropsData_perFarm_and_Soil ()
 Reads the data on crops' parameters that vary with a farm and soil type (sellingPrice) and saves them in a vector DataForOptimisation::m_sellingPrice. More...
 
void ReadCropsData_perFarm_and_Soil_and_Size ()
 Reads the data on crops' parameters that vary with a farm type, soil type and farm size (rotationMax, rotationMin) and saves them in vectors of the DataForOptimisation class. More...
 
void ReadInitialCropAreas_almass ()
 Reads the data on farms' initial crop distributions and saves them in a vector of a DataForOptimisation class. ALMaSS crop mode. More...
 
void ReadCropsData_almass ()
 Reads the data on crops' parameters that do not vary with farm variables and saves them in a vector DataForOptimisation::m_cropParameters. ALMaSS crop mode. More...
 
void ReadCropsData_perSoilType_almass ()
 Reads the data on crops' parameters that vary with a soil type (alfa, beta1, beta2, Nnorm) and saves them in vectors of the DataForOptimisation class. ALMaSS crop mode. More...
 
void ReadCropsData_perFarmType_almass ()
 Reads the data on crops' parameters that vary with a farm type (fixed, fodder, FUKey) and saves them in vectors of the DataForOptimisation class. ALMaSS crop mode. More...
 
void ReadCropsData_perFarm_and_Soil_almass ()
 Reads the data on crops' parameters that vary with a farm and soil type (sellingPrice) and saves them in a vector DataForOptimisation:m_sellingPrice. ALMaSS crop mode. More...
 
void ReadCropsData_perFarm_and_Soil_and_Size_almass ()
 Reads the data on crops' parameters that vary with a farm type, soil type and farm size (rotationMax, rotationMin) and saves them in vectors of the DataForOptimisation class. ALMaSS crop mode. More...
 
void ReadEnergyMaizePrice ()
 
void OptimisationOutput ()
 Creates output files for all crop level variables and for landscape level crop distribution. Includes results of the initial farm otpimisation. More...
 
void PrintOutput (TTypesOfCropVariables a_var, string a_fileName)
 Makes an output file for one crop variable and prints its values for each crop and each OptimisingFarm. Includes results of the initial farm otpimisation. More...
 
void CropDistribution ()
 Calculates total crop areas (at the landscape level). Includes results of the initial farm otpimisation. More...
 
void Create_Output_file_for_farms ()
 Creates an output file. Prints the crop variables in the first row of the file. The file is used then by farms (OptimisingFarm) to print the farm level results of optimisation. Includes results of the initial farm otpimisation. More...
 
void ReadLookupTable ()
 Reads the lookup table with allowed/forbidden crop order from a text file and saves it into a vector m_crop_lookup_table. More...
 
void PrintNeighbours ()
 Creates an output file with a list of neighbours of each OptimisingFarm. More...
 
void DistributeFarmerTypes ()
 Randomly assigns farmer types to farms (OptimisingFarm) in proportions specified in an input file. More...
 

Protected Attributes

vector< Farm * > m_farms
 
Population_Managerm_population_manager
 
double daydegrees
 Daydegress for period March 1st - November 1st. Used to determine yield of crops that are not harvested (and thus do not have values of biomass at harvest). More...
 
bool m_SpilledGrain
 Is it 2013 (true) or 2014 (false) as far as grain goes. More...
 
int * m_farmmapping_lookup
 Used for a dynamic array of lookups converting farm references to internal renumbering. More...
 
bool m_renumbered
 A flag to show whether renumbering was already done. More...
 
double totalOptFarmsArea
 
double totalOptFarmsArea_plant
 
double totalOptFarmsArea_pig
 
double totalOptFarmsArea_cattle
 
double totalOptFarmsArea_other
 
vector< double > m_cropTotals
 Stores crops areas at the landscape level per year. More...
 
vector< int > m_crop_lookup_table
 Specifies which crop order is allowed in a rotation (i.e. if a given crop can follow another crop). More...
 
vector< double > m_cropTotals_sum
 Stores the sums of crops areas within one simulation at the landscape level. More...
 
vector< double > m_cropTotals_plant_sum
 Stores the sums of crops areas on plant farms within one simulation at the landscape level. More...
 
vector< double > m_cropTotals_pig_sum
 Stores the sums of crops areas on pig farms within one simulation at the landscape level. More...
 
vector< double > m_cropTotals_cattle_sum
 Stores the sums of crops areas on cattle farms within one simulation at the landscape level. More...
 
vector< double > m_cropTotals_other_sum
 Stores the sums of crops areas on other farms within one simulation at the landscape level. More...
 
vector< PesticideDatam_crops_summary_BIs
 Stores information on aggregate (all farms)pesticide usage for each crop. More...
 
vector< double > m_crops_fertilizer
 Stores information on aggregate (all farms) fertilizer usage for each crop. More...
 
vector< double > m_crops_fertilizer_trade
 Stores information on aggregate (all farms) fertilizer trade (Nt) usage for each crop. More...
 
vector< double > m_crop_areas_stages
 Stores information on crop areas calculated in different stages of model development: for comparison in sensitivity analysis. More...
 

Detailed Description

The Farm Manager class.

Definition at line 1563 of file farm.h.

Constructor & Destructor Documentation

FarmManager::FarmManager ( )

Farm manager constructor.

Definition at line 2177 of file farm.cpp.

References cfg_MaizeEnergy, cfg_OptimiseBedriftsmodelCrops, cfg_OptimisingFarms, l_map_farmref_file, l_map_read_farmfile, CfgBool::value(), and CfgStr::value().

2178 {
2179 
2180  g_farmmanager = this;
2181 
2182  if ( l_map_read_farmfile.value() ) {
2183  if (cfg_OptimisingFarms.value()){
2184  //make a data object
2186  ReadFarmsData();
2190  //ReadGlobalData();
2191  ReadLookupTable();
2192  ofstream ofile ("Economic_figures.txt", ios::out);
2193  ofile.close();
2194  ofstream ofile1 ("Daydegrees.txt", ios::out);
2195  ofile1.close();
2196  if(cfg_MaizeEnergy.value()){
2197  ofstream ofileEM ("Maize_energy_price_yearly.txt", ios::out);
2198  ofileEM.close();
2199  }
2200 
2203  ReadCropsData();
2208  }
2209  else{
2216  m_crops_summary_BIs.resize(pm_data->Get_noCrops()); //no_crops - from the input file on initial crop areas
2224  m_crop_areas_stages.resize( 2 * pm_data->Get_noCrops()); //use just the results of the baseline and original model
2225  for(int i=0; i<pm_data->Get_noCrops(); i++){
2227  m_crops_summary_BIs[i].BI=0;
2228  m_crops_summary_BIs[i].BIherb=0;
2229  m_crops_summary_BIs[i].BIfi=0;
2230  m_cropTotals_sum[i]=0;
2232  m_cropTotals_pig_sum[i]=0;
2235  m_crops_fertilizer[i]=0;
2237  }
2238 
2239  if(cfg_MaizeEnergy.value()){
2241  }
2242  }
2243  }//if optimising farm
2245  }
2246 
2247 }
void ReadLivestockData()
Reads the data on livestock parameters (do not vary with farm variables) and saves them in a vector D...
Definition: farm.cpp:3735
void ReadLivestockNumbers()
Reads the data on livestock numbers and saves them in a vector DataForOptimisation::m_livestockNumber...
Definition: farm.cpp:3053
CfgBool cfg_OptimisingFarms("OPTIMISING_FARMS", CFG_CUSTOM, false)
If set to true, the farmer decision making model is active.
void ReadInitialCropAreas()
Reads the data on farms&#39; initial crop distributions and saves them in a vector DataForOptimisation::m...
Definition: farm.cpp:3094
CfgBool cfg_MaizeEnergy("MAIZE_ENERGY", CFG_CUSTOM, false)
If set to true, the energy maize crop is included in the simulation.
vector< double > m_crops_fertilizer_trade
Stores information on aggregate (all farms) fertilizer trade (Nt) usage for each crop.
Definition: farm.h:1812
vector< PesticideData > m_crops_summary_BIs
Stores information on aggregate (all farms)pesticide usage for each crop.
Definition: farm.h:1808
void ReadFarmsData()
Reads farm level parameters and saves them in a vector DataForOptimisation::m_farm_data.
Definition: farm.cpp:3007
const char * value(void)
Definition: configurator.h:139
void ReadCropsData_perFarmType()
Reads the data on crops&#39; parameters that vary with a farm type (fixed, fodder, FUKey) and saves them ...
Definition: farm.cpp:3404
Class for storing data for optimisation.
Definition: farm.h:505
void ReadCropsData()
Reads the data on crops&#39; parameters that do not vary with farm variables and saves them in a vector D...
Definition: farm.cpp:3179
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...
static CfgStr l_map_farmref_file("MAP_FARMREF_FILE", CFG_CUSTOM,"farmrefs.txt")
bool value(void)
Definition: configurator.h:123
void ReadCropsData_perFarm_and_Soil_and_Size_almass()
Reads the data on crops&#39; parameters that vary with a farm type, soil type and farm size (rotationMax...
Definition: farm.cpp:3640
void ReadCropsData_perSoilType()
Reads the data on crops&#39; parameters that vary with a soil type (alfa, beta1, beta2, Nnorm) and saves them in vectors of the DataForOptimisation class.
Definition: farm.cpp:3247
void ReadEnergyMaizePrice()
Definition: farm.cpp:3767
vector< double > m_cropTotals_other_sum
Stores the sums of crops areas on other farms within one simulation at the landscape level...
Definition: farm.h:1806
void ReadLookupTable()
Reads the lookup table with allowed/forbidden crop order from a text file and saves it into a vector ...
Definition: farm.cpp:4148
vector< double > m_cropTotals_pig_sum
Stores the sums of crops areas on pig farms within one simulation at the landscape level...
Definition: farm.h:1802
void CreateFarms(const char *a_farmfile)
Definition: farm.cpp:2323
FarmManager * g_farmmanager
Definition: farm.cpp:238
void ReadInitialCropAreas_almass()
Reads the data on farms&#39; initial crop distributions and saves them in a vector of a DataForOptimisati...
Definition: farm.cpp:3135
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void ReadFarmsData_perFarmType()
Reads the data on farms&#39; parameters that vary with a farm type and saves them in a vector of a DataFo...
Definition: farm.cpp:3707
vector< double > m_crop_areas_stages
Stores information on crop areas calculated in different stages of model development: for comparison ...
Definition: farm.h:1814
TTypesOfVegetation Get_cropTypes_almass(int i)
Definition: farm.h:579
static CfgBool l_map_read_farmfile("MAP_READ_FARMFILE", CFG_PRIVATE, true)
vector< double > m_crops_fertilizer
Stores information on aggregate (all farms) fertilizer usage for each crop.
Definition: farm.h:1810
void ReadCropsData_perFarm_and_Soil()
Reads the data on crops&#39; parameters that vary with a farm and soil type (sellingPrice) and saves them...
Definition: farm.cpp:3526
void ReadCropsData_perFarm_and_Soil_and_Size()
Reads the data on crops&#39; parameters that vary with a farm type, soil type and farm size (rotationMax...
Definition: farm.cpp:3597
void ReadCropsData_perFarm_and_Soil_almass()
Reads the data on crops&#39; parameters that vary with a farm and soil type (sellingPrice) and saves them...
Definition: farm.cpp:3559
void ReadCropsData_perSoilType_almass()
Reads the data on crops&#39; parameters that vary with a soil type (alfa, beta1, beta2, Nnorm) and saves them in vectors of the DataForOptimisation class. ALMaSS crop mode.
Definition: farm.cpp:3313
vector< double > m_cropTotals_sum
Stores the sums of crops areas within one simulation at the landscape level.
Definition: farm.h:1798
vector< double > m_cropTotals_cattle_sum
Stores the sums of crops areas on cattle farms within one simulation at the landscape level...
Definition: farm.h:1804
int Get_noCrops()
Definition: farm.h:585
vector< double > m_cropTotals_plant_sum
Stores the sums of crops areas on plant farms within one simulation at the landscape level...
Definition: farm.h:1800
void ReadCropsData_almass()
Reads the data on crops&#39; parameters that do not vary with farm variables and saves them in a vector D...
Definition: farm.cpp:3211
void ReadCropsData_perFarmType_almass()
Reads the data on crops&#39; parameters that vary with a farm type (fixed, fodder, FUKey) and saves them ...
Definition: farm.cpp:3460
FarmManager::~FarmManager ( )

Farm manager destructor.

Definition at line 2250 of file farm.cpp.

References cfg_OptimisingFarms, and CfgBool::value().

2251 {
2252 
2253  for ( unsigned int i = 0; i < m_farms.size(); i++ )
2254  delete m_farms[ i ];
2255  if (cfg_OptimisingFarms.value()) delete pm_data;
2256 }
CfgBool cfg_OptimisingFarms("OPTIMISING_FARMS", CFG_CUSTOM, false)
If set to true, the farmer decision making model is active.
vector< Farm * > m_farms
Definition: farm.h:1763
bool value(void)
Definition: configurator.h:123
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733

Member Function Documentation

void FarmManager::ActualProfit ( )

Calls OptimisingFarm::ActualProfit for all optimising farms.

Definition at line 2956 of file farm.cpp.

References OptimisingFarm::ActualProfit(), Farm::GetType(), and tof_OptimisingFarm.

2956  {
2957 
2958  for(int i=0; i<(int)m_farms.size(); i++){
2959  if(m_farms[i]->GetType() == tof_OptimisingFarm){ //take only optimising farms
2960  OptimisingFarm * opf;
2961  opf = dynamic_cast<OptimisingFarm*>(m_farms[i]);
2962  opf->ActualProfit();
2963  }
2964  }
2965 }
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
void ActualProfit()
Function that determines actual crop yields and profit in a given year.
Definition: farm.cpp:8329
void FarmManager::Add_to_cropTotals ( int  i,
double  value 
)
inline

Definition at line 1695 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1695 {m_cropTotals[i] += value;};
vector< double > m_cropTotals
Stores crops areas at the landscape level per year.
Definition: farm.h:1794
void FarmManager::AddField ( int  a_OwnerIndex,
LE a_newland,
int  a_Owner 
)

Definition at line 2292 of file farm.cpp.

References LE::SetOwner().

2293 {
2294  m_farms[ a_OwnerIndex ]->AddField( a_newland );
2295  a_newland->SetOwner( m_farms[ a_OwnerIndex ], a_Owner, a_OwnerIndex );
2296 }
void SetOwner(Farm *a_owner, int a_owner_num, int a_owner_index)
Definition: elements.h:213
vector< Farm * > m_farms
Definition: farm.h:1763
void FarmManager::AddToIllegalList ( int  a_farm_ref,
vector< int > *  a_farmlist 
)

Add to a list if a farm is not already among the illegal list of references.

a_farmlist is a pointer to a list of integers with illegal farm ref numbers.

Definition at line 2622 of file farm.cpp.

2622  {
2626  bool found = false;
2627  unsigned sz = (unsigned)a_farmlist->size();
2628  for (unsigned f = 0; f < sz; f++) {
2629  if ((*a_farmlist)[f] == a_farm_ref) {
2630  found = true;
2631  break;
2632  }
2633  }
2634  if (!found) {
2635  a_farmlist->push_back( a_farm_ref );
2636  }
2637 }
void FarmManager::CalcCentroids ( )
inline

calculate all farm centroids

Definition at line 1640 of file farm.h.

1640 { for (unsigned int i = 0; i < m_farms.size(); i++) m_farms[i]->Centroids(); }
vector< Farm * > m_farms
Definition: farm.h:1763
bool FarmManager::CheckOpenness ( int  a_openness,
int  a_ref 
)

Check if a farm has at least one field with openness above a_openness.

Definition at line 2922 of file farm.cpp.

References Farm::GetMaxOpenness().

2922  {
2923  if (m_farms[ a_ref ]->GetMaxOpenness() > a_openness) return true;
2924  return false;
2925 }
vector< Farm * > m_farms
Definition: farm.h:1763
void FarmManager::ChooseDecisionMode_for_farms ( )

Calls OptimisingFarm::ChooseDecisionMode for all optimising farms.

Definition at line 2967 of file farm.cpp.

References OptimisingFarm::ChooseDecisionMode(), Farm::GetType(), and tof_OptimisingFarm.

2967  {
2968 
2969  for(int i=0; i<(int)m_farms.size(); i++){
2970  if(m_farms[i]->GetType() == tof_OptimisingFarm){ //take only optimising farms
2971  OptimisingFarm * opf;
2972  opf = dynamic_cast<OptimisingFarm*>(m_farms[i]);
2973  opf->ChooseDecisionMode();
2974 
2975  }
2976  }
2977 }
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
void ChooseDecisionMode()
Function determines which decision mode to use. The choice depends on the values of need satisfaction...
Definition: farm.cpp:5001
int FarmManager::ConnectFarm ( int  a_owner)

Definition at line 2303 of file farm.cpp.

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

2304 {
2305  for ( unsigned int i = 0; i < m_farms.size(); i++ )
2306  {
2307  if ( a_owner == m_farms[ i ]->GetFarmNumber() )
2308  {
2309  // Found it. Set mapping and return.
2310  return i;
2311  }
2312  }
2313  // We didn't find the owner in the list of farms,
2314  // pregenerated in CreateFarms() above. Something
2315  // is not correct here, so raise an appropriate
2316  // error and exit.
2317  char error_num[ 20 ];
2318  sprintf( error_num, "%d", a_owner );
2319  g_msg->Warn( WARN_FILE, "FarmManager::ConnectFarm(): Unknown farm number"" referenced in polygon file:", error_num );
2320  exit( 1 );
2321 }
vector< Farm * > m_farms
Definition: farm.h:1763
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 FarmManager::Create_Output_file_for_farms ( )
protected

Creates an output file. Prints the crop variables in the first row of the file. The file is used then by farms (OptimisingFarm) to print the farm level results of optimisation. Includes results of the initial farm otpimisation.

Definition at line 4132 of file farm.cpp.

4132  {
4133 
4134  pm_output_file = new ofstream ("FarmVariables.txt", ios::out);
4135 
4136  (*pm_output_file) << "Farm no \t";
4137 
4138  //print variables' names (18 variables, 09.05.12)
4139  (*pm_output_file) << "mainGoal \t" << "totalArea \t" << "totalIncome \t" << "totalCosts \t" << "totalProfit \t";
4140  (*pm_output_file) << "FodderDemand \t" << "FodderDemand_bef \t" << "FodderTrade \t" << "FodderGrown \t" ;
4141  (*pm_output_file) << "Nanim \t" << "totalNanim \t" << "totalNt \t" << "totalN \t" ;
4142  (*pm_output_file) << "totalBI \t" << "totalBIHerb \t" << "totalBIFi \t" ;
4143  (*pm_output_file) << "totalGrooming \t" << "totalHoeing \t" << "totalWeeding \t";
4144  (*pm_output_file) << endl;
4145 
4146 }
ofstream * pm_output_file
Definition: farm.h:1734
void FarmManager::CreateFarms ( const char *  a_farmfile)
protected

Definition at line 2323 of file farm.cpp.

References cfg_OptimisingFarms, g_farm_fixed_rotation_enable, g_farm_fixed_rotation_farmtype, g_msg, toof_Cattle, toof_Other, toof_Pig, toof_Plant, UserDefinedFarm35::UserDefinedFarm35(), CfgInt::value(), CfgBool::value(), MapErrorMsg::Warn(), and WARN_FILE.

2324 {
2325  int No, FType, NoFarms;
2326  FILE * inpf = fopen(a_farmfile, "r" );
2327  if (!inpf) {
2328  g_msg->Warn( WARN_FILE, "Landscape::CreateFarms(): Unable to open file", a_farmfile );
2329  exit( 1 );
2330  }
2331 
2332  fscanf( inpf, "%d", & NoFarms );
2333 
2334  m_farms.resize( NoFarms );
2335 
2336  m_farmmapping_lookup = new int[NoFarms * 2];
2337 
2338  for (int i = 0; i < NoFarms; i++)
2339  {
2340  // File format:
2341  //
2342  // Two colunms of numbers 0..number of farms, 0-number of farmtypes-1
2343  // the second column determines what type of farm we have
2344  fscanf(inpf, "%d %d", &No, &FType);
2345  m_farmmapping_lookup[i * 2] = No;
2346  m_farmmapping_lookup[i * 2 + 1] = FType;
2347  }
2348  fclose(inpf);
2349 
2350  for (int i = 0; i < NoFarms; i++)
2351  {
2352  /*
2353  //If we are testing crop management, then ignore farm type from
2354  // the file and set to fixed one instead.
2355  if ( g_farm_test_crop.value() ) {
2356  FType = g_farm_test_crop_farmtype.value();
2357  }
2358  */
2359  // If we are running in fixed, sync'ed rotation mode, set all farms to
2360  // be of the requested type.
2363  }
2364 
2365  switch (m_farmmapping_lookup[i * 2 + 1]) // FType
2366  {
2367  case 0:
2368  m_farms[i] = new ConventionalCattle(this);
2369  break;
2370  case 1:
2371  m_farms[i] = new ConventionalPig(this);
2372  break;
2373  case 2:
2374  m_farms[i] = new ConventionalPlant(this);
2375  break;
2376  case 3:
2377  m_farms[i] = new OrganicCattle(this);
2378  break;
2379  case 4:
2380  m_farms[i] = new OrganicPig(this);
2381  break;
2382  case 5:
2383  m_farms[i] = new OrganicPlant(this);
2384  break;
2385  case 6:
2386  m_farms[i] = new PesticideTrialControl(this);
2387  break;
2388  case 7:
2389  m_farms[i] = new PesticideTrialToxicControl(this);
2390  break;
2391  case 8:
2392  m_farms[i] = new PesticideTrialTreatment(this);
2393  break;
2394  case 9:
2395  m_farms[i] = new ConvMarginalJord(this);
2396  break;
2397  case 10:
2398  m_farms[i] = new AgroChemIndustryCerealFarm1(this);
2399  break;
2400  case 11:
2401  m_farms[i] = new AgroChemIndustryCerealFarm2(this);
2402  break;
2403  case 12:
2404  m_farms[i] = new AgroChemIndustryCerealFarm3(this);
2405  break;
2406  case 13:
2407  m_farms[i] = new NoPesticideBaseFarm(this);
2408  break;
2409  case 14:
2410  m_farms[i] = new NoPesticideNoPFarm(this);
2411  break;
2412  case 15:
2413  m_farms[i] = new UserDefinedFarm1(this);
2414  break;
2415  case 16:
2416  m_farms[i] = new UserDefinedFarm2(this);
2417  break;
2418  case 17:
2419  m_farms[i] = new UserDefinedFarm3(this);
2420  break;
2421  case 18:
2422  m_farms[i] = new UserDefinedFarm4(this);
2423  break;
2424  case 19:
2425  m_farms[i] = new UserDefinedFarm5(this);
2426  break;
2427  case 20:
2428  m_farms[i] = new UserDefinedFarm6(this);
2429  break;
2430  case 21:
2431  m_farms[i] = new UserDefinedFarm7(this);
2432  break;
2433  case 22:
2434  m_farms[i] = new UserDefinedFarm8(this);
2435  break;
2436  case 23:
2437  m_farms[i] = new UserDefinedFarm9(this);
2438  break;
2439  case 24:
2440  m_farms[i] = new UserDefinedFarm10(this);
2441  break;
2442  case 25:
2443  m_farms[i] = new UserDefinedFarm11(this);
2444  break;
2445  case 26:
2446  m_farms[i] = new UserDefinedFarm12(this);
2447  break;
2448  case 27:
2449  m_farms[i] = new UserDefinedFarm13(this);
2450  break;
2451  case 28:
2452  m_farms[i] = new UserDefinedFarm14(this);
2453  break;
2454  case 29:
2455  m_farms[i] = new UserDefinedFarm15(this);
2456  break;
2457  case 30:
2458  m_farms[i] = new UserDefinedFarm16(this);
2459  break;
2460  case 31:
2461  m_farms[i] = new UserDefinedFarm17(this);
2462  break;
2463  // NB the user defing farms below require an extra parameter in the rotation file denoting the intensity (0 or 1 = high low)
2464  case 32:
2465  m_farms[i] = new UserDefinedFarm18("UserDefinedFarm18.rot", this);
2466  break;
2467  case 33:
2468  m_farms[i] = new UserDefinedFarm19("UserDefinedFarm19.rot", this);
2469  break;
2470  case 34:
2471  m_farms[i] = new UserDefinedFarm20("UserDefinedFarm20.rot", this);
2472  break;
2473  case 35:
2474  m_farms[i] = new UserDefinedFarm21("UserDefinedFarm21.rot", this);
2475  break;
2476  case 36:
2477  m_farms[i] = new UserDefinedFarm22("UserDefinedFarm22.rot", this);
2478  break;
2479  case 37:
2480  m_farms[i] = new UserDefinedFarm23("UserDefinedFarm23.rot", this);
2481  break;
2482  case 38:
2483  m_farms[i] = new UserDefinedFarm24("UserDefinedFarm24.rot", this);
2484  break;
2485  case 39:
2486  m_farms[i] = new UserDefinedFarm25("UserDefinedFarm25.rot", this);
2487  break;
2488  case 40:
2489  m_farms[i] = new UserDefinedFarm26("UserDefinedFarm26.rot", this);
2490  break;
2491  case 41:
2492  m_farms[i] = new UserDefinedFarm27("UserDefinedFarm27.rot", this);
2493  break;
2494  case 42:
2495  m_farms[i] = new UserDefinedFarm28("UserDefinedFarm28.rot", this);
2496  break;
2497  case 43:
2498  m_farms[i] = new UserDefinedFarm29("UserDefinedFarm29.rot", this);
2499  break;
2500  case 44:
2501  m_farms[i] = new UserDefinedFarm30("UserDefinedFarm30.rot", this);
2502  break;
2503  case 45:
2504  m_farms[i] = new UserDefinedFarm31("UserDefinedFarm31.rot", this);
2505  break;
2506  case 46:
2507  m_farms[i] = new UserDefinedFarm32("UserDefinedFarm32.rot", this);
2508  break;
2509  case 47:
2510  m_farms[i] = new UserDefinedFarm33("UserDefinedFarm33.rot", this);
2511  break;
2512  case 48:
2513  m_farms[i] = new UserDefinedFarm34("UserDefinedFarm34.rot", this);
2514  break;
2515  case 49:
2516  m_farms[i] = new UserDefinedFarm35("UserDefinedFarm35.rot", this);
2517  break;
2518  case 50: //optimising farm!
2519  if ((pm_data->Get_farmType(No)) == toof_Pig) {
2520  m_farms[i] = new OptimisingPigFarm(this, No);
2521  }
2522  else if ((pm_data->Get_farmType(No)) == toof_Cattle){
2523  m_farms[i] = new OptimisingCattleFarm(this, No);
2524  }
2525  else if ((pm_data->Get_farmType(No)) == toof_Plant){
2526  m_farms[i] = new OptimisingPlantFarm(this, No);
2527  }
2528  else if ((pm_data->Get_farmType(No)) == toof_Other){
2529  m_farms[i] = new OptimisingOtherFarm(this, No);
2530  }
2531  break;
2532 
2533  default:
2534  g_msg->Warn(WARN_FILE, "Landscape::CreateFarms(): Unknown farm ""type reference number", "");
2535  exit(1);
2536  }
2537  m_farms[i]->SetFarmNumber(i); // We use 'i' here because we renumber the farms internally. If the file did not come in this way then a dump file is created - tested in ReadPolys2
2538  }
2539 
2541  {
2542  DistributeFarmerTypes(); //added 240513
2543  }
2544 
2545  if (GetFarmNoLookup(NoFarms - 1) != NoFarms - 1) m_renumbered = false; else m_renumbered = true;
2546 }
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1234
Inbuilt farm type.
Definition: farm.h:955
Inbuilt farm type.
Definition: farm.h:967
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1252
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1189
Inbuilt special purpose farm type.
Definition: farm.h:1049
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1005
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1428
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1448
Inbuilt special purpose farm type.
Definition: farm.h:1071
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1144
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1368
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1288
Inbuilt special purpose farm type.
Definition: farm.h:1061
void DistributeFarmerTypes()
Randomly assigns farmer types to farms (OptimisingFarm) in proportions specified in an input file...
Definition: farm.cpp:4488
Subclass of the NonAnimalFarm.
Definition: farm.h:2352
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1153
CfgBool cfg_OptimisingFarms("OPTIMISING_FARMS", CFG_CUSTOM, false)
If set to true, the farmer decision making model is active.
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1225
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1243
bool m_renumbered
A flag to show whether renumbering was already done.
Definition: farm.h:1774
Subclass of the NonAnimalFarm.
Definition: farm.h:2361
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1418
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1438
Inbuilt special purpose farm type.
Definition: farm.h:1080
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1358
Inbuilt special purpose farm type.
Definition: farm.h:1029
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1279
Inbuilt special purpose farm type.
Definition: farm.h:1089
Inbuilt special purpose farm type.
Definition: farm.h:1098
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1216
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
Inbuilt special purpose farm type.
Definition: farm.h:1107
bool value(void)
Definition: configurator.h:123
TTypesOfOptFarms Get_farmType(int a_almass_no)
Used by FarmManager::CreateFarms. Finds a matching almass number and returns farm&#39;s type...
Definition: farm.cpp:4609
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1398
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1017
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:992
Subclass of the AnimalFarm.
Definition: farm.h:2290
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1408
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1180
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1328
Inbuilt special purpose farm type.
Definition: farm.h:1039
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1348
int GetFarmNoLookup(int a_ref)
Get a farm reference from the lookup table.
Definition: farm.h:1739
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1270
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1207
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1388
int value(void)
Definition: configurator.h:92
CfgBool g_farm_fixed_rotation_enable("FARM_FIXED_ROTATION_ENABLE", CFG_CUSTOM, false)
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1171
CfgInt g_farm_fixed_rotation_farmtype("FARM_FIXED_ROTATION_FARMTYPE", CFG_CUSTOM, 0)
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1318
Inbuilt farm type.
Definition: farm.h:979
Definition: farm.h:228
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
int * m_farmmapping_lookup
Used for a dynamic array of lookups converting farm references to internal renumbering.
Definition: farm.h:1772
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1338
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1261
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1198
Subclass of the AnimalFarm.
Definition: farm.h:2305
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1458
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1378
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1298
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1162
A farm that can have its rotation defined by the user at runtime.
Definition: farm.h:1308
void FarmManager::CropDistribution ( )
protected

Calculates total crop areas (at the landscape level). Includes results of the initial farm otpimisation.

Definition at line 4111 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, OptimisingFarm::Get_crop(), OptimisingFarm::Get_cropsSize(), Farm::GetType(), CropOptimised::m_area_ha, toc_Foobar, tof_OptimisingFarm, and CfgBool::value().

4111  {
4112 
4113  int no_crops = (cfg_OptimiseBedriftsmodelCrops.value())? toc_Foobar : pm_data->Get_noCrops(); //bedriftsmodel crops/almass crops
4114  m_cropTotals.resize(no_crops); //no_crops is ok for both almass and bedriftsmodel crop mode; it is taken from the input file on initial crop areas
4115 
4116  for(int i=0; i<(int)m_farms.size(); i++){
4117 
4118  OptimisingFarm * opf;
4119  int size=0;
4120  if(m_farms[i]->GetType()==tof_OptimisingFarm) { //take only optimising farms
4121  opf = dynamic_cast<OptimisingFarm*>(m_farms[i]);
4122  size = opf->Get_cropsSize();
4123  for(int j=0; j<size; j++) {
4124  CropOptimised *crop = opf->Get_crop(j);
4125  double area = crop->m_area_ha;
4126  m_cropTotals[j] += area;
4127  }
4128  }
4129  }
4130 }
int Get_cropsSize(void)
Definition: farm.h:1898
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
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
CropOptimised * Get_crop(int i)
Definition: farm.h:1897
double m_area_ha
Area of a crop in ha at a farm [ha].
Definition: farm.h:1556
A class for storing all parameters and results of crop optimisation.
Definition: farm.h:1491
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
int Get_noCrops()
Definition: farm.h:585
vector< double > m_cropTotals
Stores crops areas at the landscape level per year.
Definition: farm.h:1794
void FarmManager::DistributeFarmerTypes ( )
protected

Randomly assigns farmer types to farms (OptimisingFarm) in proportions specified in an input file.

Definition at line 4488 of file farm.cpp.

References cfg_Environmentalist_proportion, cfg_Profit_max_proportion, cfg_Yield_max_proportion, Farm::GetType(), tof_OptimisingFarm, tofg_environment, tofg_profit, tofg_yield, and CfgFloat::value().

4488  {
4489 
4490  //get the shares of certain types. Parameters in the config file.
4491  double profit_proportion = cfg_Profit_max_proportion.value();
4492  double yield_proportion = cfg_Yield_max_proportion.value();
4493  double env_proportion = cfg_Environmentalist_proportion.value();
4494 
4495  //get the number of optimising farms (count them) and make a list of opt farms and its copy
4496  int number_opt_farms=0;
4497  vector <OptimisingFarm*> opt_farms;
4498  vector <OptimisingFarm*> opt_farms_copy;
4499  for(int i=0; i<(int)m_farms.size(); i++){
4500  if(m_farms[i]->GetType()==tof_OptimisingFarm){
4501  number_opt_farms++;
4502  OptimisingFarm * opf = dynamic_cast<OptimisingFarm*>(m_farms[i]);
4503  opt_farms.push_back(opf);
4504  }
4505  }
4506  opt_farms_copy = opt_farms;
4507 
4508  //find the number of farms that should be of a certain type
4509  int number_profit = (int) (profit_proportion/100 * number_opt_farms); // + 0.5); round down - to avoid having a total number of diff types higher than the number of farms
4510  int number_yield = (int) (yield_proportion/100 * number_opt_farms + 0.5);
4511  int number_env = (int) (env_proportion/100 * number_opt_farms + 0.5);
4512 
4513  //see: http://en.cppreference.com/w/cpp/numeric/random/uniform_int_distribution
4514  random_device rd;
4515  mt19937 gen(rd());
4516 
4517  int jj=0;
4518  int index_for_farm=0;
4519 
4520  //set farms with profit as a main goal
4521  for(int j=jj; j<number_profit; j++){
4522  distribution_type2 dis(0, number_opt_farms - j - 1); //each time we remove one farm, so '-j' and '-1' casue the last element in the list is =size-1.
4523  index_for_farm = dis(gen);
4524  opt_farms_copy[index_for_farm]->Set_main_goal(tofg_profit);
4525  opt_farms_copy.erase(opt_farms_copy.begin() + index_for_farm); //remove the farm from the list after assignign the goal
4526  jj = j;
4527  }
4528  jj++; //need to increase by one here!
4529 
4530  //set farms with yield as a main goal
4531  for(int j = jj; j<number_yield + number_profit; j++){ //start with the value of 'i' as it was after leaving the last for loop!
4532  distribution_type2 dis1(0, number_opt_farms - j - 1); //each time we remove one farm, so '-j'
4533  index_for_farm = dis1(gen);
4534  opt_farms_copy[index_for_farm]->Set_main_goal(tofg_yield);
4535  opt_farms_copy.erase(opt_farms_copy.begin() + index_for_farm); //remove the farm from the list after assignign the goal
4536  jj = j;
4537  }
4538  jj++;
4539 
4540  //set farms with environment as a main goal
4541  int loop_limit = (number_env + number_profit + number_yield > number_opt_farms)? number_opt_farms : number_env + number_profit + number_yield;
4542  for(int j=jj; j<loop_limit; j++){
4543  distribution_type2 dis2(0, number_opt_farms - j - 1); //each time we remove one farm, so '-j'
4544  index_for_farm = dis2(gen);
4545  opt_farms_copy[index_for_farm]->Set_main_goal(tofg_environment);
4546  opt_farms_copy.erase(opt_farms_copy.begin() + index_for_farm); //remove the farm from the list after assignign the goal
4547  }
4548 
4549  //check if there are any farms left without assigned goal
4550  if((int)opt_farms_copy.size()>0){ //it should be not more than 1-2
4551  for(int p=(int)opt_farms_copy.size(); p>0; p--){
4552  opt_farms_copy[p-1]->Set_main_goal(tofg_profit);
4553  }
4554  }
4555 
4556 }
CfgFloat cfg_Yield_max_proportion("YIELD_MAX_PROPORTION", CFG_CUSTOM, 0)
A parameter setting the proportion of farmers of a type yield maximiser.
CfgFloat cfg_Environmentalist_proportion("ENVIRONMENTALIST_PROPORTION", CFG_CUSTOM, 0)
A parameter setting the proportion of farmers of a type environmentalist.
boost::random::uniform_int_distribution distribution_type2
double value(void)
Definition: configurator.h:107
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
CfgFloat cfg_Profit_max_proportion("PROFIT_MAX_PROPORTION", CFG_CUSTOM, 100)
A parameter setting the proportion of farmers of a type profit maximiser.
void FarmManager::DumpFarmAreas ( )

Definition at line 1536 of file farm.cpp.

References OptimisingFarm::Get_almass_no(), Farm::GetArea(), and tof_OptimisingFarm.

1536  {
1537 
1538  //create a text file with the farms
1539  ofstream ofile ("FarmTotalAreas_almass.txt", ios::out);
1540  ofile << "Farm no" << '\t' << "Area" << endl;
1541 
1542  //print each farms no and then the numbers of its neighbours
1543  for(int i=0; i<(int)m_farms.size(); i++){
1544  OptimisingFarm * opf_i;
1545  if(m_farms[i]->GetType() == tof_OptimisingFarm){ //take only optimising farms
1546  opf_i = dynamic_cast<OptimisingFarm*>(m_farms[i]);
1547  ofile << opf_i->Get_almass_no() << '\t';
1548  ofile << opf_i->GetArea() <<'\t';
1549  ofile << endl;
1550  }
1551  }
1552 }
int Get_almass_no(void)
Definition: farm.h:1896
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
int GetArea(void)
Returns the area of arable fields owned by that farm.
Definition: farm.cpp:1045
void FarmManager::DumpFarmrefs ( )

dumps the farmrefs file to a standard named file

Definition at line 2548 of file farm.cpp.

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

2549 {
2550  ofstream opf("dump_farmrefs.txt");
2551  if (!opf.is_open())
2552  {
2553  g_msg->Warn(WARN_FILE, "Landscape::CreateFarms(): Unable to open file", "dump_farmrefs.txt");
2554  exit(1);
2555  }
2556  int NoFarms = (int) m_farms.size();
2557  opf << NoFarms << endl;
2558  for (int i = 0; i < NoFarms; i++)
2559  {
2560  opf << i << '\t' << m_farmmapping_lookup[i * 2 + 1] << endl;
2561  }
2562  opf.close();
2563 }
vector< Farm * > m_farms
Definition: farm.h:1763
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
int * m_farmmapping_lookup
Used for a dynamic array of lookups converting farm references to internal renumbering.
Definition: farm.h:1772
void FarmManager::FarmManagement ( )

Runs the daily farm management for each farm, but also calculates annual spilled grain and maize.

Definition at line 2258 of file farm.cpp.

References cfg_Animals_number_test_day, cfg_AnimalsThreshold, cfg_LifeStage, OptimisingFarm::Get_main_goal(), Farm::GetFarmNumber(), Farm::GetType(), OptimisingFarm::Set_animals_no(), Landscape::SupplyDayInYear(), Landscape::SupplyFarmAnimalCensus(), Landscape::SupplyYearNumber(), tof_OptimisingFarm, tofg_environment, CfgInt::value(), and CfgFloat::value().

2259 {
2260  for ( unsigned int i = 0; i < m_farms.size(); i++ )
2261  {
2262  m_farms[ i ]->Management();
2263  }
2264 
2265  //050214
2267  if(g_landscape_p->SupplyDayInYear() == cfg_Animals_number_test_day.value()){ //check if this is the day we want to collect data on animal numbers
2268  for ( unsigned int i = 0; i < m_farms.size(); i++ )
2269  {
2270  OptimisingFarm * opf;
2271  if(m_farms[i]->GetType() == tof_OptimisingFarm){ //take only optimising farms
2272  opf = dynamic_cast<OptimisingFarm*>(m_farms[i]);
2273  if(cfg_AnimalsThreshold.value() > 0 && opf->Get_main_goal() == tofg_environment){ //take only environmentalists and check if we are in the feedback mode (no if the config is zero)
2274  int farm_ref = opf->GetFarmNumber();
2275  int animals_no = g_landscape_p->SupplyFarmAnimalCensus(farm_ref, cfg_LifeStage.value());
2276  opf->Set_animals_no(animals_no);
2277  }
2278  }
2279  }
2280  }
2281  }
2282 }
CfgInt cfg_Animals_number_test_day("ANIMALS_NUMBER_TEST_DAY", CFG_CUSTOM, 152)
This parameter specifies the day at which farmers observe the number of animals residing at their far...
TTypeOfFarmerGoal Get_main_goal()
Definition: farm.h:1915
double value(void)
Definition: configurator.h:107
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
void Set_animals_no(int a_number)
Definition: farm.h:1916
int GetFarmNumber(void)
Definition: farm.h:698
int SupplyYearNumber(void)
Definition: landscape.h:1542
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...
Landscape * g_landscape_p
Definition: Landscape.cpp:238
CfgInt cfg_LifeStage("LIFE_STAGE", CFG_CUSTOM, 0)
This parameter specifies the life stage of a species whose numbers farmers use during their decision ...
int SupplyDayInYear(void)
Definition: landscape.h:1522
int value(void)
Definition: configurator.h:92
int SupplyFarmAnimalCensus(int a_farm_ref, int a_LifeStage)
Definition: Landscape.cpp:608
int FarmManager::FindClosestFarm ( HunterInfo  a_hinfo,
vector< int > *  a_farmlist 
)

Finds the closest farm to this co-ordinate.

Centroid calculation on farms must be called before calling this method for the first time.
a_farmlist is a pointer to a list of integers with illegal farm ref numbers. The first entry lists the number of illegal numbers.

Definition at line 2649 of file farm.cpp.

References g_msg, HunterInfo::homeX, HunterInfo::homeY, and MapErrorMsg::Warn().

2649  {
2654  double best = 99999999999999999.0;
2655  int bestref = -1;
2656  double dist = best;
2657  for (unsigned i = 0; i < m_farms.size(); i++) {
2658  int fnum = m_farms[i]->GetFarmNumber();
2659  if (!InIllegalList(fnum, a_farmlist)) {
2660  if (!IsDuplicateRef(fnum, &a_hinfo)) {
2661  // Is possible to use this farm, so test it.
2662  APoint FPt = m_farms[i]->GetCentroids();
2663  dist = sqrt((double( FPt.m_x - a_hinfo.homeX ) * double( FPt.m_x - a_hinfo.homeX ) + double( FPt.m_y - a_hinfo.homeY ) * double( FPt.m_y - a_hinfo.homeY )));
2664  if (dist < best) {
2665  best = dist;
2666  bestref = fnum;
2667  }
2668  }
2669  }
2670  }
2671  if (bestref == -1) {
2672  g_msg->Warn( "FarmManager::FindClosestFarm - Cannot find open farm.", "" );
2673  exit( 0 );
2674  }
2675  return bestref;
2676 }
int homeY
Hunter home y-coord.
Definition: farm.h:446
vector< Farm * > m_farms
Definition: farm.h:1763
bool IsDuplicateRef(int a_ref, HunterInfo *a_hinfo)
Checks if we already have this ref.
Definition: farm.cpp:2639
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
int homeX
Hunter home x-coord.
Definition: farm.h:444
bool InIllegalList(int a_farm_ref, vector< int > *a_farmlist)
Checks a list to see if a farm matches the illegal list of references.
Definition: farm.cpp:2611
int FarmManager::FindClosestFarmOpenness ( HunterInfo  a_hinfo,
vector< int > *  a_farmlist,
int  a_openness 
)

Finds the closest farm to this co-ordinate but uses a probability distribtution for acceptance.

Finds the closest farm to this co-ordinate with openness more than a value

Definition at line 2678 of file farm.cpp.

References g_msg, Farm::GetMaxOpenness(), HunterInfo::homeX, HunterInfo::homeY, and MapErrorMsg::Warn().

2678  {
2679  // Centroid calculation on farms must be called before calling this method for the first time
2680  double best = 99999999999999999.0;
2681  int bestref = -1;
2682  double dist = best;
2683  for (unsigned i = 0; i < m_farms.size(); i++) {
2684  if (m_farms[ i ]->GetMaxOpenness() > a_openness) {
2685  int fref = m_farms[ i ]->GetFarmNumber();
2686  if (!InIllegalList( fref, a_farmlist )) {
2687  if (!IsDuplicateRef( fref, &a_hunterinfo )) {
2688  APoint FPt = m_farms[ i ]->GetCentroids();
2689  dist = sqrt( (double( FPt.m_x - a_hunterinfo.homeX ) * double( FPt.m_x - a_hunterinfo.homeX ) + double( FPt.m_y - a_hunterinfo.homeY ) * double( FPt.m_y - a_hunterinfo.homeY )) );
2690  if (dist < best) {
2691  best = dist;
2692  bestref = fref;
2693  }
2694  }
2695  }
2696  }
2697  }
2698  if (bestref == -1) {
2699  g_msg->Warn( "FarmManager::FindClosestFarmOpenness( ) - Cannot find open farm.", "" );
2700  exit( 0 );
2701  }
2702  return bestref;
2703 }
vector< Farm * > m_farms
Definition: farm.h:1763
bool IsDuplicateRef(int a_ref, HunterInfo *a_hinfo)
Checks if we already have this ref.
Definition: farm.cpp:2639
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
bool InIllegalList(int a_farm_ref, vector< int > *a_farmlist)
Checks a list to see if a farm matches the illegal list of references.
Definition: farm.cpp:2611
int FarmManager::FindClosestFarmOpennessProb ( HunterInfo  a_hinfo,
vector< int > *  a_farmlist,
int  a_openness 
)

Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness.

Centroid calculation on farms must be called before calling this method for the first time.
a_farmlist is a pointer to a list of integers with illegal farm ref numbers. The first entry lists the number of illegal numbers. The chance of acceptance is probability based, taking the nearest farm first then testing the next etc.. The probability is based on y = 1*EXP(-x*cfg) with cfg being a fitting parameter in cfg_ClosestFarmProbParam1

We use typedef here to create our own name for APoint - but it is just two unsigned ints. We will use 'x' for the farm num and 'y' for the distance.

We use a vector of AFarmDists to be able to sort it easily

Struct redefining operator < - used for sorting distances from smallest to largest.

Definition at line 2705 of file farm.cpp.

References cfg_ClosestFarmProbParam1, cfg_ClosestFarmProbParam2, g_msg, g_rand_uni, Farm::GetMaxOpenness(), HunterInfo::homeX, HunterInfo::homeY, CfgFloat::value(), and MapErrorMsg::Warn().

2705  {
2714  typedef APoint AFarmDist;
2716  vector <AFarmDist> farmdists;
2718  struct FarmDistSort {
2719  bool operator()( AFarmDist a, AFarmDist b ) {
2720  return a.m_y < b.m_y;
2721  }
2722  };
2723  for (unsigned i = 0; i < m_farms.size(); i++) {
2724  int fnum = m_farms[ i ]->GetFarmNumber();
2725  if (!InIllegalList( fnum, a_farmlist )) {
2726  if (m_farms[ i ]->GetMaxOpenness() > a_openness) {
2727  if (!IsDuplicateRef( fnum, &a_hunterinfo )) {
2728  // Is possible to use this farm, so test it.
2729  APoint FPt = m_farms[ i ]->GetCentroids();
2730  int dist = int(sqrt( (double( FPt.m_x - a_hunterinfo.homeX ) * double( FPt.m_x - a_hunterinfo.homeX ) + double( FPt.m_y - a_hunterinfo.homeY ) * double( FPt.m_y - a_hunterinfo.homeY )) ));
2731  if (dist>40000) dist = 40000;
2732  AFarmDist fd( int( fnum ), dist );
2733  farmdists.push_back( fd );
2734  }
2735  }
2736  }
2737  }
2738  // By here we have a list of farms and their distances - now we have the option to sort it or randomise it - one or other line below should be commented out.
2739  // sort(farmdists.begin(), farmdists.end(), FarmDistSort()); // Sort
2740  random_shuffle( farmdists.begin(), farmdists.end() ); // Randomise
2741  // Now the vector is sorted/randomised we loop through and test probabilities
2742  for (int ch = 1; ch < 100000; ch++) // This loop just makes sure small chances don't mess up the run by tripping out early
2743  {
2744  int sz = int( farmdists.size() );
2745  for (int i = 0; i < sz; i++) {
2746  double chance = g_rand_uni();
2747  // Uses ch from the outer loop to scale probabilities - tripping out here will occur often for farms a long way from the area otherwise
2748  double calc = cfg_ClosestFarmProbParam2.value()* exp( (cfg_ClosestFarmProbParam1.value() / double( ch ))* farmdists[ i ].m_y );
2749  if (chance <= calc) return farmdists[ i ].m_x;
2750  }
2751  }
2752  g_msg->Warn( "FarmManager::FindClosestFarmProb", "- No suitable farm found" );
2753  exit( 0 );
2754 }
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
CfgFloat cfg_ClosestFarmProbParam2("CLOSESTFARMPROBPARAMTWO", CFG_CUSTOM, 1.0)
A fitting parameter for the probability of hunter acceptance of a farm with distance from home - scal...
double value(void)
Definition: configurator.h:107
vector< Farm * > m_farms
Definition: farm.h:1763
bool IsDuplicateRef(int a_ref, HunterInfo *a_hinfo)
Checks if we already have this ref.
Definition: farm.cpp:2639
CfgFloat cfg_ClosestFarmProbParam1("CLOSESTFARMPROBPARAMONE", CFG_CUSTOM, 0.005)
A fitting parameter for the probability of hunter acceptance of a farm wiht distance from home - slop...
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
bool InIllegalList(int a_farm_ref, vector< int > *a_farmlist)
Checks a list to see if a farm matches the illegal list of references.
Definition: farm.cpp:2611
int FarmManager::FindClosestFarmOpennessProbNearRoostIsBest ( HunterInfo  a_hinfo,
vector< int > *  a_farmlist,
int  a_openness,
vector< APoint > *  a_farmsizelist 
)

Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness and another based on farm size.

Centroid calculation on farms must be called before calling this method for the first time.
a_farmlist is a pointer to a list of integers with illegal farm ref numbers. The first entry lists the number of illegal numbers. The chance of acceptance is probability based, taking the nearest farm first then testing the next etc.. The probability is based on y = 1*EXP(-x*cfg) with cfg being a fitting parameter in cfg_ClosestFarmProbParam1

We use typedef here to create our own name for APoint - but it is just two unsigned ints. We will use 'x' for the farm num and 'y' for the distance.

We use a vector of AFarmDists to be able to sort it easily

Struct redefining operator < - used for sorting distances from smallest to largest.

Definition at line 2812 of file farm.cpp.

References cfg_ClosestFarmProbParam1, cfg_ClosestFarmProbParam2, cfg_RoostDistProbParam1, g_msg, g_rand_uni, Farm::GetMaxOpenness(), HunterInfo::homeX, HunterInfo::homeY, CfgFloat::value(), and MapErrorMsg::Warn().

2812  {
2821  typedef APoint AFarmDist;
2823  vector <AFarmDist> farmdists;
2825  struct FarmDistSort {
2826  bool operator()( AFarmDist a, AFarmDist b ) {
2827  return a.m_y < b.m_y;
2828  }
2829  };
2830  for (unsigned i = 0; i < m_farms.size(); i++) {
2831  int fnum = m_farms[ i ]->GetFarmNumber();
2832  if (!InIllegalList( fnum, a_farmlist )) {
2833  if (m_farms[ i ]->GetMaxOpenness() > a_openness) {
2834  if (!IsDuplicateRef( fnum, &a_hunterinfo )) {
2835  // Is possible to use this farm, so test it.
2836  APoint FPt = m_farms[ i ]->GetCentroids();
2837  int dist = int(sqrt( (double( FPt.m_x - a_hunterinfo.homeX ) * double( FPt.m_x - a_hunterinfo.homeX ) + double( FPt.m_y - a_hunterinfo.homeY ) * double( FPt.m_y - a_hunterinfo.homeY )) ));
2838  if (dist>40000) dist = 40000;
2839  AFarmDist fd( unsigned( fnum ), dist );
2840  farmdists.push_back( fd );
2841  }
2842  }
2843  }
2844  }
2845  // By here we have a list of farms and their distances - now we have the option to sort it or randomise it - one or other line below should be commented out.
2846  // sort(farmdists.begin(), farmdists.end(), FarmDistSort()); // Sort
2847  random_shuffle( farmdists.begin(), farmdists.end() ); // Randomise
2848  // Now the vector is sorted/randomised we loop through and test probabilities
2849  for (int ch = 1; ch < 100000; ch++) // This loop just makes sure small chances don't mess up the run by tripping out early
2850  {
2851  int sz = int( farmdists.size() );
2852  for (int i = 0; i < sz; i++) {
2853  double chance = g_rand_uni();
2854  // Uses ch from the outer loop to scale probabilities - tripping out here will occur often for farms a long way from the area otherwise
2855  double calc = cfg_ClosestFarmProbParam2.value()* exp( (cfg_ClosestFarmProbParam1.value() / double( ch ))* farmdists[ i ].m_y );
2856  if (chance <= calc) {
2857  // We passed the first test now take a second test based on roost distance
2858  chance = g_rand_uni();
2859  // Loop through each roost and find the closest to the farm - then do probability based on that distance.
2860  double dist = 10000;
2861  for (int r = 0; r < int( a_roostlist->size() ); r++) {
2862  double fdistroostx = farmdists[ i ].m_x - (*a_roostlist)[ r ].m_x;
2863  double fdistroosty = farmdists[ i ].m_y - (*a_roostlist)[ r ].m_y;
2864  double distf = sqrt( fdistroostx * fdistroostx + fdistroosty * fdistroostx );
2865  if (distf < dist) dist = distf;
2866  }
2867  calc = -0.01 + pow( dist / 10000.0, cfg_RoostDistProbParam1.value() );
2868  if (chance>calc) return farmdists[ i ].m_x;
2869  }
2870  }
2871  }
2872  g_msg->Warn( "FarmManager::FindClosestFarmProbNearRoostBest", "- No suitable farm found" );
2873  exit( 0 );
2874 }
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
CfgFloat cfg_ClosestFarmProbParam2("CLOSESTFARMPROBPARAMTWO", CFG_CUSTOM, 1.0)
A fitting parameter for the probability of hunter acceptance of a farm with distance from home - scal...
double value(void)
Definition: configurator.h:107
vector< Farm * > m_farms
Definition: farm.h:1763
bool IsDuplicateRef(int a_ref, HunterInfo *a_hinfo)
Checks if we already have this ref.
Definition: farm.cpp:2639
CfgFloat cfg_ClosestFarmProbParam1("CLOSESTFARMPROBPARAMONE", CFG_CUSTOM, 0.005)
A fitting parameter for the probability of hunter acceptance of a farm wiht distance from home - slop...
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
CfgFloat cfg_RoostDistProbParam1("ROOSTDISTPROBPARAMONE", CFG_CUSTOM, 1.5)
A fitting parameter for the probability of hunter acceptance of a farm with distance from roost...
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
bool InIllegalList(int a_farm_ref, vector< int > *a_farmlist)
Checks a list to see if a farm matches the illegal list of references.
Definition: farm.cpp:2611
int FarmManager::FindClosestFarmOpennessProbSmallIsBest ( HunterInfo  a_hinfo,
vector< int > *  a_farmlist,
int  a_openness,
vector< int > *  a_farmsizelist 
)

Finds the closest farm to this co-ordinate with openness more than a value but uses a probability distribtution for acceptance based on closeness and another based on farm size.

Centroid calculation on farms must be called before calling this method for the first time.
a_farmlist is a pointer to a list of integers with illegal farm ref numbers. The first entry lists the number of illegal numbers. The chance of acceptance is probability based, taking the nearest farm first then testing the next etc.. The probability is based on y = 1*EXP(-x*cfg) with cfg being a fitting parameter in cfg_ClosestFarmProbParam1

We use typedef here to create our own name for APoint - but it is just two unsigned ints. We will use 'x' for the farm num and 'y' for the distance.

We use a vector of AFarmDists to be able to sort it easily

Struct redefining operator < - used for sorting distances from smallest to largest.

Definition at line 2756 of file farm.cpp.

References cfg_ClosestFarmProbParam1, cfg_ClosestFarmProbParam2, cfg_FarmSizeProbParam1, g_msg, g_rand_uni, Farm::GetMaxOpenness(), HunterInfo::homeX, HunterInfo::homeY, CfgFloat::value(), and MapErrorMsg::Warn().

2756  {
2765  typedef APoint AFarmDist;
2767  vector <AFarmDist> farmdists;
2769  struct FarmDistSort {
2770  bool operator()( AFarmDist a, AFarmDist b ) {
2771  return a.m_y < b.m_y;
2772  }
2773  };
2774  for (unsigned i = 0; i < m_farms.size(); i++) {
2775  int fnum = m_farms[ i ]->GetFarmNumber();
2776  if (!InIllegalList( fnum, a_farmlist )) {
2777  if (m_farms[ i ]->GetMaxOpenness() > a_openness) {
2778  if (!IsDuplicateRef( fnum, &a_hunterinfo )) {
2779  // Is possible to use this farm, so test it.
2780  APoint FPt = m_farms[ i ]->GetCentroids();
2781  int dist = int(sqrt( (double( FPt.m_x - a_hunterinfo.homeX ) * double( FPt.m_x - a_hunterinfo.homeX ) + double( FPt.m_y - a_hunterinfo.homeY ) * double( FPt.m_y - a_hunterinfo.homeY )) ));
2782  if (dist>40000) dist = 40000;
2783  AFarmDist fd( unsigned( fnum ), dist );
2784  farmdists.push_back( fd );
2785  }
2786  }
2787  }
2788  }
2789  // By here we have a list of farms and their distances - now we have the option to sort it or randomise it - one or other line below should be commented out.
2790  // sort(farmdists.begin(), farmdists.end(), FarmDistSort()); // Sort
2791  random_shuffle( farmdists.begin(), farmdists.end() ); // Randomise
2792  // Now the vector is sorted/randomised we loop through and test probabilities
2793  for (int ch = 1; ch < 100000; ch++) // This loop just makes sure small chances don't mess up the run by tripping out early
2794  {
2795  int sz = int( farmdists.size() );
2796  for (int i = 0; i < sz; i++) {
2797  double chance = g_rand_uni();
2798  // Uses ch from the outer loop to scale probabilities - tripping out here will occur often for farms a long way from the area otherwise
2799  double calc = cfg_ClosestFarmProbParam2.value()* exp( (cfg_ClosestFarmProbParam1.value() / double( ch ))* farmdists[ i ].m_y );
2800  if (chance <= calc) {
2801  // We passed the first test now take a second test based on farm size
2802  chance = g_rand_uni();
2803  calc = pow( double( (*a_farmsizelist)[ farmdists[ i ].m_x ] / 4000.0 ), cfg_FarmSizeProbParam1.value() );
2804  if (chance>calc) return farmdists[ i ].m_x;
2805  }
2806  }
2807  }
2808  g_msg->Warn( "FarmManager::FindClosestFarmProb", "- No suitable farm found" );
2809  exit( 0 );
2810 }
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
CfgFloat cfg_ClosestFarmProbParam2("CLOSESTFARMPROBPARAMTWO", CFG_CUSTOM, 1.0)
A fitting parameter for the probability of hunter acceptance of a farm with distance from home - scal...
double value(void)
Definition: configurator.h:107
vector< Farm * > m_farms
Definition: farm.h:1763
bool IsDuplicateRef(int a_ref, HunterInfo *a_hinfo)
Checks if we already have this ref.
Definition: farm.cpp:2639
CfgFloat cfg_FarmSizeProbParam1("FARMSIZEPROBPARAMONE", CFG_CUSTOM, 1.5)
A fitting parameter for the probability of hunter acceptance of a farm that is smaller.
CfgFloat cfg_ClosestFarmProbParam1("CLOSESTFARMPROBPARAMONE", CFG_CUSTOM, 0.005)
A fitting parameter for the probability of hunter acceptance of a farm wiht distance from home - slop...
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
bool InIllegalList(int a_farm_ref, vector< int > *a_farmlist)
Checks a list to see if a farm matches the illegal list of references.
Definition: farm.cpp:2611
int FarmManager::FindFarmWithOpenness ( vector< int > *  a_farmlist,
int  a_openness 
)

Finds a farm openness more than a value not on the list.

Definition at line 2893 of file farm.cpp.

References g_msg, Farm::GetFarmNumber(), Farm::GetMaxOpenness(), and MapErrorMsg::Warn().

2894 {
2895  // Centroid calculation on farms must be called before calling this method for the first time
2896  int sz = (int)m_farms.size();
2897  int seed = random( sz );
2898  for (unsigned i = 0; i < m_farms.size(); i++) {
2899  int index = (i + seed) % sz;
2900  if (m_farms[ index ]->GetMaxOpenness() > a_openness)
2901  {
2902  if (!InIllegalList( m_farms[ index ]->GetFarmNumber(), a_farmlist )) return m_farms[ index ]->GetFarmNumber();
2903  }
2904  else AddToIllegalList(m_farms[ index ]->GetFarmNumber(), a_farmlist );
2905  }
2906  g_msg->Warn("FarmManager::FindFarmWithOpenness", "- No suitable farm found");
2907  exit(0);
2908 }
vector< Farm * > m_farms
Definition: farm.h:1763
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 AddToIllegalList(int a_farm_ref, vector< int > *a_farmlist)
Add to a list if a farm is not already among the illegal list of references.
Definition: farm.cpp:2622
bool InIllegalList(int a_farm_ref, vector< int > *a_farmlist)
Checks a list to see if a farm matches the illegal list of references.
Definition: farm.cpp:2611
int FarmManager::FindFarmWithRandom ( vector< int > *  a_farmlist)

Finds a farm openness more than a value not on the list.

Definition at line 2876 of file farm.cpp.

References g_msg, Farm::GetFarmNumber(), and MapErrorMsg::Warn().

2877 {
2878  int sz= (int)m_farms.size();
2879  int f = random(sz);
2880  while (InIllegalList(m_farms[f]->GetFarmNumber(), a_farmlist))
2881  {
2882  f = random(sz);
2883  if (a_farmlist->size() >= m_farms.size())
2884  {
2885  g_msg->Warn("FarmManager::FindFarmWithRandom"," - farm density rule means all hunters cannot be placed");
2886  exit(0);
2887  }
2888  }
2889  return m_farms[f]->GetFarmNumber();
2890 
2891 }
vector< Farm * > m_farms
Definition: farm.h:1763
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
bool InIllegalList(int a_farm_ref, vector< int > *a_farmlist)
Checks a list to see if a farm matches the illegal list of references.
Definition: farm.cpp:2611
void FarmManager::FindNeighbours ( )

Finds all OptimisingFarms' neighbours and saves them in the farm's OptimisingFarm::m_neighbours vector.

Definition at line 4180 of file farm.cpp.

References Farm::Centroids(), cfg_Neighbor_dist, OptimisingFarm::Get_almass_no(), OptimisingFarm::GetFarmCentroidX(), OptimisingFarm::GetFarmCentroidY(), Farm::GetType(), OptimisingFarm::Set_Neighbour(), tof_OptimisingFarm, and CfgFloat::value().

4180  {
4181  //determine who is each farm's neighbour and save them in the farm's vector of its neighbours
4182  //and print the neighbours
4183 
4184  OptimisingFarm * opf_i;
4185  OptimisingFarm * opf_k;
4186 
4187  for(int i=0; i<(int)m_farms.size(); i++){
4188  if(m_farms[i]->GetType() == tof_OptimisingFarm){ //take only optimising farms
4189  opf_i = dynamic_cast<OptimisingFarm*>(m_farms[i]);
4190  opf_i->Centroids(); //finds each farm's centroid
4191  }
4192  }
4193 
4194  for(int i=0; i<(int)m_farms.size(); i++){
4195  if(m_farms[i]->GetType() == tof_OptimisingFarm){ //take only optimising farms
4196  opf_i = dynamic_cast<OptimisingFarm*>(m_farms[i]);
4197  int x = opf_i->GetFarmCentroidX();
4198  int y = opf_i->GetFarmCentroidY();
4199  int farm_no_i = opf_i->Get_almass_no();
4200 
4201  for(int k = 0; k<(int)m_farms.size(); k++) { //find neighbours of farm i
4202  if(m_farms[k]->GetType() == tof_OptimisingFarm){ //take only optimising farms
4203  opf_k = dynamic_cast<OptimisingFarm*>(m_farms[k]);
4204  int xb = opf_k->GetFarmCentroidX();
4205  int yb = opf_k->GetFarmCentroidY();
4206  double par = 1000 * cfg_Neighbor_dist.value(); //change km to m
4207  int farm_no_k = opf_k->Get_almass_no();
4208 
4209  if(abs(x - xb) <= par && abs(y - yb) <= par && farm_no_i!=farm_no_k){ //check neighbourship (make sure it is not the same farm)
4210  //this is a neighbour
4211  opf_i->Set_Neighbour(opf_k); //add farm k to the list of neighbours of farm i
4212  }
4213  }
4214  else break;
4215  }
4216  }
4217  else break; //break the for loop -there is no more optimising farms
4218  }
4219 
4220  PrintNeighbours();
4221 
4222 }
int Get_almass_no(void)
Definition: farm.h:1896
double value(void)
Definition: configurator.h:107
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
int GetFarmCentroidX()
Definition: farm.h:1912
int GetFarmCentroidY()
Definition: farm.h:1913
void Set_Neighbour(OptimisingFarm *farm)
Definition: farm.h:1905
void PrintNeighbours()
Creates an output file with a list of neighbours of each OptimisingFarm.
Definition: farm.cpp:4224
CfgFloat cfg_Neighbor_dist("NEIGHBOR_DIST", CFG_CUSTOM, 1.5)
A parameter setting the maximum distance from a farm to another farm that can be considred a neighbou...
void Centroids()
Finds farm&#39;s centroids - x and y.
Definition: farm.cpp:4857
int FarmManager::FindOpennessFarm ( int  a_openness)

Finds a random farm with at least one field with openness above a_openness.

Definition at line 2910 of file farm.cpp.

References Farm::GetFarmNumber(), and Farm::GetMaxOpenness().

2911 {
2912  int sz = (int) m_farms.size();
2913  int seed = random(sz);
2914  for (unsigned i = 0; i < m_farms.size(); i++)
2915  {
2916  int index = (i + seed) % sz;
2917  if (m_farms[index]->GetMaxOpenness() > a_openness) return m_farms[index]->GetFarmNumber();
2918  }
2919  return -1; // Should never happen but if it does we need to handle the -1 error code.
2920 }
vector< Farm * > m_farms
Definition: farm.h:1763
TTypesOfVegetation FarmManager::Get_crops_summary_BIs_tov ( int  i)
inline

Definition at line 1710 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1710 {return m_crops_summary_BIs[i].Tov;};
vector< PesticideData > m_crops_summary_BIs
Stores information on aggregate (all farms)pesticide usage for each crop.
Definition: farm.h:1808
double FarmManager::Get_cropTotals ( int  i)
inline

Definition at line 1694 of file farm.h.

1694 {return m_cropTotals[i];};
vector< double > m_cropTotals
Stores crops areas at the landscape level per year.
Definition: farm.h:1794
int FarmManager::Get_cropTotals_size ( )
inline

Definition at line 1697 of file farm.h.

1697 {return (int)m_cropTotals.size();};
vector< double > m_cropTotals
Stores crops areas at the landscape level per year.
Definition: farm.h:1794
int FarmManager::Get_lookup_table ( int  index)
inline

Definition at line 1736 of file farm.h.

Referenced by OptimisingFarm::Make_rotations(), and OptimisingFarm::Match_crop_to_field().

1736 {return m_crop_lookup_table[index];};
vector< int > m_crop_lookup_table
Specifies which crop order is allowed in a rotation (i.e. if a given crop can follow another crop)...
Definition: farm.h:1796
double FarmManager::GetDD ( void  )
inline

Returnes day degrees for the period March 1st - November 1st. Used for determining yields of crops that are not harvested.

Definition at line 1692 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1692 {return daydegrees;};
double daydegrees
Daydegress for period March 1st - November 1st. Used to determine yield of crops that are not harvest...
Definition: farm.h:1767
int FarmManager::GetFarmArableSize ( int  a_farmref)
inline

Returns the arable area from the farm ref num.

Definition at line 1590 of file farm.h.

1591  {
1592  return (GetFarmPtr(a_farmref)->GetArea());
1593  }
Farm * GetFarmPtr(int a_owner)
Returns the pointer to a farm with a specific number.
Definition: farm.h:1623
int FarmManager::GetFarmAreaOpenFields ( int  a_farmref,
int  a_openness 
)
inline

Returns the area of fields with openness more than a_openness.

Definition at line 1617 of file farm.h.

1618  {
1619  return (GetFarmPtr(a_farmref)->GetAreaOpenFields(a_openness));
1620  }
Farm * GetFarmPtr(int a_owner)
Returns the pointer to a farm with a specific number.
Definition: farm.h:1623
APoint FarmManager::GetFarmCentroid ( int  a_farmref)
inline

Gets the farm centroid as an APoint.

Definition at line 1666 of file farm.h.

References g_msg, and MapErrorMsg::Warn().

1667  {
1668  for (unsigned int i = 0; i < m_farms.size(); i++)
1669  {
1670  if (a_farmref == m_farms[i]->GetFarmNumber())
1671  {
1672  return m_farms[i]->GetCentroids();
1673  }
1674  }
1675  g_msg->Warn("FarmManager::GetFarmCentroid - missing farm ref", a_farmref);
1676  exit(92);
1677  }
vector< Farm * > m_farms
Definition: farm.h:1763
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
int FarmManager::GetFarmNoFields ( int  a_farmref)
inline

Returns the number of fields owned by a from the farm ref num.

Definition at line 1600 of file farm.h.

1601  {
1602  return (GetFarmPtr(a_farmref)->GetNoFields());
1603  }
Farm * GetFarmPtr(int a_owner)
Returns the pointer to a farm with a specific number.
Definition: farm.h:1623
int FarmManager::GetFarmNoLookup ( int  a_ref)
inline

Get a farm reference from the lookup table.

Definition at line 1739 of file farm.h.

1739 { return m_farmmapping_lookup[a_ref * 2]; }
int * m_farmmapping_lookup
Used for a dynamic array of lookups converting farm references to internal renumbering.
Definition: farm.h:1772
int FarmManager::GetFarmNoOpenFields ( int  a_farmref,
int  a_openness 
)
inline

Returns the number of fields with openness more than a_openness.

Definition at line 1611 of file farm.h.

1612  {
1613  return (GetFarmPtr(a_farmref)->GetNoOpenFields(a_openness));
1614  }
Farm * GetFarmPtr(int a_owner)
Returns the pointer to a farm with a specific number.
Definition: farm.h:1623
Farm* FarmManager::GetFarmPtr ( int  a_owner)
inline

Returns the pointer to a farm with a specific number.

Definition at line 1623 of file farm.h.

References g_msg, and MapErrorMsg::Warn().

Referenced by Landscape::SupplyFarmPtr().

1623  {
1624  for (unsigned int i = 0; i < m_farms.size( ); i++) {
1625  if (a_owner == m_farms[ i ]->GetFarmNumber( )) {
1626  return m_farms[ i ];
1627  }
1628  }
1629  g_msg->Warn( "FarmManager::GetFarmPtr - missing farm ref", a_owner );
1630  exit( 92 );
1631  }
vector< Farm * > m_farms
Definition: farm.h:1763
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
Farm* FarmManager::GetFarmPtrIndex ( int  a_index)
inline

Returns the pointer to a farm with a specific index.

Definition at line 1634 of file farm.h.

1634  {
1635  return m_farms[ a_index ];
1636  }
vector< Farm * > m_farms
Definition: farm.h:1763
int FarmManager::GetFarmTotalSize ( int  a_farmref)
inline

Returns the total farm area from the farm ref num.

Definition at line 1585 of file farm.h.

1586  {
1587  return (GetFarmPtr(a_farmref)->GetTotalArea());
1588  }
Farm * GetFarmPtr(int a_owner)
Returns the pointer to a farm with a specific number.
Definition: farm.h:1623
TTypesOfFarm FarmManager::GetFarmType ( int  a_farmref)
inline

Returns the farm type from the farm ref num.

Definition at line 1595 of file farm.h.

1596  {
1597  return (GetFarmPtr(a_farmref)->GetType());
1598  }
Farm * GetFarmPtr(int a_owner)
Returns the pointer to a farm with a specific number.
Definition: farm.h:1623
int FarmManager::GetFarmTypeLookup ( int  a_ref)
inline

Get a farm type from the lookup table.

Definition at line 1741 of file farm.h.

1741 { return m_farmmapping_lookup[a_ref * 2 + 1]; }
int * m_farmmapping_lookup
Used for a dynamic array of lookups converting farm references to internal renumbering.
Definition: farm.h:1772
APoint FarmManager::GetFarmValidCoords ( int  a_farmref)
inline

Returns the number of fields owned by a from the farm ref num.

Definition at line 1605 of file farm.h.

1606  {
1607  return (GetFarmPtr(a_farmref)->GetValidCoords());
1608  }
Farm * GetFarmPtr(int a_owner)
Returns the pointer to a farm with a specific number.
Definition: farm.h:1623
bool FarmManager::GetIsRenumbered ( )
inline

Returns the flag for renumbering.

Definition at line 1743 of file farm.h.

1743 { return m_renumbered; }
bool m_renumbered
A flag to show whether renumbering was already done.
Definition: farm.h:1774
int FarmManager::GetNoFarms ( )
inline

Definition at line 1757 of file farm.h.

1757  {
1758  return (int)m_farms.size();
1759  }
vector< Farm * > m_farms
Definition: farm.h:1763
int FarmManager::GetRandomFarmRefnum ( )
inline

Returns a random farm reference number.

Definition at line 1638 of file farm.h.

1638 { return m_farms[random((int)m_farms.size())]->GetFarmNumber(); }
vector< Farm * > m_farms
Definition: farm.h:1763
int FarmManager::GetRenumberedFarmRef ( int  a_farmref)
inline

Returns the farm ref index for a farmref.

Definition at line 1745 of file farm.h.

References g_msg, and MapErrorMsg::Warn().

1746  {
1747  for (int i = 0; i < (int)m_farms.size(); i++)
1748  {
1749  if (m_farmmapping_lookup[i * 2] == a_farmref)
1750  {
1751  return i;
1752  }
1753  }
1754  g_msg->Warn( "FarmManager::GetRenumberedFarmRef(int a_farmref) Farm reference number not found in m_farmmapping_lookup ", a_farmref );
1755  exit( 9 );
1756  }
vector< Farm * > m_farms
Definition: farm.h:1763
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
int * m_farmmapping_lookup
Used for a dynamic array of lookups converting farm references to internal renumbering.
Definition: farm.h:1772
double FarmManager::GetSpilledGrain ( )

Returns the average amount of spilled grain in KJ/m2 this year.

Definition at line 2584 of file farm.cpp.

References g_rand_uni.

2585 {
2586  /*
2587  * This data is grain distributions based on 2013 & 2014 data from cereal fields in Jutland
2588  */
2589  double graindist2013[26] = {
2590  29.59, 172.68, 60.59, 39.68, 51.02, 81.63, 268.71, 134.84, 57.40, 30.61, 204.08, 683.67, 108.04,
2591  141.29, 505.10, 444.61, 293.37, 355.18, 386.90, 381.83, 372.45, 377.55, 320.70, 392.46, 392.86, 435.17
2592  };
2593  double graindist2014[28] = {
2594  109.33, 382.65, 94.19, 765.31, 29.15, 70.15, 1096.94, 436.51, 309.21, 286.28, 480.44, 249.73, 784.10,
2595  688.78, 2035.45, 920.80, 341.61, 12.24, 113.38, 80.17, 178.57, 480.44, 0.00, 2.83, 1447.12, 1846.94, 1017.86, 477.74
2596  };
2597  if (m_SpilledGrain) return graindist2013[ (int)(g_rand_uni() * 28) ];
2598  else return graindist2014[ (int)(g_rand_uni() * 26) ];
2599 }
bool m_SpilledGrain
Is it 2013 (true) or 2014 (false) as far as grain goes.
Definition: farm.h:1769
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
double FarmManager::GetSpilledMaize ( )

Returns the average amount of spilled maize in KJ/m2 this year.

Definition at line 2601 of file farm.cpp.

References g_rand_uni.

2601  {
2602  /*
2603  * This data is maize distributions in kJ/m2 based on 2015 field data from maize fields in Jutland
2604  */
2605  double maizedist2015[ 9 ] = {
2606  102.7905327, 58.19878648, 85.65877728, 110.9055748, 30.65682555, 63.11699379, 59.05947276, 41.9277173, 95.57716202
2607  };
2608  return maizedist2015[ (int)(g_rand_uni() * 9) ];
2609 }
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
bool FarmManager::InIllegalList ( int  a_farm_ref,
vector< int > *  a_farmlist 
)

Checks a list to see if a farm matches the illegal list of references.

a_farmlist is a pointer to a list of integers with illegal farm ref numbers. The first entry lists the number of illegal numbers.

Definition at line 2611 of file farm.cpp.

2611  {
2615  unsigned sz = (unsigned) a_farmlist->size();
2616  for (unsigned f = 0; f < sz; f++) {
2617  if ((*a_farmlist)[f] == a_farm_ref) return true;
2618  }
2619  return false;
2620 }
void FarmManager::InitFarms ( )

Calls OptimisingFarm::Init for all optimising farms.

Definition at line 2565 of file farm.cpp.

References cfg_OptimisingFarms, Farm::GetType(), OptimisingFarm::Init(), tof_OptimisingFarm, and CfgBool::value().

2565  {
2566 
2567 
2569  Create_Output_file_for_farms(); //needed only for the OpitmisingFarms!
2570 }
2571 
2572 for(unsigned j=0; j<m_farms.size(); j++){
2573  if(m_farms[j]->GetType()==tof_OptimisingFarm){
2574  OptimisingFarm * opf = dynamic_cast<OptimisingFarm*>(m_farms[j]);
2575  opf->Init(pm_output_file);
2576  }
2577  }
2578 
2579 OptimisationOutput(); //03.05 - outputs of the optimisation
2580 
2581 }
CfgBool cfg_OptimisingFarms("OPTIMISING_FARMS", CFG_CUSTOM, false)
If set to true, the farmer decision making model is active.
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
void Create_Output_file_for_farms()
Creates an output file. Prints the crop variables in the first row of the file. The file is used then...
Definition: farm.cpp:4132
void OptimisationOutput()
Creates output files for all crop level variables and for landscape level crop distribution. Includes results of the initial farm otpimisation.
Definition: farm.cpp:3974
bool value(void)
Definition: configurator.h:123
void Init(ofstream *ap_output_file)
Function carrying out the initial calculations at a farm level (including the initial optimisation)...
Definition: farm.cpp:4817
ofstream * pm_output_file
Definition: farm.h:1734
void FarmManager::InitiateManagement ( void  )

Definition at line 2284 of file farm.cpp.

2285 {
2286  for ( unsigned int i = 0; i < m_farms.size(); i++ )
2287  {
2288  m_farms[ i ]->InitiateManagement();
2289  }
2290 }
vector< Farm * > m_farms
Definition: farm.h:1763
bool FarmManager::IsDuplicateRef ( int  a_ref,
HunterInfo a_hinfo 
)

Checks if we already have this ref.

Definition at line 2639 of file farm.cpp.

References HunterInfo::FarmHuntRef.

2640 {
2641  for (int i = 0; i < int( a_hinfo->FarmHuntRef.size() ); i++)
2642  {
2643 
2644  if (a_ref == a_hinfo->FarmHuntRef[ i ]) return true;
2645  }
2646  return false;
2647 }
vector< int > FarmHuntRef
The hunter&#39;s is the farm reference number to where he hunts.
Definition: farm.h:448
void FarmManager::OptimisationOutput ( )
protected

Creates output files for all crop level variables and for landscape level crop distribution. Includes results of the initial farm otpimisation.

Definition at line 3974 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, toc_Foobar, 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, and CfgBool::value().

3974  {
3975 
3976 //1. crop variables
3977  PrintOutput(tocv_AreaPercent, "AreaPercent.txt");
3978  PrintOutput(tocv_AreaHa, "AreaHa.txt");
3979  PrintOutput(tocv_N, "N.txt");
3980  PrintOutput(tocv_Nt, "Nt.txt");
3981  PrintOutput(tocv_BIHerb, "BIHerb.txt");
3982  PrintOutput(tocv_BIFi, "BIFi.txt");
3983  PrintOutput(tocv_BI, "BI.txt");
3984  PrintOutput(tocv_Grooming, "Grooming.txt");
3985  PrintOutput(tocv_Hoeing, "Hoeing.txt");
3986  PrintOutput(tocv_Weeding, "Weeding.txt");
3987  PrintOutput(tocv_TotalLoss, "TotalLoss.txt");
3988  PrintOutput(tocv_Response, "Response.txt");
3989  PrintOutput(tocv_Income, "Income.txt");
3990  PrintOutput(tocv_Costs, "Costs.txt");
3991  PrintOutput(tocv_GM, "GM.txt");
3992  PrintOutput(tocv_Savings, "Savings.txt");
3993 
3994 //2. crop total areas in ha at the landscape level
3995 
3996  CropDistribution(); //now there are total area values for each crop in the m_cropTotals vector
3997  ofstream ofile("CropDistribution.txt", ios::out);
3998 
4000  //print crop names (using vector<string>m_cropTypes)
4001  for(int c=0; c<toc_Foobar; c++) ofile << pm_data->Get_cropTypes_str(c) << '\t';
4002  ofile << endl;
4003  //print the values (total areas in ha)
4004  for(int c=0; c<toc_Foobar; c++) ofile << m_cropTotals[c] << '\t';
4005  }
4006  else{
4007  //print 'year'
4008  ofile << "Year" << '\t';
4009  //print crop names
4010  for(int c=0; c<pm_data->Get_noCrops(); c++) ofile << pm_data->Get_cropTypes_almass_str(c) << '\t';
4011  ofile << endl;
4012  //it's the first optimisation, so say the year is zero
4013  ofile << "0" << '\t';
4014  //print the values (total areas in ha)
4015  for(int c=0; c<pm_data->Get_noCrops(); c++) ofile << m_cropTotals[c] << '\t';
4016  ofile << endl;
4017  }
4018 
4019  //restart the m_cropTotals:
4020  for(int i=0; i<(int)m_cropTotals.size(); i++){
4021  m_cropTotals[i]=0;
4022  }
4023 
4024  ofile.close();
4025 }
void PrintOutput(TTypesOfCropVariables a_var, string a_fileName)
Makes an output file for one crop variable and prints its values for each crop and each OptimisingFar...
Definition: farm.cpp:4027
Definition: farm.h:352
Definition: farm.h:348
Definition: farm.h:349
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
string Get_cropTypes_almass_str(int i)
Definition: farm.h:582
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
Definition: farm.h:360
void CropDistribution()
Calculates total crop areas (at the landscape level). Includes results of the initial farm otpimisati...
Definition: farm.cpp:4111
int Get_noCrops()
Definition: farm.h:585
string Get_cropTypes_str(int i)
Definition: farm.h:515
vector< double > m_cropTotals
Stores crops areas at the landscape level per year.
Definition: farm.h:1794
void FarmManager::PrintDecModes_counts ( )

For each OptimizingFarm it prints the number of times each of the decision modes was used within a single simulation. See also OptimisingFarm::m_decision_mode_counters.

Definition at line 4243 of file farm.cpp.

References OptimisingFarm::Get_almass_no(), OptimisingFarm::Get_decision_mode_counters(), Farm::GetType(), and tof_OptimisingFarm.

4243  {
4244 
4245  //create a text file and make headers
4246  ofstream ofile ("Decision_modes_counts.txt", ios::out);
4247  ofile << "Farm_no\t" << "imitation\t" << "social comparison\t" << "repeat\t"<< "deliberation\t"<<endl;
4248 
4249  //print each farms no and then the content of the vector ...
4250  for(int i=0; i<(int)m_farms.size(); i++){
4251  OptimisingFarm * opf_i;
4252  if(m_farms[i]->GetType() == tof_OptimisingFarm){ //take only optimising farms
4253  opf_i = dynamic_cast<OptimisingFarm*>(m_farms[i]);
4254  ofile << opf_i->Get_almass_no() << '\t';
4255  for(int j=0; j<4; j++){
4256  ofile << opf_i->Get_decision_mode_counters(j) <<'\t';
4257  }
4258  ofile << endl;
4259  }
4260  }
4261 
4262 }
int Get_almass_no(void)
Definition: farm.h:1896
int Get_decision_mode_counters(int index)
Definition: farm.h:1917
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
void FarmManager::PrintFinalResults ( )

At the end of a simulation it prints results on crop distribution, pesticide and fertilizer usage.

Definition at line 4264 of file farm.cpp.

References g_date, and Calendar::GetYearNumber().

4264  {
4265 
4267 
4268  int no_years = g_date->GetYearNumber() - 21; //exclude first 9 years + one - the last one, which has just started now - it's Jan 1st//exclude first 20 (0-19) years for the wildlife runs
4269  double BIherb_sum=0;
4270  double BIfi_sum=0;
4271  double BI_sum=0;
4272  double fertilizer_sum=0;
4273  double fertilizer_trade_sum=0;
4274 
4275  totalOptFarmsArea *= 0.0001;//change to ha
4276  totalOptFarmsArea_plant *= 0.0001;
4277  totalOptFarmsArea_pig *= 0.0001;
4278  totalOptFarmsArea_cattle *= 0.0001;
4279  totalOptFarmsArea_other *= 0.0001;
4280 
4281  ofstream ofile ("CropAreasTotal_and_Average.txt", ios::out);
4282  // "This file includes summed (over all optimising farms) areas of each crop during the whole simulation, the average areas " ;
4283  //"(equal to the sum divided by the number of years the simulation was run) and areas as percentage of total optimising farms area.\t" ;
4284  ofile << "CropName\t" << "Total\t" << "Average\t" << "Area_%\t"<< endl;
4285  for(int i=0; i<(int)m_cropTotals_sum.size(); i++){
4286  ofile << pm_data->Get_cropTypes_almass_str(i) << '\t';
4287  ofile << m_cropTotals_sum[i] << '\t';
4288  ofile << m_cropTotals_sum[i]/no_years << '\t';
4289  ofile << m_cropTotals_sum[i]/no_years/totalOptFarmsArea * 100 << '%';
4290  ofile << endl;
4291  }
4292  ofile.close();
4293 
4294  //printing separate files for specific farm types - just areas in %.
4295  ofstream ofile5 ("CropAreas_plant_farms.txt", ios::out);
4296  ofile5 << "CropName\t" << "Area_%\t" << endl; //<< "Total\t" << "Average\t" <<
4297  for(int i=0; i<(int)m_cropTotals_plant_sum.size(); i++){
4298  ofile5 << pm_data->Get_cropTypes_almass_str(i) << '\t';
4299  ofile5 << m_cropTotals_plant_sum[i]/no_years/totalOptFarmsArea_plant * 100 << '%';
4300  ofile5 << endl;
4301  }
4302  ofile5.close();
4303 
4304  ofstream ofile6 ("CropAreas_pig_farms.txt", ios::out);
4305  ofile6 << "CropName\t" << "Area_%\t" << endl; //<< "Total\t" << "Average\t" <<
4306  for(int i=0; i<(int)m_cropTotals_pig_sum.size(); i++){
4307  ofile6 << pm_data->Get_cropTypes_almass_str(i) << '\t';
4308  ofile6 << m_cropTotals_pig_sum[i]/no_years/totalOptFarmsArea_pig * 100 << '%';
4309  ofile6 << endl;
4310  }
4311  ofile6.close();
4312 
4313  ofstream ofile7 ("CropAreas_cattle_farms.txt", ios::out);
4314  ofile7 << "CropName\t" << "Area_%\t" << endl; //<< "Total\t" << "Average\t" <<
4315  for(int i=0; i<(int)m_cropTotals_cattle_sum.size(); i++){
4316  ofile7 << pm_data->Get_cropTypes_almass_str(i) << '\t';
4317  ofile7 << m_cropTotals_cattle_sum[i]/no_years/totalOptFarmsArea_cattle * 100 << '%';
4318  ofile7 << endl;
4319  }
4320  ofile7.close();
4321 
4322  ofstream ofile8 ("CropAreas_other_farms.txt", ios::out);
4323  ofile8 << "CropName\t" << "Area_%\t" << endl; //<< "Total\t" << "Average\t" <<
4324  for(int i=0; i<(int)m_cropTotals_other_sum.size(); i++){
4325  ofile8 << pm_data->Get_cropTypes_almass_str(i) << '\t';
4326  ofile8 << m_cropTotals_other_sum[i]/no_years/totalOptFarmsArea_other * 100 << '%';
4327  ofile8 << endl;
4328  }
4329  ofile8.close();
4330 
4331 
4332 
4333 
4334  ofstream ofile1 ("PesticideTotals.txt", ios::out);
4335  ofile1 << "CropName\t" << "BIherb\t" << "BIfi\t" << "BI\t" ; //total values within a simulation
4336  ofile1 << "BIherb_yr\t" << "BIfi_yr\t" << "BI_yr\t"; //average values per year (total/no_years)
4337  ofile1 << "BIherb_ha\t" << "BIfi_ha\t" << "BI_ha\t"; //average values per ha (total BI/total area)
4338  ofile1 << endl;
4339  for(int i=0; i<(int)m_crops_summary_BIs.size(); i++){
4340  //ofile1 << m_crops_summary_BIs[i].Tov << '\t';
4341  ofile1 << pm_data->Get_cropTypes_almass_str(i) << '\t';
4342 
4343  ofile1 << m_crops_summary_BIs[i].BIherb << '\t';
4344  BIherb_sum += m_crops_summary_BIs[i].BIherb;
4345 
4346  ofile1 << m_crops_summary_BIs[i].BIfi << '\t';
4347  BIfi_sum += m_crops_summary_BIs[i].BIfi;
4348 
4349  ofile1 << m_crops_summary_BIs[i].BI << '\t';
4350  BI_sum += m_crops_summary_BIs[i].BI;
4351 
4352  ofile1 << m_crops_summary_BIs[i].BIherb/no_years << '\t';
4353  ofile1 << m_crops_summary_BIs[i].BIfi/no_years << '\t';
4354  ofile1 << m_crops_summary_BIs[i].BI/no_years << '\t';
4355  if(!m_cropTotals_sum[i]==0){
4356  ofile1 << m_crops_summary_BIs[i].BIherb/m_cropTotals_sum[i] << '\t';
4357  ofile1 << m_crops_summary_BIs[i].BIfi/m_cropTotals_sum[i] << '\t';
4358  ofile1 << m_crops_summary_BIs[i].BI/m_cropTotals_sum[i] << '\t';
4359  }
4360  else{
4361  ofile1 <<"0\t" << "0\t" << "0\t" ;
4362  }
4363  ofile1 << endl;
4364  }
4365  ofile1.close();
4366 
4367  ofstream ofile2 ("FertilizerTotals.txt", ios::out);
4368  ofile2 << "CropName\t" << "Fertilizer\t" << "Fertilizer_yr\t" << "Fertilizer_ha\t" << endl;
4369  for(int i=0; i<(int)m_crops_summary_BIs.size(); i++){
4370  ofile2 << pm_data->Get_cropTypes_almass_str(i) << '\t';
4371  ofile2 << m_crops_fertilizer[i] << '\t'; //total - all farms, all years
4372  fertilizer_sum += m_crops_fertilizer[i];
4373  fertilizer_trade_sum += m_crops_fertilizer_trade[i];
4374  ofile2 << m_crops_fertilizer[i]/no_years << '\t'; // average per year
4375  if(m_cropTotals_sum[i]!=0){
4376  ofile2 << m_crops_fertilizer[i]/m_cropTotals_sum[i] << '\t'; //average per ha
4377  }
4378  else{
4379  ofile2 << "0\t";
4380  }
4381  ofile2 << endl;
4382  }
4383  ofile2.close();
4384 
4385  //READ the inputs on crop areas in diff model stages
4386  ifstream ifile("crop_results_stages.txt", ios::in);
4387  //check if there is an input file
4388  if ( !ifile.is_open() ) {
4389  cout << "Cannot open input file " << "crop_results_stages.txt" << endl;
4390  char ch;
4391  cin >> ch; //so that it doesn't close immedietly
4392  exit(1);
4393  }
4394  int no_crops = pm_data->Get_noCrops();
4395  //get rid of the crop names
4396  for(int c=0; c<no_crops; c++){
4397  string type;
4398  ifile>>type;
4399  }
4400  for(int stage=0; stage<2; stage++){ //get just the results of the baseline and of the original model
4401  //stage name
4402  string stage_name;
4403  ifile>>stage_name;
4404  //save crop areas
4405  for(int a=0; a<no_crops; a++){
4406  ifile>>m_crop_areas_stages[stage * no_crops + a];
4407  }
4408  }
4409 
4410  //determine the sums of squared differences in crop areas (araes as percentages)
4411  vector<double>sums;
4412  sums.resize(2);
4413  for(int s=0; s<2; s++){
4414  sums[s]=0;
4415  }
4416 
4417  for(int st=0; st<2; st++){
4418  for(int b=0; b<no_crops; b++){
4419  double sq_diff = pow(m_cropTotals_sum[b]/no_years/totalOptFarmsArea * 100 - m_crop_areas_stages[st * no_crops + b]*100, 2);
4420  sums[st] += sq_diff;
4421  }
4422  }
4423 
4424  ofstream ofile3 ("Result_summary.txt", ios::out);
4425  ofile3 << "BIherb\t" << "BIfi\t" << "BI\t" << "Fert\t" << "Fert_trade\t" ; // sum for all crops/no_years/total_opt_farms_area
4426  ofile3 << "Sum of sq. diff: Baseline\t" << "Sum of sq. diff: Original\t"; // << "Sum of sq. diff: New opt.\t" << "Sum of sq. diff: Almass_f.area\t" << "Sum of sq. diff: Crop_choice_ev_yr\t";
4427  //ofile3 << "Sum of sq. diff: Dec.modes\t" << "Sum of sq. diff: Farmer types\t" << "Sum of sq. diff: Types+modes\t" << endl;
4428  ofile3 << BIherb_sum/totalOptFarmsArea/no_years <<'\t';
4429  ofile3 << BIfi_sum/totalOptFarmsArea/no_years <<'\t';
4430  ofile3 << BI_sum/totalOptFarmsArea/no_years <<'\t';
4431  ofile3 << fertilizer_sum/totalOptFarmsArea/no_years <<'\t';
4432  ofile3 << fertilizer_trade_sum/totalOptFarmsArea/no_years <<'\t';
4433  for(int sta=0; sta<2; sta++){
4434  ofile3 << sums[sta] << '\t';
4435  }
4436  ofile3.close();
4437 
4438  //for calibration/sensitivty analysis: comparison to baseline
4439  ofstream ofile4 ("Output.txt", ios::out);
4440  //order: 1.BI 2.BI diff%; 3. BI_abs_diff; 4.fert; 5.fert diff%; 6.fert_abs_diff 7.sum of sq. diff. compared to baseline; 8. weigthed measure
4441  double BIdiff_percent = ((BI_sum/totalOptFarmsArea/no_years/2.2) - 1) *100;//BI in the baseline = 2.2 and is the country level score!
4442  double BIdiffabs = abs(BIdiff_percent);
4443  double fert_diff_percent = ((fertilizer_sum/totalOptFarmsArea/no_years/140.07)-1) * 100;
4444  double fertdiffabs = abs(fert_diff_percent);
4445  //ofile4 << endl;
4446  ofile4 << '\t' << BI_sum/totalOptFarmsArea/no_years <<'\t' << BIdiff_percent << '\t'<< BIdiffabs <<'\t';
4447  ofile4 << fertilizer_sum/totalOptFarmsArea/no_years << '\t' << fert_diff_percent << '\t' << fertdiffabs <<'\t'; //fert in baseline = 140.07 kg/ha
4448  ofile4 << sums[0] << '\t';
4449  ofile4 << 0.2 * abs(BIdiff_percent) + 0.2 * abs(fert_diff_percent) + 0.6 * sums[0] << endl;
4450  ofile4.close();
4451 
4452  //print also areas of all crops...
4453  ofstream ofile9 ("Output_crop_areas_percent.txt", ios::out);
4454  ofile9 << '\t';
4455  for(int i=0; i<(int)m_cropTotals_sum.size(); i++){
4456  ofile9 << m_cropTotals_sum[i]/no_years/totalOptFarmsArea * 100 << '\t'; //print just areas (no crop names!)
4457  }
4458  ofile9 << endl;
4459  ofile9.close();
4460 
4461 
4462 }
double totalOptFarmsArea_cattle
Definition: farm.h:1790
double totalOptFarmsArea_other
Definition: farm.h:1791
double totalOptFarmsArea_plant
Definition: farm.h:1788
int GetYearNumber(void)
Definition: calendar.h:68
vector< double > m_crops_fertilizer_trade
Stores information on aggregate (all farms) fertilizer trade (Nt) usage for each crop.
Definition: farm.h:1812
vector< PesticideData > m_crops_summary_BIs
Stores information on aggregate (all farms)pesticide usage for each crop.
Definition: farm.h:1808
double totalOptFarmsArea
Definition: farm.h:1787
string Get_cropTypes_almass_str(int i)
Definition: farm.h:582
vector< double > m_cropTotals_other_sum
Stores the sums of crops areas on other farms within one simulation at the landscape level...
Definition: farm.h:1806
vector< double > m_cropTotals_pig_sum
Stores the sums of crops areas on pig farms within one simulation at the landscape level...
Definition: farm.h:1802
double totalOptFarmsArea_pig
Definition: farm.h:1789
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
class Calendar * g_date
Definition: calendar.cpp:38
vector< double > m_crop_areas_stages
Stores information on crop areas calculated in different stages of model development: for comparison ...
Definition: farm.h:1814
void PrintDecModes_counts()
For each OptimizingFarm it prints the number of times each of the decision modes was used within a si...
Definition: farm.cpp:4243
vector< double > m_crops_fertilizer
Stores information on aggregate (all farms) fertilizer usage for each crop.
Definition: farm.h:1810
vector< double > m_cropTotals_sum
Stores the sums of crops areas within one simulation at the landscape level.
Definition: farm.h:1798
vector< double > m_cropTotals_cattle_sum
Stores the sums of crops areas on cattle farms within one simulation at the landscape level...
Definition: farm.h:1804
int Get_noCrops()
Definition: farm.h:585
vector< double > m_cropTotals_plant_sum
Stores the sums of crops areas on plant farms within one simulation at the landscape level...
Definition: farm.h:1800
void FarmManager::PrintNeighbours ( )
protected

Creates an output file with a list of neighbours of each OptimisingFarm.

Definition at line 4224 of file farm.cpp.

References OptimisingFarm::Get_almass_no(), OptimisingFarm::Get_Neighbour(), OptimisingFarm::Get_NeighboursSize(), Farm::GetType(), and tof_OptimisingFarm.

4224  {
4225  //create a text file with the farms and their neighbours
4226  ofstream ofile ("Neighbours.txt", ios::out);
4227  ofile << "Farm no" << endl;
4228 
4229  //print each farms no and then the numbers of its neighbours
4230  for(int i=0; i<(int)m_farms.size(); i++){
4231  OptimisingFarm * opf_i;
4232  if(m_farms[i]->GetType() == tof_OptimisingFarm){ //take only optimising farms
4233  opf_i = dynamic_cast<OptimisingFarm*>(m_farms[i]);
4234  ofile << opf_i->Get_almass_no() << '\t';
4235  for(int j=0; j<opf_i->Get_NeighboursSize(); j++){
4236  ofile << opf_i->Get_Neighbour(j)->Get_almass_no() <<'\t'; //pointer to the current, i.e. 'i' farm, takes its neighbour (j) and retrieves his almass_no
4237  }
4238  ofile << endl;
4239  }
4240  }
4241 }
int Get_almass_no(void)
Definition: farm.h:1896
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
int Get_NeighboursSize(void)
Definition: farm.h:1906
OptimisingFarm * Get_Neighbour(int i)
Definition: farm.h:1907
void FarmManager::PrintOutput ( TTypesOfCropVariables  a_var,
string  a_fileName 
)
protected

Makes an output file for one crop variable and prints its values for each crop and each OptimisingFarm. Includes results of the initial farm otpimisation.

Definition at line 4027 of file farm.cpp.

References cfg_OptimiseBedriftsmodelCrops, g_msg, OptimisingFarm::Get_almass_no(), OptimisingFarm::Get_crop(), OptimisingFarm::Get_cropsSize(), Farm::GetType(), CropOptimised::m_area_ha, CropOptimised::m_areaPercent, CropOptimised::m_BI, CropOptimised::m_BIFi, CropOptimised::m_BIHerb, CropOptimised::m_costs_ha, CropOptimised::m_GM, CropOptimised::m_grooming, CropOptimised::m_hoeing, CropOptimised::m_income_ha, CropOptimised::m_n, CropOptimised::m_nt, CropOptimised::m_resp, CropOptimised::m_savings, CropOptimised::m_totalLoss, CropOptimised::m_weeding, toc_Foobar, 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, tof_OptimisingFarm, CfgBool::value(), MapErrorMsg::Warn(), and WARN_BUG.

4027  {
4028 
4029  ofstream ofile (a_fileName.c_str(), ios::out);
4030  ofile << "Farm no" << '\t';
4031  //print crop names (using vector<string>m_cropTypes)
4033  for(int c=0; c<toc_Foobar; c++) ofile << pm_data->Get_cropTypes_str(c) << '\t';
4034  }
4035  else{
4036  for(int c=0; c<pm_data->Get_noCrops(); c++) ofile << pm_data->Get_cropTypes_almass_str(c) << '\t';
4037  }
4038  ofile << endl;
4039 
4040  for (int i=0; i<(int)m_farms.size(); i++){
4041  if(m_farms[i]->GetType() == tof_OptimisingFarm){ //take only optimising farms
4042  OptimisingFarm * opf;
4043  opf = dynamic_cast<OptimisingFarm*>(m_farms[i]);
4044  int no = opf->Get_almass_no();
4045  ofile << no << '\t';
4046  int size = opf->Get_cropsSize();
4047  for(int j = 0; j < size; j++){
4048  double var_to_print = -1;
4049  CropOptimised* crop = opf->Get_crop(j);
4050  switch (a_var){
4051  case tocv_AreaPercent:
4052  var_to_print = crop ->m_areaPercent;
4053  break;
4054  case tocv_AreaHa:
4055  var_to_print = crop ->m_area_ha;
4056  break;
4057  case tocv_N:
4058  var_to_print = crop ->m_n;
4059  break;
4060  case tocv_Nt:
4061  var_to_print = crop ->m_nt;
4062  break;
4063  case tocv_BIHerb:
4064  var_to_print = crop ->m_BIHerb;
4065  break;
4066  case tocv_BIFi:
4067  var_to_print = crop ->m_BIFi;
4068  break;
4069  case tocv_BI:
4070  var_to_print = crop ->m_BI;
4071  break;
4072  case tocv_Grooming:
4073  var_to_print = crop ->m_grooming;
4074  break;
4075  case tocv_Hoeing:
4076  var_to_print = crop ->m_hoeing;
4077  break;
4078  case tocv_Weeding:
4079  var_to_print = crop ->m_weeding;
4080  break;
4081  case tocv_TotalLoss:
4082  var_to_print = crop ->m_totalLoss;
4083  break;
4084  case tocv_Response:
4085  var_to_print = crop ->m_resp;
4086  break;
4087  case tocv_Income:
4088  var_to_print = crop ->m_income_ha;
4089  break;
4090  case tocv_Costs:
4091  var_to_print = crop ->m_costs_ha;
4092  break;
4093  case tocv_GM:
4094  var_to_print = crop ->m_GM;
4095  break;
4096  case tocv_Savings:
4097  var_to_print = crop ->m_savings;
4098  break;
4099  default:
4100  g_msg->Warn( WARN_BUG, "FarmManager::PrintOutput(): ""Unknown crop variable type! ", "" );
4101  exit( 1 );
4102  }
4103  ofile << var_to_print << '\t';
4104  }
4105  ofile << endl;
4106  }
4107  }
4108  ofile.close();
4109 }
int Get_almass_no(void)
Definition: farm.h:1896
Definition: farm.h:352
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
Definition: farm.h:348
int Get_cropsSize(void)
Definition: farm.h:1898
double m_areaPercent
Area of a crop in percent of a farm&#39;s total area [%].
Definition: farm.h:1552
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
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
Definition: farm.h:349
double m_nt
Amount of purchased (and applied) fertilizer per ha of a crop [kg N/ha].
Definition: farm.h:1515
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
string Get_cropTypes_almass_str(int i)
Definition: farm.h:582
CropOptimised * Get_crop(int i)
Definition: farm.h:1897
double m_area_ha
Area of a crop in ha at a farm [ha].
Definition: farm.h:1556
A class for storing all parameters and results of crop optimisation.
Definition: farm.h:1491
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
Definition: farm.h:360
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_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
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
double m_BIHerb
Value of BI for herbicides [BI/ha].
Definition: farm.h:1524
double m_weeding
Value of mechanical weed control for a crop - manual weeding [DKK/ha].
Definition: farm.h:1534
int Get_noCrops()
Definition: farm.h:585
string Get_cropTypes_str(int i)
Definition: farm.h:515
void FarmManager::ReadCropsData ( )
protected

Reads the data on crops' parameters that do not vary with farm variables and saves them in a vector DataForOptimisation::m_cropParameters.

Definition at line 3179 of file farm.cpp.

References toc_Foobar, and top_Foobar.

3179  {
3180 
3181  //read the input file
3182  ifstream ifile("crop_parameters.txt", ios::in);
3183  //check if there is an input file
3184  if ( !ifile.is_open() ) {
3185  cout << "Cannot open input file " << "crop_parameters.txt" << endl;
3186  char ch;
3187  cin >> ch; //so that it doesn't close immedietly
3188  exit(1);
3189  }
3190 
3191  //get rid of the parameters names
3192  for(int p=0; p<top_Foobar; p++){
3193  string type;
3194  ifile>>type;
3195  }
3196 
3197  //loop through the crops - save values of the parameters in a vector of the DataForOptimisation class
3198  for(int c=0; c<toc_Foobar; c++){
3199  string crop; //in the first column of the input table
3200  ifile>>crop; //do nothing with it
3201  for(int p=0; p<top_Foobar; p++){
3202  double par_value;
3203  ifile>>par_value;
3204  int index=top_Foobar*c + p;
3205  pm_data->Set_cropParameter (par_value, index );
3206  }
3207  }
3208  ifile.close();
3209 }
void Set_cropParameter(double a_value, int i)
Definition: farm.h:537
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void FarmManager::ReadCropsData_almass ( )
protected

Reads the data on crops' parameters that do not vary with farm variables and saves them in a vector DataForOptimisation::m_cropParameters. ALMaSS crop mode.

Definition at line 3211 of file farm.cpp.

References top_Foobar.

3211  {
3212 
3213  //read the input file
3214  ifstream ifile("crop_parameters.txt", ios::in);
3215  //check if there is an input file
3216  if ( !ifile.is_open() ) {
3217  cout << "Cannot open input file " << "crop_parameters.txt" << endl;
3218  char ch;
3219  cin >> ch; //so that it doesn't close immedietly
3220  exit(1);
3221  }
3222 
3223  int noCrops=0;
3224  ifile>>noCrops;
3225 
3226  //get rid of the parameters names
3227  for(int p=0; p<top_Foobar; p++){
3228  string type;
3229  ifile>>type;
3230  }
3231 
3232  //loop through the crops - save values of the parameters in a vector of the DataForOptimisation class
3233  for(int c=0; c<noCrops; c++){
3234  string crop; //in the first column of the input table
3235  ifile>>crop; //do nothing with it
3236  for(int p=0; p<top_Foobar; p++){
3237  double par_value;
3238  ifile>>par_value;
3239  int index=top_Foobar*(pm_data->Get_cropTypes_almass(c)) + p; //Get_cropTypes_almass(c) - gives as a tov type crop at position c
3240  pm_data->Set_cropParameter (par_value, index );
3241  }
3242  }
3243  ifile.close();
3244 
3245 }
void Set_cropParameter(double a_value, int i)
Definition: farm.h:537
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
TTypesOfVegetation Get_cropTypes_almass(int i)
Definition: farm.h:579
void FarmManager::ReadCropsData_perFarm_and_Soil ( )
protected

Reads the data on crops' parameters that vary with a farm and soil type (sellingPrice) and saves them in a vector DataForOptimisation::m_sellingPrice.

Definition at line 3526 of file farm.cpp.

References toc_Foobar, toof_Foobar, and tos_Foobar.

3526  {
3527 
3528  //read the input files
3529  ifstream ifile1("sellingPrice.txt", ios::in);
3530 
3531  //check if there are all input files
3532  if ( !ifile1.is_open() ) {
3533  cout << "Cannot open input file " << "sellingPrice.txt" << endl;
3534  char ch;
3535  cin >> ch; //so that it doesn't close immedietly
3536  exit(1);
3537  }
3538 
3539  //get rid off the crops names;
3540  for(int c=0; c<toc_Foobar; c++){
3541  string type;
3542  ifile1>>type;
3543  }
3544 
3545  //loop through the farm and soil types!
3546  for(int f=0; f<(toof_Foobar * tos_Foobar); f++){
3547  string farm_type;
3548  string soil_type;
3549  ifile1>>farm_type>>soil_type; //get rid off the farm type and soil type names
3550  for(int c=0; c<toc_Foobar; c++){
3551  double par_value;
3552  ifile1>>par_value;
3553  pm_data->Set_sellingPrice(par_value, toc_Foobar*f + c);
3554  }
3555  }
3556  ifile1.close();
3557 }
void Set_sellingPrice(double a_value, int i)
Definition: farm.h:563
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void FarmManager::ReadCropsData_perFarm_and_Soil_almass ( )
protected

Reads the data on crops' parameters that vary with a farm and soil type (sellingPrice) and saves them in a vector DataForOptimisation:m_sellingPrice. ALMaSS crop mode.

Definition at line 3559 of file farm.cpp.

References toof_Foobar, tos_Foobar, and tov_Undefined.

3559  {
3560 
3561  //read the input files
3562  ifstream ifile1("sellingPrice.txt", ios::in);
3563 
3564  //check if there are all input files
3565  if ( !ifile1.is_open() ) {
3566  cout << "Cannot open input file " << "sellingPrice.txt" << endl;
3567  char ch;
3568  cin >> ch; //so that it doesn't close immedietly
3569  exit(1);
3570  }
3571 
3572  int noCrops=0;
3573  ifile1>>noCrops;
3574 
3575  //get rid off the crops names;
3576  for(int c=0; c<noCrops; c++){
3577  string type;
3578  ifile1>>type;
3579  }
3580 
3581  //loop through the farm and soil types!
3582  for(int f=0; f<(toof_Foobar * tos_Foobar); f++){
3583  string farm_type;
3584  string soil_type;
3585  ifile1>>farm_type>>soil_type; //get rid off the farm type and soil type names
3586  for(int c=0; c<noCrops; c++){
3587  double par_value;
3588  ifile1>>par_value;
3590  }
3591  }
3592  ifile1.close();
3593 
3594 
3595  }
void Set_sellingPrice(double a_value, int i)
Definition: farm.h:563
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
TTypesOfVegetation Get_cropTypes_almass(int i)
Definition: farm.h:579
void FarmManager::ReadCropsData_perFarm_and_Soil_and_Size ( )
protected

Reads the data on crops' parameters that vary with a farm type, soil type and farm size (rotationMax, rotationMin) and saves them in vectors of the DataForOptimisation class.

Definition at line 3597 of file farm.cpp.

References toc_Foobar, tofs_Foobar, toof_Foobar, and tos_Foobar.

3597  {
3598 
3599  //read the input files
3600  ifstream ifile1("rotationMax.txt", ios::in);
3601  ifstream ifile2("rotationMin.txt", ios::in);
3602 
3603  //check if there are all input files
3604  if ( !ifile1.is_open() ) {
3605  cout << "Cannot open input file " << "rotationMax.txt" << endl;
3606  char ch;
3607  cin >> ch; //so that it doesn't close immedietly
3608  exit(1);
3609  } else if(!ifile2.is_open() ){
3610  cout << "Cannot open input file " << "rotationMin.txt" << endl;
3611  char ch;
3612  cin >> ch; //so that it doesn't close immedietly
3613  exit(1);
3614  }
3615 
3616  //get rid off the crops names;
3617  for(int c=0; c<toc_Foobar; c++){
3618  string type;
3619  ifile1>>type;
3620  ifile2>>type;
3621  }
3622 
3623  //loop through the farm types, soil types and farm sizes!
3624  for(int f=0; f<(toof_Foobar *tos_Foobar * tofs_Foobar); f++){
3625  string farm_type, soil_type, farm_size;
3626  ifile1>>farm_type>>soil_type>>farm_size; //get rid off the farm type, soil type ad farm size names
3627  ifile2>>farm_type>>soil_type>>farm_size;
3628  for(int c=0; c<toc_Foobar; c++){
3629  double par_value;
3630  ifile1>>par_value;
3631  pm_data->Set_rotationMax(par_value, toc_Foobar*f + c);
3632  ifile2>>par_value;
3633  pm_data->Set_rotationMin(par_value, toc_Foobar*f + c);
3634  }
3635  }
3636  ifile1.close();
3637  ifile2.close();
3638 }
void Set_rotationMin(double a_value, int i)
Definition: farm.h:570
void Set_rotationMax(double a_value, int i)
Definition: farm.h:568
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void FarmManager::ReadCropsData_perFarm_and_Soil_and_Size_almass ( )
protected

Reads the data on crops' parameters that vary with a farm type, soil type and farm size (rotationMax, rotationMin) and saves them in vectors of the DataForOptimisation class. ALMaSS crop mode.

Definition at line 3640 of file farm.cpp.

References cfg_Areas_Based_on_Distribution, g_msg, tofs_Foobar, toof_Foobar, tos_Foobar, tov_Undefined, CfgBool::value(), MapErrorMsg::Warn(), and WARN_FILE.

3640  {
3641 
3642  //read the input files
3643 
3644  string rot_max;
3645  string rot_min;
3646 
3648  rot_max = "rotationMax_almass.txt";
3649  rot_min = "rotationMin_almass.txt";
3650  }
3651  else{ //rot max and min as specified in the Original Bedriftsmodel
3652  rot_max = "rotationMax.txt";
3653  rot_min = "rotationMin.txt";
3654  }
3655 
3656  ifstream ifile1(rot_max.c_str(), ios::in);
3657  ifstream ifile2(rot_min.c_str(), ios::in);
3658 
3659 
3660 
3661  //check if there are all input files
3662  if ( !ifile1.is_open() ) {
3663  cout << "Cannot open input file with rotation max" << endl;
3664  char ch;
3665  cin >> ch; //so that it doesn't close immedietly
3666  exit(1);
3667  } else if(!ifile2.is_open() ){
3668  cout << "Cannot open input file with rotation min" << endl;
3669  char ch;
3670  cin >> ch; //so that it doesn't close immedietly
3671  exit(1);
3672  }
3673 
3674  int noCrops, noCrops1=0;
3675  ifile1>>noCrops;
3676  ifile2>>noCrops1; //should be always same number!
3677  if(noCrops!=noCrops1){
3678  g_msg->Warn( WARN_FILE, "FarmManager::ReadCropsData_perSoilType_almass():"" Numbers of crops differ between input files! ", " " );
3679  exit( 1 );
3680  }
3681 
3682  //get rid off the crops names;
3683  for(int c=0; c<noCrops; c++){
3684  string type;
3685  ifile1>>type;
3686  ifile2>>type;
3687  }
3688 
3689  //loop through the farm types, soil types and farm sizes!
3690  for(int f=0; f<(toof_Foobar *tos_Foobar * tofs_Foobar); f++){
3691  string farm_type, soil_type, farm_size;
3692  ifile1>>farm_type>>soil_type>>farm_size; //get rid off the farm type, soil type ad farm size names
3693  ifile2>>farm_type>>soil_type>>farm_size;
3694  for(int c=0; c<noCrops; c++){
3695  double par_value;
3696  ifile1>>par_value;
3698  ifile2>>par_value;
3700  }
3701  }
3702  ifile1.close();
3703  ifile2.close();
3704 
3705 }
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...
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
bool value(void)
Definition: configurator.h:123
void Set_rotationMin(double a_value, int i)
Definition: farm.h:570
void Set_rotationMax(double a_value, int i)
Definition: farm.h:568
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
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
void FarmManager::ReadCropsData_perFarmType ( )
protected

Reads the data on crops' parameters that vary with a farm type (fixed, fodder, FUKey) and saves them in vectors of the DataForOptimisation class.

Definition at line 3404 of file farm.cpp.

References toc_Foobar, and toof_Foobar.

3404  {
3405 
3406  //read the input files
3407  ifstream ifile1("fixed.txt", ios::in);
3408  ifstream ifile2("fodder.txt", ios::in);
3409  ifstream ifile3("FUKey.txt", ios::in);
3410 
3411  //check if there are all input files
3412  if ( !ifile1.is_open() ) {
3413  cout << "Cannot open input file " << "fixed.txt" << endl;
3414  char ch;
3415  cin >> ch; //so that it doesn't close immedietly
3416  exit(1);
3417  } else if(!ifile2.is_open() ){
3418  cout << "Cannot open input file " << "fodder.txt" << endl;
3419  char ch;
3420  cin >> ch; //so that it doesn't close immedietly
3421  exit(1);
3422  }
3423  else if(!ifile3.is_open() ){
3424  cout << "Cannot open input file " << "FUKey.txt" << endl;
3425  char ch;
3426  cin >> ch; //so that it doesn't close immedietly
3427  exit(1);
3428  }
3429 
3430  //get rid off the crops names;
3431  for(int c=0; c<toc_Foobar; c++){
3432  string type;
3433  ifile1>>type;
3434  ifile2>>type;
3435  ifile3>>type;
3436  }
3437 
3438  //loop through the farm types!
3439  for(int f=0; f<toof_Foobar; f++){
3440  string farm_type;
3441  ifile1>>farm_type; //get rid off the farm type name
3442  ifile2>>farm_type;
3443  ifile3>>farm_type;
3444  for(int c=0; c<toc_Foobar; c++){
3445  string par;
3446  ifile1>>par;
3447  pm_data->Set_fixed(par, toc_Foobar*f + c);
3448  ifile2>>par;
3449  pm_data->Set_fodder(par, toc_Foobar*f + c);
3450  double par_value;
3451  ifile3>>par_value;
3452  pm_data->Set_FUKey(par_value, toc_Foobar*f + c);
3453  }
3454  }
3455  ifile1.close();
3456  ifile2.close();
3457  ifile3.close();
3458 }
void Set_fodder(string a_value, int i)
Definition: farm.h:555
void Set_fixed(string a_value, int i)
Definition: farm.h:550
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void Set_FUKey(double a_value, int i)
Definition: farm.h:560
void FarmManager::ReadCropsData_perFarmType_almass ( )
protected

Reads the data on crops' parameters that vary with a farm type (fixed, fodder, FUKey) and saves them in vectors of the DataForOptimisation class. ALMaSS crop mode.

Definition at line 3460 of file farm.cpp.

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

3460  {
3461 
3462  //read the input files
3463  ifstream ifile1("fixed.txt", ios::in);
3464  ifstream ifile2("fodder.txt", ios::in);
3465  ifstream ifile3("FUKey.txt", ios::in);
3466 
3467  //check if there are all input files
3468  if ( !ifile1.is_open() ) {
3469  cout << "Cannot open input file " << "fixed.txt" << endl;
3470  char ch;
3471  cin >> ch; //so that it doesn't close immedietly
3472  exit(1);
3473  } else if(!ifile2.is_open() ){
3474  cout << "Cannot open input file " << "fodder.txt" << endl;
3475  char ch;
3476  cin >> ch; //so that it doesn't close immedietly
3477  exit(1);
3478  }
3479  else if(!ifile3.is_open() ){
3480  cout << "Cannot open input file " << "FUKey.txt" << endl;
3481  char ch;
3482  cin >> ch; //so that it doesn't close immedietly
3483  exit(1);
3484  }
3485 
3486  int noCrops, noCrops1, noCrops2=0;
3487  ifile1>>noCrops;
3488  ifile2>>noCrops1;
3489  ifile3>>noCrops2; //should be always same number!
3490  if(noCrops!=noCrops1 || noCrops!=noCrops2){
3491  g_msg->Warn( WARN_FILE, "FarmManager::ReadCropsData_perSoilType_almass():"" Numbers of crops differ between input files! ", " " );
3492  exit( 1 );
3493  }
3494 
3495 
3496  //get rid off the crops names;
3497  for(int c=0; c<noCrops; c++){
3498  string type;
3499  ifile1>>type;
3500  ifile2>>type;
3501  ifile3>>type;
3502  }
3503 
3504  //loop through the farm types!
3505  for(int f=0; f<toof_Foobar; f++){
3506  string farm_type;
3507  ifile1>>farm_type; //get rid off the farm type name
3508  ifile2>>farm_type;
3509  ifile3>>farm_type;
3510  for(int c=0; c<noCrops; c++){
3511  string par;
3512  ifile1>>par;
3514  ifile2>>par;
3516  double par_value;
3517  ifile3>>par_value;
3519  }
3520  }
3521  ifile1.close();
3522  ifile2.close();
3523  ifile3.close();
3524 }
void Set_fodder(string a_value, int i)
Definition: farm.h:555
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
void Set_fixed(string a_value, int i)
Definition: farm.h:550
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
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
void Set_FUKey(double a_value, int i)
Definition: farm.h:560
void FarmManager::ReadCropsData_perSoilType ( )
protected

Reads the data on crops' parameters that vary with a soil type (alfa, beta1, beta2, Nnorm) and saves them in vectors of the DataForOptimisation class.

Definition at line 3247 of file farm.cpp.

References toc_Foobar, and tos_Foobar.

3247  {
3248 
3249  //read the input files
3250  ifstream ifile1("alfa.txt", ios::in);
3251  ifstream ifile2("beta1.txt", ios::in);
3252  ifstream ifile3("beta2.txt", ios::in);
3253  ifstream ifile4("Nnorm.txt", ios::in);
3254  //check if there are all input files
3255  if ( !ifile1.is_open() ) {
3256  cout << "Cannot open input file " << "alfa.txt" << endl;
3257  char ch;
3258  cin >> ch; //so that it doesn't close immedietly
3259  exit(1);
3260  } else if(!ifile2.is_open() ){
3261  cout << "Cannot open input file " << "beta1.txt" << endl;
3262  char ch;
3263  cin >> ch; //so that it doesn't close immedietly
3264  exit(1);
3265  }
3266  else if(!ifile3.is_open() ){
3267  cout << "Cannot open input file " << "beta2.txt" << endl;
3268  char ch;
3269  cin >> ch; //so that it doesn't close immedietly
3270  exit(1);
3271  }
3272  else if(!ifile4.is_open() ){
3273  cout << "Cannot open input file " << "Nnorm.txt" << endl;
3274  char ch;
3275  cin >> ch; //so that it doesn't close immedietly
3276  exit(1);
3277  }
3278  //get rid off the crops names;
3279  for(int c=0; c<toc_Foobar; c++){
3280  string type;
3281  ifile1>>type;
3282  ifile2>>type;
3283  ifile3>>type;
3284  ifile4>>type;
3285  }
3286 
3287  //loop through the soil types!
3288  for(int s=0; s<tos_Foobar; s++){
3289  string soil;
3290  ifile1>>soil; //get rid off the soil type name
3291  ifile2>>soil;
3292  ifile3>>soil;
3293  ifile4>>soil;
3294  for(int c=0; c<toc_Foobar; c++){
3295  double par_value;
3296  ifile1>>par_value;
3297  pm_data->Set_alfa(par_value, toc_Foobar*s + c);
3298  ifile2>>par_value;
3299  pm_data->Set_beta1(par_value, toc_Foobar*s + c);
3300  ifile3>>par_value;
3301  pm_data->Set_beta2(par_value, toc_Foobar*s + c);
3302  ifile4>>par_value;
3303  pm_data->Set_Nnorm(par_value, toc_Foobar*s + c);
3304 
3305  }
3306  }
3307  ifile1.close();
3308  ifile2.close();
3309  ifile3.close();
3310  ifile4.close();
3311 }
void Set_Nnorm(double a_value, int i)
Definition: farm.h:546
void Set_beta1(double a_value, int i)
Definition: farm.h:542
void Set_beta2(double a_value, int i)
Definition: farm.h:544
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void Set_alfa(double a_value, int i)
Definition: farm.h:540
void FarmManager::ReadCropsData_perSoilType_almass ( )
protected

Reads the data on crops' parameters that vary with a soil type (alfa, beta1, beta2, Nnorm) and saves them in vectors of the DataForOptimisation class. ALMaSS crop mode.

Definition at line 3313 of file farm.cpp.

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

3313  {
3314 
3315  //read the input files
3316  ifstream ifile1("alfa.txt", ios::in);
3317  ifstream ifile2("beta1.txt", ios::in);
3318  ifstream ifile3("beta2.txt", ios::in);
3319  ifstream ifile4("Nnorm.txt", ios::in);
3320  ifstream ifile5("biomass_factor_almass.txt", ios::in);
3321 
3322  //check if there are all input files
3323  if ( !ifile1.is_open() ) {
3324  cout << "Cannot open input file " << "alfa.txt" << endl;
3325  char ch;
3326  cin >> ch; //so that it doesn't close immedietly
3327  exit(1);
3328  } else if(!ifile2.is_open() ){
3329  cout << "Cannot open input file " << "beta1.txt" << endl;
3330  char ch;
3331  cin >> ch; //so that it doesn't close immedietly
3332  exit(1);
3333  }
3334  else if(!ifile3.is_open() ){
3335  cout << "Cannot open input file " << "beta2.txt" << endl;
3336  char ch;
3337  cin >> ch; //so that it doesn't close immedietly
3338  exit(1);
3339  }
3340  else if(!ifile4.is_open() ){
3341  cout << "Cannot open input file " << "Nnorm.txt" << endl;
3342  char ch;
3343  cin >> ch; //so that it doesn't close immedietly
3344  exit(1);
3345  }
3346  if (!ifile5.is_open() ) {
3347  cout << "Cannot open input file " << "biomass_factor_almass.txt" << endl;
3348  char ch;
3349  cin >> ch; //so that it doesn't close immedietly
3350  exit(1);
3351  }
3352 
3353  int noCrops, noCrops1, noCrops2, noCrops3, noCrops4=0;
3354  ifile1>>noCrops;
3355  ifile2>>noCrops1;
3356  ifile3>>noCrops2;
3357  ifile4>>noCrops3;
3358  ifile5>>noCrops4; //should be always same number!
3359  if(noCrops!=noCrops1 || noCrops!=noCrops2 || noCrops!=noCrops3 || noCrops!=noCrops4){
3360  g_msg->Warn( WARN_FILE, "FarmManager::ReadCropsData_perSoilType_almass():"" Numbers of crops differ between input files! ", " " );
3361  exit( 1 );
3362  }
3363 
3364  //get rid off the crops names;
3365  for(int c=0; c<noCrops; c++){
3366  string type;
3367  ifile1>>type;
3368  ifile2>>type;
3369  ifile3>>type;
3370  ifile4>>type;
3371  ifile5>>type;
3372  }
3373 
3374  //loop through the soil types!
3375  for(int s=0; s<tos_Foobar; s++){
3376  string soil;
3377  ifile1>>soil; //get rid off the soil type name
3378  ifile2>>soil;
3379  ifile3>>soil;
3380  ifile4>>soil;
3381  ifile5>>soil;
3382  for(int c=0; c<noCrops; c++){
3383  double par_value;
3384  ifile1>>par_value;
3385  pm_data->Set_alfa(par_value, tov_Undefined*s + pm_data->Get_cropTypes_almass(c)); //Get_cropTypes_almass(c) - gives as a tov type crop at position c
3386  ifile2>>par_value;
3388  ifile3>>par_value;
3390  ifile4>>par_value;
3392  ifile5>>par_value;
3394 
3395  }
3396  }
3397  ifile1.close();
3398  ifile2.close();
3399  ifile3.close();
3400  ifile4.close();
3401  ifile5.close();
3402 }
void Set_biomass_factor(double a_value, int i)
Definition: farm.h:575
void Set_Nnorm(double a_value, int i)
Definition: farm.h:546
void Set_beta1(double a_value, int i)
Definition: farm.h:542
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
void Set_beta2(double a_value, int i)
Definition: farm.h:544
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void Set_alfa(double a_value, int i)
Definition: farm.h:540
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
void FarmManager::ReadEnergyMaizePrice ( )
protected

Definition at line 3767 of file farm.cpp.

References l_emaize_price_file, and CfgStr::value().

3767  {
3768 
3769 
3770  //read the input files
3771  ifstream ifile1(l_emaize_price_file.value(), ios::in);
3772 
3773  //check if there are all input files
3774  if ( !ifile1.is_open() ) {
3775  cout << "Cannot open input file " << l_emaize_price_file.value() << endl;
3776  char ch;
3777  cin >> ch; //so that it doesn't close immedietly
3778  exit(1);
3779  }
3780  //get th enumber of years he file has data for
3781  int no_years=0;
3782  ifile1>>no_years;
3783 
3784  //loop
3785  for(int i=0; i<no_years; i++){
3786  int year;
3787  ifile1>>year; //get rid off the year number
3788  double par_value;
3789  ifile1>>par_value;
3790  pm_data->Set_emaize_price(par_value);
3791  }
3792  ifile1.close();
3793 }
void Set_emaize_price(double a_value)
Definition: farm.h:587
const char * value(void)
Definition: configurator.h:139
static CfgStr l_emaize_price_file("EMAIZE_PRICE_FILE", CFG_CUSTOM,"EM_price.txt")
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void FarmManager::ReadFarmsData ( )
protected

Reads farm level parameters and saves them in a vector DataForOptimisation::m_farm_data.

Definition at line 3007 of file farm.cpp.

References DataForOptimisation::FarmData::md_almass_no, DataForOptimisation::FarmData::md_farmRealID, DataForOptimisation::FarmData::md_farmSize, DataForOptimisation::FarmData::md_farmType, DataForOptimisation::FarmData::md_soilSubType, and DataForOptimisation::FarmData::md_soilType.

3007  {
3008 
3009  int noFarms;
3010  int noParameters=6; //farm number, farm type, soil type, farm size, real ID, soil subtype
3011 
3012  //read the input file
3013  ifstream ifile("farms_data.txt", ios::in); //change it later - so that the nme can be set in the config file
3014 
3015  //check if there is an input file
3016  if ( !ifile.is_open() ) {
3017  cout << "Cannot open input file " << "farms_data.txt" << endl;
3018  char ch;
3019  cin >> ch; //so that it doesn't close immedietly
3020  exit(1);
3021  }
3022 
3023  //get the number of farms
3024  ifile>>noFarms;
3025  //get rid off the parameters' names
3026  string rubbish=""; //put here the names of the parameters;
3027  for(int i=0; i<noParameters; i++){
3028  ifile>>rubbish;
3029  }
3030  //read the data and assign values to the farm's variables
3031  for(int f=0; f<noFarms; f++){
3032  int almass_no, realID, soilSubType;
3033  string farm_type, soil_type, farm_size;
3034  ifile >> almass_no >> farm_type >> soil_type >> farm_size >> realID >> soilSubType;
3035  TTypesOfOptFarms farmType = TranslateFarmCodes (farm_type);
3036  TTypesOfSoils soilType = TranslateSoilCodes (soil_type);
3037  TTypesOfFarmSize farmSize = TranslateFarmSizeCodes (farm_size);
3038 
3041  pm_data->m_farm_data.push_back(fd);
3042  fd->md_almass_no=almass_no;
3043  fd->md_farmType=farmType;
3044  fd->md_soilType=soilType;
3045  fd->md_farmSize=farmSize;
3046  fd->md_farmRealID=realID;
3047  fd->md_soilSubType=soilSubType;
3048  }
3049 
3050  ifile.close();
3051 }
TTypesOfOptFarms
Definition: farm.h:224
TTypesOfFarmSize md_farmSize
Definition: farm.h:596
TTypesOfFarmSize TranslateFarmSizeCodes(string &str)
Definition: farm.cpp:3821
Class storing farm information: farm&#39;s number used in ALMaSS system, farm&#39;s soil type, farm&#39;s size (business or private) and farm&#39;s real ID number.
Definition: farm.h:591
TTypesOfOptFarms TranslateFarmCodes(string &str)
Definition: farm.cpp:3796
TTypesOfFarmSize
Definition: farm.h:239
TTypesOfOptFarms md_farmType
Definition: farm.h:594
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
TTypesOfSoils TranslateSoilCodes(string &str)
Definition: farm.cpp:3809
vector< FarmData * > m_farm_data
Definition: farm.h:601
TTypesOfSoils
Definition: farm.h:232
TTypesOfSoils md_soilType
Definition: farm.h:595
void FarmManager::ReadFarmsData_perFarmType ( )
protected

Reads the data on farms' parameters that vary with a farm type and saves them in a vector of a DataForOptimisation class.

Definition at line 3707 of file farm.cpp.

References toof_Foobar.

3707  {
3708 
3709  //read the input files
3710  ifstream ifile1("winterMax.txt", ios::in);
3711 
3712  //check if there are all input files
3713  if ( !ifile1.is_open() ) {
3714  cout << "Cannot open input file " << "winterMax.txt" << endl;
3715  char ch;
3716  cin >> ch; //so that it doesn't close immedietly
3717  exit(1);
3718  }
3719 
3720  //get rid off the parameter name;
3721  string type;
3722  ifile1>>type;
3723 
3724  //loop through the farm types!
3725  for(int f=0; f<toof_Foobar; f++){
3726  string farm_type;
3727  ifile1>>farm_type; //get rid off the farm type name
3728  int par_value;
3729  ifile1>>par_value;
3730  pm_data->Set_winterMax(par_value, f);
3731  }
3732  ifile1.close();
3733 }
void Set_winterMax(int a_value, int i)
Definition: farm.h:529
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void FarmManager::ReadInitialCropAreas ( )
protected

Reads the data on farms' initial crop distributions and saves them in a vector DataForOptimisation::m_cropAreas.

Definition at line 3094 of file farm.cpp.

References toc_Foobar.

3094  {
3095 
3096  int noFarms;
3097  //vector<TTypesOfCrops>crops_types; //vector of crops types (enums)
3098 
3099  //read the input file
3100  ifstream ifile("crop_areas.txt", ios::in);
3101  //check if there is an input file
3102  if ( !ifile.is_open() ) {
3103  cout << "Cannot open input file " << "crop_areas.txt" << endl;
3104  char ch;
3105  cin >> ch; //so that it doesn't close immedietly
3106  exit(1);
3107  }
3108 
3109  //get the number of farms /
3110  ifile>>noFarms;
3111 
3112  //put the names of the crop types to TWO vectors: one with strings, one with enums
3113  for(int c=0; c<toc_Foobar; c++){
3114  string type;
3115  ifile>>type;
3116  TTypesOfCrops type_enum = TranslateCropsCodes(type);
3117  pm_data->Set_cropTypes(type_enum);
3118  pm_data->Set_cropTypes_str(type);
3119  }
3120 
3121  //loop through the farms; create an instance of each crop type - also when the initial area is zero!
3122  for(int f=0; f<noFarms; f++){
3123  double almass_no; //in the first column of the input table
3124  ifile>>almass_no;
3125  pm_data->Set_cropArea(almass_no); //put it here so that you can search for the part of a vector - that contains numbers of a given farm
3126  for(int c=0; c<toc_Foobar; c++){
3127  double area;
3128  ifile >> area;
3129  pm_data->Set_cropArea(area);
3130  }
3131  }
3132  ifile.close();
3133 }
void Set_cropArea(double a_area)
Definition: farm.h:520
void Set_cropTypes_str(string crop_type)
Definition: farm.h:513
TTypesOfCrops
Definition: farm.h:269
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
TTypesOfCrops TranslateCropsCodes(string &str)
Definition: farm.cpp:3861
void Set_cropTypes(TTypesOfCrops crop_type)
Definition: farm.h:512
void FarmManager::ReadInitialCropAreas_almass ( )
protected

Reads the data on farms' initial crop distributions and saves them in a vector of a DataForOptimisation class. ALMaSS crop mode.

Definition at line 3135 of file farm.cpp.

3135  {
3136 
3137  int noFarms;
3138  int noCrops;
3139 
3140  //read the input file
3141  ifstream ifile("crop_areas.txt", ios::in);
3142  //check if there is an input file
3143  if ( !ifile.is_open() ) {
3144  cout << "Cannot open input file " << "crop_areas.txt" << endl;
3145  char ch;
3146  cin >> ch; //so that it doesn't close immedietly
3147  exit(1);
3148  }
3149 
3150  //get the number of crops
3151  ifile>>noCrops;
3152  //get the number of farms
3153  ifile>>noFarms;
3154  pm_data->Set_noCrops(noCrops);
3155 
3156  //put the names of the crop types to vector with enums and to the vector with strings - will be used for output
3157  for(int c=0; c<noCrops; c++){
3158  string type;
3159  ifile>>type;
3160  TTypesOfVegetation type_enum = TranslateCropCodes(type);
3161  pm_data->Set_cropTypes_almass(type_enum);
3163  }
3164 
3165  //loop through the farms; create an instance of each crop type - also when the initial area is zero!
3166  for(int f=0; f<noFarms; f++){
3167  double almass_no; //in the first column of the input table
3168  ifile>>almass_no;
3169  pm_data->Set_cropArea(almass_no); //put it here so that you can search for the part of a vector - that contains numbers of a given far
3170  for(int c=0; c<noCrops; c++){
3171  double area;
3172  ifile >> area;
3173  pm_data->Set_cropArea(area);
3174  }
3175  }
3176  ifile.close();
3177 }
void Set_cropArea(double a_area)
Definition: farm.h:520
void Set_noCrops(int no)
Definition: farm.h:584
void Set_cropTypes_almass_str(string crop_type)
Definition: farm.h:581
TTypesOfVegetation
TTypesOfVegetation TranslateCropCodes(std::string &str)
Definition: farm.cpp:1435
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void Set_cropTypes_almass(TTypesOfVegetation crop_type)
Definition: farm.h:578
void FarmManager::ReadLivestockData ( )
protected

Reads the data on livestock parameters (do not vary with farm variables) and saves them in a vector DataForOptimisation::m_livestockParameters.

Definition at line 3735 of file farm.cpp.

References toa_Foobar, and tolp_Foobar.

3735  {
3736 
3737  //read the input file
3738  ifstream ifile("livestock_parameters.txt", ios::in);
3739  //check if there is an input file
3740  if ( !ifile.is_open() ) {
3741  cout << "Cannot open input file " << "livestock_parameters.txt" << endl;
3742  char ch;
3743  cin >> ch; //so that it doesn't close immedietly
3744  exit(1);
3745  }
3746 
3747  //get rid off the parameter names
3748  for(int p=0; p<tolp_Foobar; p++){
3749  string type;
3750  ifile>>type;
3751  }
3752 
3753  //loop through the livestock types - save values of the parameters in a vector of the DataForOptimisation class
3754  for(int l=0; l<toa_Foobar; l++){
3755  string livestock; //in the first column of the input table
3756  ifile>>livestock; //do nothing with it
3757  for(int p=0; p<tolp_Foobar; p++){
3758  double par_value;
3759  ifile>>par_value;
3760  pm_data->Set_livestockParameter(par_value, tolp_Foobar*l + p);
3761  }
3762  }
3763  ifile.close();
3764 }
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
void Set_livestockParameter(double a_value, int i)
Definition: farm.h:533
void FarmManager::ReadLivestockNumbers ( )
protected

Reads the data on livestock numbers and saves them in a vector DataForOptimisation::m_livestockNumbers.

Definition at line 3053 of file farm.cpp.

References toa_Foobar.

3053  {
3054 
3055  int noFarms;
3056  //vector<TTypesOfAnimals>livestock_types; //vector of livestock types (enums)
3057 
3058  //read the input file
3059  ifstream ifile("livestock_numbers.txt", ios::in);
3060  //check if there is an input file
3061  if ( !ifile.is_open() ) {
3062  cout << "Cannot open input file " << "livestock_numbers.txt" << endl;
3063  char ch;
3064  cin >> ch; //so that it doesn't close immedietly
3065  exit(1);
3066  }
3067 
3068  //get the number of farms //and of types of livestock
3069  ifile>>noFarms; //>>noLivestockTypes;
3070 
3071  //put the names of the livestock types to the this vector;
3072  for(int l=0; l<toa_Foobar; l++){
3073  string type;
3074  ifile>>type;
3075  //livestock_types.push_back(TranslateAnimalsCodes(type));
3077  }
3078 
3079  //loop through the farms; create an instance of each livestock type
3080  for(int f=0; f<noFarms; f++){
3081  int almass_no; //in the first column of the input table
3082  ifile>>almass_no;
3083  pm_data->Set_livestockNumber(almass_no); //put it here so that you can search for the part of a vector - that contains numbers of a given farm
3084  for(int l=0; l<toa_Foobar; l++){
3085  int number;
3086  ifile >> number;
3087  pm_data->Set_livestockNumber(number);
3088  }
3089  }
3090  ifile.close();
3091 
3092 }
void Set_livestockNumber(int a_number)
Definition: farm.h:519
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
TTypesOfAnimals TranslateAnimalsCodes(string &str)
Definition: farm.cpp:3832
void Set_livestockTypes(TTypesOfAnimals livestock_type)
Definition: farm.h:511
void FarmManager::ReadLookupTable ( )
protected

Reads the lookup table with allowed/forbidden crop order from a text file and saves it into a vector m_crop_lookup_table.

Definition at line 4148 of file farm.cpp.

References tov_Undefined.

4148  {
4149 
4150  //read the input file
4151  ifstream ifile("crops_lookup.txt", ios::in);
4152  //check if there is an input file
4153  if ( !ifile.is_open() ) {
4154  cout << "Cannot open input file " << "crops_lookup.txt" << endl;
4155  char ch;
4156  cin >> ch; //so that it doesn't close immedietly
4157  exit(1);
4158  }
4159 
4160  //get rid of the crop tov names - first line of the input file
4161  for(int p=0; p<tov_Undefined+1; p++){
4162  string tov_type;
4163  ifile>>tov_type;
4164  }
4165 
4166  //loop through the crops - save values (-1, 0 or 1) in the vector<int>m_crop_lookup_table;
4167  for(int r=0; r<tov_Undefined+1; r++){ //rows
4168  string tov_type; //in the first column of the input table
4169  ifile>>tov_type; //do nothing with it
4170  for(int c=0; c<tov_Undefined+1; c++){ //you are at row r, go through all the columns c
4171  int value;
4172  ifile >> value;
4173  m_crop_lookup_table.push_back(value);
4174  }
4175  }
4176  ifile.close();
4177 
4178 }
vector< int > m_crop_lookup_table
Specifies which crop order is allowed in a rotation (i.e. if a given crop can follow another crop)...
Definition: farm.h:1796
void FarmManager::RemoveField ( int  a_OwnerIndex,
LE a_field 
)

Definition at line 2298 of file farm.cpp.

2299 {
2300  m_farms[ a_OwnerIndex ]->RemoveField( a_field );
2301 }
vector< Farm * > m_farms
Definition: farm.h:1763
void FarmManager::Save_diff_farm_types_areas ( )

Calculates and saves total areas of all optimising farms and specific farm types.

Definition at line 2927 of file farm.cpp.

References OptimisingFarm::Get_farmType(), Farm::GetAreaDouble(), Farm::GetType(), tof_OptimisingFarm, toof_Cattle, toof_Other, toof_Pig, and toof_Plant.

2927  {
2928 
2929  //get farms areas and save them
2935  OptimisingFarm * opf;
2936  for(int j=0; j<(int)m_farms.size(); j++){
2937  if(m_farms[j]->GetType() == tof_OptimisingFarm){
2938  opf = dynamic_cast<OptimisingFarm*>(m_farms[j]);
2939  totalOptFarmsArea += opf->GetAreaDouble();
2940  if(opf->Get_farmType() == toof_Plant){
2942  }
2943  else if(opf->Get_farmType() == toof_Pig){
2945  }
2946  else if(opf->Get_farmType() == toof_Cattle){
2948  }
2949  else if(opf->Get_farmType() == toof_Other){
2951  }
2952  }
2953  }
2954 }
double totalOptFarmsArea_cattle
Definition: farm.h:1790
double totalOptFarmsArea_other
Definition: farm.h:1791
double totalOptFarmsArea_plant
Definition: farm.h:1788
TTypesOfOptFarms Get_farmType(void)
Definition: farm.h:1891
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
double totalOptFarmsArea
Definition: farm.h:1787
double totalOptFarmsArea_pig
Definition: farm.h:1789
Definition: farm.h:228
double GetAreaDouble(void)
Returns the area of arable fields owned by that farm.
Definition: farm.cpp:1064
void FarmManager::Save_last_years_crops_for_farms ( )

Calls OptimisingFarm::Save_last_years_crops for all optimising farms.

Definition at line 2979 of file farm.cpp.

References Farm::GetType(), OptimisingFarm::Save_last_years_crops(), and tof_OptimisingFarm.

2979  {
2980 
2981  for(int i=0; i<(int)m_farms.size(); i++){
2982  if(m_farms[i]->GetType() == tof_OptimisingFarm){ //take only optimising farms
2983  OptimisingFarm * opf;
2984  opf = dynamic_cast<OptimisingFarm*>(m_farms[i]);
2985  opf->Save_last_years_crops();
2986  }
2987  }
2988 }
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
void Save_last_years_crops()
It saves the OptimisingFarm::m_rotational_crops in a vector m_rotational_crops_visible which is acces...
Definition: farm.cpp:4995
void FarmManager::Set_crops_fertilizer ( int  i,
double  fert 
)
inline

Definition at line 1720 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1720 {m_crops_fertilizer[i] += fert;};
vector< double > m_crops_fertilizer
Stores information on aggregate (all farms) fertilizer usage for each crop.
Definition: farm.h:1810
void FarmManager::Set_crops_fertilizer_trade ( int  i,
double  fert_trade 
)
inline

Definition at line 1721 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1721 {m_crops_fertilizer_trade[i] += fert_trade;};
vector< double > m_crops_fertilizer_trade
Stores information on aggregate (all farms) fertilizer trade (Nt) usage for each crop.
Definition: farm.h:1812
void FarmManager::Set_crops_summary_BIs ( int  i,
double  BI 
)
inline

Definition at line 1713 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1713 {m_crops_summary_BIs[i].BI += BI;};
vector< PesticideData > m_crops_summary_BIs
Stores information on aggregate (all farms)pesticide usage for each crop.
Definition: farm.h:1808
void FarmManager::Set_crops_summary_BIs_fi ( int  i,
double  BIfi 
)
inline

Definition at line 1712 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1712 {m_crops_summary_BIs[i].BIfi += BIfi;};
vector< PesticideData > m_crops_summary_BIs
Stores information on aggregate (all farms)pesticide usage for each crop.
Definition: farm.h:1808
void FarmManager::Set_crops_summary_BIs_herb ( int  i,
double  BIherb 
)
inline

Definition at line 1711 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1711 {m_crops_summary_BIs[i].BIherb += BIherb;};
vector< PesticideData > m_crops_summary_BIs
Stores information on aggregate (all farms)pesticide usage for each crop.
Definition: farm.h:1808
void FarmManager::Set_cropTotals ( int  i,
double  value 
)
inline

Definition at line 1696 of file farm.h.

1696 {m_cropTotals[i] = value;};
vector< double > m_cropTotals
Stores crops areas at the landscape level per year.
Definition: farm.h:1794
void FarmManager::Set_cropTotals_cattle_sum ( int  i,
double  crop_area 
)
inline

Definition at line 1717 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1717 {m_cropTotals_cattle_sum[i] += crop_area;};
vector< double > m_cropTotals_cattle_sum
Stores the sums of crops areas on cattle farms within one simulation at the landscape level...
Definition: farm.h:1804
void FarmManager::Set_cropTotals_other_sum ( int  i,
double  crop_area 
)
inline

Definition at line 1718 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1718 {m_cropTotals_other_sum[i] += crop_area;};
vector< double > m_cropTotals_other_sum
Stores the sums of crops areas on other farms within one simulation at the landscape level...
Definition: farm.h:1806
void FarmManager::Set_cropTotals_pig_sum ( int  i,
double  crop_area 
)
inline

Definition at line 1716 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1716 {m_cropTotals_pig_sum[i] += crop_area;};
vector< double > m_cropTotals_pig_sum
Stores the sums of crops areas on pig farms within one simulation at the landscape level...
Definition: farm.h:1802
void FarmManager::Set_cropTotals_plant_sum ( int  i,
double  crop_area 
)
inline

Definition at line 1715 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1715 {m_cropTotals_plant_sum[i] += crop_area;};
vector< double > m_cropTotals_plant_sum
Stores the sums of crops areas on plant farms within one simulation at the landscape level...
Definition: farm.h:1800
void FarmManager::Set_cropTotals_sum ( int  i,
double  crop_area 
)
inline

Definition at line 1714 of file farm.h.

Referenced by OptimisingFarm::ActualProfit().

1714 {m_cropTotals_sum[i] += crop_area;};
vector< double > m_cropTotals_sum
Stores the sums of crops areas within one simulation at the landscape level.
Definition: farm.h:1798
void FarmManager::SetDD ( double  a_dd)
inline

Definition at line 1693 of file farm.h.

1693 {daydegrees = a_dd;};
double daydegrees
Daydegress for period March 1st - November 1st. Used to determine yield of crops that are not harvest...
Definition: farm.h:1767
void FarmManager::SetSpilledGrain ( bool  a_spilledgrain)
inline

Set m_SpilledGrain which is the flag for either 2013 (true) or 2014 (false) spilled grain distributions.

Definition at line 1685 of file farm.h.

1685  {
1686  m_SpilledGrain = a_spilledgrain;
1687  }
bool m_SpilledGrain
Is it 2013 (true) or 2014 (false) as far as grain goes.
Definition: farm.h:1769
void FarmManager::Switch_rotation ( )

Switches OptimisingFarms Farm::m_rotation to the list of all possible rotational crops.

Definition at line 4465 of file farm.cpp.

References Farm::Assign_rotation(), Farm::GetType(), tof_OptimisingFarm, tov_OrchardCrop, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_PermanentSetaside, and tov_YoungForest.

4465  {
4466 
4467  //1. make a new rotation: include all rotational crops
4468  vector<TTypesOfVegetation> new_rotation;
4469  TTypesOfVegetation tov;
4470  for(int i=0; i<pm_data->Get_cropTypes_almass_size(); i++){
4471  tov = pm_data->Get_cropTypes_almass(i);
4474  new_rotation.push_back(tov);
4475  }
4476  }
4477 
4478  //2. assign it to each farm's m_rotation
4479  for(int i=0; i<(int)m_farms.size(); i++){
4480  OptimisingFarm * opf;
4481  if(m_farms[i]->GetType() == tof_OptimisingFarm){ //take only optimising farms
4482  opf = dynamic_cast<OptimisingFarm*>(m_farms[i]);
4483  opf->Assign_rotation(new_rotation);
4484  }
4485  }
4486 }
TTypesOfVegetation
vector< Farm * > m_farms
Definition: farm.h:1763
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
Definition: farm.h:1885
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Definition: farm.h:1733
TTypesOfVegetation Get_cropTypes_almass(int i)
Definition: farm.h:579
void Assign_rotation(vector< TTypesOfVegetation >a_new_rotation)
Definition: farm.cpp:1201
int Get_cropTypes_almass_size()
Definition: farm.h:580
TTypesOfAnimals FarmManager::TranslateAnimalsCodes ( string &  str)

Definition at line 3832 of file farm.cpp.

References g_msg, toa_DCalf, toa_DCow, toa_Deer, toa_Duck, toa_EHen, toa_Finisher, toa_Goat, toa_Goose, toa_Horse, toa_MCalf, toa_MCattle, toa_MDuck, toa_MHen, toa_Mink, toa_Ostrich, toa_Piglet, toa_Sheep, toa_So, toa_Suckler, toa_Turkey, MapErrorMsg::Warn(), and WARN_FILE.

3832  {
3833  // This simply checks through the list of legal animal (livestock) types and returns
3834  // the correct animal type
3835  string str = astr;
3836  if ( str == "Horse") return toa_Horse;
3837  if ( str == "DCow") return toa_DCow;
3838  if ( str == "Suckler") return toa_Suckler;
3839  if ( str == "DCalf") return toa_DCalf;
3840  if ( str == "MCalf") return toa_MCalf;
3841  if ( str == "MCattle") return toa_MCattle;
3842  if ( str == "Sheep") return toa_Sheep;
3843  if ( str == "Goat") return toa_Goat;
3844  if ( str == "So") return toa_So;
3845  if ( str == "Finisher") return toa_Finisher;
3846  if ( str == "Piglet") return toa_Piglet;
3847  if ( str == "Deer") return toa_Deer;
3848  if ( str == "Mink") return toa_Mink;
3849  if ( str == "EHen") return toa_EHen;
3850  if ( str == "MHen") return toa_MHen;
3851  if ( str == "Turkey") return toa_Turkey;
3852  if ( str == "Goose") return toa_Goose;
3853  if ( str == "Duck") return toa_Duck;
3854  if ( str == "MDuck") return toa_MDuck;
3855  if ( str == "Ostrich") return toa_Ostrich;
3856  // No match so issue a warning and quit
3857  g_msg->Warn( WARN_FILE, "FarmManager::TranslateAnimalsCodes():"" Unknown Animal type Code ", str.c_str() );
3858  exit( 1 );
3859 }
Definition: farm.h:253
Definition: farm.h:258
Definition: farm.h:247
Definition: farm.h:259
Definition: farm.h:263
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
Definition: farm.h:260
Definition: farm.h:254
Definition: farm.h:257
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
TTypesOfVegetation FarmManager::TranslateCropCodes ( std::string &  str)
Todo:
Create a OSpringRape crop class and management
Todo:
Create a OSpringWheat crop class and management

Definition at line 1435 of file farm.cpp.

References g_msg, tov_AgroChemIndustryCereal, tov_BroadBeans, tov_Carrots, tov_CloverGrassGrazed1, tov_CloverGrassGrazed2, tov_FieldPeas, tov_FieldPeasSilage, tov_FieldPeasStrigling, tov_FodderBeet, tov_FodderGrass, tov_Maize, tov_MaizeSilage, tov_MaizeStrigling, tov_Oats, tov_OBarleyPeaCloverGrass, tov_OCarrots, tov_OCloverGrassGrazed1, tov_OCloverGrassGrazed2, tov_OCloverGrassSilage1, tov_OFieldPeas, tov_OFieldPeasSilage, tov_OFodderBeet, tov_OGrazingPigs, tov_OMaizeSilage, tov_OOats, tov_OPermanentGrassGrazed, tov_OPotatoes, tov_OrchardCrop, tov_OSBarleySilage, tov_OSeedGrass1, tov_OSeedGrass2, tov_OSpringBarley, tov_OSpringBarleyClover, tov_OSpringBarleyExt, tov_OSpringBarleyGrass, tov_OSpringBarleyPigs, tov_OTriticale, tov_OWinterBarley, tov_OWinterBarleyExt, tov_OWinterRape, tov_OWinterRye, tov_OWinterWheat, tov_OWinterWheatUndersown, tov_OWinterWheatUndersownExt, tov_PermanentGrassGrazed, tov_PermanentGrassLowYield, tov_PermanentGrassTussocky, tov_PermanentSetaside, tov_Potatoes, tov_PotatoesIndustry, tov_SeedGrass1, tov_SeedGrass2, tov_Setaside, tov_SpringBarley, tov_SpringBarleyCloverGrass, tov_SpringBarleyCloverGrassStrigling, tov_SpringBarleyGrass, tov_SpringBarleyPeaCloverGrassStrigling, tov_SpringBarleyPTreatment, tov_SpringBarleySeed, tov_SpringBarleySilage, tov_SpringBarleySpr, tov_SpringBarleyStrigling, tov_SpringBarleyStriglingCulm, tov_SpringBarleyStriglingSingle, tov_SpringRape, tov_SpringWheat, tov_SugarBeet, tov_Triticale, tov_WinterBarley, tov_WinterBarleyStrigling, tov_WinterRape, tov_WinterRapeStrigling, tov_WinterRye, tov_WinterRyeStrigling, tov_WinterWheat, tov_WinterWheatShort, tov_WinterWheatStrigling, tov_WinterWheatStriglingCulm, tov_WinterWheatStriglingSingle, tov_WWheatPControl, tov_WWheatPToxicControl, tov_WWheatPTreatment, tov_YoungForest, MapErrorMsg::Warn(), and WARN_FILE.

Referenced by OptimisingFarm::findCropByName_almass(), Farm::ReadRotation(), and UserDefinedFarm::UserDefinedFarm().

1435  { //changed to farm manager - was a Farm function, 19.03.13
1436  // This simply checks through the list of legal crop names and returns
1437  // the correct tov type
1438 
1439  string str = astr;
1440 
1441  // Unfortunately switch cannot use string so the long way:
1442  if (str == "SpringBarley") return tov_SpringBarley;
1443  if (str == "SpringBarleySpr") return tov_SpringBarleySpr;
1444  if (str == "SpringBarleyPTreatment") return tov_SpringBarleyPTreatment;
1445  if (str == "WinterBarley") return tov_WinterBarley;
1446  if (str == "SpringWheat") return tov_SpringWheat;
1447  if (str == "WinterWheat") return tov_WinterWheat;
1448  if (str == "WinterRye") return tov_WinterRye;
1449  if (str == "OrchardCrop") return tov_OrchardCrop;
1450  if (str == "Oats") return tov_Oats;
1451  if (str == "OOats") return tov_OOats;
1452  if (str == "Triticale") return tov_Triticale;
1453  if (str == "OTriticale") return tov_OTriticale;
1454  if (str == "Maize") return tov_Maize;
1455  if (str == "MaizeSilage") return tov_MaizeSilage;
1456  if (str == "SpringBarleySeed") return tov_SpringBarleySeed;
1457  if (str == "OSpringRape") return tov_SpringRape;
1458  if (str == "SpringRape") return tov_SpringRape;
1459  if (str == "WinterRape") return tov_WinterRape;
1460  if (str == "BroadBeans") return tov_BroadBeans;
1461  if (str == "FieldPeas") return tov_FieldPeas;
1462  if (str == "FieldPeasSilage") return tov_FieldPeasSilage;
1463  if (str == "Setaside") return tov_Setaside;
1464  if (str == "PermanentSetaside") return tov_PermanentSetaside;
1465  if (str == "SugarBeet") return tov_SugarBeet;
1466  if (str == "FodderBeet") return tov_FodderBeet;
1467  if (str == "OFodderBeet") return tov_OFodderBeet;
1468  if (str == "FodderGrass") return tov_FodderGrass;
1469  if (str == "CloverGrassGrazed1") return tov_CloverGrassGrazed1;
1470  if (str == "PotatoesIndustry") return tov_PotatoesIndustry;
1471  if (str == "Potatoes") return tov_Potatoes;
1472  if (str == "SeedGrass1") return tov_SeedGrass1;
1473  if (str == "OWinterBarley") return tov_OWinterBarley;
1474  if (str == "OWinterBarleyExt") return tov_OWinterBarleyExt;
1475  if (str == "SpringBarleySilage") return tov_SpringBarleySilage;
1476  if (str == "OWinterRye") return tov_OWinterRye;
1477  if (str == "OFieldPeasSilage") return tov_OFieldPeasSilage;
1478  if (str == "SpringBarleyGrass") return tov_SpringBarleyGrass;
1479  if (str == "SpringBarleyCloverGrass") return tov_SpringBarleyCloverGrass;
1480  if (str == "OBarleyPeaCloverGrass") return tov_OBarleyPeaCloverGrass;
1481  if (str == "OWinterRape") return tov_OWinterRape;
1482  if (str == "PermanentGrassGrazed") return tov_PermanentGrassGrazed;
1483  if (str == "PermanentGrassLowYield") return tov_PermanentGrassLowYield;
1484  if (str == "PermanentGrassTussocky") return tov_PermanentGrassTussocky;
1485  if (str == "CloverGrassGrazed2") return tov_CloverGrassGrazed2;
1486  if (str == "SeedGrass2") return tov_SeedGrass2;
1487  if (str == "OSpringWheat") return tov_OSpringBarley;
1488  if (str == "OSpringBarley") return tov_OSpringBarley;
1489  if (str == "OSpringBarleyExt") return tov_OSpringBarleyExt;
1490  if (str == "OWinterWheat") return tov_OWinterWheat;
1491  if (str == "OWinterWheatUndersown") return tov_OWinterWheatUndersown;
1492  if (str == "OWinterWheatUndersownExt") return tov_OWinterWheatUndersownExt;
1493  if (str == "OOats") return tov_OOats;
1494  if (str == "OFieldPeas") return tov_OFieldPeas;
1495  if (str == "OCloverGrassGrazed1") return tov_OCloverGrassGrazed1;
1496  if (str == "OGrazingPigs") return tov_OGrazingPigs;
1497  if (str == "OCarrots") return tov_OCarrots;
1498  if (str == "Carrots") return tov_Carrots;
1499  if (str == "OPotatoes") return tov_OPotatoes;
1500  if (str == "OSeedGrass1") return tov_OSeedGrass1;
1501  if (str == "OSpringBarleyGrass") return tov_OSpringBarleyGrass;
1502  if (str == "OSpringBarleyClover") return tov_OSpringBarleyClover;
1503  if (str == "OPermanentGrassGrazed") return tov_OPermanentGrassGrazed;
1504  if (str == "OCloverGrassSilage1") return tov_OCloverGrassSilage1;
1505  if (str == "OCloverGrassGrazed2") return tov_OCloverGrassGrazed2;
1506  if (str == "OSeedGrass2") return tov_OSeedGrass2;
1507  if (str == "WWheatPControl") return tov_WWheatPControl;
1508  if (str == "WWheatPToxicControl") return tov_WWheatPToxicControl;
1509  if (str == "WWheatPTreatment") return tov_WWheatPTreatment;
1510  if (str == "AgroChemIndustryCereal") return tov_AgroChemIndustryCereal;
1511  if (str == "WinterWheatShort") return tov_WinterWheatShort;
1512  if (str == "WinterWheatStrigling") return tov_WinterWheatStrigling;
1513  if (str == "WinterWheatStriglingCulm") return tov_WinterWheatStriglingCulm;
1514  if (str == "WinterWheatStriglingSgl") return tov_WinterWheatStriglingSingle;
1515  if (str == "SpringBarleyCloverGrassStrigling") return tov_SpringBarleyCloverGrassStrigling;
1516  if (str == "SpringBarleyStrigling") return tov_SpringBarleyStrigling;
1517  if (str == "SpringBarleyStriglingSingle") return tov_SpringBarleyStriglingSingle;
1518  if (str == "SpringBarleyStriglingCulm") return tov_SpringBarleyStriglingCulm;
1519  if (str == "MaizeStrigling") return tov_MaizeStrigling;
1520  if (str == "WinterRapeStrigling") return tov_WinterRapeStrigling;
1521  if (str == "WinterRyeStrigling") return tov_WinterRyeStrigling;
1522  if (str == "WinterBarleyStrigling") return tov_WinterBarleyStrigling;
1523  if (str == "FieldPeasStrigling") return tov_FieldPeasStrigling;
1524  if (str == "SpringBarleyPeaCloverGrassStrigling") return tov_SpringBarleyPeaCloverGrassStrigling;
1525  if (str == "YoungForest") return tov_YoungForest;
1526  if (str == "OMaizeSilage") return tov_OMaizeSilage;
1527  if (str == "OSpringBarleySilage") return tov_OSBarleySilage;
1528  if (str == "OSpringBarleyPigs") return tov_OSpringBarleyPigs;
1529 
1530  // No match so issue a warning and quit
1531  g_msg->Warn( WARN_FILE, "FarmManager::TranslateCropCodes():"" Unknown Crop Code ", str.c_str() );
1532  exit( 1 );
1533 }
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
TTypesOfCrops FarmManager::TranslateCropsCodes ( string &  str)

Definition at line 3861 of file farm.cpp.

References g_msg, toc_ChrisTree, toc_CloverGrz, toc_EnergyFor, toc_Fruit, toc_FruitTree, toc_GrassClover, toc_GrassEnv1, toc_GrassEnv2, toc_GrassRot, toc_GrassSeed, toc_MaizeSil, toc_Oats, toc_OFodderBeet, toc_OLSeed, toc_OLSeedCut, toc_OOilseed, toc_OSCrops, toc_OSpecCrops, toc_Other, toc_OUncult, toc_Peas, toc_PeasSil, toc_PerGrassLow, toc_PerGrassNorm, toc_Potato, toc_PotatoFood, toc_SBarley, toc_SCerealG, toc_SCerealSil, toc_Setaside, toc_SRape, toc_SugarBeet, toc_Triticale, toc_Uncult, toc_Veg, toc_WBarley, toc_WCerealSil, toc_WRape, toc_WRye, toc_WWheat, MapErrorMsg::Warn(), and WARN_FILE.

Referenced by OptimisingFarm::findCropByName().

3861  {
3862 // This simply checks through the list of legal crops types and returns
3863 // the correct crop type
3864  string str = astr;
3865  if ( str == "SBarley") return toc_SBarley;
3866  if ( str == "Oats") return toc_Oats;
3867  if ( str == "OSCrops") return toc_OSCrops;
3868  if ( str == "WBarley") return toc_WBarley;
3869  if ( str == "WWheat") return toc_WWheat;
3870  if ( str == "WRye") return toc_WRye;
3871  if ( str == "Triticale") return toc_Triticale;
3872  if ( str == "SRape") return toc_SRape;
3873  if ( str == "WRape") return toc_WRape;
3874  if ( str == "OOilseed") return toc_OOilseed;
3875  if ( str == "Peas") return toc_Peas;
3876  if ( str == "OLSeed") return toc_OLSeed;
3877  if ( str == "GrassSeed") return toc_GrassSeed;
3878  if ( str == "Potato") return toc_Potato;
3879  if ( str == "PotatoFood") return toc_PotatoFood;
3880  if ( str == "SugarBeet") return toc_SugarBeet;
3881  if ( str == "GrassClover") return toc_GrassClover;
3882  if ( str == "OLSeedCut") return toc_OLSeedCut;
3883  if ( str == "SCerealSil") return toc_SCerealSil;
3884  if ( str == "PeasSil") return toc_PeasSil;
3885  if ( str == "MaizeSil") return toc_MaizeSil;
3886  if ( str == "WCerealSil") return toc_WCerealSil;
3887  if ( str == "SCerealG") return toc_SCerealG;
3888  if ( str == "PerGrassLow") return toc_PerGrassLow;
3889  if ( str == "PerGrassNorm") return toc_PerGrassNorm;
3890  if ( str == "GrassEnv1") return toc_GrassEnv1;
3891  if ( str == "GrassEnv2") return toc_GrassEnv2;
3892  if ( str == "GrassRot") return toc_GrassRot;
3893  if ( str == "Setaside") return toc_Setaside;
3894  if ( str == "Uncult") return toc_Uncult;
3895  if ( str == "OUncult") return toc_OUncult;
3896  if ( str == "OFodderBeet") return toc_OFodderBeet;
3897  if ( str == "CloverGrz") return toc_CloverGrz;
3898  if ( str == "Veg") return toc_Veg;
3899  if ( str == "Fruit") return toc_Fruit;
3900  if ( str == "FruitTree") return toc_FruitTree;
3901  if ( str == "OSpecCrops") return toc_OSpecCrops;
3902  if ( str == "ChrisTree") return toc_ChrisTree;
3903  if ( str == "EnergyFor") return toc_EnergyFor;
3904  if ( str == "Other") return toc_Other;
3905  // No match so issue a warning and quit
3906  g_msg->Warn( WARN_FILE, "FarmManager::TranslateCropCodes():"" Unknown Crop type Code ", str.c_str() );
3907  exit( 1 );
3908 }
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
Definition: farm.h:275
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
Definition: farm.h:271
Definition: farm.h:304
Definition: farm.h:280
TTypesOfCropVariables FarmManager::TranslateCropVariablesCodes ( string &  str)

Definition at line 3949 of file farm.cpp.

References g_msg, 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_FILE.

3949  {
3950  // This simply checks through the list of legal crop variables and returns the correct enum
3951  string str = astr;
3952  if ( str == "m_areaPercent" ) return tocv_AreaPercent;
3953  if ( str == "m_area_ha" ) return tocv_AreaHa;
3954  if ( str == "m_n" ) return tocv_N;
3955  if ( str == "m_nt" ) return tocv_Nt;
3956  if ( str == "m_BIHerb" ) return tocv_BIHerb;
3957  if ( str == "m_BIFi" ) return tocv_BIFi;
3958  if ( str == "m_BI" ) return tocv_BI;
3959  if ( str == "m_grooming" ) return tocv_Grooming;
3960  if ( str == "m_hoeing" ) return tocv_Hoeing;
3961  if ( str == "m_weeding" ) return tocv_Weeding;
3962  if ( str == "m_totalLoss" ) return tocv_TotalLoss;
3963  if ( str == "m_resp" ) return tocv_Response;
3964  if ( str == "m_income" ) return tocv_Income;
3965  if ( str == "m_costs" ) return tocv_Costs;
3966  if ( str == "m_GM" ) return tocv_GM;
3967  if ( str == "m_savings" ) return tocv_Savings;
3968 
3969  // No match so issue a warning and quit
3970  g_msg->Warn( WARN_FILE, "FarmManager::TTypesOfCropVariables():"" Unknown crop variable Code ", str.c_str() );
3971  exit( 1 );
3972 }
Definition: farm.h:352
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
TTypesOfOptFarms FarmManager::TranslateFarmCodes ( string &  str)

Definition at line 3796 of file farm.cpp.

References g_msg, toof_Cattle, toof_Other, toof_Pig, toof_Plant, MapErrorMsg::Warn(), and WARN_FILE.

3796  {
3797  // This simply checks through the list of legal farm types and returns
3798  // the correct farm type
3799  string str = astr;
3800  if ( str == "Other" ) return toof_Other;
3801  if ( str == "Cattle" ) return toof_Cattle;
3802  if ( str == "Plant" ) return toof_Plant;
3803  if ( str == "Pig" ) return toof_Pig;
3804  // No match so issue a warning and quit
3805  g_msg->Warn( WARN_FILE, "FarmManager::TranslateFarmCodes():"" Unknown Farm type Code ", str.c_str() );
3806  exit( 1 );
3807 }
class MapErrorMsg * g_msg
Definition: maperrormsg.cpp:38
Definition: farm.h:228
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: maperrormsg.cpp:56
TTypesOfFarmSize FarmManager::TranslateFarmSizeCodes ( string &  str)

Definition at line 3821 of file farm.cpp.

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

3821  {
3822  // This simply checks through the list of legal farm sizes and returns
3823  // the correct farm size
3824  string str = astr;
3825  if ( str == "business" ) return tofs_Business;
3826  if ( str == "private" ) return tofs_Private;
3827  // No match so issue a warning and quit
3828  g_msg->Warn( WARN_FILE, "FarmManager::TranslateFarmSizeCodes():"" Unknown Farm Size Code ", str.c_str() );
3829  exit( 1 );
3830 }
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
TTypesOfLivestockParameters FarmManager::TranslateLivestockParametersCodes ( string &  str)

Definition at line 3937 of file farm.cpp.

References g_msg, tolp_AUKey, tolp_FUuKey, tolp_Nusable, MapErrorMsg::Warn(), and WARN_FILE.

Referenced by OptimisingFarm::findFodderDemand(), and OptimisingFarm::findTotalNanim().

3937  {
3938  // This simply checks through the list of legal livestock parameters and returns the correct enum
3939  string str = astr;
3940  if ( str == "AUKey" ) return tolp_AUKey;
3941  if ( str == "Nusable" ) return tolp_Nusable;
3942  if ( str == "FUuKey" ) return tolp_FUuKey;
3943 
3944  // No match so issue a warning and quit
3945  g_msg->Warn( WARN_FILE, "FarmManager::TranslateLivestockParametersCodes():"" Unknown Livestock Parameter Code ", str.c_str() );
3946  exit( 1 );
3947 }
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
TTypesOfParameters FarmManager::TranslateParametersCodes ( string &  str)

Definition at line 3910 of file farm.cpp.

References g_msg, top_AlfaFi, top_AlfaG, top_AlfaH, top_AlfaHerb, top_AlfaW, top_BetaFi, top_BetaG, top_BetaH, top_BetaHerb, top_BetaW, top_PriceFi, top_PriceG, top_PriceH, top_PriceHerb, top_PriceLM, top_PriceW, top_Subsidy, MapErrorMsg::Warn(), and WARN_FILE.

Referenced by OptimisingFarm::crop_parameter().

3910  {
3911  // This simply checks through the list of legal crop parameters (those not varying with farm type etc.)
3912  //and returns the correct enum
3913  string str = astr;
3914  if ( str == "Subsidy" ) return top_Subsidy;
3915  if ( str == "PriceLM" ) return top_PriceLM;
3916  if ( str == "PriceHerb" ) return top_PriceHerb;
3917  if ( str == "PriceFi" ) return top_PriceFi;
3918  if ( str == "PriceG" ) return top_PriceG;
3919  if ( str == "PriceH" ) return top_PriceH;
3920  if ( str == "PriceW" ) return top_PriceW;
3921  if ( str == "AlfaHerb" ) return top_AlfaHerb;
3922  if ( str == "BetaHerb" ) return top_BetaHerb;
3923  if ( str == "AlfaFi" ) return top_AlfaFi;
3924  if ( str == "BetaFi" ) return top_BetaFi;
3925  if ( str == "AlfaG" ) return top_AlfaG;
3926  if ( str == "BetaG" ) return top_BetaG;
3927  if ( str == "AlfaH" ) return top_AlfaH;
3928  if ( str == "BetaH" ) return top_BetaH;
3929  if ( str == "AlfaW" ) return top_AlfaW;
3930  if ( str == "BetaW" ) return top_BetaW;
3931 
3932  // No match so issue a warning and quit
3933  g_msg->Warn( WARN_FILE, "FarmManager::TranslateParametersCodes():"" Unknown Parameter Code ", str.c_str() );
3934  exit( 1 );
3935 }
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
TTypesOfSoils FarmManager::TranslateSoilCodes ( string &  str)

Definition at line 3809 of file farm.cpp.

References g_msg, tos_Clay, tos_Other, tos_Sand, MapErrorMsg::Warn(), and WARN_FILE.

3809  {
3810  // This simply checks through the list of legal soil types and returns
3811  // the correct soil type
3812  string str = astr;
3813  if ( str == "Other" ) return tos_Other;
3814  if ( str == "Sand" ) return tos_Sand;
3815  if ( str == "Clay" ) return tos_Clay;
3816  // No match so issue a warning and quit
3817  g_msg->Warn( WARN_FILE, "FarmManager::TranslateSoilCodes():"" Unknown Soil type Code ", str.c_str() );
3818  exit( 1 );
3819 }
Definition: farm.h:235
Definition: farm.h:233
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

Member Data Documentation

double FarmManager::daydegrees
protected

Daydegress for period March 1st - November 1st. Used to determine yield of crops that are not harvested (and thus do not have values of biomass at harvest).

Definition at line 1767 of file farm.h.

vector<double> FarmManager::m_crop_areas_stages
protected

Stores information on crop areas calculated in different stages of model development: for comparison in sensitivity analysis.

Definition at line 1814 of file farm.h.

vector<int> FarmManager::m_crop_lookup_table
protected

Specifies which crop order is allowed in a rotation (i.e. if a given crop can follow another crop).

Definition at line 1796 of file farm.h.

vector<double> FarmManager::m_crops_fertilizer
protected

Stores information on aggregate (all farms) fertilizer usage for each crop.

Definition at line 1810 of file farm.h.

vector<double> FarmManager::m_crops_fertilizer_trade
protected

Stores information on aggregate (all farms) fertilizer trade (Nt) usage for each crop.

Definition at line 1812 of file farm.h.

vector<PesticideData> FarmManager::m_crops_summary_BIs
protected

Stores information on aggregate (all farms)pesticide usage for each crop.

Definition at line 1808 of file farm.h.

vector<double> FarmManager::m_cropTotals
protected

Stores crops areas at the landscape level per year.

Definition at line 1794 of file farm.h.

vector<double> FarmManager::m_cropTotals_cattle_sum
protected

Stores the sums of crops areas on cattle farms within one simulation at the landscape level.

Definition at line 1804 of file farm.h.

vector<double> FarmManager::m_cropTotals_other_sum
protected

Stores the sums of crops areas on other farms within one simulation at the landscape level.

Definition at line 1806 of file farm.h.

vector<double> FarmManager::m_cropTotals_pig_sum
protected

Stores the sums of crops areas on pig farms within one simulation at the landscape level.

Definition at line 1802 of file farm.h.

vector<double> FarmManager::m_cropTotals_plant_sum
protected

Stores the sums of crops areas on plant farms within one simulation at the landscape level.

Definition at line 1800 of file farm.h.

vector<double> FarmManager::m_cropTotals_sum
protected

Stores the sums of crops areas within one simulation at the landscape level.

Definition at line 1798 of file farm.h.

int* FarmManager::m_farmmapping_lookup
protected

Used for a dynamic array of lookups converting farm references to internal renumbering.

Definition at line 1772 of file farm.h.

vector<Farm*> FarmManager::m_farms
protected

Definition at line 1763 of file farm.h.

Population_Manager* FarmManager::m_population_manager
protected

Definition at line 1764 of file farm.h.

bool FarmManager::m_renumbered
protected

A flag to show whether renumbering was already done.

Definition at line 1774 of file farm.h.

bool FarmManager::m_SpilledGrain
protected

Is it 2013 (true) or 2014 (false) as far as grain goes.

Definition at line 1769 of file farm.h.

DataForOptimisation* FarmManager::pm_data
ofstream* FarmManager::pm_output_file

Definition at line 1734 of file farm.h.

double FarmManager::totalOptFarmsArea
protected

Definition at line 1787 of file farm.h.

double FarmManager::totalOptFarmsArea_cattle
protected

Definition at line 1790 of file farm.h.

double FarmManager::totalOptFarmsArea_other
protected

Definition at line 1791 of file farm.h.

double FarmManager::totalOptFarmsArea_pig
protected

Definition at line 1789 of file farm.h.

double FarmManager::totalOptFarmsArea_plant
protected

Definition at line 1788 of file farm.h.


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