42 #define _CRT_SECURE_NO_DEPRECATE 49 #include "../BatchALMaSS/BoostRandomGenerators.h" 54 #define _CRTDBG_MAP_ALLOC 58 #define _CRT_SECURE_NO_DEPRECATE 60 #include "../BatchALMaSS/ALMaSS_Setup.h" 61 #include "../Landscape/ls.h" 62 #include "../Landscape/cropprogs/BroadBeans.h" 63 #include "../Landscape/cropprogs/Carrots.h" 64 #include "../Landscape/cropprogs/CloverGrassGrazed1.h" 65 #include "../Landscape/cropprogs/CloverGrassGrazed2.h" 66 #include "../Landscape/cropprogs/FieldPeas.h" 67 #include "../Landscape/cropprogs/FieldPeasSilage.h" 68 #include "../Landscape/cropprogs/Fodderbeet.h" 69 #include "../Landscape/cropprogs/Sugarbeet.h" 70 #include "../Landscape/cropprogs/FodderGrass.h" 71 #include "../Landscape/cropprogs/Maize.h" 72 #include "../Landscape/cropprogs/MaizeSilage.h" 73 #include "../Landscape/cropprogs/OFodderbeet.h" 74 #include "../Landscape/cropprogs/OMaizeSilage.h" 75 #include "../Landscape/cropprogs/OBarleyPeaCloverGrass.h" 76 #include "../Landscape/cropprogs/OSBarleySilage.h" 77 #include "../Landscape/cropprogs/OCarrots.h" 78 #include "../Landscape/cropprogs/OCloverGrassGrazed1.h" 79 #include "../Landscape/cropprogs/OCloverGrassGrazed2.h" 80 #include "../Landscape/cropprogs/OCloverGrassSilage1.h" 81 #include "../Landscape/cropprogs/OFirstYearDanger.h" 82 #include "../Landscape/cropprogs/OGrazingPigs.h" 83 #include "../Landscape/cropprogs/OPermanentGrassGrazed.h" 84 #include "../Landscape/cropprogs/OSeedGrass1.h" 85 #include "../Landscape/cropprogs/OSeedGrass2.h" 86 #include "../Landscape/cropprogs/OSpringBarleyPigs.h" 87 #include "../Landscape/cropprogs/OFieldPeas.h" 88 #include "../Landscape/cropprogs/OFieldPeasSilage.h" 89 #include "../Landscape/cropprogs/OrchardCrop.h" 90 #include "../Landscape/cropprogs/OOats.h" 91 #include "../Landscape/cropprogs/Oats.h" 92 #include "../Landscape/cropprogs/OPotatoes.h" 93 #include "../Landscape/cropprogs/OSpringBarley.h" 94 #include "../Landscape/cropprogs/OSpringBarleyExt.h" 95 #include "../Landscape/cropprogs/OWinterBarley.h" 96 #include "../Landscape/cropprogs/OWinterBarleyExt.h" 97 #include "../Landscape/cropprogs/OWinterRape.h" 98 #include "../Landscape/cropprogs/OWinterRye.h" 99 #include "../Landscape/cropprogs/OWinterWheat.h" 100 #include "../Landscape/cropprogs/OWinterWheatUndersown.h" 101 #include "../Landscape/cropprogs/OWinterWheatUndersownExt.h" 102 #include "../Landscape/cropprogs/PermanentGrassGrazed.h" 103 #include "../Landscape/cropprogs/PermanentGrassLowYield.h" 104 #include "../Landscape/cropprogs/PermanentGrassTussocky.h" 105 #include "../Landscape/cropprogs/PermanentSetAside.h" 106 #include "../Landscape/cropprogs/Potatoes.h" 107 #include "../Landscape/cropprogs/PotatoesIndustry.h" 108 #include "../Landscape/cropprogs/seedgrass1.h" 109 #include "../Landscape/cropprogs/seedgrass2.h" 110 #include "../Landscape/cropprogs/setaside.h" 111 #include "../Landscape/cropprogs/SpringBarley.h" 112 #include "../Landscape/cropprogs/SpringBarleySpr.h" 113 #include "../Landscape/cropprogs/SpringBarleyPTreatment.h" 114 #include "../Landscape/cropprogs/SpringBarleySKManagement.h" 115 #include "../Landscape/cropprogs/SpringBarleyCloverGrass.h" 116 #include "../Landscape/cropprogs/SpringBarleySeed.h" 117 #include "../Landscape/cropprogs/SpringBarleySilage.h" 118 #include "../Landscape/cropprogs/SpringRape.h" 119 #include "../Landscape/cropprogs/Triticale.h" 120 #include "../Landscape/cropprogs/OTriticale.h" 121 #include "../Landscape/cropprogs/WinterBarley.h" 122 #include "../Landscape/cropprogs/winterrape.h" 123 #include "../Landscape/cropprogs/WinterRye.h" 124 #include "../Landscape/cropprogs/WinterWheat.h" 125 #include "../Landscape/cropprogs/WWheatPControl.h" 126 #include "../Landscape/cropprogs/WWheatPTreatment.h" 127 #include "../Landscape/cropprogs/WWheatPToxicControl.h" 128 #include "../Landscape/cropprogs/AgroChemIndustryCereal.h" 130 #include "../Landscape/cropprogs/WinterWheatStrigling.h" 131 #include "../Landscape/cropprogs/WinterWheatStriglingCulm.h" 132 #include "../Landscape/cropprogs/WinterWheatStriglingSingle.h" 133 #include "../Landscape/cropprogs/SpringBarleyCloverGrassStrigling.h" 134 #include "../Landscape/cropprogs/SpringBarleyStrigling.h" 135 #include "../Landscape/cropprogs/SpringBarleyStriglingCulm.h" 136 #include "../Landscape/cropprogs/SpringBarleyStriglingSingle.h" 137 #include "../Landscape/cropprogs/MaizeStrigling.h" 138 #include "../Landscape/cropprogs/winterrapestrigling.h" 139 #include "../Landscape/cropprogs/WinterRyeStrigling.h" 140 #include "../Landscape/cropprogs/WinterBarleyStrigling.h" 141 #include "../Landscape/cropprogs/FieldPeasStrigling.h" 142 #include "../Landscape/cropprogs/SpringBarleyPeaCloverGrassStrigling.h" 143 #include "../Landscape/cropprogs/YoungForest.h" 146 #include "../Landscape/map_cfg.h" 147 #include "../BatchALMaSS/BoostRandomGenerators.h" 149 extern boost::variate_generator<base_generator_type&, boost::uniform_real<> >
g_rand_uni;
250 m_ddegstoharvest = -1;
259 m_farm->AddNewEvent( m_field->GetVegType(), a_date, m_field, a_todo, m_field->GetRunNum(), a_lock, 0,
false, (
TTypesOfVegetation) 0 );
278 if (m_field->GetMDates(0,0) >=m_ev->m_startday)
280 g_msg->
Warn(
WARN_BUG,
"Crop::ChooseNextCrop(): ",
"Harvest too late for the next crop to start!!!" );
284 for (
int i=0; i<a_no_dates; i++) {
285 if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
286 m_field->SetMDates(0,i,m_ev->m_startday-1);
288 if(m_field->GetMDates(1,i)>=m_ev->m_startday){
289 m_field->SetMConstants(i,0);
290 m_field->SetMDates(1,i,m_ev->m_startday-1);
308 for (
unsigned int i = 0; i < m_fields.size(); i++ ) {
310 int count = m_fields[ i ]->GetVegStore();
312 m_fields[ i ]->SetVegStore( ++count );
316 char error_num[ 20 ];
317 sprintf( error_num,
"%d", m_fields[ i ]->GetVegType() );
318 g_msg->
Warn(
WARN_BUG,
"I the Farm Manager caught infinite loop in tov type:", error_num );
319 sprintf( error_num,
"%d", m_fields[ i ]->m_tried_to_do );
320 g_msg->
Warn(
WARN_BUG,
"It was last seen trying to perform action # ""(or thereabouts):", error_num );
344 done = m_carrots->Do(
this, ev->
m_field, ev );
347 done = m_broadbeans->Do(
this, ev->
m_field, ev );
350 done = m_foddergrass->Do(
this, ev->
m_field, ev );
353 done = m_CGG1->Do(
this, ev->
m_field, ev );
356 done = m_CGG2->Do(
this, ev->
m_field, ev );
359 done = m_fieldpeas->Do(
this, ev->
m_field, ev );
362 done = m_fieldpeassilage->Do(
this, ev->
m_field, ev );
365 done = m_fodderbeet->Do(
this, ev->
m_field, ev );
368 done = m_sugarbeet->Do(
this, ev->
m_field, ev );
371 done = m_ofodderbeet->Do(
this, ev->
m_field, ev );
374 done = m_maize->Do(
this, ev->
m_field, ev );
377 done = m_OBarleyPCG->Do(
this, ev->
m_field, ev );
380 done = m_ocarrots->Do(
this, ev->
m_field, ev );
383 done = m_OCGS1->Do(
this, ev->
m_field, ev );
386 done = m_OCGG1->Do(
this, ev->
m_field, ev );
389 done = m_OCGG2->Do(
this, ev->
m_field, ev );
392 done = m_ofieldpeas->Do(
this, ev->
m_field, ev );
395 done = m_ofieldpeassilage->Do(
this, ev->
m_field, ev );
398 done = m_ograzingpigs->Do(
this, ev->
m_field, ev );
401 done = m_orchardcrop->Do(
this, ev->
m_field, ev );
404 done = m_ooats->Do(
this, ev->
m_field, ev );
407 done = m_oats->Do(
this, ev->
m_field, ev );
410 done = m_opermgrassgrazed->Do(
this, ev->
m_field, ev );
413 done = m_opotatoes->Do(
this, ev->
m_field, ev );
416 done = m_ospringbarley->Do(
this, ev->
m_field, ev );
419 done = m_osbarleysilage->Do(
this, ev->
m_field, ev );
422 done = m_oseedgrass1->Do(
this, ev->
m_field, ev );
425 done = m_oseedgrass2->Do(
this, ev->
m_field, ev );
428 done = m_ospringbarleyext->Do(
this, ev->
m_field, ev );
431 done = m_ospringbarleypigs->Do(
this, ev->
m_field, ev );
434 done = m_owinterbarley->Do(
this, ev->
m_field, ev );
437 done = m_owinterbarleyext->Do(
this, ev->
m_field, ev );
440 done = m_owinterwheatundersown->Do(
this, ev->
m_field, ev );
443 done = m_owinterwheat->Do(
this, ev->
m_field, ev );
446 done = m_owinterwheatundersownext->Do(
this, ev->
m_field, ev );
449 done = m_owinterrape->Do(
this, ev->
m_field, ev );
452 done = m_owinterrye->Do(
this, ev->
m_field, ev );
455 done = m_permgrassgrazed->Do(
this, ev->
m_field, ev );
458 done = m_permgrasslowyield->Do(
this, ev->
m_field, ev );
461 done = m_permgrasstussocky->Do(
this, ev->
m_field, ev );
464 done = m_permanentsetaside->Do(
this, ev->
m_field, ev );
467 done = m_potatoes->Do(
this, ev->
m_field, ev );
470 done = m_potatoesindustry->Do(
this, ev->
m_field, ev );
473 done = m_seedgrass1->Do(
this, ev->
m_field, ev );
476 done = m_seedgrass2->Do(
this, ev->
m_field, ev );
479 done = m_setaside->Do(
this, ev->
m_field, ev );
482 done = m_springbarley->Do(
this, ev->
m_field, ev );
485 done = m_springbarleyspr->Do(
this, ev->
m_field, ev );
488 done = m_springbarleyptreatment->Do(
this, ev->
m_field, ev );
491 done = m_springbarleyskmanagement->Do(
this, ev->
m_field, ev );
494 done = m_sbarleyclovergrass->Do(
this, ev->
m_field, ev );
497 done = m_springbarleyseed->Do(
this, ev->
m_field, ev );
500 done = m_springbarleysilage->Do(
this, ev->
m_field, ev );
503 done = m_springrape->Do(
this, ev->
m_field, ev );
506 done = m_triticale->Do(
this, ev->
m_field, ev );
509 done = m_otriticale->Do(
this, ev->
m_field, ev );
512 done = m_winterbarley->Do(
this, ev->
m_field, ev );
515 done = m_winterrape->Do(
this, ev->
m_field, ev );
518 done = m_winterrye->Do(
this, ev->
m_field, ev );
521 done = m_winterwheat->Do(
this, ev->
m_field, ev );
524 done = m_wwheatpcontrol->Do(
this, ev->
m_field, ev );
527 done = m_wwheatptoxiccontrol->Do(
this, ev->
m_field, ev );
530 done = m_wwheatptreatment->Do(
this, ev->
m_field, ev );
533 done = m_agrochemindustrycereal->Do(
this, ev->
m_field, ev );
536 done = m_winterwheatstrigling->Do(
this, ev->
m_field, ev );
539 done = m_winterwheatstriglingsingle->Do(
this, ev->
m_field, ev );
542 done = m_winterwheatstriglingculm->Do(
this, ev->
m_field, ev );
545 done = m_springbarleyclovergrassstrigling->Do(
this, ev->
m_field, ev );
548 done = m_springbarleystrigling->Do(
this, ev->
m_field, ev );
551 done = m_springbarleystriglingsingle->Do(
this, ev->
m_field, ev );
554 done = m_springbarleystriglingculm->Do(
this, ev->
m_field, ev );
557 done = m_maizestrigling->Do(
this, ev->
m_field, ev );
560 done = m_maizesilage->Do(
this, ev->
m_field, ev );
563 done = m_omaizesilage->Do(
this, ev->
m_field, ev );
566 done = m_winterrapestrigling->Do(
this, ev->
m_field, ev );
569 done = m_winterryestrigling->Do(
this, ev->
m_field, ev );
572 done = m_winterbarleystrigling->Do(
this, ev->
m_field, ev );
575 done = m_fieldpeasstrigling->Do(
this, ev->
m_field, ev );
578 done = m_springbarleypeaclovergrassstrigling->Do(
this, ev->
m_field, ev );
581 done = m_youngforest->Do(
this, ev->
m_field, ev );
586 sprintf( veg_type,
"%d", ev->
m_event );
601 FarmEvent * ev =
new FarmEvent( a_event, a_field, a_todo, a_run, a_lock, a_start, a_first_year, a_crop );
602 m_queue.Push( ev, a_date );
611 return ( a_probability > (
int )( rand() % 100 ) );
621 ifile.open(str.c_str(),ios::in);
622 if ( !ifile.is_open() ) {
623 g_msg->
Warn(
"Cannot open file: ", str.c_str() );
628 m_rotation.resize( nocrops );
630 for (
int i = 0; i < nocrops; i++ ) {
633 m_rotation[ i ] = tov;
652 sprintf( errornum,
"%d", m_farmtype );
653 g_msg->
Warn(
WARN_BUG,
"Rotation management loop detected in farmtype ", errornum );
673 l_tov2 = m_rotation[ GetNextCropIndex( a_field->
GetRotIndex() ) ];
676 return GetFirstDate( l_tov2 );
685 if ( m_queue.Empty() )
693 if ( LeSwitch( ev ) ) {
699 CheckRotationManagementLoop( ev );
709 new_veg = m_rotation[ new_index ];
735 int l_nextcropstartdate = GetNextCropStartDate( ev->
m_field, l_tov );
739 false, l_nextcropstartdate,
false, l_tov );
747 if ( m_queue.Empty() )
749 pair = m_queue.Bottom();
756 if ( m_queue.Empty() )
764 if ( LeSwitch( ev ) ) {
770 CheckRotationManagementLoop( ev );
780 new_veg = m_rotation[ new_index ];
802 char error_num[ 20 ];
803 sprintf( error_num,
"%d", new_veg );
804 g_msg->
Warn(
WARN_FILE,
"Farm::HandleEvents(): there is 3rd crop starting when 2 previous were not calculated yet, the 3rd crop is", error_num );
836 int l_nextcropstartdate = GetNextCropStartDate( ev->
m_field, l_tov );
840 false, l_nextcropstartdate,
false, l_tov );
848 if ( m_queue.Empty() )
850 pair = m_queue.Bottom();
864 m_OurManager = a_manager;
865 m_carrots =
new Carrots;
866 m_broadbeans =
new BroadBeans;
867 m_CGG1 =
new CloverGrassGrazed1;
868 m_CGG2 =
new CloverGrassGrazed2;
869 m_fieldpeas =
new FieldPeas;
870 m_fieldpeassilage =
new FieldPeasSilage;
871 m_fodderbeet =
new Fodderbeet;
872 m_sugarbeet =
new Sugarbeet;
873 m_ofodderbeet =
new OFodderbeet;
874 m_foddergrass =
new FodderGrass;
876 m_maizesilage =
new MaizeSilage;
877 m_omaizesilage =
new OMaizeSilage;
878 m_OBarleyPCG =
new OBarleyPeaCloverGrass;
879 m_ocarrots =
new OCarrots;
880 m_OCGG1 =
new OCloverGrassGrazed1;
881 m_OCGG2 =
new OCloverGrassGrazed2;
882 m_OCGS1 =
new OCloverGrassSilage1;
883 m_ofieldpeas =
new OFieldPeas;
884 m_ofieldpeassilage =
new OFieldPeasSilage;
885 m_ofirstyeardanger =
new OFirstYearDanger;
886 m_ograzingpigs =
new OGrazingPigs;
887 m_orchardcrop =
new OrchardCrop;
890 m_opermgrassgrazed =
new OPermanentGrassGrazed;
891 m_opotatoes =
new OPotatoes;
892 m_oseedgrass1 =
new OSeedGrass1;
893 m_oseedgrass2 =
new OSeedGrass2;
894 m_ospringbarley =
new OSpringBarley;
895 m_osbarleysilage =
new OSBarleySilage;
896 m_ospringbarleyext =
new OSpringBarleyExt;
897 m_ospringbarleypigs =
new OSpringBarleyPigs;
898 m_owinterbarley =
new OWinterBarley;
899 m_owinterbarleyext =
new OWinterBarleyExt;
900 m_owinterrape =
new OWinterRape;
901 m_owinterrye =
new OWinterRye;
902 m_owinterwheat =
new OWinterWheat;
903 m_owinterwheatundersown =
new OWinterWheatUndersown;
904 m_owinterwheatundersownext =
new OWinterWheatUndersownExt;
905 m_permanentsetaside =
new PermanentSetAside;
906 m_permgrassgrazed =
new PermanentGrassGrazed;
907 m_permgrasslowyield =
new PermanentGrassLowYield;
908 m_permgrasstussocky =
new PermanentGrassTussocky;
909 m_potatoes =
new Potatoes;
910 m_potatoesindustry =
new PotatoesIndustry;
911 m_sbarleyclovergrass =
new SpringBarleyCloverGrass;
912 m_seedgrass1 =
new SeedGrass1;
913 m_seedgrass2 =
new SeedGrass2;
914 m_setaside =
new SetAside;
915 m_springbarley =
new SpringBarley;
916 m_springbarleyspr =
new SpringBarleySpr;
917 m_springbarleyptreatment =
new SpringBarleyPTreatment;
918 m_springbarleyskmanagement =
new SpringBarleySKManagement;
919 m_springbarleyseed =
new SpringBarleySeed;
920 m_springbarleysilage =
new SpringBarleySilage;
921 m_springrape =
new SpringRape;
922 m_triticale =
new Triticale;
923 m_otriticale =
new OTriticale;
924 m_winterbarley =
new WinterBarley;
925 m_winterrape =
new WinterRape;
926 m_winterrye =
new WinterRye;
927 m_winterwheat =
new WinterWheat;
928 m_wwheatpcontrol =
new WWheatPControl;
929 m_wwheatptoxiccontrol =
new WWheatPToxicControl;
930 m_wwheatptreatment =
new WWheatPTreatment;
931 m_agrochemindustrycereal =
new AgroChemIndustryCereal;
932 m_winterwheatstrigling =
new WinterWheatStrigling;
933 m_winterwheatstriglingsingle =
new WinterWheatStriglingSingle;
934 m_winterwheatstriglingculm =
new WinterWheatStriglingCulm;
935 m_springbarleyclovergrassstrigling =
new SpringBarleyCloverGrassStrigling;
936 m_springbarleystrigling =
new SpringBarleyStrigling;
937 m_springbarleystriglingsingle =
new SpringBarleyStriglingSingle;
938 m_springbarleystriglingculm =
new SpringBarleyStriglingCulm;
939 m_maizestrigling =
new MaizeStrigling;
940 m_winterrapestrigling =
new WinterRapeStrigling;
941 m_winterryestrigling =
new WinterRyeStrigling;
942 m_winterbarleystrigling =
new WinterBarleyStrigling;
943 m_fieldpeasstrigling =
new FieldPeasStrigling;
944 m_springbarleypeaclovergrassstrigling =
new SpringBarleyPeaCloverGrassStrigling;
945 m_youngforest =
new YoungForestCrop;
946 m_rotation_sync_index = -1;
948 m_stockfarmer =
false;
950 m_HuntersList.resize(0);
964 delete m_fieldpeassilage;
967 delete m_ofodderbeet;
968 delete m_foddergrass;
969 delete m_maizesilage;
970 delete m_omaizesilage;
977 delete m_ofieldpeassilage;
978 delete m_ofirstyeardanger;
979 delete m_ograzingpigs;
980 delete m_orchardcrop;
983 delete m_opermgrassgrazed;
985 delete m_ospringbarley;
986 delete m_ospringbarleyext;
987 delete m_osbarleysilage;
988 delete m_ospringbarleypigs;
989 delete m_owinterbarley;
990 delete m_owinterbarleyext;
991 delete m_owinterrape;
993 delete m_owinterwheatundersown;
994 delete m_owinterwheatundersownext;
996 delete m_permanentsetaside;
997 delete m_permgrassgrazed;
998 delete m_permgrasstussocky;
999 delete m_permgrasslowyield;
1001 delete m_potatoesindustry;
1002 delete m_sbarleyclovergrass;
1003 delete m_seedgrass2;
1004 delete m_seedgrass1;
1006 delete m_springbarley;
1007 delete m_springbarleyptreatment;
1008 delete m_springbarleyskmanagement;
1009 delete m_springbarleyseed;
1010 delete m_springrape;
1011 delete m_springbarleysilage;
1012 delete m_agrochemindustrycereal;
1014 delete m_winterbarley;
1015 delete m_winterrape;
1017 delete m_winterwheat;
1018 delete m_wwheatpcontrol;
1019 delete m_wwheatptoxiccontrol;
1020 delete m_wwheatptreatment;
1021 delete m_winterwheatstrigling;
1022 delete m_winterwheatstriglingsingle;
1023 delete m_winterwheatstriglingculm;
1024 delete m_springbarleyclovergrassstrigling;
1025 delete m_springbarleystrigling;
1026 delete m_springbarleystriglingsingle;
1027 delete m_springbarleystriglingculm;
1028 delete m_maizestrigling;
1029 delete m_winterrapestrigling;
1030 delete m_winterryestrigling;
1031 delete m_winterbarleystrigling;
1032 delete m_fieldpeasstrigling;
1033 delete m_springbarleypeaclovergrassstrigling;
1034 delete m_youngforest;
1037 while ( !m_queue.Empty() ) {
1038 pair = m_queue.Bottom();
1047 for (
unsigned int i = 0; i < m_fields.size(); i++) {
1048 if (m_fields[i]->GetElementType() ==
tole_Field) area += (
int)m_fields[i]->GetArea();
1056 for (
unsigned int i = 0; i < m_fields.size(); i++)
1058 area += (int)m_fields[i]->GetArea();
1066 for (
unsigned int i = 0; i < m_fields.size(); i++ ) {
1067 if (m_fields[i]->GetElementType()==
tole_Field) area += m_fields[i]->GetArea();
1076 for (
unsigned int i = 0; i < m_fields.size(); i++) {
1077 if (m_fields[i]->GetOpenness() > a_openness) num++;
1086 for (
unsigned int i = 0; i < m_fields.size(); i++) {
1087 if (m_fields[i]->GetOpenness() > a_openness) area +=
int(m_fields[i]->GetArea());
1116 if ( -1 == m_rotation_sync_index ) {
1117 m_rotation_sync_index = (int) (rand() % m_rotation.size());
1120 return m_rotation_sync_index;
1126 if ( -1 == m_rotation_sync_index ) {
1127 m_rotation_sync_index = (int) (rand() % m_rotation.size());
1129 else m_rotation_sync_index = (int) ((m_rotation_sync_index+1) % m_rotation.size());
1130 return m_rotation_sync_index;
1147 if ( a_rot_index == -1 )
1150 if ( (
unsigned int ) ( ++a_rot_index ) == m_rotation.size() )
1162 int i = (int) m_fields.size();
1164 m_fields.resize( i + 1 );
1165 m_fields[ i ] = a_newfield;
1175 m_fields[ i ]->SetRotIndex(-2);
1178 m_fields[ i ]->SetRotIndex(-1);
1187 int nf = (int) m_fields.size();
1188 for (
int i = 0; i < nf; i++ ) {
1189 if ( m_fields[ i ] == a_field ) {
1190 m_fields.erase( m_fields.begin() + i );
1196 g_msg->
Warn(
WARN_BUG,
"Farm::RemoveField(LE* a_field): ""Unknown field! ",
"" );
1204 m_rotation = a_new_rotation;
1214 if (m_PermCrops.size()>0) {
1216 for (
int i=0; i<(int)m_PermCrops.size(); i++) {
1217 AssignPermanentCrop(m_PermCrops[i].Tov, m_PermCrops[i].Pct);
1228 for (
unsigned int i = 0; i < m_fields.size(); i++ ) {
1229 int rot_index = m_fields[ i ]->GetRotIndex();
1232 if ( rot_index < -1 ) {
1255 if (rot_index != -4) {
1257 g_msg->
Warn(
"Unexpected negative value in Farm::InitiateManagement",
"");
1259 }
else new_veg = m_fields[ i ]->GetVegType();
1263 rot_index = GetFirstCropIndex( m_fields[ i ]->GetElementType() );
1264 new_veg = m_rotation[ rot_index ];
1272 m_fields[ i ]->SetRotIndex( rot_index );
1273 m_fields[ i ]->SetGrowthPhase(
janfirst );
1277 m_fields[ i ]->SetVegStore( 0 );
1279 int l_nextcropstartdate = GetNextCropStartDate( m_fields[ i ], l_tov );
1280 AddNewEvent( new_veg, prog_start_date, m_fields[ i ],
PROG_START, 0,
false, l_nextcropstartdate,
true, l_tov );
1291 return m_carrots->GetFirstDate();
1293 return m_broadbeans->GetFirstDate( );
1295 return m_foddergrass->GetFirstDate();
1297 return m_CGG1->GetFirstDate();
1299 return m_CGG2->GetFirstDate();
1301 return m_fieldpeas->GetFirstDate();
1303 return m_fieldpeassilage->GetFirstDate();
1305 return m_fodderbeet->GetFirstDate();
1307 return m_sugarbeet->GetFirstDate();
1309 return m_ofodderbeet->GetFirstDate();
1311 return m_maize->GetFirstDate();
1313 return m_omaizesilage->GetFirstDate();
1315 return m_maizesilage->GetFirstDate();
1317 return m_OBarleyPCG->GetFirstDate();
1319 return m_ocarrots->GetFirstDate();
1321 return m_OCGG1->GetFirstDate();
1323 return m_OCGG2->GetFirstDate();
1325 return m_OCGS1->GetFirstDate();
1327 return m_ofieldpeas->GetFirstDate();
1329 return m_ofirstyeardanger->GetFirstDate();
1331 return m_ograzingpigs->GetFirstDate();
1333 return m_orchardcrop->GetFirstDate();
1335 return m_ooats->GetFirstDate();
1337 return m_oats->GetFirstDate();
1339 return m_opermgrassgrazed->GetFirstDate();
1341 return m_opotatoes->GetFirstDate();
1343 return m_ospringbarley->GetFirstDate();
1345 return m_osbarleysilage->GetFirstDate();
1347 return m_ospringbarleyext->GetFirstDate();
1349 return m_ospringbarleypigs->GetFirstDate();
1351 return m_owinterbarley->GetFirstDate();
1353 return m_owinterbarleyext->GetFirstDate();
1355 return m_owinterrape->GetFirstDate();
1357 return m_owinterrye->GetFirstDate();
1359 return m_owinterwheatundersown->GetFirstDate();
1361 return m_owinterwheat->GetFirstDate();
1363 return m_owinterwheatundersownext->GetFirstDate();
1365 return m_permgrassgrazed->GetFirstDate();
1367 return m_permgrasslowyield->GetFirstDate();
1369 return m_permgrasstussocky->GetFirstDate();
1371 return m_permanentsetaside->GetFirstDate();
1373 return m_potatoes->GetFirstDate();
1375 return m_seedgrass1->GetFirstDate();
1377 return m_seedgrass2->GetFirstDate();
1379 return m_setaside->GetFirstDate();
1381 return m_springbarley->GetFirstDate();
1383 return m_springbarleyspr->GetFirstDate();
1385 return m_springbarleyptreatment->GetFirstDate();
1387 return m_springbarleyskmanagement->GetFirstDate();
1389 return m_sbarleyclovergrass->GetFirstDate();
1391 return m_springbarleyseed->GetFirstDate();
1393 return m_springbarleysilage->GetFirstDate();
1395 return m_springbarleystrigling->GetFirstDate();
1397 return m_springbarleystriglingsingle->GetFirstDate();
1399 return m_springbarleystriglingculm->GetFirstDate();
1401 return m_springrape->GetFirstDate();
1403 return m_triticale->GetFirstDate();
1405 return m_otriticale->GetFirstDate();
1407 return m_winterbarley->GetFirstDate();
1409 return m_winterrape->GetFirstDate();
1411 return m_winterrye->GetFirstDate();
1413 return m_winterwheat->GetFirstDate();
1415 return m_winterwheatstrigling->GetFirstDate();
1417 return m_winterwheatstriglingsingle->GetFirstDate();
1419 return m_winterwheatstriglingculm->GetFirstDate();
1421 return m_wwheatpcontrol->GetFirstDate();
1423 return m_wwheatptoxiccontrol->GetFirstDate();
1425 return m_wwheatptreatment->GetFirstDate();
1427 return m_agrochemindustrycereal->GetFirstDate();
1429 return m_youngforest->GetFirstDate();
1450 if (str ==
"Oats")
return tov_Oats;
1531 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateCropCodes():"" Unknown Crop Code ", str.c_str() );
1539 ofstream ofile (
"FarmTotalAreas_almass.txt", ios::out);
1540 ofile <<
"Farm no" <<
'\t' <<
"Area" << endl;
1543 for(
int i=0; i<(int)m_farms.size(); i++){
1548 ofile << opf_i->
GetArea() <<
'\t';
1934 ifile.open(fname,ios::in);
1935 if (!ifile.is_open()) {
1939 int input, intensity;
1942 ifile >> input >> intensity;
1946 std::string cropref =
"";
1951 for (
int i=0; i<permcrops; i++) {
1964 for (
int i = 0; i < nocrops; i++ ) {
1978 vector<LE*> fields_cpy;
1979 fields_cpy.resize(
m_fields.size());
1983 int sz = (int) fields_cpy.size();
1984 for (
int i=sz-1; i>=0; i--) {
1985 if ( fields_cpy[i]->GetRotIndex()<-1) {
1986 if (fields_cpy[i]->GetRotIndex()==-4) area += fields_cpy[i]->GetArea();
1987 fields_cpy.erase(fields_cpy.begin()+i);
1989 else area += fields_cpy[i]->GetArea();
1992 int fnos = (int) fields_cpy.size();
1996 if (random(100)>=pct)
return;
1999 fields_cpy[0]->SetRotIndex(-4);
2005 for (
int i=0; i<fnos; i++) {
2006 a_tpct.
pct = (int) floor(0.5+((fields_cpy[i]->
GetArea()/area)*100));
2008 pcts.push_back(a_tpct);
2012 sort (pcts.begin(), pcts.end(),
CompPcts);
2017 while ((index==-1) && (ind< (int)pcts.size())) {
2018 if (pcts[ind++].pct>apct) index=ind;
2020 if (index!=-1) pcts.erase(pcts.begin()+index,pcts.end());
2028 for (
int h=0; h< (int)pcts.size(); h++) check+=fields_cpy[pcts[h].index]->
GetArea();
2030 if ((bits & mask) > 0) {
2032 fields_cpy[pcts[ind].index]->SetRotIndex(-4);
2034 fields_cpy[pcts[ind].index]->SetVegType(tov,
tov_Undefined);
2035 used += (int) fields_cpy[pcts[ind].index]->
GetArea();
2050 int sz = (int) items->size();
2052 g_msg->
Warn(
"Too many potential fields in UserDefinedFarm::InvIntPartition: ",sz);
2056 long int calcs = (1 << sz);
2061 for (
long int i=1; i<calcs; i++) {
2066 for (
int bit=0; bit<sz; bit++) {
2067 if ((i & mask) > 0) {
2068 sum+=(*items)[bit].pct;
2073 if (abs(sum-target) < diff ){
2075 diff = abs(sum-target);
2180 g_farmmanager =
this;
2187 ReadLivestockNumbers();
2188 ReadFarmsData_perFarmType();
2189 ReadLivestockData();
2192 ofstream ofile (
"Economic_figures.txt", ios::out);
2194 ofstream ofile1 (
"Daydegrees.txt", ios::out);
2197 ofstream ofileEM (
"Maize_energy_price_yearly.txt", ios::out);
2202 ReadInitialCropAreas();
2204 ReadCropsData_perSoilType();
2205 ReadCropsData_perFarmType();
2206 ReadCropsData_perFarm_and_Soil();
2207 ReadCropsData_perFarm_and_Soil_and_Size();
2210 ReadInitialCropAreas_almass();
2211 ReadCropsData_almass();
2212 ReadCropsData_perSoilType_almass();
2213 ReadCropsData_perFarmType_almass();
2214 ReadCropsData_perFarm_and_Soil_almass();
2215 ReadCropsData_perFarm_and_Soil_and_Size_almass();
2216 m_crops_summary_BIs.resize(pm_data->Get_noCrops());
2217 m_cropTotals_sum.resize(pm_data->Get_noCrops());
2218 m_cropTotals_plant_sum.resize(pm_data->Get_noCrops());
2219 m_cropTotals_pig_sum.resize(pm_data->Get_noCrops());
2220 m_cropTotals_cattle_sum.resize(pm_data->Get_noCrops());
2221 m_cropTotals_other_sum.resize(pm_data->Get_noCrops());
2222 m_crops_fertilizer.resize(pm_data->Get_noCrops());
2223 m_crops_fertilizer_trade.resize(pm_data->Get_noCrops());
2224 m_crop_areas_stages.resize( 2 * pm_data->Get_noCrops());
2225 for(
int i=0; i<pm_data->Get_noCrops(); i++){
2226 m_crops_summary_BIs[i].Tov = pm_data->Get_cropTypes_almass(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;
2231 m_cropTotals_plant_sum[i]=0;
2232 m_cropTotals_pig_sum[i]=0;
2233 m_cropTotals_cattle_sum[i]=0;
2234 m_cropTotals_other_sum[i]=0;
2235 m_crops_fertilizer[i]=0;
2236 m_crops_fertilizer_trade[i]=0;
2240 ReadEnergyMaizePrice();
2253 for (
unsigned int i = 0; i < m_farms.size(); i++ )
2254 delete m_farms[ i ];
2260 for (
unsigned int i = 0; i < m_farms.size(); i++ )
2262 m_farms[ i ]->Management();
2268 for (
unsigned int i = 0; i < m_farms.size(); i++ )
2286 for (
unsigned int i = 0; i < m_farms.size(); i++ )
2288 m_farms[ i ]->InitiateManagement();
2294 m_farms[ a_OwnerIndex ]->AddField( a_newland );
2295 a_newland->
SetOwner( m_farms[ a_OwnerIndex ], a_Owner, a_OwnerIndex );
2300 m_farms[ a_OwnerIndex ]->RemoveField( a_field );
2305 for (
unsigned int i = 0; i < m_farms.size(); i++ )
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 );
2325 int No, FType, NoFarms;
2326 FILE * inpf = fopen(a_farmfile,
"r" );
2328 g_msg->
Warn(
WARN_FILE,
"Landscape::CreateFarms(): Unable to open file", a_farmfile );
2332 fscanf( inpf,
"%d", & NoFarms );
2334 m_farms.resize( NoFarms );
2336 m_farmmapping_lookup =
new int[NoFarms * 2];
2338 for (
int i = 0; i < NoFarms; i++)
2344 fscanf(inpf,
"%d %d", &No, &FType);
2345 m_farmmapping_lookup[i * 2] = No;
2346 m_farmmapping_lookup[i * 2 + 1] = FType;
2350 for (
int i = 0; i < NoFarms; i++)
2365 switch (m_farmmapping_lookup[i * 2 + 1])
2519 if ((pm_data->Get_farmType(No)) ==
toof_Pig) {
2522 else if ((pm_data->Get_farmType(No)) ==
toof_Cattle){
2525 else if ((pm_data->Get_farmType(No)) ==
toof_Plant){
2528 else if ((pm_data->Get_farmType(No)) ==
toof_Other){
2534 g_msg->
Warn(
WARN_FILE,
"Landscape::CreateFarms(): Unknown farm ""type reference number",
"");
2537 m_farms[i]->SetFarmNumber(i);
2542 DistributeFarmerTypes();
2545 if (GetFarmNoLookup(NoFarms - 1) != NoFarms - 1) m_renumbered =
false;
else m_renumbered =
true;
2550 ofstream opf(
"dump_farmrefs.txt");
2553 g_msg->
Warn(
WARN_FILE,
"Landscape::CreateFarms(): Unable to open file",
"dump_farmrefs.txt");
2556 int NoFarms = (int) m_farms.size();
2557 opf << NoFarms << endl;
2558 for (
int i = 0; i < NoFarms; i++)
2560 opf << i <<
'\t' << m_farmmapping_lookup[i * 2 + 1] << endl;
2569 Create_Output_file_for_farms();
2572 for(
unsigned j=0; j<m_farms.size(); j++){
2575 opf->
Init(pm_output_file);
2579 OptimisationOutput();
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
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
2597 if (m_SpilledGrain)
return graindist2013[ (int)(
g_rand_uni() * 28) ];
2598 else return graindist2014[ (int)(
g_rand_uni() * 26) ];
2605 double maizedist2015[ 9 ] = {
2606 102.7905327, 58.19878648, 85.65877728, 110.9055748, 30.65682555, 63.11699379, 59.05947276, 41.9277173, 95.57716202
2608 return maizedist2015[ (int)(
g_rand_uni() * 9) ];
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;
2627 unsigned sz = (unsigned)a_farmlist->size();
2628 for (
unsigned f = 0; f < sz; f++) {
2629 if ((*a_farmlist)[f] == a_farm_ref) {
2635 a_farmlist->push_back( a_farm_ref );
2641 for (
int i = 0; i < int( a_hinfo->
FarmHuntRef.size() ); i++)
2644 if (a_ref == a_hinfo->
FarmHuntRef[ i ])
return true;
2654 double best = 99999999999999999.0;
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)) {
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 )));
2671 if (bestref == -1) {
2672 g_msg->
Warn(
"FarmManager::FindClosestFarm - Cannot find open farm.",
"" );
2680 double best = 99999999999999999.0;
2683 for (
unsigned i = 0; i < m_farms.size(); i++) {
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 )) );
2698 if (bestref == -1) {
2699 g_msg->
Warn(
"FarmManager::FindClosestFarmOpenness( ) - Cannot find open farm.",
"" );
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;
2723 for (
unsigned i = 0; i < m_farms.size(); i++) {
2724 int fnum = m_farms[ i ]->GetFarmNumber();
2725 if (!InIllegalList( fnum, a_farmlist )) {
2727 if (!IsDuplicateRef( fnum, &a_hunterinfo )) {
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 );
2740 random_shuffle( farmdists.begin(), farmdists.end() );
2742 for (
int ch = 1; ch < 100000; ch++)
2744 int sz = int( farmdists.size() );
2745 for (
int i = 0; i < sz; i++) {
2749 if (chance <= calc)
return farmdists[ i ].m_x;
2752 g_msg->
Warn(
"FarmManager::FindClosestFarmProb",
"- No suitable farm found" );
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;
2774 for (
unsigned i = 0; i < m_farms.size(); i++) {
2775 int fnum = m_farms[ i ]->GetFarmNumber();
2776 if (!InIllegalList( fnum, a_farmlist )) {
2778 if (!IsDuplicateRef( fnum, &a_hunterinfo )) {
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 );
2791 random_shuffle( farmdists.begin(), farmdists.end() );
2793 for (
int ch = 1; ch < 100000; ch++)
2795 int sz = int( farmdists.size() );
2796 for (
int i = 0; i < sz; i++) {
2800 if (chance <= calc) {
2804 if (chance>calc)
return farmdists[ i ].m_x;
2808 g_msg->
Warn(
"FarmManager::FindClosestFarmProb",
"- No suitable farm found" );
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;
2830 for (
unsigned i = 0; i < m_farms.size(); i++) {
2831 int fnum = m_farms[ i ]->GetFarmNumber();
2832 if (!InIllegalList( fnum, a_farmlist )) {
2834 if (!IsDuplicateRef( fnum, &a_hunterinfo )) {
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 );
2847 random_shuffle( farmdists.begin(), farmdists.end() );
2849 for (
int ch = 1; ch < 100000; ch++)
2851 int sz = int( farmdists.size() );
2852 for (
int i = 0; i < sz; i++) {
2856 if (chance <= calc) {
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;
2868 if (chance>calc)
return farmdists[ i ].m_x;
2872 g_msg->
Warn(
"FarmManager::FindClosestFarmProbNearRoostBest",
"- No suitable farm found" );
2878 int sz= (int)m_farms.size();
2880 while (InIllegalList(m_farms[f]->
GetFarmNumber(), a_farmlist))
2883 if (a_farmlist->size() >= m_farms.size())
2885 g_msg->
Warn(
"FarmManager::FindFarmWithRandom",
" - farm density rule means all hunters cannot be placed");
2889 return m_farms[f]->GetFarmNumber();
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;
2902 if (!InIllegalList( m_farms[ index ]->
GetFarmNumber(), a_farmlist ))
return m_farms[ index ]->GetFarmNumber();
2904 else AddToIllegalList(m_farms[ index ]->
GetFarmNumber(), a_farmlist );
2906 g_msg->
Warn(
"FarmManager::FindFarmWithOpenness",
"- No suitable farm found");
2912 int sz = (int) m_farms.size();
2913 int seed = random(sz);
2914 for (
unsigned i = 0; i < m_farms.size(); i++)
2916 int index = (i + seed) % sz;
2923 if (m_farms[ a_ref ]->
GetMaxOpenness() > a_openness)
return true;
2930 totalOptFarmsArea=0;
2931 totalOptFarmsArea_plant=0;
2932 totalOptFarmsArea_pig=0;
2933 totalOptFarmsArea_cattle=0;
2934 totalOptFarmsArea_other=0;
2936 for(
int j=0; j<(int)m_farms.size(); j++){
2958 for(
int i=0; i<(int)m_farms.size(); i++){
2969 for(
int i=0; i<(int)m_farms.size(); i++){
2981 for(
int i=0; i<(int)m_farms.size(); i++){
3013 ifstream ifile(
"farms_data.txt", ios::in);
3016 if ( !ifile.is_open() ) {
3017 cout <<
"Cannot open input file " <<
"farms_data.txt" << endl;
3027 for(
int i=0; i<noParameters; i++){
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;
3041 pm_data->m_farm_data.push_back(fd);
3059 ifstream ifile(
"livestock_numbers.txt", ios::in);
3061 if ( !ifile.is_open() ) {
3062 cout <<
"Cannot open input file " <<
"livestock_numbers.txt" << endl;
3076 pm_data->Set_livestockTypes(TranslateAnimalsCodes(type));
3080 for(
int f=0; f<noFarms; f++){
3083 pm_data->Set_livestockNumber(almass_no);
3087 pm_data->Set_livestockNumber(number);
3100 ifstream ifile(
"crop_areas.txt", ios::in);
3102 if ( !ifile.is_open() ) {
3103 cout <<
"Cannot open input file " <<
"crop_areas.txt" << endl;
3117 pm_data->Set_cropTypes(type_enum);
3118 pm_data->Set_cropTypes_str(type);
3122 for(
int f=0; f<noFarms; f++){
3125 pm_data->Set_cropArea(almass_no);
3129 pm_data->Set_cropArea(area);
3141 ifstream ifile(
"crop_areas.txt", ios::in);
3143 if ( !ifile.is_open() ) {
3144 cout <<
"Cannot open input file " <<
"crop_areas.txt" << endl;
3154 pm_data->Set_noCrops(noCrops);
3157 for(
int c=0; c<noCrops; c++){
3161 pm_data->Set_cropTypes_almass(type_enum);
3162 pm_data->Set_cropTypes_almass_str(type);
3166 for(
int f=0; f<noFarms; f++){
3169 pm_data->Set_cropArea(almass_no);
3170 for(
int c=0; c<noCrops; c++){
3173 pm_data->Set_cropArea(area);
3182 ifstream ifile(
"crop_parameters.txt", ios::in);
3184 if ( !ifile.is_open() ) {
3185 cout <<
"Cannot open input file " <<
"crop_parameters.txt" << endl;
3204 int index=top_Foobar*c + p;
3205 pm_data->Set_cropParameter (par_value, index );
3214 ifstream ifile(
"crop_parameters.txt", ios::in);
3216 if ( !ifile.is_open() ) {
3217 cout <<
"Cannot open input file " <<
"crop_parameters.txt" << endl;
3233 for(
int c=0; c<noCrops; c++){
3239 int index=top_Foobar*(pm_data->Get_cropTypes_almass(c)) + p;
3240 pm_data->Set_cropParameter (par_value, index );
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);
3255 if ( !ifile1.is_open() ) {
3256 cout <<
"Cannot open input file " <<
"alfa.txt" << endl;
3260 }
else if(!ifile2.is_open() ){
3261 cout <<
"Cannot open input file " <<
"beta1.txt" << endl;
3266 else if(!ifile3.is_open() ){
3267 cout <<
"Cannot open input file " <<
"beta2.txt" << endl;
3272 else if(!ifile4.is_open() ){
3273 cout <<
"Cannot open input file " <<
"Nnorm.txt" << endl;
3297 pm_data->Set_alfa(par_value, toc_Foobar*s + c);
3299 pm_data->Set_beta1(par_value, toc_Foobar*s + c);
3301 pm_data->Set_beta2(par_value, toc_Foobar*s + c);
3303 pm_data->Set_Nnorm(par_value, toc_Foobar*s + c);
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);
3323 if ( !ifile1.is_open() ) {
3324 cout <<
"Cannot open input file " <<
"alfa.txt" << endl;
3328 }
else if(!ifile2.is_open() ){
3329 cout <<
"Cannot open input file " <<
"beta1.txt" << endl;
3334 else if(!ifile3.is_open() ){
3335 cout <<
"Cannot open input file " <<
"beta2.txt" << endl;
3340 else if(!ifile4.is_open() ){
3341 cout <<
"Cannot open input file " <<
"Nnorm.txt" << endl;
3346 if (!ifile5.is_open() ) {
3347 cout <<
"Cannot open input file " <<
"biomass_factor_almass.txt" << endl;
3353 int noCrops, noCrops1, noCrops2, noCrops3, noCrops4=0;
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! ",
" " );
3365 for(
int c=0; c<noCrops; c++){
3382 for(
int c=0; c<noCrops; c++){
3385 pm_data->Set_alfa(par_value,
tov_Undefined*s + pm_data->Get_cropTypes_almass(c));
3387 pm_data->Set_beta1(par_value,
tov_Undefined*s + pm_data->Get_cropTypes_almass(c));
3389 pm_data->Set_beta2(par_value,
tov_Undefined*s + pm_data->Get_cropTypes_almass(c));
3391 pm_data->Set_Nnorm(par_value,
tov_Undefined*s + pm_data->Get_cropTypes_almass(c));
3393 pm_data->Set_biomass_factor(par_value,
tov_Undefined*s + pm_data->Get_cropTypes_almass(c));
3407 ifstream ifile1(
"fixed.txt", ios::in);
3408 ifstream ifile2(
"fodder.txt", ios::in);
3409 ifstream ifile3(
"FUKey.txt", ios::in);
3412 if ( !ifile1.is_open() ) {
3413 cout <<
"Cannot open input file " <<
"fixed.txt" << endl;
3417 }
else if(!ifile2.is_open() ){
3418 cout <<
"Cannot open input file " <<
"fodder.txt" << endl;
3423 else if(!ifile3.is_open() ){
3424 cout <<
"Cannot open input file " <<
"FUKey.txt" << endl;
3447 pm_data->Set_fixed(par, toc_Foobar*f + c);
3449 pm_data->Set_fodder(par, toc_Foobar*f + c);
3452 pm_data->Set_FUKey(par_value, toc_Foobar*f + c);
3463 ifstream ifile1(
"fixed.txt", ios::in);
3464 ifstream ifile2(
"fodder.txt", ios::in);
3465 ifstream ifile3(
"FUKey.txt", ios::in);
3468 if ( !ifile1.is_open() ) {
3469 cout <<
"Cannot open input file " <<
"fixed.txt" << endl;
3473 }
else if(!ifile2.is_open() ){
3474 cout <<
"Cannot open input file " <<
"fodder.txt" << endl;
3479 else if(!ifile3.is_open() ){
3480 cout <<
"Cannot open input file " <<
"FUKey.txt" << endl;
3486 int noCrops, noCrops1, noCrops2=0;
3490 if(noCrops!=noCrops1 || noCrops!=noCrops2){
3491 g_msg->
Warn(
WARN_FILE,
"FarmManager::ReadCropsData_perSoilType_almass():"" Numbers of crops differ between input files! ",
" " );
3497 for(
int c=0; c<noCrops; c++){
3510 for(
int c=0; c<noCrops; c++){
3513 pm_data->Set_fixed(par,
tov_Undefined*f + pm_data->Get_cropTypes_almass(c));
3515 pm_data->Set_fodder(par,
tov_Undefined*f + pm_data->Get_cropTypes_almass(c));
3518 pm_data->Set_FUKey(par_value,
tov_Undefined*f + pm_data->Get_cropTypes_almass(c));
3529 ifstream ifile1(
"sellingPrice.txt", ios::in);
3532 if ( !ifile1.is_open() ) {
3533 cout <<
"Cannot open input file " <<
"sellingPrice.txt" << endl;
3549 ifile1>>farm_type>>soil_type;
3553 pm_data->Set_sellingPrice(par_value, toc_Foobar*f + c);
3562 ifstream ifile1(
"sellingPrice.txt", ios::in);
3565 if ( !ifile1.is_open() ) {
3566 cout <<
"Cannot open input file " <<
"sellingPrice.txt" << endl;
3576 for(
int c=0; c<noCrops; c++){
3585 ifile1>>farm_type>>soil_type;
3586 for(
int c=0; c<noCrops; c++){
3589 pm_data->Set_sellingPrice(par_value,
tov_Undefined*f + pm_data->Get_cropTypes_almass(c));
3600 ifstream ifile1(
"rotationMax.txt", ios::in);
3601 ifstream ifile2(
"rotationMin.txt", ios::in);
3604 if ( !ifile1.is_open() ) {
3605 cout <<
"Cannot open input file " <<
"rotationMax.txt" << endl;
3609 }
else if(!ifile2.is_open() ){
3610 cout <<
"Cannot open input file " <<
"rotationMin.txt" << endl;
3625 string farm_type, soil_type, farm_size;
3626 ifile1>>farm_type>>soil_type>>farm_size;
3627 ifile2>>farm_type>>soil_type>>farm_size;
3631 pm_data->Set_rotationMax(par_value, toc_Foobar*f + c);
3633 pm_data->Set_rotationMin(par_value, toc_Foobar*f + c);
3648 rot_max =
"rotationMax_almass.txt";
3649 rot_min =
"rotationMin_almass.txt";
3652 rot_max =
"rotationMax.txt";
3653 rot_min =
"rotationMin.txt";
3656 ifstream ifile1(rot_max.c_str(), ios::in);
3657 ifstream ifile2(rot_min.c_str(), ios::in);
3662 if ( !ifile1.is_open() ) {
3663 cout <<
"Cannot open input file with rotation max" << endl;
3667 }
else if(!ifile2.is_open() ){
3668 cout <<
"Cannot open input file with rotation min" << endl;
3674 int noCrops, noCrops1=0;
3677 if(noCrops!=noCrops1){
3678 g_msg->
Warn(
WARN_FILE,
"FarmManager::ReadCropsData_perSoilType_almass():"" Numbers of crops differ between input files! ",
" " );
3683 for(
int c=0; c<noCrops; c++){
3691 string farm_type, soil_type, farm_size;
3692 ifile1>>farm_type>>soil_type>>farm_size;
3693 ifile2>>farm_type>>soil_type>>farm_size;
3694 for(
int c=0; c<noCrops; c++){
3697 pm_data->Set_rotationMax(par_value,
tov_Undefined*f + pm_data->Get_cropTypes_almass(c));
3699 pm_data->Set_rotationMin(par_value,
tov_Undefined*f + pm_data->Get_cropTypes_almass(c));
3710 ifstream ifile1(
"winterMax.txt", ios::in);
3713 if ( !ifile1.is_open() ) {
3714 cout <<
"Cannot open input file " <<
"winterMax.txt" << endl;
3730 pm_data->Set_winterMax(par_value, f);
3738 ifstream ifile(
"livestock_parameters.txt", ios::in);
3740 if ( !ifile.is_open() ) {
3741 cout <<
"Cannot open input file " <<
"livestock_parameters.txt" << endl;
3760 pm_data->Set_livestockParameter(par_value, tolp_Foobar*l + p);
3774 if ( !ifile1.is_open() ) {
3785 for(
int i=0; i<no_years; i++){
3790 pm_data->Set_emaize_price(par_value);
3803 if ( str ==
"Pig" )
return toof_Pig;
3805 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateFarmCodes():"" Unknown Farm type Code ", str.c_str() );
3814 if ( str ==
"Sand" )
return tos_Sand;
3815 if ( str ==
"Clay" )
return tos_Clay;
3817 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateSoilCodes():"" Unknown Soil type Code ", str.c_str() );
3828 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateFarmSizeCodes():"" Unknown Farm Size Code ", str.c_str() );
3837 if ( str ==
"DCow")
return toa_DCow;
3843 if ( str ==
"Goat")
return toa_Goat;
3844 if ( str ==
"So")
return toa_So;
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;
3853 if ( str ==
"Duck")
return toa_Duck;
3857 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateAnimalsCodes():"" Unknown Animal type Code ", str.c_str() );
3866 if ( str ==
"Oats")
return toc_Oats;
3870 if ( str ==
"WRye")
return toc_WRye;
3875 if ( str ==
"Peas")
return toc_Peas;
3898 if ( str ==
"Veg")
return toc_Veg;
3906 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateCropCodes():"" Unknown Crop type Code ", str.c_str() );
3933 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateParametersCodes():"" Unknown Parameter Code ", str.c_str() );
3945 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateLivestockParametersCodes():"" Unknown Livestock Parameter Code ", str.c_str() );
3954 if ( str ==
"m_n" )
return tocv_N;
3955 if ( str ==
"m_nt" )
return tocv_Nt;
3957 if ( str ==
"m_BIFi" )
return tocv_BIFi;
3958 if ( str ==
"m_BI" )
return tocv_BI;
3966 if ( str ==
"m_GM" )
return tocv_GM;
3970 g_msg->
Warn(
WARN_FILE,
"FarmManager::TTypesOfCropVariables():"" Unknown crop variable Code ", str.c_str() );
3979 PrintOutput(
tocv_N,
"N.txt");
3980 PrintOutput(
tocv_Nt,
"Nt.txt");
3983 PrintOutput(
tocv_BI,
"BI.txt");
3991 PrintOutput(
tocv_GM,
"GM.txt");
3997 ofstream ofile(
"CropDistribution.txt", ios::out);
4001 for(
int c=0; c<
toc_Foobar; c++) ofile << pm_data->Get_cropTypes_str(c) <<
'\t';
4004 for(
int c=0; c<
toc_Foobar; c++) ofile << m_cropTotals[c] <<
'\t';
4008 ofile <<
"Year" <<
'\t';
4010 for(
int c=0; c<pm_data->Get_noCrops(); c++) ofile << pm_data->Get_cropTypes_almass_str(c) <<
'\t';
4013 ofile <<
"0" <<
'\t';
4015 for(
int c=0; c<pm_data->Get_noCrops(); c++) ofile << m_cropTotals[c] <<
'\t';
4020 for(
int i=0; i<(int)m_cropTotals.size(); i++){
4029 ofstream ofile (a_fileName.c_str(), ios::out);
4030 ofile <<
"Farm no" <<
'\t';
4033 for(
int c=0; c<
toc_Foobar; c++) ofile << pm_data->Get_cropTypes_str(c) <<
'\t';
4036 for(
int c=0; c<pm_data->Get_noCrops(); c++) ofile << pm_data->Get_cropTypes_almass_str(c) <<
'\t';
4040 for (
int i=0; i<(int)m_farms.size(); i++){
4045 ofile << no <<
'\t';
4047 for(
int j = 0; j < size; j++){
4048 double var_to_print = -1;
4058 var_to_print = crop ->
m_n;
4061 var_to_print = crop ->
m_nt;
4067 var_to_print = crop ->
m_BIFi;
4070 var_to_print = crop ->
m_BI;
4085 var_to_print = crop ->
m_resp;
4094 var_to_print = crop ->
m_GM;
4100 g_msg->
Warn(
WARN_BUG,
"FarmManager::PrintOutput(): ""Unknown crop variable type! ",
"" );
4103 ofile << var_to_print <<
'\t';
4114 m_cropTotals.resize(no_crops);
4116 for(
int i=0; i<(int)m_farms.size(); i++){
4123 for(
int j=0; j<size; j++) {
4126 m_cropTotals[j] += area;
4134 pm_output_file =
new ofstream (
"FarmVariables.txt", ios::out);
4136 (*pm_output_file) <<
"Farm no \t";
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;
4151 ifstream ifile(
"crops_lookup.txt", ios::in);
4153 if ( !ifile.is_open() ) {
4154 cout <<
"Cannot open input file " <<
"crops_lookup.txt" << endl;
4167 for(
int r=0; r<tov_Undefined+1; r++){
4170 for(
int c=0; c<tov_Undefined+1; c++){
4173 m_crop_lookup_table.push_back(value);
4187 for(
int i=0; i<(int)m_farms.size(); i++){
4194 for(
int i=0; i<(int)m_farms.size(); i++){
4201 for(
int k = 0; k<(int)m_farms.size(); k++) {
4209 if(abs(x - xb) <= par && abs(y - yb) <= par && farm_no_i!=farm_no_k){
4226 ofstream ofile (
"Neighbours.txt", ios::out);
4227 ofile <<
"Farm no" << endl;
4230 for(
int i=0; i<(int)m_farms.size(); i++){
4246 ofstream ofile (
"Decision_modes_counts.txt", ios::out);
4247 ofile <<
"Farm_no\t" <<
"imitation\t" <<
"social comparison\t" <<
"repeat\t"<<
"deliberation\t"<<endl;
4250 for(
int i=0; i<(int)m_farms.size(); i++){
4255 for(
int j=0; j<4; j++){
4266 PrintDecModes_counts();
4269 double BIherb_sum=0;
4272 double fertilizer_sum=0;
4273 double fertilizer_trade_sum=0;
4275 totalOptFarmsArea *= 0.0001;
4276 totalOptFarmsArea_plant *= 0.0001;
4277 totalOptFarmsArea_pig *= 0.0001;
4278 totalOptFarmsArea_cattle *= 0.0001;
4279 totalOptFarmsArea_other *= 0.0001;
4281 ofstream ofile (
"CropAreasTotal_and_Average.txt", ios::out);
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 <<
'%';
4295 ofstream ofile5 (
"CropAreas_plant_farms.txt", ios::out);
4296 ofile5 <<
"CropName\t" <<
"Area_%\t" << endl;
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 <<
'%';
4304 ofstream ofile6 (
"CropAreas_pig_farms.txt", ios::out);
4305 ofile6 <<
"CropName\t" <<
"Area_%\t" << endl;
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 <<
'%';
4313 ofstream ofile7 (
"CropAreas_cattle_farms.txt", ios::out);
4314 ofile7 <<
"CropName\t" <<
"Area_%\t" << endl;
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 <<
'%';
4322 ofstream ofile8 (
"CropAreas_other_farms.txt", ios::out);
4323 ofile8 <<
"CropName\t" <<
"Area_%\t" << endl;
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 <<
'%';
4334 ofstream ofile1 (
"PesticideTotals.txt", ios::out);
4335 ofile1 <<
"CropName\t" <<
"BIherb\t" <<
"BIfi\t" <<
"BI\t" ;
4336 ofile1 <<
"BIherb_yr\t" <<
"BIfi_yr\t" <<
"BI_yr\t";
4337 ofile1 <<
"BIherb_ha\t" <<
"BIfi_ha\t" <<
"BI_ha\t";
4339 for(
int i=0; i<(int)m_crops_summary_BIs.size(); i++){
4341 ofile1 << pm_data->Get_cropTypes_almass_str(i) <<
'\t';
4343 ofile1 << m_crops_summary_BIs[i].BIherb <<
'\t';
4344 BIherb_sum += m_crops_summary_BIs[i].BIherb;
4346 ofile1 << m_crops_summary_BIs[i].BIfi <<
'\t';
4347 BIfi_sum += m_crops_summary_BIs[i].BIfi;
4349 ofile1 << m_crops_summary_BIs[i].BI <<
'\t';
4350 BI_sum += m_crops_summary_BIs[i].BI;
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';
4361 ofile1 <<
"0\t" <<
"0\t" <<
"0\t" ;
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';
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';
4375 if(m_cropTotals_sum[i]!=0){
4376 ofile2 << m_crops_fertilizer[i]/m_cropTotals_sum[i] <<
'\t';
4386 ifstream ifile(
"crop_results_stages.txt", ios::in);
4388 if ( !ifile.is_open() ) {
4389 cout <<
"Cannot open input file " <<
"crop_results_stages.txt" << endl;
4394 int no_crops = pm_data->Get_noCrops();
4396 for(
int c=0; c<no_crops; c++){
4400 for(
int stage=0; stage<2; stage++){
4405 for(
int a=0; a<no_crops; a++){
4406 ifile>>m_crop_areas_stages[stage * no_crops + a];
4413 for(
int s=0; s<2; s++){
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;
4424 ofstream ofile3 (
"Result_summary.txt", ios::out);
4425 ofile3 <<
"BIherb\t" <<
"BIfi\t" <<
"BI\t" <<
"Fert\t" <<
"Fert_trade\t" ;
4426 ofile3 <<
"Sum of sq. diff: Baseline\t" <<
"Sum of sq. diff: Original\t";
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';
4439 ofstream ofile4 (
"Output.txt", ios::out);
4441 double BIdiff_percent = ((BI_sum/totalOptFarmsArea/no_years/2.2) - 1) *100;
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);
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';
4448 ofile4 << sums[0] <<
'\t';
4449 ofile4 << 0.2 * abs(BIdiff_percent) + 0.2 * abs(fert_diff_percent) + 0.6 * sums[0] << endl;
4453 ofstream ofile9 (
"Output_crop_areas_percent.txt", ios::out);
4455 for(
int i=0; i<(int)m_cropTotals_sum.size(); i++){
4456 ofile9 << m_cropTotals_sum[i]/no_years/totalOptFarmsArea * 100 <<
'\t';
4468 vector<TTypesOfVegetation> new_rotation;
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);
4479 for(
int i=0; i<(int)m_farms.size(); i++){
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++){
4503 opt_farms.push_back(opf);
4506 opt_farms_copy = opt_farms;
4509 int number_profit = (int) (profit_proportion/100 * number_opt_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);
4518 int index_for_farm=0;
4521 for(
int j=jj; j<number_profit; j++){
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);
4531 for(
int j = jj; j<number_yield + number_profit; 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);
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++){
4544 index_for_farm = dis2(gen);
4546 opt_farms_copy.erase(opt_farms_copy.begin() + index_for_farm);
4550 if((
int)opt_farms_copy.size()>0){
4551 for(
int p=(
int)opt_farms_copy.size(); p>0; p--){
4564 for(
int i=0; i<(int)vector.size(); i++){
4579 m_beta1.resize(foobar*tos_Foobar);
4580 m_beta2.resize(foobar*tos_Foobar);
4581 m_Nnorm.resize(foobar*tos_Foobar);
4582 m_biomass_factors.resize(foobar*tos_Foobar);
4584 m_fodder.resize(foobar*toof_Foobar);
4585 m_FUKey.resize(foobar*toof_Foobar);
4586 m_sellingPrice.resize(foobar*toof_Foobar*tos_Foobar);
4587 m_sellingPrice_lastyr.resize(foobar*toof_Foobar*tos_Foobar);
4588 m_rotationMax.resize(foobar*toof_Foobar*tos_Foobar*
tofs_Foobar);
4589 m_rotationMin.resize(foobar*toof_Foobar*tos_Foobar*tofs_Foobar);
4590 m_winterMax.resize(toof_Foobar);
4595 InitializeVector (m_cropParameters);
4596 InitializeVector (m_alfa);
4597 InitializeVector (m_beta1);
4598 InitializeVector (m_beta2);
4599 InitializeVector (m_Nnorm);
4600 InitializeVector (m_biomass_factors);
4601 InitializeVector (m_FUKey);
4602 InitializeVector (m_sellingPrice);
4603 InitializeVector (m_rotationMax);
4604 InitializeVector (m_rotationMin);
4610 for(
int i=0; i< (int) m_farm_data.size(); i++){
4611 if(m_farm_data[i]->md_almass_no == a_almass_no)
return m_farm_data[i] -> md_farmType;
4613 g_msg->
Warn(
WARN_BUG,
"almass_no from farms_data doesn't match any of the numbers from farmrefs file",
"" );
4618 m_animalType=a_animalType;
4630 m_cropType=a_cropType;
4632 m_initialArea=a_initialArea;
4636 m_cropType_almass = a_cropType;
4638 m_initialArea=a_initialArea;
4661 if(m_area_rot ==0) {
4662 for(
int i=0; i<(int)
m_fields.size(); i++){
4663 if(
m_fields[i]->GetRotIndex() != -4){
4714 for(
int i=0; i<size; i++){
4729 for(j=0; j<size; j += (toa_Foobar+1)){
4736 g_msg->
Warn(
WARN_BUG,
"Farm's almass_no doesn't match any of the numbers within the livestock numbers vector",
"" );
4739 int index2 = index + 1 + i;
4744 p_lvs =
new Livestock(livestock_type, number);
4752 for(
int i=0; i<no_crops; i++){
4756 for(j=0; j<size; j+=(no_crops+1)){
4764 g_msg->
Warn(
WARN_BUG,
"Farm's almass_no doesn't match any of the numbers within the crop areas vector",
"" );
4767 int index2= index + 1 + i;
4860 int sum_centroidx = 0;
4861 int sum_centroidy = 0;
4862 int no_fields = (int)
m_fields.size();
4863 for (
int i=0; i<no_fields; i++){
4864 sum_centroidx +=
m_fields[i]->GetCentroidX();
4865 sum_centroidy +=
m_fields[i]->GetCentroidY();
4878 if (BIherb > 0)
return true;
4890 if (BIfi > 0)
return true;
4913 for(
int a=0; ok==
false && neighbours_copy.size()>0; a++){
4914 srand ((
unsigned)time(NULL));
4915 int neighbour = rand() % (no_farmers-a);
4924 neighbours_copy.erase(neighbours_copy.begin() + neighbour);
4933 neighbours_copy.erase(neighbours_copy.begin() + neighbour);
4943 neighbours_copy.erase(neighbours_copy.begin() + neighbour);
4952 neighbours_copy.erase(neighbours_copy.begin() + neighbour);
4962 for(
int a=0; ok==
false && neighbours_copy.size()>0; a++){
4963 srand ((
unsigned)time(NULL));
4964 int neighbour = rand() % (no_farmers-a);
4970 neighbours_copy.erase(neighbours_copy.begin() + neighbour);
4979 char errornum[ 20 ];
4981 g_msg->
Warn(
WARN_BUG,
"No farm with a matching farm type to imitate: ", errornum );
5018 double sum_of_sat_levels=0;
5019 for(
int i=0; i<5; i++){
5074 int value_for_satisfaction = 1;
5099 createFodderCrops(a_foobar);
5106 for (
int i=0; i < n; ++i) {
5123 for (
int i=0; i < n; ++i) {
5129 m_fodderCrops.push_back(cs);
5153 for (
int i=0; i< (int)
m_crops.size(); i++) {
5171 string str_AUKey=
"AUKey";
5172 string str_Nusable=
"Nusable";
5182 double NanimUsable = number*AUKey*Nusable*100;
5198 string str_FUuKey=
"FUuKey";
5208 double FUdemand=FUuKey*number;
5260 cash_crops_allowed=
false;
5265 std::random_device rd;
5266 std::mt19937 gen(rd());
5268 double random_no = dis(gen);
5270 if(random_no > 0.1){
5281 cash_crops_allowed=
false;
5324 for (
int i=0; i< (int)
m_crops.size(); i++){
5411 if(CGG1area!= CGG2area){
5412 double area_sum = CGG1area + CGG2area;
5417 if(GS1area!=GS2area){
5418 double area_sum = GS1area + GS2area;
5451 double n1=-(beta1/beta2)*0.5;
5457 a_crop->
m_n = nNorm;
5462 double nt1= 0.5*(priceNt/(benefit*beta2) - beta1/beta2) -
m_Nanim;
5471 if(p>=0){a_crop->
m_nt = p;}
5472 else{a_crop->
m_nt = 0;}
5473 a_crop->
m_n = nNorm;
5478 else {a_crop->
m_n = nNorm;}
5485 else {a_crop->
m_n = nNorm;}
5493 double n1=-(beta1/beta2)*0.5;
5499 a_crop->
m_n = nNorm;
5507 a_crop->
m_n = nNorm;
5517 else {a_crop->
m_n = nNorm;}
5530 a_crop->
m_n = nNorm;
5538 a_crop->
m_n = nNorm;
5548 else {a_crop->
m_n = nNorm;}
5565 double ntotal=a_crop->
m_n;
5566 double resp1=alfa + beta1*ntotal + beta2*pow(ntotal,2);
5592 double resp1=a_crop->
m_resp;
5595 double BIHerbMax = betaHerb/alfaHerb;
5596 double gainHerb = 0;
5600 gainHerb = benefit*resp1*alfaHerb/100 + priceG*alfaG + priceH*alfaH + priceW*alfaW;
5601 BIHerb = (gainHerb>priceHerb)? BIHerbMax : 0;
5608 gainHerb = benefit*resp1*alfaHerb/100 + priceG*alfaG + priceH*alfaH + priceW*alfaW;
5616 double BIFiMax = betaFi/alfaFi;
5620 gainFi = benefit*resp1*alfaFi/100;
5621 BIFi = (gainFi > priceFi) ? BIFiMax : 0;
5625 a_crop->
m_BIFi = BIFiMax;
5628 gainFi = benefit*resp1*alfaFi/100;
5640 double BIFi = a_crop->
m_BIFi;
5642 double BI = BIFi+BIHerb;
5670 PotatoesIndustry->
m_BIHerb = 1.41; PotatoesIndustry->
m_BIFi = 9.28; PotatoesIndustry->
m_BI = 10.69;
5690 double grooming, hoeing, weeding =0;
5691 double g = betaG - BIHerb*alfaG;
5692 double h = betaH - BIHerb*alfaH;
5693 double w = betaW - BIHerb*alfaW;
5694 double BIHerbCorr = BIHerb;
5698 if(alfaG!=0) BIHerbCorr=betaG/alfaG;
5703 if(betaH/alfaH < BIHerbCorr) BIHerbCorr=betaH/alfaH;
5708 if(betaW/alfaW < BIHerbCorr) BIHerbCorr = betaW/alfaW;
5716 if(BIHerbCorr < BIHerb){
5736 double BIFi=a_crop->
m_BIFi;
5738 double lossHerb = betaHerb - alfaHerb*BIHerb;
5741 double lossFi = betaFi - alfaFi*BIFi;
5744 double totalLoss = lossHerb + lossFi;
5762 double resp = a_crop->
m_resp;
5764 double BIFi = a_crop->
m_BIFi;
5769 double nt = a_crop->
m_nt;
5772 double income_ha = benefit*resp*(1-totalLoss/100)+subsidy;
5773 double costs_ha = BIHerb*priceHerb + BIFi*priceFi + grooming*priceG + hoeing*priceH + weeding*priceW + nt*priceNt + priceLM;
5774 double profit = income_ha - costs_ha;
5784 a_crop->
m_GM = subsidy-costs_ha;
5789 a_crop->
m_GM = profit;
5839 double areaPercent=0;
5858 double base_prob = 0;
5865 std::random_device rd;
5867 std::mt19937 engine(rd());
5868 double random_number = dis(engine);
5869 if(base_prob == 1) random_number = 0;
5870 double area_1 = base_prob * (1 + 0.2 * random_number) * (100 -
m_assigned);
5871 areaPercent = ( area_1 <= rotationMax)? area_1 : rotationMax;
5876 areaPercent = (rotationMax-minArea <= 100-
m_assigned)? rotationMax : (100 -
m_assigned+minArea);
5884 else {areaPercent = minArea;}
5887 double areaVar=areaPercent-minArea;
5906 m_fakeCropTest=
false;
5908 m_fakeCropTest =
true;
5911 m_fakeCrop->m_GM = -1000000;
5912 m_fakeCrop->m_rotationMax = 100;
5913 m_fakeCrop->m_rotationMin = 0;
5914 m_fakeCrop->m_areaPercent = areaP;
5915 m_fakeCrop->m_areaVariable = areaP;
5925 correctFodderDemand(a_foobar);
5926 determineFodderAreas(a_foobar);
5972 checkCattleRotation();
5975 checkCattleRotation_almass();
5987 check_WRape_WBarley();
6025 double diff = areaWWheat - (areaWRape + areaSRape + areaOats + areaPeas);
6044 double GM_WWheat = wWheat->
m_GM;
6050 if(areaRC < rotationMaxRC){
6052 bool stopInnerLoop =
false;
6058 if(GM_RC + GM_WWheat < 2*GM_var){
6062 if(areaWWheat - areaMin >= diff){
6063 if(rotationMaxVC - areaVC >= diff){
6067 stopInnerLoop =
true;
6070 areaWWheat -= rotationMaxVC - areaVC;
6071 diff -= (rotationMaxVC - areaVC);
6072 areaVC = rotationMaxVC;
6076 if(rotationMaxVC - areaVC >= areaWWheat - areaMin){
6077 areaVC += areaWWheat - areaMin;
6078 diff -= (areaWWheat - areaMin);
6079 areaWWheat = areaMin;
6080 stopInnerLoop =
true;
6083 areaWWheat -= rotationMaxVC - areaVC;
6084 diff -= (rotationMaxVC - areaVC);
6085 areaVC = rotationMaxVC;
6094 if(areaWWheat - areaMin >= diff/2){
6095 if(rotationMaxRC - areaRC >= diff/2){
6097 areaWWheat -= diff/2;
6099 stopInnerLoop =
true;
6102 areaWWheat -= rotationMaxRC - areaRC;
6103 diff -= 2 * (rotationMaxRC - areaRC);
6104 areaRC = rotationMaxRC;
6105 stopInnerLoop =
true;
6109 if(rotationMaxRC - areaRC >= areaWWheat - areaMin){
6110 areaRC += areaWWheat - areaMin;
6111 diff -= 2 * (areaWWheat - areaMin);
6112 areaWWheat = areaMin;
6113 stopInnerLoop =
true;
6116 areaWWheat -= rotationMaxRC - areaRC;
6117 diff -= 2 * (rotationMaxRC - areaRC);
6118 areaRC = rotationMaxRC;
6119 stopInnerLoop =
true;
6131 if(areaWWheat==areaMin && diff > 0){
6137 double toCut = diff - diff1;
6140 ofstream ofile(
"Restrictions.txt",ios::app);
6141 ofile <<
m_almass_no <<
'\t' <<
"winter rotation1 restriction broken, WWheat area at 0. Diff is: " << diff << endl;
6149 if(diff > 0 && areaWWheat - areaMin >= diff){
6192 double diff = areaWWheat - (areaWRape + areaSRape + areaOats + areaPeas);
6212 double GM_WWheat = wWheat->
m_GM;
6218 double areaBeforeRC = areaRC;
6219 if(areaRC < rotationMaxRC){
6221 bool stopInnerLoop =
false;
6227 if(GM_RC + GM_WWheat < 2 * GM_var){
6231 double areaBefore = areaVC;
6232 if(areaWWheat - areaMin >= diff){
6233 if(rotationMaxVC - areaVC >= diff){
6237 stopInnerLoop =
true;
6240 areaWWheat -= rotationMaxVC - areaVC;
6241 diff -= (rotationMaxVC - areaVC);
6242 areaVC = rotationMaxVC;
6246 if(rotationMaxVC - areaVC >= areaWWheat - areaMin){
6247 areaVC += (areaWWheat - areaMin);
6248 diff -= (areaWWheat - areaMin);
6249 areaWWheat = areaMin;
6253 areaWWheat -= rotationMaxVC - areaVC;
6254 diff -= (rotationMaxVC - areaVC);
6255 areaVC = rotationMaxVC;
6260 if(areaVC > areaBefore){
6267 double FUha = resp * (1-loss/100) * FUKey;
6268 double changeFU = (areaVC - areaBefore) *
m_totalArea/100 * FUha;
6277 if(areaWWheat - areaMin >= diff/2){
6278 if(rotationMaxRC - areaRC >= diff/2){
6280 areaWWheat -= diff/2;
6282 stopInnerLoop =
true;
6285 areaWWheat -= rotationMaxRC - areaRC;
6286 diff -= 2 * (rotationMaxRC - areaRC);
6287 areaRC = rotationMaxRC;
6288 stopInnerLoop =
true;
6292 if(rotationMaxRC - areaRC >= areaWWheat - areaMin){
6293 areaRC += areaWWheat - areaMin;
6294 diff -= 2 * (areaWWheat - areaMin);
6295 areaWWheat = areaMin;
6296 stopInnerLoop =
true;
6299 areaWWheat -= rotationMaxRC - areaRC;
6300 diff -= 2 * (rotationMaxRC - areaRC);
6301 areaRC = rotationMaxRC;
6302 stopInnerLoop =
true;
6310 if(areaRC>areaBeforeRC){
6317 double FUha = resp * (1-loss/100) * FUKey;
6318 double changeFU = (areaRC - areaBeforeRC) *
m_totalArea/100 * FUha;
6329 if(areaWWheat==areaMin && diff>0){
6330 double diff1 = diff;
6336 double toCut = diff-diff1;
6339 ofstream ofile(
"Restrictions.txt",ios::app);
6340 ofile <<
m_almass_no <<
'\t' <<
"winter rotation1 restriction broken. Animal farm. WWheat area at 0. Diff is: " << diff << endl;
6348 if(diff>0 && areaWWheat-areaMin >= diff){
6391 double areaWCerealSil = 0;
6397 double sum = areaWBarley + areaWWheat + areaWRye + areaWRape + areaWCerealSil;
6400 if(sum > winterMax){
6419 double diff = sum - winterMax;
6420 double diffBefore = diff;
6442 ofstream ofile(
"Restrictions.txt",ios::app);
6443 ofile <<
m_almass_no <<
'\t' <<
"winter crops restriction broken, non-animal farm. Diff is: " << diff << endl;
6448 double toIncrease = diffBefore - diff;
6486 double areaWCerealSil = 0;
6492 double sum = areaWBarley + areaWWheat + areaWRye + areaWRape + areaWCerealSil;
6495 if(sum > winterMax){
6496 double diff = sum - winterMax;
6497 double diffBefore = diff;
6537 ofstream ofile(
"Restrictions.txt",ios::app);
6538 ofile <<
m_almass_no <<
'\t' <<
"winter crops restriction broken, Animal farm. Diff is: " << diff << endl;
6543 double toIncrease = diffBefore - diff;
6553 for(
int i=0; i<(int)m_cattleCrops.size(); i++){
6554 double area = m_cattleCrops[i].crop->m_areaPercent;
6555 double areaBefore = area;
6556 double rotationMin = m_cattleCrops[i].crop->m_rotationMin;
6558 m_cattleCrops[i].crop->m_areaPercent = area;
6560 if(areaBefore > area){
6564 double resp = m_cattleCrops[i].crop->m_resp;
6565 double loss = m_cattleCrops[i].crop->m_totalLoss;
6567 double FUha = resp * (1-loss/100) * FUKey;
6568 double changeFU = (areaBefore - area) *
m_totalArea/100 * FUha;
6597 double diff = areaGClover + areaGSeed - areaSBarley;
6604 m_cattleCrops.push_back(cs1);
6605 m_cattleCrops.push_back(cs2);
6618 for(
int i=(
int)m_cattleCrops.size()-1; i>=0 && diff>0; i--){
6619 double areaCC = m_cattleCrops[i].crop->m_areaPercent;
6620 double areaMinCC = m_cattleCrops[i].crop->m_rotationMin;
6621 double areaCCBefore = areaCC;
6622 if(areaCC > areaMinCC){
6623 bool cCropAtMin =
false;
6626 double GM_CC = m_cattleCrops[i].crop->m_GM_Savings;
6628 if(GM_SBarley + GM_CC > 2*GM_var){
6634 double areaVarBefore = areaVar;
6636 if(areaCC - areaMinCC >= diff){
6637 if(areaMaxVar - areaVar >= diff){
6644 diff -= (areaMaxVar - areaVar);
6645 areaCC -= (areaMaxVar - areaVar);
6646 areaVar = areaMaxVar;
6650 if(areaMaxVar - areaVar >= areaCC - areaMinCC){
6651 diff -= areaCC - areaMinCC;
6652 areaVar += areaCC - areaMinCC;
6657 diff -= areaMaxVar - areaVar;
6658 areaCC -= areaMaxVar - areaVar;
6659 areaVar = areaMaxVar;
6665 m_cattleCrops[i].crop->m_areaPercent = areaCC;
6669 if(areaVar > areaVarBefore){
6676 double FUha = resp * (1-loss/100) * FUKey;
6677 double changeFU = (areaVar - areaVarBefore) *
m_totalArea/100 * FUha;
6683 if(areaCC < areaCCBefore){
6687 double resp = m_cattleCrops[i].crop->m_resp;
6688 double loss = m_cattleCrops[i].crop->m_totalLoss;
6690 double FUha = resp * (1-loss/100) * FUKey;
6691 double changeFU = (areaCCBefore - areaCC) *
m_totalArea/100 * FUha;
6711 double SBarleyAvailableArea = areaSBarleyMax-areaSBarley;
6712 double areaSBarleyBefore = areaSBarley;
6714 double available = 0;
6715 for(
int i=0; i<(int)m_cattleCrops.size(); i++){
6716 double areaMin = m_cattleCrops[i].crop->m_rotationMin;
6717 double area = m_cattleCrops[i].crop->m_areaPercent;
6718 available += (area - areaMin);
6721 if(areaSBarley < areaSBarleyMax){
6722 if(SBarleyAvailableArea >= diff/2){
6723 if(available >= diff/2){
6724 areaSBarley += diff/2;
6730 areaSBarley += available;
6731 diff -= 2 * available;
6732 setCattleCropsAtMin();
6734 if(SBarleyAvailableArea >= diff){
6735 areaSBarley += diff;
6740 double toDecrease = areaSBarleyMax - areaSBarley;
6741 areaSBarley = areaSBarleyMax;
6745 ofstream ofile(
"Restrictions.txt",ios::app);
6746 ofile <<
m_almass_no <<
'\t' <<
"cattle restriction: broken after N 3.2" << endl;
6753 if(available >= SBarleyAvailableArea){
6754 areaSBarley = areaSBarleyMax;
6755 diff -= 2 * SBarleyAvailableArea;
6756 available -= SBarleyAvailableArea;
6759 double diffBefore = diff;
6760 if(available >= diff){
6766 setCattleCropsAtMin();
6768 double toDecrease = available;
6771 ofstream ofile(
"Restrictions.txt",ios::out);
6772 ofile <<
m_almass_no <<
'\t' <<
"cattle restriction: broken after Y 3.1" << endl;
6777 areaSBarley += available;
6778 setCattleCropsAtMin();
6779 diff -= 2 * available;
6780 double toDecrease = areaSBarleyMax - areaSBarley;
6781 areaSBarley = areaSBarleyMax;
6785 ofstream ofile(
"Restrictions.txt",ios::out);
6786 ofile <<
m_almass_no <<
'\t' <<
"cattle restriction: broken after N 3.1" << endl;
6794 double resp = sBarley->
m_resp;
6797 double FUha = resp * (1-loss/100) * FUKey;
6798 double changeFU = (areaSBarley - areaSBarleyBefore) *
m_totalArea/100 * FUha;
6804 if(available >= diff){
6805 double diffBefore = diff;
6810 setCattleCropsAtMin();
6812 double toIncrease = available;
6815 ofstream ofile(
"Restrictions.txt",ios::out);
6816 ofile <<
m_almass_no <<
'\t' <<
"cattle restriction: broken after N 1" << endl;
6838 double diff = areaCGG/2 - areaSBarley;
6850 double new_area_sbarley = areaSBarley;
6851 double new_area_cgg = areaCGG;
6856 available += areaVariableCrop;
6859 if(areaCGG/2 *3 <= available){
6860 new_area_sbarley = areaCGG/2;
6861 double area_to_decrease = new_area_sbarley - areaSBarley;
6865 new_area_cgg = available/3 * 2;
6866 new_area_sbarley = available/3;
6867 double current_sbarley_and_grasses = areaSBarley + areaCGG;
6868 double other_crops_area = available - current_sbarley_and_grasses;
6869 if(current_sbarley_and_grasses < available){
6876 double resp = sBarley->
m_resp;
6880 double FUha = resp * (1-loss/100) * FUKey;
6881 double changeFU = (new_area_sbarley - areaSBarley) *
m_totalArea/100 * FUha;
6889 FUha = resp * (1-loss/100) * FUKey;
6890 changeFU = (areaCGG - new_area_cgg) *
m_totalArea/100 * FUha;
6917 if(area_WB < area_WR){
6931 available += areaVariableCrop;
6934 double new_area_wbarley = area_WB;
6935 double new_area_wrape = area_WR;
6937 if(2 * area_WR <= available){
6938 new_area_wbarley = area_WR;
6939 double area_to_decrease = new_area_wbarley - area_WB;
6943 new_area_wrape = available/2;
6944 new_area_wbarley = available/2;
6945 double current_wbarley_and_wrape = area_WB + area_WR;
6946 double other_crops_area = available - current_wbarley_and_wrape;
6947 if(current_wbarley_and_wrape < available){
6954 double winter_crops=0;
6955 for(
unsigned j=0; j<
m_crops.size(); j++){
6958 winter_crops +=
m_crops[j]->m_areaPercent;
6969 for(
unsigned j=0; j<
m_crops.size(); j++){
6972 winter_crops +=
m_crops[j]->m_areaPercent;
6977 if(winter_crops > winterMax){
6978 double diff = winter_crops - winterMax;
6986 new_area_wrape -= diff/2;
6987 new_area_wbarley -= diff/2;
6996 double resp = wBarley->
m_resp;
7000 double FUha = resp * (1-loss/100) * FUKey;
7001 double changeFU = (new_area_wbarley - area_WB) *
m_totalArea/100 * FUha;
7021 double fodderFromFixed=0;
7024 if(area_percent!=0){
7031 double FU = area*resp*(1-loss/100)*FUKey;
7032 fodderFromFixed += FU;
7036 double fodderFromMinAreas=0;
7039 if(areaMinPercent!=0){
7046 double FU = area*resp*(1-loss/100)*FUKey;
7047 fodderFromMinAreas += FU;
7054 m_fodderToProduce = m_totalFodderToProduce - (fodderFromFixed + fodderFromMinAreas);
7055 m_fodderToProduceBefore = m_fodderToProduce;
7067 double areaAssignedToFodder=0;
7068 if(m_fodderToProduce > 0){
7072 available += areaVariableCrop;
7075 for(
int i=0; available>0 && i<(int)m_fodderCrops.size() && m_fodderToProduce > 0 ; i++){
7077 double rotationMax = m_fodderCrops[i].crop->m_rotationMax;
7078 double area = m_fodderCrops[i].crop->m_areaPercent;
7079 double areaBefore = area;
7081 double resp = m_fodderCrops[i].crop->m_resp;
7082 double loss = m_fodderCrops[i].crop->m_totalLoss;
7083 double FUha = resp * (1-loss/100) * FUKey;
7084 double haNeeded = m_fodderToProduce/FUha;
7086 if(percNeeded <= rotationMax - area){
7087 if(percNeeded <= available){
7089 available -= percNeeded;
7097 if(rotationMax-area >= available){
7102 available -= rotationMax-area;
7106 m_fodderCrops[i].crop->m_areaPercent = area;
7107 double Funits = FUha * (area-areaBefore) *
m_totalArea/100;
7108 m_fodderToProduce -= Funits;
7111 areaAssignedToFodder += (area-areaBefore);
7114 if(m_fodderToProduce>0.1){
7118 g_msg->
Warn(
WARN_BUG,
"AnimalFarm::determineMinFodder(): impossible to cover the min. fodder prod., farm no: ", index );
7123 vector<CropSort>grownVarCrops_key;
7126 grownVarCrops_key.push_back(gc);
7130 if(areaAssignedToFodder>0){
7134 g_msg->
Warn(
WARN_BUG,
"AnimalFarm::determineMinFodder(): not enough space to grow the min. fodder, farm no.: ", index );
7166 if(!cash_crops_allowed) determineMinFodder(a_foobar);
7177 double rotationMax = m_fodderCrops[p].crop->m_rotationMax;
7178 double areaFodder = m_fodderCrops[p].crop->m_areaPercent;
7179 if(areaFodder < rotationMax){
7180 double savings = m_fodderCrops[p].crop->m_savings;
7181 bool assigningFinished =
false;
7184 double minGM = 1000000;
7189 if(savings > minGM){
7193 double resp = m_fodderCrops[p].crop->m_resp;
7194 double loss = m_fodderCrops[p].crop->m_totalLoss;
7195 double FUha = resp*(1-loss/100)*FUKey;
7199 if(percNeeded <= rotationMax - areaFodder){
7200 if(percNeeded <= areaVariable){
7201 areaFodder += percNeeded;
7204 areaVariable -= percNeeded;
7205 assigningFinished =
true;
7208 areaFodder += areaVariable;
7215 if(rotationMax - areaFodder <= areaVariable){
7216 areaVariable -= rotationMax-areaFodder;
7219 areaFodder = rotationMax;
7220 assigningFinished =
true;
7224 areaFodder += areaVariable;
7232 double areaPer = areaMin + areaVariable;
7240 assigningFinished =
true;
7243 }
while (assigningFinished==
false && v>=0);
7245 m_fodderCrops[p].crop->m_areaPercent = areaFodder;
7247 if(assigningFinished==
false){
7260 if(m_fakeCropTest==
true){
7264 if(areaFakeCrop > 0){
7286 for(
int c=0; c< (int)
m_crops.size(); c++){
7289 g_msg->
Warn(
WARN_FILE,
"OptimisingFarm::findCropByName():" "Unknown Code Identificator", crop_name.c_str() );
7294 for(
int c=0; c< (int)
m_crops.size(); c++){
7297 g_msg->
Warn(
WARN_FILE,
"OptimisingFarm::findCropByName_almass():" "Unknown Code Identificator", crop_name.c_str() );
7302 for(
int c=0; c< (int)
m_crops.size(); c++){
7303 if(
m_crops[c]->m_cropType_almass == a_tov_type)
return m_crops[c];
7305 char error_num[ 20 ];
7306 sprintf( error_num,
"%d", a_tov_type);
7307 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::findCropByName_almass():" "Unknown Code Identificator", error_num );
7316 for (
int i=0; i<(int)cropsToSort.size(); i++){
7317 cropsToSort[i].key = cropsToSort[i].crop->m_GM;
7320 else if (sortKey==
"Savings"){
7321 for (
int i=0; i<(int)cropsToSort.size(); i++){
7322 cropsToSort[i].key = cropsToSort[i].crop->m_savings;
7326 for (
int i=0; i<(int)cropsToSort.size(); i++){
7327 cropsToSort[i].key = cropsToSort[i].crop->m_GM_Savings;
7331 sort(cropsToSort.begin(), cropsToSort.end(),
reverseSort());
7337 std::vector<CropSort>helper;
7338 helper.push_back(listToRandomize[0]);
7340 for(
int i=1; i<(int)listToRandomize.size(); i++){
7341 double key_current, key_previous;
7343 key_current=listToRandomize[i].crop->m_GM;
7344 key_previous=listToRandomize[i-1].crop->m_GM;
7346 else if (key==
"Savings"){
7347 key_current=listToRandomize[i].crop->m_savings;
7348 key_previous=listToRandomize[i-1].crop->m_savings;
7350 else if(key==
"GM_Savings"){
7351 key_current=listToRandomize[i].crop->m_GM_Savings;
7352 key_previous=listToRandomize[i-1].crop->m_GM_Savings;
7355 key_current=key_previous=0;
7356 g_msg->
Warn(
WARN_FILE,
"OptimisingFarm::randomizeCropList():" "Unknown sorting key identificator", key.c_str() );
7360 if(key_current==key_previous){
7361 helper.push_back(listToRandomize[i]);
7364 std::random_shuffle(helper.begin(), helper.end());
7368 for(
int j=(
int)helper.size()-1; j>=0; j--){
7369 listToRandomize[i-1-j]=helper[j];
7372 helper.push_back(listToRandomize[i]);
7380 for(
int i=0; howMuchToIncrease>0 && i<(int)cropsToIncrease.size(); i++){
7381 double area = cropsToIncrease[i].crop->m_areaPercent;
7382 double rotationMax = cropsToIncrease[i].crop->m_rotationMax;
7383 double rotMinCrop = cropsToIncrease[i].crop->m_rotationMin;
7384 if(area + howMuchToIncrease <= rotationMax){
7385 area += howMuchToIncrease;
7386 howMuchToIncrease = 0;
7389 howMuchToIncrease -= rotationMax-area;
7392 cropsToIncrease[i].crop->m_areaPercent = area;
7393 cropsToIncrease[i].crop->m_areaVariable = area - rotMinCrop;
7402 for(
int i=0; howMuchToIncrease>0 && i<(int)cropsToIncrease.size(); i++){
7403 double area = cropsToIncrease[i].crop->m_areaPercent;
7404 double areaBefore = area;
7405 double rotationMax = cropsToIncrease[i].crop->m_rotationMax;
7406 double rotMinCrop = cropsToIncrease[i].crop->m_rotationMin;
7407 if(area + howMuchToIncrease <= rotationMax){
7408 area += howMuchToIncrease;
7409 howMuchToIncrease = 0;
7412 howMuchToIncrease -= rotationMax-area;
7415 cropsToIncrease[i].crop->m_areaPercent = area;
7416 cropsToIncrease[i].crop->m_areaVariable = area - rotMinCrop;
7419 if(area > areaBefore){
7423 double resp = cropsToIncrease[i].crop->m_resp;
7424 double loss = cropsToIncrease[i].crop->m_totalLoss;
7426 double FUha = resp * (1-loss/100) * FUKey;
7427 double changeFU = (area-areaBefore) *
m_totalArea/100 * FUha;
7438 for(
int j=(
int)cropsToDecrease.size()-1; howMuchToDecrease>0 && j>=0; j--){
7439 double areaCrop = cropsToDecrease[j].crop->m_areaPercent;
7440 double rotMinCrop = cropsToDecrease[j].crop->m_rotationMin;
7441 if(areaCrop - howMuchToDecrease >= rotMinCrop){
7442 areaCrop -= howMuchToDecrease;
7443 howMuchToDecrease = 0;
7446 howMuchToDecrease -= areaCrop - rotMinCrop;
7447 areaCrop = rotMinCrop;
7449 cropsToDecrease[j].crop->m_areaPercent = areaCrop;
7450 cropsToDecrease[j].crop->m_areaVariable = areaCrop - rotMinCrop;
7459 for(
int j=(
int)cropsToDecrease.size()-1; howMuchToDecrease>0 && j>=0; j--){
7460 double areaCrop = cropsToDecrease[j].crop->m_areaPercent;
7461 double areaBefore = areaCrop;
7462 double rotMinCrop = cropsToDecrease[j].crop->m_rotationMin;
7463 if(areaCrop - howMuchToDecrease >= rotMinCrop){
7464 areaCrop -= howMuchToDecrease;
7465 howMuchToDecrease = 0;
7468 howMuchToDecrease -= areaCrop - rotMinCrop;
7469 areaCrop = rotMinCrop;
7471 cropsToDecrease[j].crop->m_areaPercent = areaCrop;
7472 cropsToDecrease[j].crop->m_areaVariable = areaCrop - rotMinCrop;
7474 if(areaCrop < areaBefore){
7478 double resp = cropsToDecrease[j].crop->m_resp;
7479 double loss = cropsToDecrease[j].crop->m_totalLoss;
7481 double FUha = resp * (1-loss/100) * FUKey;
7482 double changeFU = (areaBefore - areaCrop) *
m_totalArea/100 * FUha;
7493 for(
int i=0; i<(int)allCrops.size(); i++){
7494 double areaPercent = allCrops[i]->m_areaPercent;
7495 double area_ha = (areaPercent==0) ? 0 : (areaPercent/100 *
m_totalArea);
7496 allCrops[i]->m_area_ha = area_ha;
7504 double totalAmount = 0;
7505 for (
int i=0; i<(int)
m_crops.size(); i++){
7506 double area_ha =
m_crops[i]->m_area_ha;
7508 double value_per_ha;
7511 value_per_ha =
m_crops[i] ->m_areaPercent;
7514 value_per_ha =
m_crops[i] ->m_area_ha;
7517 value_per_ha =
m_crops[i] ->m_n;
7520 value_per_ha =
m_crops[i] ->m_nt;
7523 value_per_ha =
m_crops[i] ->m_BIHerb;
7526 value_per_ha =
m_crops[i] ->m_BIFi;
7529 value_per_ha =
m_crops[i] ->m_BI;
7532 value_per_ha =
m_crops[i] ->m_grooming;
7535 value_per_ha =
m_crops[i] ->m_hoeing;
7538 value_per_ha =
m_crops[i] ->m_weeding;
7541 value_per_ha =
m_crops[i] ->m_totalLoss;
7544 value_per_ha =
m_crops[i] ->m_resp;
7547 value_per_ha =
m_crops[i] ->m_income_ha;
7550 value_per_ha =
m_crops[i] ->m_costs_ha;
7553 value_per_ha =
m_crops[i] ->m_GM;
7556 value_per_ha =
m_crops[i] ->m_savings;
7559 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::total(): ""Unknown crop variable type! ",
"" );
7562 totalAmount += value_per_ha * area_ha;
7580 (*ap_output_file) << endl;
7586 double area_to_check = 0.0;
7587 for(
int i=0; i<(int)
m_crops.size(); i++) {
7588 area_to_check +=
m_crops[i]->m_areaPercent;
7591 if(area_to_check > 100.0001 || area_to_check < 99.999){
7592 ofstream ofile(
"Check_if_area_is_100%.txt",ios::app);
7593 ofile <<
m_almass_no <<
'\t' <<
"Farms area is not equal to 100%. The sum of crops areaPercent is: " << area_to_check << endl;
7603 for(
int i = 0; i < (int)
m_crops.size(); i++){
7604 if(
m_crops[i]->m_areaPercent > 0){
7730 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Translate_crops_to_almass(): ""Unknown crop type! ",
"" );
7743 vector<AlmassCrop>crops_almass_aggregated;
7746 for(
int i = 0; i < size; i++){
7751 for(
int p = 0; p < i; p++){
7757 for(
int j = i+1; j < size; j++){
7763 crops_almass_aggregated.push_back(crop);
7798 for(
int i = 0; i < (int)
m_crops.size(); i++){
7799 if(
m_crops[i]->m_areaPercent > 0){
7837 double new_area = area_cgg;
7842 if(area_sb < area_cgg){
7843 new_area = (area_sb + 2*area_cgg)/3;
7850 new_area = area_cgg*2/3;
7904 if(pct<0.5) pct+=0.5;
7921 (*ap_output_file) << i <<
'\t' << crop << endl;
7923 (*ap_output_file) << endl;
7944 int no_rotational = 0;
7961 if(pct<0.5) pct+=0.5;
7975 vector<TTypesOfVegetation>all_crops;
7976 vector<MakeRotation>rotation;
7977 rotation.resize(100);
7988 int area_scaled = (int)(100 * area / area_rot_int + 0.5);
7996 if(SBarley_area < CGG1_area){
7997 if(SBarley_area == 0){
8001 int new_area = (int)((CGG1_area * 2 + SBarley_area)/3 + 0.5);
8014 for(
int j = 0; j<area; j++){
8021 vector<TTypesOfVegetation>all_crops_helper;
8023 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8025 all_crops_helper.push_back(all_crops[i]);
8026 all_crops.erase(all_crops.begin() + i);
8030 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8032 all_crops_helper.push_back(all_crops[i]);
8033 all_crops.erase(all_crops.begin() + i);
8036 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8038 all_crops_helper.push_back(all_crops[i]);
8039 all_crops.erase(all_crops.begin() + i);
8042 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8044 all_crops_helper.push_back(all_crops[i]);
8045 all_crops.erase(all_crops.begin() + i);
8048 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8050 all_crops_helper.push_back(all_crops[i]);
8051 all_crops.erase(all_crops.begin() + i);
8054 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8056 all_crops_helper.push_back(all_crops[i]);
8057 all_crops.erase(all_crops.begin() + i);
8060 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8062 all_crops_helper.push_back(all_crops[i]);
8063 all_crops.erase(all_crops.begin() + i);
8066 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8068 all_crops_helper.push_back(all_crops[i]);
8069 all_crops.erase(all_crops.begin() + i);
8072 for(
int i = 0; i<(int)all_crops.size(); i++){
8074 all_crops_helper.push_back(all_crops[i]);
8075 all_crops.erase(all_crops.begin() + i);
8078 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8080 all_crops_helper.push_back(all_crops[i]);
8081 all_crops.erase(all_crops.begin() + i);
8084 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8086 all_crops_helper.push_back(all_crops[i]);
8087 all_crops.erase(all_crops.begin() + i);
8090 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8092 all_crops_helper.push_back(all_crops[i]);
8093 all_crops.erase(all_crops.begin() + i);
8096 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8098 all_crops_helper.push_back(all_crops[i]);
8099 all_crops.erase(all_crops.begin() + i);
8102 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8104 all_crops_helper.push_back(all_crops[i]);
8105 all_crops.erase(all_crops.begin() + i);
8109 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8111 all_crops_helper.push_back(all_crops[i]);
8112 all_crops.erase(all_crops.begin() + i);
8117 for(
int i = 0; i<(int)all_crops.size(); i++){
8118 all_crops_helper.push_back(all_crops[i]);
8122 if(all_crops_helper.size()!=100){
8123 if(all_crops_helper.size()>100){
8124 for(
int i = (
int)all_crops_helper.size(); i>100; i--){
8125 all_crops_helper.erase(all_crops_helper.end()-1);
8129 for(
int i = (
int)all_crops_helper.size(); i<100; i++){
8137 all_crops = all_crops_helper;
8141 for(
int i = 0; i<(int)rotation.size(); i++){
8148 for(
int i = 0; i < (int)all_crops.size(); i++){
8155 int step=no_rotational;
8158 for(
int j = p; count<101 && test==
false; j=j+step){
8160 if (crop_index ==
tov_SpringBarley && sb_area > (100/step)) step = (int)(100/sb_area + 0.5);
8166 if(!(rotation[j].taken)){
8170 crop_before = (j==0) ? rotation[99].Tov : rotation[j-1].Tov;
8171 crop_after = (j==99) ? rotation[0].Tov : rotation[j+1].Tov;
8176 if(lookup_before==-1 || lookup_after==-1){
8178 sprintf( index,
"%d", crop_index);
8179 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Make_rotations(): Error (possibly caused by a new tov type that is not incuded in the crops_lookup table) in reading the lookup table; tov type that should not appear: ", index );
8183 if(lookup_before==1 && lookup_after==1){
8184 rotation[j].Tov = all_crops[i];
8185 rotation[j].taken =
true;
8200 for(
int r=0; r<(int)rotation.size() && test==
false; r++){
8204 crop_before = rotation[r].Tov;
8205 crop_after = (r==99) ? rotation[0].Tov : rotation[r+1].Tov;
8209 if(lookup_before==1 && lookup_after==1){
8211 rotation.insert(rotation.begin() + r+1, crop);
8217 for(
int p=(
int)rotation.size()-1; p>=0; p--){
8219 rotation.erase(rotation.begin() + p);
8221 crop_before = (p==0) ? rotation[99].Tov : rotation[p-1].Tov;
8222 crop_after = (p==100) ? rotation[0].Tov : rotation[p].Tov;
8223 int crop_after_position = (p==100) ? 0 : p;
8229 int crop_before2_position;
8232 while(lookup_before!=1){
8241 sprintf( index,
"%d", problem_crop);
8242 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Make_rotations(): The following crop was changed to spring barley: ", index );
8246 crop_index = crop_after;
8248 for(
int t=0; t<(int)rotation.size() && test2==
false; t++){
8249 crop_before1 = rotation[t].Tov;
8250 crop_after1 = (t==99) ? rotation[0].Tov : rotation[t+1].Tov;
8254 if(lookup_before1==1 && lookup_after1==1){
8258 for(
int s=crop_after_position; s!=t+1; s++){
8271 rotation.insert(rotation.begin() + t+1, crop);
8274 if(t+1 > crop_after_position){
8275 rotation.erase(rotation.begin() + crop_after_position);
8276 crop_before2 = (crop_after_position==0) ? rotation[99].Tov : rotation[crop_after_position-1].Tov;
8277 crop_before2_position = (crop_after_position==0) ? 99 : crop_after_position-1;
8278 crop_after = (crop_after_position==99) ? rotation[0].Tov : rotation[crop_after_position].Tov;
8279 crop_after_position = (crop_after_position==99) ? 0 : crop_after_position;
8283 rotation.erase(rotation.begin() + crop_after_position + 1);
8284 crop_before2 = (crop_after_position==0) ? rotation[99].Tov : rotation[crop_after_position].Tov;
8285 crop_before2_position = (crop_after_position==0) ? 99 : crop_after_position;
8286 crop_after = (crop_after_position==99) ? rotation[0].Tov : rotation[crop_after_position+1].Tov;
8287 crop_after_position = (crop_after_position==99) ? 0 : crop_after_position+1;
8307 sprintf( index,
"%d", crop_index);
8309 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Make_rotations(): The following tov type cannot be assigned a place in the rotation: ", index );
8318 for(
int i=0; i<100; i++){
8337 vector<TTypesOfVegetation> veg_type;
8350 for(
int i=0; i<(int)
m_fields.size(); i++){
8354 double biomass=0;
double area=0;
double yield_loss_pest=0;
double no_herb_app=0;
double no_fi_app=0;
8355 double unit_loss_herb=0;
double unit_loss_fi=0;
8356 double yield_ha=0;
double income_ha=0;
double income=0;
double costs_ha=0;
double costs=0;
double profit_ha=0;
double profit=0;
8357 double yield_exp=0;
double yield_ratio=0;
double income_exp=0;
double costs_exp=0;
double profit_exp=0;
8358 double sellingPrice=0;
double priceHerb=0;
double priceFi=0;
double priceLM=0;
double priceH=0;
double priceW=0;
double priceG=0;
double subsidy=0;
8359 double no_missed_herb_app, no_missed_fi_app = 0;
8360 double fert_applied=0;
double fert_opt=0;
double fert_trade=0;
double beta1=0;
double beta2=0;
double alfaH=0;
double alfaFI=0;
8361 double yield_factor = 0;
8364 int cropDataStorage_index=-1;
8368 cropDataStorage_index = 1;
8372 cropDataStorage_index = 0;
8373 if(crop_data.
taken==
false){
8374 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::ActualProfit(): There is no crop data in the fields m_CropDataStorage",
"" );
8385 bool do_accounting =
true;
8386 if(cropDataStorage_index==0){
8392 do_accounting =
false;
8397 area = crop_data.
area * 0.0001;
8402 unit_loss_herb = betaH/100/2;
8403 unit_loss_fi = alfaFI/100;
8408 unit_loss_herb = alfaH/100;
8409 unit_loss_fi = alfaFI/100;
8414 std::random_device rd;
8415 std::normal_distribution<double> dist(1, 0.2);
8416 std::mt19937 engine(rd());
8417 double r_number_1 = dist(engine);
8418 double r_number_2 = dist(engine);
8424 yield_loss_pest = no_missed_herb_app * unit_loss_herb * r_number_1 + no_missed_fi_app * unit_loss_fi * r_number_2;
8440 yield_ha = (biomass==-1)? dd : biomass;
8441 yield_ha *= yield_factor;
8443 yield_ha -= (1 - fert_applied/fert_opt) * (beta1 * fert_opt + beta2 * fert_opt*fert_opt);
8445 yield_ha *= (1-yield_loss_pest);
8490 income_ha = yield_ha * sellingPrice + subsidy;
8491 income = income_ha * area;
8494 costs_ha = no_herb_app*priceHerb + no_fi_app*priceFi + grooming*priceG + hoeing*priceH + weeding*priceW + fert_trade*priceNt+ priceLM;
8495 costs = costs_ha * area;
8498 profit_ha = income_ha - costs_ha;
8499 profit = profit_ha * area;
8504 yield_ratio = yield_ha/yield_exp;
8527 if (fodder) income_exp = subsidy;
8528 else income_exp = (sellingPrice_lastyr*resp*(1-totalLoss/100)+subsidy)*area;
8531 profit_exp = income_exp - costs_exp;
8542 g_msg->
Warn(
"OptimisingFarm::ActualProfit(): There was no accounting for tov: ", crop);
8550 int index_for_croptotals=0;
8552 for(
int k = 0; k<size; k++){
8554 if(crop_type == crop){
8555 index_for_croptotals = k;
8585 ofstream ofile (
"Economic_figures.txt", ios::app);
8590 ofile << endl <<endl;
8604 min_need_satisfaction1 = 100;
8605 min_need_satisfaction2 = 100;
8645 double avrg_animals_no = 0;
8679 m_actual_aggregated_yield = 0;
8708 crop_to_grow = current_crop;
8718 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): rot crops vector is empty! Farm no: ", index );
8745 bool other_crop_than_cgg =
false;
8749 other_crop_than_cgg =
true;
8753 if (!other_crop_than_cgg){
8758 bool Sb_inserted=
false;
8762 vector<int>probability_line;
8763 probability_line.push_back(0);
8767 probability_line.push_back(area + (
int)probability_line[probability_line.size() - 1]);
8772 std::random_device rd;
8773 std::mt19937 gen(rd());
8774 int last_number = probability_line[(int)probability_line.size() - 1];
8776 double crop_index = 0;
8780 bool crop_found =
false;
8781 for(
int c = 0; !crop_found; c++){
8782 crop_index = dis(gen);
8784 for(
int j=0; j < (int)probability_line.size(); j++){
8785 if(j==(
int)probability_line.size()-1) {
8788 sprintf( index,
"%d", (
int) crop_index);
8789 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): no crops left, index drawn is ", index );
8794 sprintf( index,
"%d", (
int) crop_index);
8795 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): index not found in the prob. line", index );
8799 if(crop_index >= probability_line[j] && crop_index < probability_line[j+1]) {
8802 sprintf( index,
"%d", j);
8803 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): index out of a range", index );
8814 if(lookup_before==-1){
8816 sprintf( index,
"%d", current_crop);
8817 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): Error (possibly caused by a new tov type that is not incuded in the crops_lookup table) in reading the lookup table; tov type that should not appear: ", index );
8820 if(lookup_before==1){
8822 bool WRape_grown =
false;
8825 for(
int w=0; w<(int)
m_fields.size(); w++){
8833 if(diff <= 20 && !WRape_grown){
8846 if(c==1000 && !crop_found){
8848 probability_line.clear();
8849 probability_line.push_back(0);
8853 probability_line.push_back(area + (
int)probability_line[probability_line.size() - 1]);
8856 last_number = probability_line[(int)probability_line.size() - 1];
8862 sprintf( index,
"%d", current_crop);
8863 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): There is no crop that can follow the current crop. Sbarley will be grown. The current crop is: ", index );
8880 sprintf( index,
"%d", current_crop);
8881 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): m_rotational_crops_copy is empty, the crop chosen is: ", index );
8892 int position_in_mrotation=-1;
8895 for(
int c=0; c< (int)
m_rotation.size(); c++){
8897 position_in_mrotation=c;
8902 if(position_in_mrotation==-1){
8903 char error_num[ 20 ];
8904 sprintf( error_num,
"%d", crop_to_grow );
8905 g_msg->
Warn(
WARN_FILE,
"OptimisingFarm::Match_crop_to_field(): ""Unknown vegetation type:", error_num );
8909 if(position_in_mrotation!=0){
8926 for (
int i = 0; i < nf; i++ )
8928 if (
m_fields[ i ]->GetOpenness() >= a_openness )
8930 p_list->push_back(
m_fields[i]->GetPoly());
A farm that can have its rotation defined by the user at runtime.
TTypesOfFarmSize Get_farmSize(void)
double m_rotationMin
Minimum area in percent of farm's arable area for a given crop (depends on a farm size...
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...
UserDefinedFarm11(FarmManager *a_manager)
TTypeOfFarmerGoal Get_main_goal()
void Print_FarmVariables(ofstream *ap_output_file)
Prints farm-level variables to a text file (one file for all farms).
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...
CfgBool cfg_UseBedriftsmodelFarmAreas("USE_BEDRIFTSMODEL_FARM_AREAS", CFG_CUSTOM, false)
If set to true, the farm areas from the original farm optimisation model are used in the optimisation...
UserDefinedFarm5(FarmManager *a_manager)
TTypesOfLivestockParameters
A farm that can have its rotation defined by the user at runtime.
DataForOptimisation()
The constructor.
vector< double > m_previous_satisfaction_levels
Vector of satisfaction levels in five previous years.
CfgBool g_farm_fixed_rotation_farms_async("FARM_FIXED_ROTATION_FARMS_ASYNC", CFG_CUSTOM, false)
UserDefinedFarm13(FarmManager *a_manager)
vector< CropSort > m_winterCrops
Vector of structs containing pointers to winter crops.
The landscape class containing all environmental and topographical data.
virtual int GetFirstCropIndex(TTypesOfLandscapeElement a_type)
Gets the first crop for the farm.
UserDefinedFarm28(const char *fname, FarmManager *a_manager)
void sumMinAreas()
Adds minimum required areas of variable crops to the variable m_assigned.
Subclass of the OptimisingFarm. Either pig or cattle farm.
virtual void decreaseCrops(vector< CropSort >cropsToDecrease, double &howMuchToDecrease)
Decreases area of cropsToDecrease by howMuchToDecrease.
OrganicPig(FarmManager *a_manager)
virtual void checkWinterRotation1()
Animal farm version of the OptimisingFarm::checkWinterRotation1() function (accounts for fodder chang...
void ActualProfit()
Calls OptimisingFarm::ActualProfit for all optimising farms.
virtual void HandleEvents(void)
If there are events to carry out do this, and perhaps start a new crop.
A farm that can have its rotation defined by the user at runtime.
void randomizeCropList(vector< CropSort > &listToRandomize, string key)
Swaps randomly elements of the list holding same values of the key (according to which the list was p...
Inbuilt special purpose farm type.
~FarmManager()
Farm manager destructor.
void Make_rotational_crops()
Creates a vector m_rotational_crops using the results of optimisation.
CfgBool cfg_OnlyDeliberation("ONLY_DELIBERATION", CFG_CUSTOM, true)
If set to yes, the only decision mode/startegy the farmers can use is deliberation (i...
int GetNextCropStartDate(LE *a_field, TTypesOfVegetation &a_curr_veg)
Returns the start date of the next crop in the rotation.
UserDefinedFarm1(FarmManager *a_manager)
A farm that can have its rotation defined by the user at runtime.
TTypesOfFarmSize md_farmSize
void AssignPermanentCrop(TTypesOfVegetation tov, int pct)
Used to assign a permanent crop to an otherwise rotational field polygon.
void ChooseDecisionMode_for_farms()
Calls OptimisingFarm::ChooseDecisionMode for all optimising farms.
void Check_SG_and_CGG()
Modifies areas of SeedGrass1 and SeedGrass2, CloverGrassGrazed1 and CloverGrassGrazed2 to be even...
void findFertilizer(CropOptimised *a_crop, int a_foobar, double benefit)
Determines the optimal amounts of: total fertilizer (CropOptimised::m_n) and purchased fertilizer (Cr...
vector< CropOptimised * > m_fixedCrops
Vector of pointers to fixed crops.
TTypesOfFarmSize TranslateFarmSizeCodes(string &str)
double crop_parameter(int index, string par_name)
Reads in crop parameters that do NOT vary with any farm level parameters.
UserDefinedFarm26(const char *fname, FarmManager *a_manager)
void ReadLivestockData()
Reads the data on livestock parameters (do not vary with farm variables) and saves them in a vector D...
void Set_Crop(CropOptimised *p_crop)
TTypesOfFarm GetType(void)
CfgFloat cfg_Price_SBarley("PRICE_SBARLEY", CFG_CUSTOM, 83)
A farm that can have its rotation defined by the user at runtime.
TTypesOfOptFarms m_farmType
Farm's type (cattle, pig, plant, other).
UserDefinedFarm34(const char *fname, FarmManager *a_manager)
CfgFloat cfg_Min_certainty("MIN_CERTAINTY", CFG_CUSTOM, 0)
A parameter setting the minimum certainty level.
void findBIs(CropOptimised *a_crop, double benefit)
Determines the optimal Treatment frequency indices (behandling index, BI in Danish) (CropOptimised::m...
bool DoIt(int a_probability)
Return chance out of 100.
UserDefinedFarm10(FarmManager *a_manager)
double m_totalFUgrown
Fodder grown, i.e. obtained from growing fodder crops. [fodder units].
virtual void increaseCrops(vector< CropSort >cropsToIncrease, double &howMuchToIncrease)
Increases area of cropsToIncrease by howMuchToIncrease.
CfgBool g_farm_enable_crop_rotation("FARM_ENABLE_CROP_ROTATION", CFG_CUSTOM, true)
vector< int > FarmHuntRef
The hunter's is the farm reference number to where he hunts.
void Print_rotations(ofstream *ap_output_file)
Prints the content of a farm's m_rotation. Not used in ALMaSS crop mode.
vector< double > m_previous_incomes
Vector of incomes from previous years.
int GetNoOpenFields(int a_openness)
Returns the number of the fields above an openness of a_openness.
double m_totalBIHerb
Total amount of herbicides which is planned to be applied at a farm. Expressed as a Treatment frequen...
virtual bool Spraying_herbicides(TTypesOfVegetation a_tov_type)
Returns true if a farmer decided to treat a given crop with herbicides.
bool CheckOpenness(int a_openness, int a_ref)
Check if a farm has at least one field with openness above a_openness.
void determineMinFodder(int a_foobar)
Covers the min. required fodder production for animal farms.
A farm that can have its rotation defined by the user at runtime.
double Get_sellingPrice_lastyr(int i)
Inbuilt special purpose farm type.
void ReadLivestockNumbers()
Reads the data on livestock numbers and saves them in a vector DataForOptimisation::m_livestockNumber...
UserDefinedFarm3(FarmManager *a_manager)
vector< int > m_decision_mode_counters
Vector with counters for each decision mode. 0 - imitation, 1 - social comparison, 2 - repeat, 3 - deliberation.
OptimisingFarm * Find_neighbour_to_imitate()
Picks randomly a farmer to imitate/compare with. It chooses among neighbouring farmers with similar f...
void setCattleCropsAtMin()
Decreases area of cattle crops to their min. required area.
Class storing farm information: farm's number used in ALMaSS system, farm's soil type, farm's size (business or private) and farm's real ID number.
A farm that can have its rotation defined by the user at runtime.
virtual void SetVegType(TTypesOfVegetation, TTypesOfVegetation)
CropOptimised * findCropByName(string crop_name)
Returns a pointer to a crop whose name is specified as the argument (bedriftsmodel, i.e. original farm optimization model, crops mode).
A farm that can have its rotation defined by the user at runtime.
bool LeSwitch(FarmEvent *ev)
Call do function for any crop with an outstanding event. Signal if the crop has terminated.
vector< CropOptimised * > m_crops
Vector of pointers to all crops.
vector< AlmassCrop > m_crops_almass
Vector of structs with almass type crops with positive areas in % (result of optimisation).
virtual void InitiateManagement(void)
Kicks off the farm's management.
void FarmManagement()
Runs the daily farm management for each farm, but also calculates annual spilled grain and maize...
void Set_tov_type(TTypesOfVegetation a_tov_type, int index)
UserDefinedFarm24(const char *fname, FarmManager *a_manager)
CropOptimised * findCropByName_almass(string crop_name)
Returns a pointer to almass crop whose name is specified as the argument (ALMaSS crops mode)...
void Set_crops_summary_BIs(int i, double BI)
vector< CropSort > m_variableCrops
Vector of structs containing pointers to crops which are not fixed.
CfgBool g_farm_fixed_crop_enable("FARM_FIXED_CROP_ENABLE", CFG_CUSTOM, false)
void checkCattleRotation_almass()
Checks if the cattle restriction is fulfilled - in the ALMaSS crops mode.
A farm that can have its rotation defined by the user at runtime.
TTypeOfFarmerGoal m_main_goal
Farmer's main goal (determined by a farmer's type) .
CfgFloat cfg_Price_FU("PRICE_FU", CFG_CUSTOM, 1.157)
Price of a fodder unit. [DKK/FU].
void SetRotIndex(int a_index)
Inbuilt special purpose farm type.
UserDefinedFarm31(const char *fname, FarmManager *a_manager)
UserDefinedFarm18(const char *fname, FarmManager *a_manager)
void DistributeFarmerTypes()
Randomly assigns farmer types to farms (OptimisingFarm) in proportions specified in an input file...
ConventionalCattle(FarmManager *a_manager)
double m_exp_income
An expected farm's income at a farm in a given year.
boost::variate_generator< base_generator_type &, boost::uniform_real<> > g_rand_uni
double m_area_rot
Area assigned to rotational crops. [ha].
CfgFloat cfg_Yield_max_proportion("YIELD_MAX_PROPORTION", CFG_CUSTOM, 0)
A parameter setting the proportion of farmers of a type yield maximiser.
UserDefinedFarm(const char *fname, FarmManager *a_manager)
double m_actual_profit
An actual profit realised at a farm in a given year.
virtual void preventCashCrops()
Prevents small cattle farms from growing cash crops and maize silage.
TTypesOfFarmSize m_farmSize
Scale of the farm - business (size above 10 ha) or private (size below 10 ha).
A data structure to hold hunter information for distribution.
int GetTotalArea(void)
Returns the area of all fields owned by that farm.
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...
void DumpFarmrefs()
dumps the farmrefs file to a standard named file
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
UserDefinedFarm33(const char *fname, FarmManager *a_manager)
double m_income_ha
Value of income per ha of a crop. Includes value of sales and subsidy [DKK/ha].
Subclass of the NonAnimalFarm.
A farm that can have its rotation defined by the user at runtime.
UserDefinedFarm19(const char *fname, FarmManager *a_manager)
vector< CropSort > m_rotationCrops
Vector of structs containing pointers to (winter) rotation crops.
double m_costs_ha
Costs of growing 1 ha of a crop. Include costs of labour and machine (constant), pesticides (herbicid...
void determineFodderAreas(int a_foobar)
Determines areas of fodder crops and corrects areas of non-fodder crops.
CfgBool cfg_OptimisingFarms("OPTIMISING_FARMS", CFG_CUSTOM, false)
If set to true, the farmer decision making model is active.
void SetOwner(Farm *a_owner, int a_owner_num, int a_owner_index)
void Make_rotations()
Creates m_rotation. Not used in ALMaSS crop mode.
FarmManager()
Farm manager constructor.
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 dis...
int homeY
Hunter home y-coord.
Integer configurator entry class.
A farm that can have its rotation defined by the user at runtime.
double m_BIFi
Value of BI for fung- and insecticides [BI/ha].
void FarmLevelCalculation()
Calls functions determining farm level values before the initial optimisation.
void Save_diff_farm_types_areas()
Calculates and saves total areas of all optimising farms and specific farm types. ...
CfgBool cfg_DumpFarmAreas("DUMP_FARM_AREAS", CFG_CUSTOM, false)
If set to true, an output file with farm areas is produced.
void Set_crops_summary_BIs_fi(int i, double BIfi)
TTypesOfOptFarms TranslateFarmCodes(string &str)
virtual void findFodderDemand()
Determines farm's total demand for fodder (m_totalFUdemand).
void ReadInitialCropAreas()
Reads the data on farms' initial crop distributions and saves them in a vector DataForOptimisation::m...
double total(TTypesOfCropVariables variable_name)
Function for determining total values per farm after initial optimisation.
A class for storing livestock parameters and variables for optimising farms.
A farm that can have its rotation defined by the user at runtime.
void RemoveField(int a_OwnerIndex, LE *a_field)
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...
CfgFloat cfg_Environmentalist_proportion("ENVIRONMENTALIST_PROPORTION", CFG_CUSTOM, 0)
A parameter setting the proportion of farmers of a type environmentalist.
int Get_decision_mode_counters(int index)
TTypesOfAnimals Get_livestockTypes(int i)
CfgFloat cfg_Price_WWheat("PRICE_WWHEAT", CFG_CUSTOM, 94)
double Get_cropArea(int index)
double m_Nanim
Amount of animal fertilizer available at a farm per hectar. [kg/ha].
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 m_totalNanim
Total animal fertilizer at a farm. A sum of Livestock::m_NanimUsable (from all types of livestock)...
void Check_if_area_100()
Checks if the sum of crops' areaPercent is 100%.
CfgBool cfg_MaizeEnergy("MAIZE_ENERGY", CFG_CUSTOM, false)
If set to true, the energy maize crop is included in the simulation.
void assignFixed()
Adds areas of fixed crops to the variable m_assigned. For each fixed crop it saves its area under var...
void PrintFinalResults()
At the end of a simulation it prints results on crop distribution, pesticide and fertilizer usage...
CfgFloat cfg_Yield_max_pest_prob_multiplier("YIELD_MAX_PEST_PROB_MULITPLIER", CFG_CUSTOM, 1.5)
A parameter of the yield maximizer farmer type: it increases the chance of necessity of carrying out ...
boost::random::uniform_int_distribution distribution_type2
double Get_actual_profit()
double m_lossFi
Value of the yield loss due to the limited use of fung- and insecticides [%].
Struct redefining operator < - used for sorting crops.
double m_actual_aggregated_yield
Actual aggregated yield at a farm in a given year.
TTypesOfOptFarms Get_farmType(void)
vector< AlmassCrop > m_rotational_crops_copy
A copy of m_rotational_crops used when matching crops to fields.
double m_totalWeeding
Total manual weeding planned at a farm.
double m_totalFUdemandBefore
Farm's total demand for fodder. [fodder units]
double m_areaPercent
Area of a crop in percent of a farm's total area [%].
long GetMgtLoopDetectCount(void)
Subclass of the NonAnimalFarm.
A farm that carries out crop, pesticide and fertilizer planning using simplified optimisation or othe...
virtual int GetNextCropIndex(int a_rot_index)
Returns the next crop in the rotation.
UserDefinedFarm30(const char *fname, FarmManager *a_manager)
double m_resp
Response - yield of a crop per ha [hkg/ha].
A farm that can have its rotation defined by the user at runtime.
TTypesOfVegetation m_event
void AddField(int a_OwnerIndex, LE *a_newland, int a_Owner)
bool IsDuplicateRef(int a_ref, HunterInfo *a_hinfo)
Checks if we already have this ref.
Struct for storing ALMaSS crop type (TTypesOfVegetation) with a corresponding value (mainly crop area...
CfgBool cfg_organic_extensive("FARM_ORGANIC_EXTENSIVE", CFG_CUSTOM, false)
void Set_animals_no(int a_number)
void Make_almass_crops_vector()
Creates a vector storing crops with positive area. Used in ALMaSS crop mode.
double m_totalFUt
Fodder from trade (has to be purchased). [fodder units].
void Set_Livestock(Livestock *p_lvs)
virtual double Prob_multiplier()
Used when determining whether there should be a spraying event (i.e. pesticides application) or not...
double m_totalArea
Total area of a farm. A sum of initial crop areas (if in bedriftsmodel, i.e. original farm optimizati...
A farm that can have its rotation defined by the user at runtime.
Inbuilt special purpose farm type.
double m_areaVariable
Area of a crop that can be changed when checking for restrictions (=m_areaPercent - m_rotationMin) [%...
void InitFarms()
Calls OptimisingFarm::Init for all optimising farms.
vector< CropSort > m_variableCrops2
Vector of structs containing pointers to crops which are not fixed and: in case of the winter rotatio...
void ReadFarmsData()
Reads farm level parameters and saves them in a vector DataForOptimisation::m_farm_data.
CfgFloat cfg_FarmSizeProbParam1("FARMSIZEPROBPARAMONE", CFG_CUSTOM, 1.5)
A fitting parameter for the probability of hunter acceptance of a farm that is smaller.
double m_actual_costs
Actual costs at a farm in a given year.
vector< TTypesOfVegetation > m_rotation
virtual void InitiateManagement(void)
Kicks off the farm's management.
int Get_livestockNumber(int index)
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...
A farm that can have its rotation defined by the user at runtime.
Livestock(TTypesOfAnimals a_animalType, int a_number)
Constructor.
UserDefinedFarm2(FarmManager *a_manager)
OptimisingPigFarm(FarmManager *a_myfarmmanager, int a_No)
TTypesOfSoils Get_soilType(void)
OptimisingOtherFarm(FarmManager *a_myfarmmanager, int a_No)
virtual void createCropsLists(int a_foobar)
Creates lists of crops.
double m_grooming
Value of mechanical weed control for a crop - grooming [DKK/ha].
CfgFloat cfg_Env_fert_multiplier("ENV_FERT_MULTIPLIER", CFG_CUSTOM, 0.8)
A parameter of the environmentalist farmer type: reduces environmentalist's use of fertiliser...
void ReadRotation(std::string fname)
Reads a rotation file into the rotation.
Inbuilt special purpose farm type.
A farm that can have its rotation defined by the user at runtime.
double m_GM
Value of gross margin for a crop (m_income_ha - m_costs_ha) [DKK/ha].
double m_totalLoss
Summary value of the yield loss due to the limited use of herbicides and fung- and insecticides [%]...
CfgFloat cfg_Price_Oats("PRICE_OATS", CFG_CUSTOM, 75)
double m_exp_aggregated_yield
Expected aggregated yield at a farm in a given year.
void determineAreas_ha(vector< CropOptimised * >crops)
Determines areas of crops in ha.
double Get_sellingPrice(int i)
UserDefinedFarm16(FarmManager *a_manager)
void ReadCropsData_perFarmType()
Reads the data on crops' parameters that vary with a farm type (fixed, fodder, FUKey) and saves them ...
double m_totalArea_original
Total area of a farm as in bedriftsmodel, i.e. original farm optimization model. [ha].
int InvIntPartition(vector< tpct > *items, int target)
Finds all possible sums of the integers in the items array.
CfgFloat cfg_PriceChangeThreshold("PRICE_CHANGE_THRESHOLD", CFG_CUSTOM, 0.2)
This parameter specifies the relative difference in energy maize price which causes a farmer to delib...
virtual TTypesOfVegetation GetVegType(void)
class LE_TypeClass * g_letype
int m_soilSubType
Farm's soil subtype. Defined only for cattle farms on sandy soil (0-bad, 1-good, 2-undefined).
TTypesOfParameters TranslateParametersCodes(string &str)
NoPesticideNoPFarm(FarmManager *a_manager)
CfgFloat cfg_Min_fodder_prod_pig("MIN_FODDER_PROD_PIG", CFG_CUSTOM, 20)
A parameter setting the minimum proportion of fodder demand that has to be supplied from own fodder p...
Inbuilt special purpose farm type.
virtual void findFodderDemand()
Determines farm's total demand for fodder (m_totalFUdemand).
double m_nt
Amount of purchased (and applied) fertilizer per ha of a crop [kg N/ha].
virtual void preventCashCrops()
Prevents small cattle farms from growing cash crops and maize silage.
double Get_livestockParameter(int i)
void Set_Neighbour(OptimisingFarm *farm)
Inbuilt special purpose farm type.
double m_totalCosts
Planned total costs of growing crops at a farm. [DKK].
virtual void determineAreas(int a_foobar)
Determines areas of variable crops.
TTypesOfOptFarms md_farmType
A farm that can have its rotation defined by the user at runtime.
int m_farm_centroidy
Farm's centroid, value y. Equal to the average of the y centroid values of all farm's fields...
CropActualValues Get_CropDataStorage(int index)
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...
class MapErrorMsg * g_msg
boost::random::uniform_real_distribution< double > distribution_type3
UserDefinedFarm6(FarmManager *a_manager)
Inbuilt special purpose farm type.
int ConnectFarm(int a_owner)
Class for storing data for optimisation.
void ReadCropsData()
Reads the data on crops' parameters that do not vary with farm variables and saves them in a vector D...
void Set_area_in_crop_data(double a_area)
vector< CropOptimised * > m_grownVariableCrops
Vector of pointers to variable crops that are grown on area larger than areaMin (after determineAreas...
NonAnimalFarm(FarmManager *a_myfarmmanager, int a_No)
void FindNeighbours()
Finds all OptimisingFarms' neighbours and saves them in the farm's OptimisingFarm::m_neighbours vecto...
CfgInt g_farm_fixed_crop_type("FARM_FIXED_CROP_TYPE", CFG_CUSTOM, 22)
int m_farm_centroidx
Farm's centroid, value x. Equal to the average of the x centroid values of all farm's fields...
UserDefinedFarm9(FarmManager *a_manager)
int FindFarmWithRandom(vector< int > *a_farmlist)
Finds a farm openness more than a value not on the list.
The base class for all farm types.
int SupplyYearNumber(void)
double Get_rotationMax(int i)
CfgBool cfg_OptimiseBedriftsmodelCrops("OPTIMISE_BEDRIFTSMODEL_CROPS", CFG_CUSTOM, false)
If set to true, the original farm optimisation model's crop set is used in the farmer decision making...
virtual void checkWinterRotation1()
Checks if the restriction on a winter rotation is fulfilled.
virtual void checkRestrictions()
Checks if the restrictions are fulfilled and corrects crops' areas if necessary.
static CfgStr l_map_farmref_file("MAP_FARMREF_FILE", CFG_CUSTOM,"farmrefs.txt")
UserDefinedFarm14(FarmManager *a_manager)
void OptimisationOutput()
Creates output files for all crop level variables and for landscape level crop distribution. Includes results of the initial farm otpimisation.
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...
void Init(ofstream *ap_output_file)
Function carrying out the initial calculations at a farm level (including the initial optimisation)...
UserDefinedFarm22(const char *fname, FarmManager *a_manager)
int FindOpennessFarm(int a_openness)
Finds a random farm with at least one field with openness above a_openness.
virtual bool Spraying_fungins(TTypesOfVegetation a_tov_type)
Returns true if a farmer decided to treat a given crop with fung- and insecticides.
void findGrossMargin(CropOptimised *a_crop, int a_foobar, double benefit)
Determines the gross margin (CropOptimised::m_GM) for a given crop at a farm.
void ChooseDecisionMode()
Function determines which decision mode to use. The choice depends on the values of need satisfaction...
TTypesOfOptFarms Get_farmType(int a_almass_no)
Used by FarmManager::CreateFarms. Finds a matching almass number and returns farm's type...
vector< AlmassCrop > m_rotational_crops
Vector of structs with almass type crops with positive areas in % (result of optimisation): includes ...
void PrintNeighbours()
Creates an output file with a list of neighbours of each OptimisingFarm.
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.
OptimisingPlantFarm(FarmManager *a_myfarmmanager, int a_No)
int m_farmRealID
Farm's real ID number.
double Get_cropParameter(int i)
void fixBI()
Sets values of Treatment frequency indices (BI) for crops with fixed amount of pesticides (CropOptimi...
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...
bool cash_crops_allowed
Sets to true if cash crops are allowed. True by default.
A farm that can have its rotation defined by the user at runtime.
void ReadEnergyMaizePrice()
CfgFloat cfg_Min_need_satisfaction1("MIN_NEED_SATISFACTION_ONE", CFG_CUSTOM, 100)
A parameter setting the minimum satisfaction level for profit.
virtual void checkRestrictions()
Checks if the restrictions are fulfilled and corrects crops' areas if necessary.
double m_totalBIFi
Total amount of fung- and insecticides which is planned to be applied at a farm. Expressed as a Treat...
vector< double > m_previous_profits
Vector of profits from previous years.
A farm that can have its rotation defined by the user at runtime.
static CfgStr l_emaize_price_file("EMAIZE_PRICE_FILE", CFG_CUSTOM,"EM_price.txt")
A farm that can have its rotation defined by the user at runtime.
Subclass of the AnimalFarm.
Struct used for sorting crops.
CropOptimised * Get_crop(int i)
CfgFloat cfg_Price_SRape("PRICE_SRAPE", CFG_CUSTOM, 163)
vector< Livestock * > m_livestock
Vector of pointers to animals belonging to a farm.
double m_area_ha
Area of a crop in ha at a farm [ha].
double m_totalProfit
Planned total profit (= income - costs) at a farm. In case of animal farms costs of purchased fodder ...
double GetSpilledGrain()
Returns the average amount of spilled grain in KJ/m2 this year.
double m_actual_income
An actual income at a farm in a given year.
Landscape * g_landscape_p
CropOptimised * m_fakeCrop
Crop used to fill up area of a farm up to 100% in case its non-fodder crops do not sum to 100% in det...
A farm that can have its rotation defined by the user at runtime.
void ReadLookupTable()
Reads the lookup table with allowed/forbidden crop order from a text file and saves it into a vector ...
UserDefinedFarm32(const char *fname, FarmManager *a_manager)
A farm that can have its rotation defined by the user at runtime.
A struct to hold the information required to trigger a farm event.
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 dis...
TTypesOfCrops Get_cropTypes(int i)
double m_exp_costs
Expected costs at a farm in a given year.
PesticideTrialTreatment(FarmManager *a_manager)
A farm that can have its rotation defined by the user at runtime.
Inbuilt special purpose farm type.
CfgInt cfg_LifeStage("LIFE_STAGE", CFG_CUSTOM, 0)
This parameter specifies the life stage of a species whose numbers farmers use during their decision ...
UserDefinedFarm8(FarmManager *a_manager)
void Switch_rotation()
Switches OptimisingFarms Farm::m_rotation to the list of all possible rotational crops.
void CreateFarms(const char *a_farmfile)
TTypesOfVegetation m_cropType_almass
Type/name of a crop (ALMaSS crops).
vector< double > m_previous_costs
Vector of costs from previous years.
virtual void checkWinterCrops()
Checks if the restriction on a max. share of winter crops is fulfilled.
A class for storing all parameters and results of crop optimisation.
FarmManager * g_farmmanager
int Get_NeighboursSize(void)
void Match_crop_to_field(LE *a_field)
Finds a crop to be grown on a given field next year.
A farm that can have its rotation defined by the user at runtime.
int GetMaxOpenness()
Returns the maximum openness score of the fields.
ConventionalPlant(FarmManager *a_manager)
void Set_CropDataStorage(int index, CropActualValues a_struct)
virtual TTypesOfLandscapeElement GetElementType(void)
OptimisingFarm(FarmManager *a_myfarmmanager, int a_No)
The constructor.
int FindFarmWithOpenness(vector< int > *a_farmlist, int a_openness)
Finds a farm openness more than a value not on the list.
OrganicPlant(FarmManager *a_manager)
void optimizeCrops(int a_foobar)
Carries out crop optimisation at a farm.
A farm that can have its rotation defined by the user at runtime.
CfgFloat cfg_Env_pest_multiplier("ENV_PEST_MULTIPLIER", CFG_CUSTOM, 1.25)
A parameter of the environmentalist farmer type: increases the chance that environmentalist does not ...
double m_assigned
Variable holding a value of area already reserved for certain crops at a farm. [0-100%].
void ReadInitialCropAreas_almass()
Reads the data on farms' initial crop distributions and saves them in a vector of a DataForOptimisati...
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 findResponse(CropOptimised *a_crop, int a_foobar)
Determines the response (CropOptimised::m_resp) of a crop at a farm.
double m_certainty_level
Farmer's certainty level.
virtual void increaseCrops(vector< CropSort >cropsToIncrease, double &howMuchToIncrease)
Increases area of crops by a specified number.
int FindClosestFarm(HunterInfo a_hinfo, vector< int > *a_farmlist)
Finds the closest farm to this co-ordinate.
long GetMgtLoopDetectDate(void)
TTypesOfVegetation TranslateCropCodes(std::string &str)
FarmManager * m_OurManager
Pointer to the FarmManager.
void findYieldLoss(CropOptimised *a_crop)
Determines the yield losses (CropOptimised::m_lossHerb, CropOptimised::m_lossFi, CropOptimised::m_tot...
TTypesOfVegetation TranslateVegTypes(int VegReference)
AnimalFarm(FarmManager *a_myfarmmanager, int a_No)
CfgFloat cfg_Price_Triticale("PRICE_TRITICALE", CFG_CUSTOM, 80)
void Initialize(FarmManager *a_pfm)
Assigns to each farm its farm type, farm size, farm's real ID number, and soil type. It creates livestock and crops.
String configurator entry class.
vector< PermCropData > m_PermCrops
Bool configurator entry class.
A farm that can have its rotation defined by the user at runtime.
double Get_biomass_factor(int i)
virtual bool Do(Farm *a_farm, LE *a_field, FarmEvent *a_ev)
AgroChemIndustryCerealFarm3(FarmManager *a_manager)
double m_n
Total amount of fertilizer applied per ha of a crop [kg N/ha].
void Save_last_years_crops()
It saves the OptimisingFarm::m_rotational_crops in a vector m_rotational_crops_visible which is acces...
CfgFloat cfg_Profit_max_proportion("PROFIT_MAX_PROPORTION", CFG_CUSTOM, 100)
A parameter setting the proportion of farmers of a type profit maximiser.
CfgFloat cfg_RoostDistProbParam1("ROOSTDISTPROBPARAMONE", CFG_CUSTOM, 1.5)
A fitting parameter for the probability of hunter acceptance of a farm with distance from roost...
DataForOptimisation * pm_data
Pointer to the DataForOptimisation.
Struct used only in Bedriftsmodel crop type mode for creating m_rotation vector. Bool member used for...
void AddNewEvent(TTypesOfVegetation a_event, long a_date, LE *a_field, int a_todo, long a_num, bool a_lock, int a_start, bool a_first_year, TTypesOfVegetation a_crop)
Adds an event to the event queue for a farm.
void Set_cropTotals_plant_sum(int i, double crop_area)
int SupplyDayInYear(void)
vector< unsigned > polylist
int Get_livestockNumbersSize()
int GetArea(void)
Returns the area of arable fields owned by that farm.
void Save_last_years_crops_for_farms()
Calls OptimisingFarm::Save_last_years_crops for all optimising farms.
bool Get_taken(int index)
vector< AlmassCrop > Get_rotational_crops_visible()
void ReadFarmsData_perFarmType()
Reads the data on farms' parameters that vary with a farm type and saves them in a vector of a DataFo...
double m_savings
Value of savings resulting from growing a fodder crop and not purchasing amount of fodder correspondi...
Used for storing permanent crop data for the farm rotation.
TTypesOfCrops TranslateCropsCodes(string &str)
void Set_cropTotals_other_sum(int i, double crop_area)
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 dis...
vector< OptimisingFarm * > m_neighbours
Vector of pointers to the farms considered neighbours (fulfilling the neighbourship condition) of a g...
double m_area_scaling_factor
Factor used to scale areas of fixed crops and livestock numbers. Used to adjust these values to the f...
void SetMgtLoopDetectCount(long a_num)
UserDefinedFarm12(FarmManager *a_manager)
double m_totalGrooming
Total grooming planned at a farm.
double m_optimalN
Optimal amount of fertilizer per ha of a crop supposing ferilizer price equals zero [kg N/ha]...
void findMWeedControl(CropOptimised *a_crop)
Determines the optimal mechanical weed control means (CropOptimised::m_grooming, CropOptimised::m_hoe...
double m_GM_Savings
Holds the value of m_GM in case of non-fodder crops and a value of m_savings in case of fodder crops ...
double Get_actual_aggregated_yield()
double GetSpilledMaize()
Returns the average amount of spilled maize in KJ/m2 this year.
void findNanim()
Determines amount of animal fertilizer per ha (m_Nanim) at a farm.
TTypesOfVegetation Get_cropTypes_almass(int i)
UserDefinedFarm4(FarmManager *a_manager)
Subclass of the OptimisingFarm. Either plant or other farm.
bool CompPcts(tpct i, tpct j)
Used for sorting a farmers field size vector.
static CfgBool l_map_read_farmfile("MAP_READ_FARMFILE", CFG_PRIVATE, true)
void findTotalNanim()
Determines total animal fertilizer (m_totalNanim) available at a farm.
double m_totalNt
Total amount of fertilizer purchased at a farm. [kg].
UserDefinedFarm7(FarmManager *a_manager)
void Set_taken(bool a_taken, int index)
void createFodderCrops(int a_foobar)
Creates a list of pointers to all fodder crops.
A farm that can have its rotation defined by the user at runtime.
virtual void decreaseCrops(vector< CropSort >cropsToDecrease, double &howMuchToDecrease)
Decreases area of a crops by a specified number.
void Set_crops_fertilizer(int i, double fert)
CfgFloat cfg_Price_WBarley("PRICE_WBARLEY", CFG_CUSTOM, 93)
UserDefinedFarm23(const char *fname, FarmManager *a_manager)
void Assign_rotation(vector< TTypesOfVegetation >a_new_rotation)
void ActualProfit()
Function that determines actual crop yields and profit in a given year.
void RemoveField(LE *a_field)
Removes a field from a farm.
double m_totalIncome
Planned total income from growing crops at a farm. [DKK].
virtual void HandleEvents(void)
If there are events to carry out do this, and perhaps start a new crop.
bool force_deliberation
If set to true, a farm must use deliberation as a decision strategy.
virtual void checkWinterCrops()
Animal farm version of the checkWinterCrops() function (accounts for fodder changes).
void checkCattleRotation()
Checks if the cattle restriction is fulfilled - in the Bedriftsmodel (original farm optimization mode...
void PrintDecModes_counts()
For each OptimizingFarm it prints the number of times each of the decision modes was used within a si...
double m_lossHerb
Value of the yield loss due to the limited use of herbicides [%].
void OptimiseFarm(int a_foobar)
Carries out the whole farm optimisation.
void CropDistribution()
Calculates total crop areas (at the landscape level). Includes results of the initial farm otpimisati...
double m_totalHoeing
Total hoeing planned at a farm.
TTypesOfAnimals TranslateAnimalsCodes(string &str)
vector< double > m_animals_numbers
Vector for storing numbers of animals at a farm in previous years (3).
void findTotalArea()
Determines m_totalArea of a farm.
double m_hoeing
Value of mechanical weed control for a crop - hoeing [DKK/ha].
void createVariableCrops(int a_foobar)
Creates a list of pointers to all variable crops included in the optimisation and a list of pointers ...
double GetDD(void)
Returnes day degrees for the period March 1st - November 1st. Used for determining yields of crops th...
UserDefinedFarm25(const char *fname, FarmManager *a_manager)
UserDefinedFarm15(FarmManager *a_manager)
OptimisingFarm * m_previously_imitated_neighbour
The neighbouring farmer whose crops might be copied in imitation and social comparison decision modes...
CfgFloat cfg_Price_Nt("PRICE_NT", CFG_CUSTOM, 1.93)
Price of fertilizer. [DKK/kg].
void ReadCropsData_perFarm_and_Soil()
Reads the data on crops' parameters that vary with a farm and soil type (sellingPrice) and saves them...
CfgFloat cfg_Min_fodder_prod_cattle("MIN_FODDER_PROD_CATTLE", CFG_CUSTOM, 35)
A parameter setting the minimum proportion of fodder demand that has to be supplied from own fodder p...
void Set_cropTotals_sum(int i, double crop_area)
UserDefinedFarm35(const char *fname, FarmManager *a_manager)
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.
double m_BI
Summary value of BI for herbicides and fung- and insecticides [BI/ha].
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.
virtual void createCropsLists(int a_foobar)
Creates lists of crops.
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
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...
void check_WRape_WBarley()
Checks if the restriction on winter rape and winter barley attachment is fulfilled and corrects crops...
double biomass_at_harvest
A farm that can have its rotation defined by the user at runtime.
void SetVegStore(int a_veg)
void SetMgtLoopDetectDate(long a_num)
Used for storing farmers field size vectors.
double m_exp_profit
An expected farm's profit for a given year.
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.
void ReadCropsData_perFarm_and_Soil_almass()
Reads the data on crops' parameters that vary with a farm and soil type (sellingPrice) and saves them...
double GetAreaDouble(void)
Returns the area of arable fields owned by that farm.
virtual void Management(void)
Starts the main management loop for the farm and performs some error checking.
TTypesOfSoils TranslateSoilCodes(string &str)
A farm that can have its rotation defined by the user at runtime.
UserDefinedFarm21(const char *fname, FarmManager *a_manager)
OrganicCattle(FarmManager *a_manager)
vector< double > m_previous_aggregated_yields
Vector of aggregated yields from previous years.
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.
A farm that can have its rotation defined by the user at runtime.
int Get_cropTypes_almass_size()
vector< FarmData * > m_farm_data
int GetAreaOpenFields(int a_openness)
Returns the area of the fields above an openness of a_openness.
virtual void determineAreas(int a_foobar)
Determines areas of variable crops.
CfgFloat cfg_Price_WRape("PRICE_WRAPE", CFG_CUSTOM, 163)
void Add_to_cropTotals(int i, double value)
int animals_no
Holds the number of animals in a farm at a particular day in a year (depends on a species)...
void Translate_crops_to_almass()
Translates crops from Bedriftsmodel (original farm optimization model) to Almass crops. Used in Bedriftsmodel crop mode.
A farm that can have its rotation defined by the user at runtime.
double m_need_satisfaction_level
Farmer's actual satisfaction level.
virtual ~Farm(void)
Farm destructor - deletes all crop instances and empties event queues.
double m_rotationMax
Maximum area in percent of farm's arable area for a given crop (depends on a farm size...
int homeX
Hunter home x-coord.
double m_BIHerb
Value of BI for herbicides [BI/ha].
UserDefinedFarm29(const char *fname, FarmManager *a_manager)
TTypesOfCrops m_cropType
Type/name of a crop (original farm optimization model crop types).
void sortCrops(vector< CropSort > &cropsToSort, string sortingKey)
Sorts structs of type CropSort.
UserDefinedFarm27(const char *fname, FarmManager *a_manager)
Farm(FarmManager *a_manager)
Farm constructor - creates an instance of each possible crop type.
int m_almass_no
Farm's almass number.
Subclass of the AnimalFarm.
double m_weeding
Value of mechanical weed control for a crop - manual weeding [DKK/ha].
Double configurator entry class.
void Set_cropTotals_pig_sum(int i, double crop_area)
double m_totalFUdemand
Farm's total demand for fodder (it is covered by growing fodder crops and/or purchasing fodder and th...
TTypesOfVegetation Get_crops_summary_BIs_tov(int i)
void Set_crops_summary_BIs_herb(int i, double BIherb)
AgroChemIndustryCerealFarm1(FarmManager *a_manager)
polylist * ListOpenFields(int a_openness)
Returns a list of fields with openness above a_openness.
A farm that can have its rotation defined by the user at runtime.
Struct for storing actual data on crop type, area of a field it is grown in, biomass at harvest...
TTypesOfSoils md_soilType
ConventionalPig(FarmManager *a_manager)
ConvMarginalJord(FarmManager *a_manager)
PesticideTrialToxicControl(FarmManager *a_manager)
A farm that can have its rotation defined by the user at runtime.
CfgFloat cfg_Min_need_satisfaction2("MIN_NEED_SATISFACTION_TWO", CFG_CUSTOM, 100)
A parameter setting the minimum satisfaction level for yield.
int SupplyFarmAnimalCensus(int a_farm_ref, int a_LifeStage)
PesticideTrialControl(FarmManager *a_manager)
TTypesOfCropVariables TranslateCropVariablesCodes(string &str)
void Set_cropTotals_cattle_sum(int i, double crop_area)
double Get_rotationMin(int i)
CfgBool cfg_Sensitivity_analysis("SENSITIVITY_ANALYSIS", CFG_CUSTOM, false)
virtual void InitiateManagement(void)
Kicks off the farm's management.
void InitializeVector(vector< double > &vector)
Initializes vector with -1 values.
vector< AlmassCrop > m_rotational_crops_visible
Stores a copy of m_rotational_crops from a previous year and is accessible to farmers who want to cop...
NoPesticideBaseFarm(FarmManager *a_manager)
void correctFodderDemand(int a_foobar)
Determines how much fodder is produced from fixed crops and min. areas of variable crops...
void ReadCropsData_almass()
Reads the data on crops' parameters that do not vary with farm variables and saves them in a vector D...
void AddField(LE *a_newfield)
Adds a field to a farm.
TTypesOfVegetation tov_type
UserDefinedFarm20(const char *fname, FarmManager *a_manager)
double m_totalBI
Total amount of pesticides (sum of m_totalBIHerb and m_totalBIFi) which is planned to be applied at a...
TTypesOfSoils m_soilType
Farm's soil type (sandy, clay, other).
bool InIllegalList(int a_farm_ref, vector< int > *a_farmlist)
Checks a list to see if a farm matches the illegal list of references.
A farm that can have its rotation defined by the user at runtime.
AgroChemIndustryCerealFarm2(FarmManager *a_manager)
int Get_lookup_table(int index)
OptimisingFarm * Get_Neighbour(int i)
A farm that can have its rotation defined by the user at runtime.
void InitiateManagement(void)
OptimisingCattleFarm(FarmManager *a_myfarmmanager, int a_No)
virtual void checkRestrictions()
Checks if the restrictions are fulfilled and corrects crops' areas if necessary.
UserDefinedFarm17(FarmManager *a_manager)
void CheckRotationManagementLoop(FarmEvent *ev)
int GetFirstDate(TTypesOfVegetation a_tov)
Gets the start date for a crop type.
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
double m_benefit
A value of selling price for non-fodder crops or a value of fodder units obtained from a hkg of a fod...
TTypesOfLivestockParameters TranslateLivestockParametersCodes(string &str)
double m_totalN
Total amount of fertilizer used at a farm. [kg].
void Set_crops_fertilizer_trade(int i, double fert_trade)
void Centroids()
Finds farm's centroids - x and y.
void Clean_CropDataStorage(int index)
void ReadCropsData_perFarmType_almass()
Reads the data on crops' parameters that vary with a farm type (fixed, fodder, FUKey) and saves them ...