42 #define _CRT_SECURE_NO_DEPRECATE
49 #include "../BatchALMaSS/BoostRandomGenerators.h"
50 #include "../ALMaSSDefines.h"
55 #define _CRTDBG_MAP_ALLOC
59 #define _CRT_SECURE_NO_DEPRECATE
61 #include "../BatchALMaSS/ALMaSS_Setup.h"
62 #include "../Landscape/ls.h"
63 #include "../Landscape/cropprogs/BroadBeans.h"
64 #include "../Landscape/cropprogs/Carrots.h"
65 #include "../Landscape/cropprogs/CloverGrassGrazed1.h"
66 #include "../Landscape/cropprogs/CloverGrassGrazed2.h"
67 #include "../Landscape/cropprogs/FieldPeas.h"
68 #include "../Landscape/cropprogs/FieldPeasSilage.h"
69 #include "../Landscape/cropprogs/Fodderbeet.h"
70 #include "../Landscape/cropprogs/Sugarbeet.h"
71 #include "../Landscape/cropprogs/FodderGrass.h"
72 #include "../Landscape/cropprogs/Maize.h"
73 #include "../Landscape/cropprogs/MaizeSilage.h"
74 #include "../Landscape/cropprogs/OFodderbeet.h"
75 #include "../Landscape/cropprogs/OMaizeSilage.h"
76 #include "../Landscape/cropprogs/OBarleyPeaCloverGrass.h"
77 #include "../Landscape/cropprogs/OSBarleySilage.h"
78 #include "../Landscape/cropprogs/OCarrots.h"
79 #include "../Landscape/cropprogs/OCloverGrassGrazed1.h"
80 #include "../Landscape/cropprogs/OCloverGrassGrazed2.h"
81 #include "../Landscape/cropprogs/OCloverGrassSilage1.h"
82 #include "../Landscape/cropprogs/OFirstYearDanger.h"
83 #include "../Landscape/cropprogs/OGrazingPigs.h"
84 #include "../Landscape/cropprogs/OPermanentGrassGrazed.h"
85 #include "../Landscape/cropprogs/OSeedGrass1.h"
86 #include "../Landscape/cropprogs/OSeedGrass2.h"
87 #include "../Landscape/cropprogs/OSpringBarleyPigs.h"
88 #include "../Landscape/cropprogs/OFieldPeas.h"
89 #include "../Landscape/cropprogs/OFieldPeasSilage.h"
90 #include "../Landscape/cropprogs/OrchardCrop.h"
91 #include "../Landscape/cropprogs/OOats.h"
92 #include "../Landscape/cropprogs/Oats.h"
93 #include "../Landscape/cropprogs/OPotatoes.h"
94 #include "../Landscape/cropprogs/OSpringBarley.h"
95 #include "../Landscape/cropprogs/OSpringBarleyExt.h"
96 #include "../Landscape/cropprogs/OWinterBarley.h"
97 #include "../Landscape/cropprogs/OWinterBarleyExt.h"
98 #include "../Landscape/cropprogs/OWinterRape.h"
99 #include "../Landscape/cropprogs/OWinterRye.h"
100 #include "../Landscape/cropprogs/OWinterWheat.h"
101 #include "../Landscape/cropprogs/OWinterWheatUndersown.h"
102 #include "../Landscape/cropprogs/OWinterWheatUndersownExt.h"
103 #include "../Landscape/cropprogs/PermanentGrassGrazed.h"
104 #include "../Landscape/cropprogs/PermanentGrassLowYield.h"
105 #include "../Landscape/cropprogs/PermanentGrassTussocky.h"
106 #include "../Landscape/cropprogs/PermanentSetAside.h"
107 #include "../Landscape/cropprogs/Potatoes.h"
108 #include "../Landscape/cropprogs/PotatoesIndustry.h"
109 #include "../Landscape/cropprogs/seedgrass1.h"
110 #include "../Landscape/cropprogs/seedgrass2.h"
111 #include "../Landscape/cropprogs/setaside.h"
112 #include "../Landscape/cropprogs/SpringBarley.h"
113 #include "../Landscape/cropprogs/SpringBarleySpr.h"
114 #include "../Landscape/cropprogs/SpringBarleyPTreatment.h"
115 #include "../Landscape/cropprogs/SpringBarleySKManagement.h"
116 #include "../Landscape/cropprogs/SpringBarleyCloverGrass.h"
117 #include "../Landscape/cropprogs/SpringBarleySeed.h"
118 #include "../Landscape/cropprogs/SpringBarleySilage.h"
119 #include "../Landscape/cropprogs/SpringRape.h"
120 #include "../Landscape/cropprogs/Triticale.h"
121 #include "../Landscape/cropprogs/OTriticale.h"
122 #include "../Landscape/cropprogs/WinterBarley.h"
123 #include "../Landscape/cropprogs/winterrape.h"
124 #include "../Landscape/cropprogs/WinterRye.h"
125 #include "../Landscape/cropprogs/WinterWheat.h"
126 #include "../Landscape/cropprogs/WWheatPControl.h"
127 #include "../Landscape/cropprogs/WWheatPTreatment.h"
128 #include "../Landscape/cropprogs/WWheatPToxicControl.h"
129 #include "../Landscape/cropprogs/AgroChemIndustryCereal.h"
131 #include "../Landscape/cropprogs/WinterWheatStrigling.h"
132 #include "../Landscape/cropprogs/WinterWheatStriglingCulm.h"
133 #include "../Landscape/cropprogs/WinterWheatStriglingSingle.h"
134 #include "../Landscape/cropprogs/SpringBarleyCloverGrassStrigling.h"
135 #include "../Landscape/cropprogs/SpringBarleyStrigling.h"
136 #include "../Landscape/cropprogs/SpringBarleyStriglingCulm.h"
137 #include "../Landscape/cropprogs/SpringBarleyStriglingSingle.h"
138 #include "../Landscape/cropprogs/MaizeStrigling.h"
139 #include "../Landscape/cropprogs/winterrapestrigling.h"
140 #include "../Landscape/cropprogs/WinterRyeStrigling.h"
141 #include "../Landscape/cropprogs/WinterBarleyStrigling.h"
142 #include "../Landscape/cropprogs/FieldPeasStrigling.h"
143 #include "../Landscape/cropprogs/SpringBarleyPeaCloverGrassStrigling.h"
144 #include "../Landscape/cropprogs/YoungForest.h"
145 #include "../Landscape/cropprogs/NorwegianPotatoes.h"
146 #include "../Landscape/cropprogs/NorwegianOats.h"
147 #include "../Landscape/cropprogs/NorwegianSpringBarley.h"
149 #include "../Landscape/cropprogs/PLWinterWheat.h"
150 #include "../Landscape/cropprogs/PLWinterRape.h"
151 #include "../Landscape/cropprogs/PLWinterBarley.h"
152 #include "../Landscape/cropprogs/PLWinterTriticale.h"
153 #include "../Landscape/cropprogs/PLWinterRye.h"
154 #include "../Landscape/cropprogs/PLSpringWheat.h"
155 #include "../Landscape/cropprogs/PLSpringBarley.h"
156 #include "../Landscape/cropprogs/PLMaize.h"
157 #include "../Landscape/cropprogs/PLMaizeSilage.h"
158 #include "../Landscape/cropprogs/PLPotatoes.h"
159 #include "../Landscape/cropprogs/PLBeet.h"
160 #include "../Landscape/cropprogs/PLFodderLucerne1.h"
161 #include "../Landscape/cropprogs/PLFodderLucerne2.h"
162 #include "../Landscape/cropprogs/PLCarrots.h"
163 #include "../Landscape/cropprogs/PLSpringBarleySpr.h"
164 #include "../Landscape/cropprogs/PLWinterWheatLate.h"
165 #include "../Landscape/cropprogs/PLBeetSpr.h"
166 #include "../Landscape/cropprogs/PLBeans.h"
168 #include "../Landscape/cropprogs/NLBeet.h"
169 #include "../Landscape/cropprogs/NLCarrots.h"
170 #include "../Landscape/cropprogs/NLMaize.h"
171 #include "../Landscape/cropprogs/NLPotatoes.h"
172 #include "../Landscape/cropprogs/NLSpringBarley.h"
173 #include "../Landscape/cropprogs/NLWinterWheat.h"
174 #include "../Landscape/cropprogs/NLCabbage.h"
175 #include "../Landscape/cropprogs/NLTulips.h"
176 #include "../Landscape/cropprogs/NLGrassGrazed1.h"
177 #include "../Landscape/cropprogs/NLGrassGrazed1Spring.h"
178 #include "../Landscape/cropprogs/NLGrassGrazed2.h"
179 #include "../Landscape/cropprogs/NLGrassGrazedLast.h"
180 #include "../Landscape/cropprogs/NLPermanentGrassGrazed.h"
181 #include "../Landscape/cropprogs/NLBeetSpring.h"
182 #include "../Landscape/cropprogs/NLCarrotsSpring.h"
183 #include "../Landscape/cropprogs/NLMaizeSpring.h"
184 #include "../Landscape/cropprogs/NLPotatoesSpring.h"
185 #include "../Landscape/cropprogs/NLSpringBarleySpring.h"
186 #include "../Landscape/cropprogs/NLCabbageSpring.h"
187 #include "../Landscape/cropprogs/NLCatchPeaCrop.h"
189 #include "../Landscape/cropprogs/DummyCropPestTesting.h"
192 #include "../Landscape/map_cfg.h"
193 #include "../BatchALMaSS/BoostRandomGenerators.h"
195 extern boost::variate_generator<base_generator_type&, boost::uniform_real<> >
g_rand_uni;
299 m_ddegstoharvest = -1;
309 m_farm->AddNewEvent(m_field->GetVegType(), a_date, m_field, a_todo, m_field->GetRunNum(), a_lock, 0,
false, (
TTypesOfVegetation)0);
329 opf = dynamic_cast<OptimisingFarm*>(m_farm);
333 if (m_field->GetMDates(0,0) >=m_ev->m_startday)
335 g_msg->
Warn(
WARN_BUG,
"Crop::ChooseNextCrop(): ",
"Harvest too late for the next crop to start!!!" );
339 for (
int i=0; i<a_no_dates; i++) {
340 if(m_field->GetMDates(0,i)>=m_ev->m_startday) {
341 m_field->SetMDates(0,i,m_ev->m_startday-1);
343 if(m_field->GetMDates(1,i)>=m_ev->m_startday){
344 m_field->SetMConstants(i,0);
345 m_field->SetMDates(1,i,m_ev->m_startday-1);
363 for (
unsigned int i = 0; i < m_fields.size(); i++ ) {
365 int count = m_fields[ i ]->GetVegStore();
367 m_fields[ i ]->SetVegStore( ++count );
371 char error_num[ 20 ];
372 sprintf( error_num,
"%d", m_fields[ i ]->GetVegType() );
373 g_msg->
Warn(
WARN_BUG,
"I the Farm Manager caught infinite loop in tov type:", error_num );
374 sprintf( error_num,
"%d", m_fields[ i ]->m_tried_to_do );
375 g_msg->
Warn(
WARN_BUG,
"It was last seen trying to perform action # ""(or thereabouts):", error_num );
398 done = m_carrots->Do(
this, ev->
m_field, ev );
401 done = m_broadbeans->Do(
this, ev->
m_field, ev );
404 done = m_foddergrass->Do(
this, ev->
m_field, ev );
407 done = m_CGG1->Do(
this, ev->
m_field, ev );
410 done = m_CGG2->Do(
this, ev->
m_field, ev );
413 done = m_fieldpeas->Do(
this, ev->
m_field, ev );
416 done = m_fieldpeassilage->Do(
this, ev->
m_field, ev );
419 done = m_fodderbeet->Do(
this, ev->
m_field, ev );
422 done = m_sugarbeet->Do(
this, ev->
m_field, ev );
425 done = m_ofodderbeet->Do(
this, ev->
m_field, ev );
428 done = m_maize->Do(
this, ev->
m_field, ev );
431 done = m_OBarleyPCG->Do(
this, ev->
m_field, ev );
434 done = m_ocarrots->Do(
this, ev->
m_field, ev );
437 done = m_OCGS1->Do(
this, ev->
m_field, ev );
440 done = m_OCGG1->Do(
this, ev->
m_field, ev );
443 done = m_OCGG2->Do(
this, ev->
m_field, ev );
446 done = m_ofieldpeas->Do(
this, ev->
m_field, ev );
449 done = m_ofieldpeassilage->Do(
this, ev->
m_field, ev );
452 done = m_ograzingpigs->Do(
this, ev->
m_field, ev );
455 done = m_orchardcrop->Do(
this, ev->
m_field, ev );
458 done = m_ooats->Do(
this, ev->
m_field, ev );
461 done = m_oats->Do(
this, ev->
m_field, ev );
464 done = m_opermgrassgrazed->Do(
this, ev->
m_field, ev );
467 done = m_opotatoes->Do(
this, ev->
m_field, ev );
470 done = m_ospringbarley->Do(
this, ev->
m_field, ev );
473 done = m_osbarleysilage->Do(
this, ev->
m_field, ev );
476 done = m_oseedgrass1->Do(
this, ev->
m_field, ev );
479 done = m_oseedgrass2->Do(
this, ev->
m_field, ev );
482 done = m_ospringbarleyext->Do(
this, ev->
m_field, ev );
485 done = m_ospringbarleypigs->Do(
this, ev->
m_field, ev );
488 done = m_owinterbarley->Do(
this, ev->
m_field, ev );
491 done = m_owinterbarleyext->Do(
this, ev->
m_field, ev );
494 done = m_owinterwheatundersown->Do(
this, ev->
m_field, ev );
497 done = m_owinterwheat->Do(
this, ev->
m_field, ev );
500 done = m_owinterwheatundersownext->Do(
this, ev->
m_field, ev );
503 done = m_owinterrape->Do(
this, ev->
m_field, ev );
506 done = m_owinterrye->Do(
this, ev->
m_field, ev );
509 done = m_permgrassgrazed->Do(
this, ev->
m_field, ev );
512 done = m_permgrasslowyield->Do(
this, ev->
m_field, ev );
515 done = m_permgrasstussocky->Do(
this, ev->
m_field, ev );
518 done = m_permanentsetaside->Do(
this, ev->
m_field, ev );
521 done = m_potatoes->Do(
this, ev->
m_field, ev );
524 done = m_potatoesindustry->Do(
this, ev->
m_field, ev );
527 done = m_seedgrass1->Do(
this, ev->
m_field, ev );
530 done = m_seedgrass2->Do(
this, ev->
m_field, ev );
533 done = m_setaside->Do(
this, ev->
m_field, ev );
536 done = m_springbarley->Do(
this, ev->
m_field, ev );
539 done = m_springbarleyspr->Do(
this, ev->
m_field, ev );
542 done = m_springbarleyptreatment->Do(
this, ev->
m_field, ev );
545 done = m_springbarleyskmanagement->Do(
this, ev->
m_field, ev );
548 done = m_sbarleyclovergrass->Do(
this, ev->
m_field, ev );
551 done = m_springbarleyseed->Do(
this, ev->
m_field, ev );
554 done = m_springbarleysilage->Do(
this, ev->
m_field, ev );
557 done = m_springrape->Do(
this, ev->
m_field, ev );
560 done = m_triticale->Do(
this, ev->
m_field, ev );
563 done = m_otriticale->Do(
this, ev->
m_field, ev );
566 done = m_winterbarley->Do(
this, ev->
m_field, ev );
569 done = m_winterrape->Do(
this, ev->
m_field, ev );
572 done = m_winterrye->Do(
this, ev->
m_field, ev );
575 done = m_winterwheat->Do(
this, ev->
m_field, ev );
578 done = m_wwheatpcontrol->Do(
this, ev->
m_field, ev );
581 done = m_wwheatptoxiccontrol->Do(
this, ev->
m_field, ev );
584 done = m_wwheatptreatment->Do(
this, ev->
m_field, ev );
587 done = m_agrochemindustrycereal->Do(
this, ev->
m_field, ev );
590 done = m_winterwheatstrigling->Do(
this, ev->
m_field, ev );
593 done = m_winterwheatstriglingsingle->Do(
this, ev->
m_field, ev );
596 done = m_winterwheatstriglingculm->Do(
this, ev->
m_field, ev );
599 done = m_springbarleyclovergrassstrigling->Do(
this, ev->
m_field, ev );
602 done = m_springbarleystrigling->Do(
this, ev->
m_field, ev );
605 done = m_springbarleystriglingsingle->Do(
this, ev->
m_field, ev );
608 done = m_springbarleystriglingculm->Do(
this, ev->
m_field, ev );
611 done = m_maizestrigling->Do(
this, ev->
m_field, ev );
614 done = m_maizesilage->Do(
this, ev->
m_field, ev );
617 done = m_omaizesilage->Do(
this, ev->
m_field, ev );
620 done = m_winterrapestrigling->Do(
this, ev->
m_field, ev );
623 done = m_winterryestrigling->Do(
this, ev->
m_field, ev );
626 done = m_winterbarleystrigling->Do(
this, ev->
m_field, ev );
629 done = m_fieldpeasstrigling->Do(
this, ev->
m_field, ev );
632 done = m_springbarleypeaclovergrassstrigling->Do(
this, ev->
m_field, ev );
637 done = m_youngforest->Do(
this, ev->
m_field, ev);
640 done = m_norwegianpotatoes->Do(
this, ev->
m_field, ev);
643 done = m_norwegianoats->Do(
this, ev->
m_field, ev);
646 done = m_norwegianspringbarley->Do(
this, ev->
m_field, ev);
650 done = m_plwinterwheat->Do(
this, ev->
m_field, ev);
653 done = m_plwinterrape->Do(
this, ev->
m_field, ev);
656 done = m_plwinterbarley->Do(
this, ev->
m_field, ev);
659 done = m_plwintertriticale->Do(
this, ev->
m_field, ev);
662 done = m_plwinterrye->Do(
this, ev->
m_field, ev);
665 done = m_plspringwheat->Do(
this, ev->
m_field, ev);
668 done = m_plspringbarley->Do(
this, ev->
m_field, ev);
671 done = m_plmaize->Do(
this, ev->
m_field, ev);
674 done = m_plmaizesilage->Do(
this, ev->
m_field, ev);
677 done = m_plpotatoes->Do(
this, ev->
m_field, ev);
680 done = m_plbeet->Do(
this, ev->
m_field, ev);
683 done = m_plfodderlucerne1->Do(
this, ev->
m_field, ev);
686 done = m_plfodderlucerne2->Do(
this, ev->
m_field, ev);
689 done = m_plcarrots->Do(
this, ev->
m_field, ev);
692 done = m_plspringbarleyspr->Do(
this, ev->
m_field, ev);
695 done = m_plwinterwheatlate->Do(
this, ev->
m_field, ev);
698 done = m_plbeetspr->Do(
this, ev->
m_field, ev);
701 done = m_plbeans->Do(
this, ev->
m_field, ev);
705 done = m_nlbeet->Do(
this, ev->
m_field, ev);
708 done = m_nlcarrots->Do(
this, ev->
m_field, ev);
711 done = m_nlmaize->Do(
this, ev->
m_field, ev);
714 done = m_nlpotatoes->Do(
this, ev->
m_field, ev);
717 done = m_nlspringbarley->Do(
this, ev->
m_field, ev);
720 done = m_nlwinterwheat->Do(
this, ev->
m_field, ev);
723 done = m_nlcabbage->Do(
this, ev->
m_field, ev);
726 done = m_nltulips->Do(
this, ev->
m_field, ev);
729 done = m_nlgrassgrazed1->Do(
this, ev->
m_field, ev);
732 done = m_nlgrassgrazed1spring->Do(
this, ev->
m_field, ev);
735 done = m_nlgrassgrazed2->Do(
this, ev->
m_field, ev);
738 done = m_nlgrassgrazedlast->Do(
this, ev->
m_field, ev);
741 done = m_nlpermanentgrassgrazed->Do(
this, ev->
m_field, ev);
744 done = m_nlbeetspring->Do(
this, ev->
m_field, ev);
747 done = m_nlcarrotsspring->Do(
this, ev->
m_field, ev);
750 done = m_nlmaizespring->Do(
this, ev->
m_field, ev);
753 done = m_nlpotatoesspring->Do(
this, ev->
m_field, ev);
756 done = m_nlspringbarleyspring->Do(
this, ev->
m_field, ev);
759 done = m_nlcabbagespring->Do(
this, ev->
m_field, ev);
762 done = m_nlcatchpeacrop->Do(
this, ev->
m_field, ev);
766 done = m_dummycroppesttesting->Do(
this, ev->
m_field, ev);
776 sprintf( veg_type,
"%d", ev->
m_event );
791 FarmEvent * ev =
new FarmEvent( a_event, a_field, a_todo, a_run, a_lock, a_start, a_first_year, a_crop );
792 m_queue.Push( ev, a_date );
801 return (
g_rand_uni() < (a_probability/100.0));
819 ifile.open(str.c_str(),ios::in);
820 if ( !ifile.is_open() ) {
821 g_msg->
Warn(
"Cannot open file: ", str.c_str() );
826 m_rotation.resize( nocrops );
828 for (
int i = 0; i < nocrops; i++ ) {
831 m_rotation[ i ] = tov;
845 ev->
m_field->SetMgtLoopDetectCount( ev->
m_field->GetMgtLoopDetectCount() + 1 );
847 if ( ev->
m_field->GetMgtLoopDetectCount() > ( long )( m_rotation.size() + 2 ) ) {
850 sprintf( errornum,
"%d", m_farmtype );
851 g_msg->
Warn(
WARN_BUG,
"Rotation management loop detected in farmtype ", errornum );
855 ev->
m_field->SetMgtLoopDetectCount( 0 );
871 l_tov2 = m_rotation[ GetNextCropIndex( a_field->
GetRotIndex() ) ];
874 return GetFirstDate( l_tov2 );
883 if ( m_queue.Empty() )
891 if ( LeSwitch( ev ) ) {
897 CheckRotationManagementLoop( ev );
907 new_veg = m_rotation[ new_index ];
933 int l_nextcropstartdate = GetNextCropStartDate( ev->
m_field, l_tov );
944 if ( m_queue.Empty() )
946 pair = m_queue.Bottom();
953 if ( m_queue.Empty() )
961 if ( LeSwitch( ev ) ) {
967 CheckRotationManagementLoop( ev );
977 new_veg = m_rotation[ new_index ];
999 char error_num[ 20 ];
1000 sprintf( error_num,
"%d", new_veg );
1001 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 );
1021 ev->
m_field->SetVegStore( 0 );
1033 int l_nextcropstartdate = GetNextCropStartDate( ev->
m_field, l_tov );
1044 if ( m_queue.Empty() )
1046 pair = m_queue.Bottom();
1060 m_OurManager = a_manager;
1061 m_carrots =
new Carrots;
1062 m_broadbeans =
new BroadBeans;
1063 m_CGG1 =
new CloverGrassGrazed1;
1064 m_CGG2 =
new CloverGrassGrazed2;
1065 m_fieldpeas =
new FieldPeas;
1066 m_fieldpeassilage =
new FieldPeasSilage;
1067 m_fodderbeet =
new Fodderbeet;
1068 m_sugarbeet =
new Sugarbeet;
1069 m_ofodderbeet =
new OFodderbeet;
1070 m_foddergrass =
new FodderGrass;
1071 m_maize =
new Maize;
1072 m_maizesilage =
new MaizeSilage;
1073 m_omaizesilage =
new OMaizeSilage;
1074 m_OBarleyPCG =
new OBarleyPeaCloverGrass;
1075 m_ocarrots =
new OCarrots;
1076 m_OCGG1 =
new OCloverGrassGrazed1;
1077 m_OCGG2 =
new OCloverGrassGrazed2;
1078 m_OCGS1 =
new OCloverGrassSilage1;
1079 m_ofieldpeas =
new OFieldPeas;
1080 m_ofieldpeassilage =
new OFieldPeasSilage;
1081 m_ofirstyeardanger =
new OFirstYearDanger;
1082 m_ograzingpigs =
new OGrazingPigs;
1083 m_orchardcrop =
new OrchardCrop;
1085 m_ooats =
new OOats;
1086 m_opermgrassgrazed =
new OPermanentGrassGrazed;
1087 m_opotatoes =
new OPotatoes;
1088 m_oseedgrass1 =
new OSeedGrass1;
1089 m_oseedgrass2 =
new OSeedGrass2;
1090 m_ospringbarley =
new OSpringBarley;
1091 m_osbarleysilage =
new OSBarleySilage;
1092 m_ospringbarleyext =
new OSpringBarleyExt;
1093 m_ospringbarleypigs =
new OSpringBarleyPigs;
1094 m_owinterbarley =
new OWinterBarley;
1095 m_owinterbarleyext =
new OWinterBarleyExt;
1096 m_owinterrape =
new OWinterRape;
1097 m_owinterrye =
new OWinterRye;
1098 m_owinterwheat =
new OWinterWheat;
1099 m_owinterwheatundersown =
new OWinterWheatUndersown;
1100 m_owinterwheatundersownext =
new OWinterWheatUndersownExt;
1101 m_permanentsetaside =
new PermanentSetAside;
1102 m_permgrassgrazed =
new PermanentGrassGrazed;
1103 m_permgrasslowyield =
new PermanentGrassLowYield;
1104 m_permgrasstussocky =
new PermanentGrassTussocky;
1105 m_potatoes =
new Potatoes;
1106 m_potatoesindustry =
new PotatoesIndustry;
1107 m_sbarleyclovergrass =
new SpringBarleyCloverGrass;
1108 m_seedgrass1 =
new SeedGrass1;
1109 m_seedgrass2 =
new SeedGrass2;
1110 m_setaside =
new SetAside;
1111 m_springbarley =
new SpringBarley;
1112 m_springbarleyspr =
new SpringBarleySpr;
1113 m_springbarleyptreatment =
new SpringBarleyPTreatment;
1114 m_springbarleyskmanagement =
new SpringBarleySKManagement;
1115 m_springbarleyseed =
new SpringBarleySeed;
1116 m_springbarleysilage =
new SpringBarleySilage;
1117 m_springrape =
new SpringRape;
1118 m_triticale =
new Triticale;
1119 m_otriticale =
new OTriticale;
1120 m_winterbarley =
new WinterBarley;
1121 m_winterrape =
new WinterRape;
1122 m_winterrye =
new WinterRye;
1123 m_winterwheat =
new WinterWheat;
1124 m_wwheatpcontrol =
new WWheatPControl;
1125 m_wwheatptoxiccontrol =
new WWheatPToxicControl;
1126 m_wwheatptreatment =
new WWheatPTreatment;
1127 m_agrochemindustrycereal =
new AgroChemIndustryCereal;
1128 m_winterwheatstrigling =
new WinterWheatStrigling;
1129 m_winterwheatstriglingsingle =
new WinterWheatStriglingSingle;
1130 m_winterwheatstriglingculm =
new WinterWheatStriglingCulm;
1131 m_springbarleyclovergrassstrigling =
new SpringBarleyCloverGrassStrigling;
1132 m_springbarleystrigling =
new SpringBarleyStrigling;
1133 m_springbarleystriglingsingle =
new SpringBarleyStriglingSingle;
1134 m_springbarleystriglingculm =
new SpringBarleyStriglingCulm;
1135 m_maizestrigling =
new MaizeStrigling;
1136 m_winterrapestrigling =
new WinterRapeStrigling;
1137 m_winterryestrigling =
new WinterRyeStrigling;
1138 m_winterbarleystrigling =
new WinterBarleyStrigling;
1139 m_fieldpeasstrigling =
new FieldPeasStrigling;
1140 m_springbarleypeaclovergrassstrigling =
new SpringBarleyPeaCloverGrassStrigling;
1141 m_youngforest =
new YoungForestCrop;
1142 m_norwegianpotatoes =
new NorwegianPotatoes;
1143 m_norwegianoats =
new NorwegianOats;
1144 m_norwegianspringbarley =
new NorwegianSpringBarley;
1145 m_plwinterwheat =
new PLWinterWheat;
1146 m_plwinterrape =
new PLWinterRape;
1147 m_plwinterbarley =
new PLWinterBarley;
1148 m_plwintertriticale =
new PLWinterTriticale;
1149 m_plwinterrye =
new PLWinterRye;
1150 m_plspringwheat =
new PLSpringWheat;
1151 m_plspringbarley =
new PLSpringBarley;
1152 m_plmaize =
new PLMaize;
1153 m_plmaizesilage =
new PLMaizeSilage;
1154 m_plpotatoes =
new PLPotatoes;
1155 m_plbeet =
new PLBeet;
1156 m_plfodderlucerne1 =
new PLFodderLucerne1;
1157 m_plfodderlucerne2 =
new PLFodderLucerne2;
1158 m_plcarrots =
new PLCarrots;
1159 m_plspringbarleyspr =
new PLSpringBarleySpr;
1160 m_plwinterwheatlate =
new PLWinterWheatLate;
1161 m_plbeetspr =
new PLBeetSpr;
1162 m_plbeans =
new PLBeans;
1164 m_nlbeet =
new NLBeet;
1165 m_nlcarrots =
new NLCarrots;
1166 m_nlmaize =
new NLMaize;
1167 m_nlpotatoes =
new NLPotatoes;
1168 m_nlspringbarley =
new NLSpringBarley;
1169 m_nlwinterwheat =
new NLWinterWheat;
1170 m_nlcabbage =
new NLCabbage;
1171 m_nltulips =
new NLTulips;
1172 m_nlgrassgrazed1 =
new NLGrassGrazed1;
1173 m_nlgrassgrazed1spring =
new NLGrassGrazed1Spring;
1174 m_nlgrassgrazed2 =
new NLGrassGrazed2;
1175 m_nlgrassgrazedlast =
new NLGrassGrazedLast;
1176 m_nlpermanentgrassgrazed =
new NLPermanentGrassGrazed;
1177 m_nlbeetspring =
new NLBeetSpring;
1178 m_nlcarrotsspring =
new NLCarrotsSpring;
1179 m_nlmaizespring =
new NLMaizeSpring;
1180 m_nlpotatoesspring =
new NLPotatoesSpring;
1181 m_nlspringbarleyspring =
new NLSpringBarleySpring;
1182 m_nlcabbagespring =
new NLCabbageSpring;
1183 m_nlcatchpeacrop =
new NLCatchPeaCrop;
1185 m_dummycroppesttesting =
new DummyCropPestTesting;
1187 m_rotation_sync_index = -1;
1189 m_stockfarmer =
false;
1191 m_HuntersList.resize(0);
1201 delete m_broadbeans;
1205 delete m_fieldpeassilage;
1206 delete m_fodderbeet;
1208 delete m_ofodderbeet;
1209 delete m_foddergrass;
1210 delete m_maizesilage;
1211 delete m_omaizesilage;
1217 delete m_ofieldpeas;
1218 delete m_ofieldpeassilage;
1219 delete m_ofirstyeardanger;
1220 delete m_ograzingpigs;
1221 delete m_orchardcrop;
1224 delete m_opermgrassgrazed;
1226 delete m_ospringbarley;
1227 delete m_ospringbarleyext;
1228 delete m_osbarleysilage;
1229 delete m_ospringbarleypigs;
1230 delete m_owinterbarley;
1231 delete m_owinterbarleyext;
1232 delete m_owinterrape;
1233 delete m_owinterrye;
1234 delete m_owinterwheatundersown;
1235 delete m_owinterwheatundersownext;
1236 delete m_OBarleyPCG;
1237 delete m_permanentsetaside;
1238 delete m_permgrassgrazed;
1239 delete m_permgrasstussocky;
1240 delete m_permgrasslowyield;
1242 delete m_potatoesindustry;
1243 delete m_sbarleyclovergrass;
1244 delete m_seedgrass2;
1245 delete m_seedgrass1;
1247 delete m_springbarley;
1248 delete m_springbarleyptreatment;
1249 delete m_springbarleyskmanagement;
1250 delete m_springbarleyseed;
1251 delete m_springrape;
1252 delete m_springbarleysilage;
1253 delete m_agrochemindustrycereal;
1255 delete m_winterbarley;
1256 delete m_winterrape;
1258 delete m_winterwheat;
1259 delete m_wwheatpcontrol;
1260 delete m_wwheatptoxiccontrol;
1261 delete m_wwheatptreatment;
1262 delete m_winterwheatstrigling;
1263 delete m_winterwheatstriglingsingle;
1264 delete m_winterwheatstriglingculm;
1265 delete m_springbarleyclovergrassstrigling;
1266 delete m_springbarleystrigling;
1267 delete m_springbarleystriglingsingle;
1268 delete m_springbarleystriglingculm;
1269 delete m_maizestrigling;
1270 delete m_winterrapestrigling;
1271 delete m_winterryestrigling;
1272 delete m_winterbarleystrigling;
1273 delete m_fieldpeasstrigling;
1274 delete m_springbarleypeaclovergrassstrigling;
1275 delete m_youngforest;
1276 delete m_norwegianoats;
1277 delete m_norwegianspringbarley;
1279 delete m_plwinterwheat;
1280 delete m_plwinterrape;
1281 delete m_plwinterbarley;
1282 delete m_plwintertriticale;
1283 delete m_plwinterrye;
1284 delete m_plspringwheat;
1285 delete m_plspringbarley;
1287 delete m_plmaizesilage;
1288 delete m_plpotatoes;
1290 delete m_plfodderlucerne1;
1291 delete m_plfodderlucerne2;
1293 delete m_plspringbarleyspr;
1294 delete m_plwinterwheatlate;
1301 delete m_nlpotatoes;
1302 delete m_nlspringbarley;
1303 delete m_nlwinterwheat;
1306 delete m_nlgrassgrazed1;
1307 delete m_nlgrassgrazed1spring;
1308 delete m_nlgrassgrazed2;
1309 delete m_nlgrassgrazedlast;
1310 delete m_nlpermanentgrassgrazed;
1311 delete m_nlbeetspring;
1312 delete m_nlcarrotsspring;
1313 delete m_nlmaizespring;
1314 delete m_nlpotatoesspring;
1315 delete m_nlspringbarleyspring;
1316 delete m_nlcabbagespring;
1317 delete m_nlcatchpeacrop;
1319 delete m_dummycroppesttesting;
1323 while (!m_queue.Empty()) {
1324 pair = m_queue.Bottom();
1333 for (
unsigned int i = 0; i < m_fields.size(); i++) {
1334 if (m_fields[i]->GetElementType() ==
tole_Field) area += (
int)m_fields[i]->GetArea();
1342 for (
unsigned int i = 0; i < m_fields.size(); i++)
1344 area += (int)m_fields[i]->GetArea();
1352 for (
unsigned int i = 0; i < m_fields.size(); i++ ) {
1353 if (m_fields[i]->GetElementType()==
tole_Field) area += m_fields[i]->GetArea();
1362 for (
unsigned int i = 0; i < m_fields.size(); i++) {
1363 if (m_fields[i]->GetOpenness() > a_openness) num++;
1372 for (
unsigned int i = 0; i < m_fields.size(); i++) {
1373 if (m_fields[i]->GetOpenness() > a_openness) area +=
int(m_fields[i]->GetArea());
1402 if ( -1 == m_rotation_sync_index ) {
1403 m_rotation_sync_index = (int) (rand() % m_rotation.size());
1406 return m_rotation_sync_index;
1412 if ( -1 == m_rotation_sync_index ) {
1413 if (m_rotation.size() > 0) m_rotation_sync_index = (
int)(rand() % m_rotation.size());
else m_rotation_sync_index = 0;
1415 else m_rotation_sync_index = (int) ((m_rotation_sync_index+1) % m_rotation.size());
1416 return m_rotation_sync_index;
1433 if ( a_rot_index == -1 )
1436 if ( (
unsigned int ) ( ++a_rot_index ) == m_rotation.size() )
1448 int i = (int) m_fields.size();
1450 m_fields.resize( i + 1 );
1451 m_fields[ i ] = a_newfield;
1462 m_fields[i]->SetRotIndex(-2);
1465 m_fields[ i ]->SetRotIndex(-1);
1474 int nf = (int) m_fields.size();
1475 for (
int i = 0; i < nf; i++ ) {
1476 if ( m_fields[ i ] == a_field ) {
1477 m_fields.erase( m_fields.begin() + i );
1483 g_msg->
Warn(
WARN_BUG,
"Farm::RemoveField(LE* a_field): ""Unknown field! ",
"" );
1491 m_rotation = a_new_rotation;
1501 if (m_PermCrops.size()>0) {
1503 for (
int i=0; i<(int)m_PermCrops.size(); i++) {
1504 AssignPermanentCrop(m_PermCrops[i].Tov, m_PermCrops[i].Pct);
1515 for (
unsigned int i = 0; i < m_fields.size(); i++ ) {
1516 int rot_index = m_fields[ i ]->GetRotIndex();
1519 if ( rot_index < -1 ) {
1545 if (rot_index != -4) {
1547 g_msg->
Warn(
"Unexpected negative value in Farm::InitiateManagement",
"");
1552 new_veg = m_fields[i]->GetVegType();
1557 rot_index = GetFirstCropIndex( m_fields[ i ]->GetElementType() );
1558 new_veg = m_rotation[ rot_index ];
1566 m_fields[ i ]->SetRotIndex( rot_index );
1567 m_fields[ i ]->SetGrowthPhase(
janfirst );
1571 m_fields[ i ]->SetVegStore( 0 );
1573 int l_nextcropstartdate = GetNextCropStartDate( m_fields[ i ], l_tov );
1574 AddNewEvent( new_veg, prog_start_date, m_fields[ i ],
PROG_START, 0,
false, l_nextcropstartdate,
true, l_tov );
1585 return m_carrots->GetFirstDate();
1587 return m_broadbeans->GetFirstDate();
1589 return m_foddergrass->GetFirstDate();
1591 return m_CGG1->GetFirstDate();
1593 return m_CGG2->GetFirstDate();
1595 return m_fieldpeas->GetFirstDate();
1597 return m_fieldpeassilage->GetFirstDate();
1599 return m_fodderbeet->GetFirstDate();
1601 return m_sugarbeet->GetFirstDate();
1603 return m_ofodderbeet->GetFirstDate();
1605 return m_maize->GetFirstDate();
1607 return m_omaizesilage->GetFirstDate();
1609 return m_maizesilage->GetFirstDate();
1611 return m_OBarleyPCG->GetFirstDate();
1613 return m_ocarrots->GetFirstDate();
1615 return m_OCGG1->GetFirstDate();
1617 return m_OCGG2->GetFirstDate();
1619 return m_OCGS1->GetFirstDate();
1621 return m_ofieldpeas->GetFirstDate();
1623 return m_ofirstyeardanger->GetFirstDate();
1625 return m_ograzingpigs->GetFirstDate();
1627 return m_orchardcrop->GetFirstDate();
1629 return m_ooats->GetFirstDate();
1631 return m_oats->GetFirstDate();
1633 return m_opermgrassgrazed->GetFirstDate();
1635 return m_opotatoes->GetFirstDate();
1637 return m_ospringbarley->GetFirstDate();
1639 return m_osbarleysilage->GetFirstDate();
1641 return m_ospringbarleyext->GetFirstDate();
1643 return m_ospringbarleypigs->GetFirstDate();
1645 return m_owinterbarley->GetFirstDate();
1647 return m_owinterbarleyext->GetFirstDate();
1649 return m_owinterrape->GetFirstDate();
1651 return m_owinterrye->GetFirstDate();
1653 return m_owinterwheatundersown->GetFirstDate();
1655 return m_owinterwheat->GetFirstDate();
1657 return m_owinterwheatundersownext->GetFirstDate();
1659 return m_permgrassgrazed->GetFirstDate();
1661 return m_permgrasslowyield->GetFirstDate();
1663 return m_permgrasstussocky->GetFirstDate();
1665 return m_permanentsetaside->GetFirstDate();
1667 return m_potatoes->GetFirstDate();
1669 return m_seedgrass1->GetFirstDate();
1671 return m_seedgrass2->GetFirstDate();
1673 return m_setaside->GetFirstDate();
1675 return m_springbarley->GetFirstDate();
1677 return m_springbarleyspr->GetFirstDate();
1679 return m_springbarleyptreatment->GetFirstDate();
1681 return m_springbarleyskmanagement->GetFirstDate();
1683 return m_sbarleyclovergrass->GetFirstDate();
1685 return m_springbarleyseed->GetFirstDate();
1687 return m_springbarleysilage->GetFirstDate();
1689 return m_springbarleystrigling->GetFirstDate();
1691 return m_springbarleystriglingsingle->GetFirstDate();
1693 return m_springbarleystriglingculm->GetFirstDate();
1695 return m_springrape->GetFirstDate();
1697 return m_triticale->GetFirstDate();
1699 return m_otriticale->GetFirstDate();
1701 return m_winterbarley->GetFirstDate();
1703 return m_winterrape->GetFirstDate();
1705 return m_winterrye->GetFirstDate();
1707 return m_winterwheat->GetFirstDate();
1709 return m_winterwheatstrigling->GetFirstDate();
1711 return m_winterwheatstriglingsingle->GetFirstDate();
1713 return m_winterwheatstriglingculm->GetFirstDate();
1715 return m_wwheatpcontrol->GetFirstDate();
1717 return m_wwheatptoxiccontrol->GetFirstDate();
1719 return m_wwheatptreatment->GetFirstDate();
1721 return m_agrochemindustrycereal->GetFirstDate();
1723 return m_youngforest->GetFirstDate();
1725 return m_norwegianpotatoes->GetFirstDate();
1727 return m_norwegianoats->GetFirstDate();
1729 return m_norwegianspringbarley->GetFirstDate();
1732 return m_plwinterwheat->GetFirstDate();
1734 return m_plwinterrape->GetFirstDate();
1736 return m_plwinterbarley->GetFirstDate();
1738 return m_plwintertriticale->GetFirstDate();
1740 return m_plwinterrye->GetFirstDate();
1742 return m_plspringwheat->GetFirstDate();
1744 return m_plspringbarley->GetFirstDate();
1746 return m_plmaize->GetFirstDate();
1748 return m_plmaizesilage->GetFirstDate();
1750 return m_plpotatoes->GetFirstDate();
1752 return m_plbeet->GetFirstDate();
1754 return m_plfodderlucerne1->GetFirstDate();
1756 return m_plfodderlucerne2->GetFirstDate();
1758 return m_plcarrots->GetFirstDate();
1760 return m_plspringbarleyspr->GetFirstDate();
1762 return m_plwinterwheatlate->GetFirstDate();
1764 return m_plbeetspr->GetFirstDate();
1766 return m_plbeans->GetFirstDate();
1769 return m_nlbeet->GetFirstDate();
1771 return m_nlcarrots->GetFirstDate();
1773 return m_nlmaize->GetFirstDate();
1775 return m_nlpotatoes->GetFirstDate();
1777 return m_nlspringbarley->GetFirstDate();
1779 return m_nlwinterwheat->GetFirstDate();
1781 return m_nlcabbage->GetFirstDate();
1783 return m_nltulips->GetFirstDate();
1785 return m_nlgrassgrazed1->GetFirstDate();
1787 return m_nlgrassgrazed1spring->GetFirstDate();
1789 return m_nlgrassgrazed2->GetFirstDate();
1791 return m_nlgrassgrazedlast->GetFirstDate();
1793 return m_nlpermanentgrassgrazed->GetFirstDate();
1795 return m_nlbeetspring->GetFirstDate();
1797 return m_nlcarrotsspring->GetFirstDate();
1799 return m_nlmaizespring->GetFirstDate();
1801 return m_nlpotatoesspring->GetFirstDate();
1803 return m_nlspringbarleyspring->GetFirstDate();
1805 return m_nlcabbagespring->GetFirstDate();
1807 return m_nlcatchpeacrop->GetFirstDate();
1810 return m_dummycroppesttesting->GetFirstDate();
1833 if (str ==
"Oats")
return tov_Oats;
1959 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateCropCodes():"" Unknown Crop Code ", str.c_str() );
1967 ofstream ofile (
"FarmTotalAreas_almass.txt", ios::out);
1968 ofile <<
"Farm no" <<
'\t' <<
"Area" << endl;
1971 for(
int i=0; i<(int)m_farms.size(); i++){
1974 opf_i = dynamic_cast<OptimisingFarm*>(m_farms[i]);
1976 ofile << opf_i->
GetArea() <<
'\t';
2362 ifile.open(fname,ios::in);
2363 if (!ifile.is_open()) {
2367 int input, intensity;
2370 ifile >> input >> intensity;
2374 std::string cropref =
"";
2379 for (
int i=0; i<permcrops; i++) {
2392 for (
int i = 0; i < nocrops; i++ ) {
2411 (*cfi)->SetRotIndex(-4);
2420 vector<LE*> fields_cpy;
2421 fields_cpy.resize(
m_fields.size());
2428 int sz = (int) fields_cpy.size();
2430 for (
int i = sz - 1; i >= 0; i--) {
2431 if (fields_cpy[i]->GetRotIndex() < -1) {
2432 fields_cpy.erase(fields_cpy.begin() + i);
2436 for (
auto cfi = fields_cpy.begin(); cfi != fields_cpy.end(); ++cfi) area += (*cfi)->GetArea();
2439 int fnos = (int) fields_cpy.size();
2443 if (random(100)>=a_pct)
return;
2446 fields_cpy[0]->SetRotIndex(-4);
2453 for (
int i=0; i<fnos; i++) {
2454 a_tpct.
pct = (int) floor(0.5+((fields_cpy[i]->
GetArea()/area)*100));
2456 pcts.push_back(a_tpct);
2460 sort (pcts.begin(), pcts.end(),
CompPcts);
2465 while ((index==-1) && (ind< (int)pcts.size())) {
2466 if (pcts[ind++].pct>apct) index=ind;
2468 if (index!=-1) pcts.erase(pcts.begin()+index,pcts.end());
2476 for (
int h=0; h< (int)pcts.size(); h++) check+=fields_cpy[pcts[h].index]->
GetArea();
2478 if ((bits & mask) > 0) {
2480 fields_cpy[pcts[ind].index]->SetRotIndex(-4);
2482 fields_cpy[pcts[ind].index]->SetVegType(a_tov,
tov_Undefined);
2483 used += (int) fields_cpy[pcts[ind].index]->
GetArea();
2498 long long int sz = (
long long int) items->size();
2501 g_msg->
Warn(
"Too many potential fields in UserDefinedFarm::InvIntPartition: ",sz);
2505 long int calcs = (1 << sz);
2510 for (
long int i=1; i<calcs; i++) {
2515 for (
int bit=0; bit<sz; bit++) {
2516 if ((i & mask) > 0) {
2517 sum+=(*items)[bit].pct;
2522 if (abs(sum-target) < diff ){
2524 diff = abs(sum-target);
2641 ofstream ofile (
"Economic_figures.txt", ios::out);
2643 ofstream ofile1 (
"Daydegrees.txt", ios::out);
2646 ofstream ofileEM (
"Maize_energy_price_yearly.txt", ios::out);
2702 for (
unsigned int i = 0; i <
m_farms.size(); i++ )
2709 for (
unsigned int i = 0; i <
m_farms.size(); i++ )
2717 for (
unsigned int i = 0; i <
m_farms.size(); i++ )
2721 opf = dynamic_cast<OptimisingFarm*>(
m_farms[i]);
2735 for (
unsigned int i = 0; i <
m_farms.size(); i++ )
2737 m_farms[ i ]->InitiateManagement();
2743 m_farms[ a_OwnerIndex ]->AddField( a_newland );
2744 a_newland->
SetOwner(
m_farms[ a_OwnerIndex ], a_Owner, a_OwnerIndex );
2749 m_farms[ a_OwnerIndex ]->RemoveField( a_field );
2754 for (
unsigned int i = 0; i <
m_farms.size(); i++ )
2756 if ( a_owner ==
m_farms[ i ]->GetFarmNumber() )
2766 char error_num[ 20 ];
2767 sprintf( error_num,
"%d", a_owner );
2768 g_msg->
Warn(
WARN_FILE,
"FarmManager::ConnectFarm(): Unknown farm number"" referenced in polygon file:", error_num );
2774 int No, FType, NoFarms;
2775 FILE * inpf = fopen(a_farmfile,
"r" );
2777 g_msg->
Warn(
WARN_FILE,
"Landscape::CreateFarms(): Unable to open file", a_farmfile );
2781 fscanf( inpf,
"%d", & NoFarms );
2787 for (
int i = 0; i < NoFarms; i++)
2793 fscanf(inpf,
"%d %d", &No, &FType);
2799 for (
int i = 0; i < NoFarms; i++)
2999 ofstream opf(
"dump_farmrefs.txt");
3002 g_msg->
Warn(
WARN_FILE,
"Landscape::CreateFarms(): Unable to open file",
"dump_farmrefs.txt");
3005 int NoFarms = (int)
m_farms.size();
3006 opf << NoFarms << endl;
3007 for (
int i = 0; i < NoFarms; i++)
3021 for(
unsigned j=0; j<
m_farms.size(); j++){
3040 double graindist2013[26] = {
3041 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,
3042 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
3044 double graindist2014[28] = {
3045 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,
3046 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,
3050 if (grain_dist_value == 0)
3053 else return graindist2014[(int)(
g_rand_uni() * 28)];
3055 if (grain_dist_value == 1) {
3056 return graindist2013[(int)(
g_rand_uni() * 26)];
3060 return graindist2014[(int)(
g_rand_uni() * 28)];
3069 double maizedist[15] = {
3092 unsigned sz = (unsigned) a_farmlist->size();
3093 for (
unsigned f = 0; f < sz; f++) {
3094 if ((*a_farmlist)[f] == a_farm_ref)
return true;
3104 unsigned sz = (unsigned)a_farmlist->size();
3105 for (
unsigned f = 0; f < sz; f++) {
3106 if ((*a_farmlist)[f] == a_farm_ref) {
3112 a_farmlist->push_back( a_farm_ref );
3118 for (
int i = 0; i < int( a_hinfo->
FarmHuntRef.size() ); i++)
3121 if (a_ref == a_hinfo->
FarmHuntRef[ i ])
return true;
3131 double best = 99999999999999999.0;
3134 for (
unsigned i = 0; i <
m_farms.size(); i++) {
3135 int fnum =
m_farms[i]->GetFarmNumber();
3139 APoint FPt =
m_farms[i]->GetCentroids();
3140 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 )));
3148 if (bestref == -1) {
3149 g_msg->
Warn(
"FarmManager::FindClosestFarm - Cannot find open farm.",
"" );
3157 double best = 99999999999999999.0;
3160 for (
unsigned i = 0; i <
m_farms.size(); i++) {
3161 if (
m_farms[ i ]->GetMaxOpenness() > a_openness) {
3162 int fref =
m_farms[ i ]->GetFarmNumber();
3165 APoint FPt =
m_farms[ i ]->GetCentroids();
3166 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 )) );
3175 if (bestref == -1) {
3176 g_msg->
Warn(
"FarmManager::FindClosestFarmOpenness( ) - Cannot find open farm.",
"" );
3191 typedef APoint AFarmDist;
3193 vector <AFarmDist> farmdists;
3195 struct FarmDistSort {
3196 bool operator()( AFarmDist a, AFarmDist b ) {
3197 return a.m_y < b.m_y;
3200 for (
unsigned i = 0; i <
m_farms.size(); i++) {
3201 int fnum =
m_farms[ i ]->GetFarmNumber();
3203 if (
m_farms[ i ]->GetMaxOpenness() > a_openness) {
3206 APoint FPt =
m_farms[ i ]->GetCentroids();
3207 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 )) ));
3208 if (dist>40000) dist = 40000;
3209 AFarmDist fd(
int( fnum ), dist );
3210 farmdists.push_back( fd );
3217 random_shuffle( farmdists.begin(), farmdists.end() );
3219 for (
int ch = 1; ch < 100000; ch++)
3221 int sz = int( farmdists.size() );
3222 for (
int i = 0; i < sz; i++) {
3226 if (chance <= calc)
return farmdists[ i ].m_x;
3229 g_msg->
Warn(
"FarmManager::FindClosestFarmProb",
"- No suitable farm found" );
3242 typedef APoint AFarmDist;
3244 vector <AFarmDist> farmdists;
3246 struct FarmDistSort {
3247 bool operator()( AFarmDist a, AFarmDist b ) {
3248 return a.m_y < b.m_y;
3251 for (
unsigned i = 0; i <
m_farms.size(); i++) {
3252 int fnum =
m_farms[ i ]->GetFarmNumber();
3254 if (
m_farms[ i ]->GetMaxOpenness() > a_openness) {
3257 APoint FPt =
m_farms[ i ]->GetCentroids();
3258 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 )) ));
3259 if (dist>40000) dist = 40000;
3260 AFarmDist fd(
unsigned( fnum ), dist );
3261 farmdists.push_back( fd );
3268 random_shuffle( farmdists.begin(), farmdists.end() );
3270 for (
int ch = 1; ch < 100000; ch++)
3272 int sz = int( farmdists.size() );
3273 for (
int i = 0; i < sz; i++) {
3277 if (chance <= calc) {
3281 if (chance>calc)
return farmdists[ i ].m_x;
3285 g_msg->
Warn(
"FarmManager::FindClosestFarmProb",
"- No suitable farm found" );
3298 typedef APoint AFarmDist;
3300 vector <AFarmDist> farmdists;
3302 struct FarmDistSort {
3303 bool operator()( AFarmDist a, AFarmDist b ) {
3304 return a.m_y < b.m_y;
3307 for (
unsigned i = 0; i <
m_farms.size(); i++) {
3308 int fnum =
m_farms[ i ]->GetFarmNumber();
3310 if (
m_farms[ i ]->GetMaxOpenness() > a_openness) {
3313 APoint FPt =
m_farms[ i ]->GetCentroids();
3314 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 )) ));
3315 if (dist>40000) dist = 40000;
3316 AFarmDist fd(
unsigned( fnum ), dist );
3317 farmdists.push_back( fd );
3324 random_shuffle( farmdists.begin(), farmdists.end() );
3326 for (
int ch = 1; ch < 100000; ch++)
3328 int sz = int( farmdists.size() );
3329 for (
int i = 0; i < sz; i++) {
3333 if (chance <= calc) {
3337 double dist = 10000;
3338 for (
int r = 0; r < int( a_roostlist->size() ); r++) {
3339 double fdistroostx = farmdists[ i ].m_x - (*a_roostlist)[ r ].m_x;
3340 double fdistroosty = farmdists[ i ].m_y - (*a_roostlist)[ r ].m_y;
3341 double distf = sqrt( fdistroostx * fdistroostx + fdistroosty * fdistroostx );
3342 if (distf < dist) dist = distf;
3345 if (chance>calc)
return farmdists[ i ].m_x;
3349 g_msg->
Warn(
"FarmManager::FindClosestFarmProbNearRoostBest",
"- No suitable farm found" );
3360 if (a_farmlist->size() >=
m_farms.size())
3362 g_msg->
Warn(
"FarmManager::FindFarmWithRandom",
" - farm density rule means all hunters cannot be placed");
3366 return m_farms[f]->GetFarmNumber();
3374 int seed = random( sz );
3375 for (
unsigned i = 0; i <
m_farms.size(); i++) {
3376 int index = (i + seed) % sz;
3377 if (
m_farms[ index ]->GetMaxOpenness() > a_openness)
3383 g_msg->
Warn(
"FarmManager::FindFarmWithOpenness",
"- No suitable farm found");
3389 int sz = (int)
m_farms.size();
3390 int seed = random(sz);
3391 for (
unsigned i = 0; i <
m_farms.size(); i++)
3393 int index = (i + seed) % sz;
3394 if (
m_farms[index]->GetMaxOpenness() > a_openness)
return m_farms[index]->GetFarmNumber();
3400 if (
m_farms[ a_ref ]->GetMaxOpenness() > a_openness)
return true;
3413 for(
int j=0; j<(int)
m_farms.size(); j++){
3415 opf = dynamic_cast<OptimisingFarm*>(
m_farms[j]);
3435 for(
int i=0; i<(int)
m_farms.size(); i++){
3438 opf = dynamic_cast<OptimisingFarm*>(
m_farms[i]);
3446 for(
int i=0; i<(int)
m_farms.size(); i++){
3449 opf = dynamic_cast<OptimisingFarm*>(
m_farms[i]);
3458 for(
int i=0; i<(int)
m_farms.size(); i++){
3461 opf = dynamic_cast<OptimisingFarm*>(
m_farms[i]);
3490 ifstream ifile(
"farms_data.txt", ios::in);
3493 if ( !ifile.is_open() ) {
3494 cout <<
"Cannot open input file " <<
"farms_data.txt" << endl;
3504 for(
int i=0; i<noParameters; i++){
3508 for(
int f=0; f<noFarms; f++){
3509 int almass_no, realID, soilSubType;
3510 string farm_type, soil_type, farm_size;
3511 ifile >> almass_no >> farm_type >> soil_type >> farm_size >> realID >> soilSubType;
3536 ifstream ifile(
"livestock_numbers.txt", ios::in);
3538 if ( !ifile.is_open() ) {
3539 cout <<
"Cannot open input file " <<
"livestock_numbers.txt" << endl;
3557 for(
int f=0; f<noFarms; f++){
3577 ifstream ifile(
"crop_areas.txt", ios::in);
3579 if ( !ifile.is_open() ) {
3580 cout <<
"Cannot open input file " <<
"crop_areas.txt" << endl;
3599 for(
int f=0; f<noFarms; f++){
3618 ifstream ifile(
"crop_areas.txt", ios::in);
3620 if ( !ifile.is_open() ) {
3621 cout <<
"Cannot open input file " <<
"crop_areas.txt" << endl;
3634 for(
int c=0; c<noCrops; c++){
3643 for(
int f=0; f<noFarms; f++){
3647 for(
int c=0; c<noCrops; c++){
3659 ifstream ifile(
"crop_parameters.txt", ios::in);
3661 if ( !ifile.is_open() ) {
3662 cout <<
"Cannot open input file " <<
"crop_parameters.txt" << endl;
3691 ifstream ifile(
"crop_parameters.txt", ios::in);
3693 if ( !ifile.is_open() ) {
3694 cout <<
"Cannot open input file " <<
"crop_parameters.txt" << endl;
3710 for(
int c=0; c<noCrops; c++){
3727 ifstream ifile1(
"alfa.txt", ios::in);
3728 ifstream ifile2(
"beta1.txt", ios::in);
3729 ifstream ifile3(
"beta2.txt", ios::in);
3730 ifstream ifile4(
"Nnorm.txt", ios::in);
3732 if ( !ifile1.is_open() ) {
3733 cout <<
"Cannot open input file " <<
"alfa.txt" << endl;
3737 }
else if(!ifile2.is_open() ){
3738 cout <<
"Cannot open input file " <<
"beta1.txt" << endl;
3743 else if(!ifile3.is_open() ){
3744 cout <<
"Cannot open input file " <<
"beta2.txt" << endl;
3749 else if(!ifile4.is_open() ){
3750 cout <<
"Cannot open input file " <<
"Nnorm.txt" << endl;
3793 ifstream ifile1(
"alfa.txt", ios::in);
3794 ifstream ifile2(
"beta1.txt", ios::in);
3795 ifstream ifile3(
"beta2.txt", ios::in);
3796 ifstream ifile4(
"Nnorm.txt", ios::in);
3797 ifstream ifile5(
"biomass_factor_almass.txt", ios::in);
3800 if ( !ifile1.is_open() ) {
3801 cout <<
"Cannot open input file " <<
"alfa.txt" << endl;
3805 }
else if(!ifile2.is_open() ){
3806 cout <<
"Cannot open input file " <<
"beta1.txt" << endl;
3811 else if(!ifile3.is_open() ){
3812 cout <<
"Cannot open input file " <<
"beta2.txt" << endl;
3817 else if(!ifile4.is_open() ){
3818 cout <<
"Cannot open input file " <<
"Nnorm.txt" << endl;
3823 if (!ifile5.is_open() ) {
3824 cout <<
"Cannot open input file " <<
"biomass_factor_almass.txt" << endl;
3830 int noCrops, noCrops1, noCrops2, noCrops3, noCrops4=0;
3836 if(noCrops!=noCrops1 || noCrops!=noCrops2 || noCrops!=noCrops3 || noCrops!=noCrops4){
3837 g_msg->
Warn(
WARN_FILE,
"FarmManager::ReadCropsData_perSoilType_almass():"" Numbers of crops differ between input files! ",
" " );
3842 for(
int c=0; c<noCrops; c++){
3859 for(
int c=0; c<noCrops; c++){
3884 ifstream ifile1(
"fixed.txt", ios::in);
3885 ifstream ifile2(
"fodder.txt", ios::in);
3886 ifstream ifile3(
"FUKey.txt", ios::in);
3889 if ( !ifile1.is_open() ) {
3890 cout <<
"Cannot open input file " <<
"fixed.txt" << endl;
3894 }
else if(!ifile2.is_open() ){
3895 cout <<
"Cannot open input file " <<
"fodder.txt" << endl;
3900 else if(!ifile3.is_open() ){
3901 cout <<
"Cannot open input file " <<
"FUKey.txt" << endl;
3940 ifstream ifile1(
"fixed.txt", ios::in);
3941 ifstream ifile2(
"fodder.txt", ios::in);
3942 ifstream ifile3(
"FUKey.txt", ios::in);
3945 if ( !ifile1.is_open() ) {
3946 cout <<
"Cannot open input file " <<
"fixed.txt" << endl;
3950 }
else if(!ifile2.is_open() ){
3951 cout <<
"Cannot open input file " <<
"fodder.txt" << endl;
3956 else if(!ifile3.is_open() ){
3957 cout <<
"Cannot open input file " <<
"FUKey.txt" << endl;
3963 int noCrops, noCrops1, noCrops2=0;
3967 if(noCrops!=noCrops1 || noCrops!=noCrops2){
3968 g_msg->
Warn(
WARN_FILE,
"FarmManager::ReadCropsData_perSoilType_almass():"" Numbers of crops differ between input files! ",
" " );
3974 for(
int c=0; c<noCrops; c++){
3987 for(
int c=0; c<noCrops; c++){
4006 ifstream ifile1(
"sellingPrice.txt", ios::in);
4009 if ( !ifile1.is_open() ) {
4010 cout <<
"Cannot open input file " <<
"sellingPrice.txt" << endl;
4026 ifile1>>farm_type>>soil_type;
4039 ifstream ifile1(
"sellingPrice.txt", ios::in);
4042 if ( !ifile1.is_open() ) {
4043 cout <<
"Cannot open input file " <<
"sellingPrice.txt" << endl;
4053 for(
int c=0; c<noCrops; c++){
4062 ifile1>>farm_type>>soil_type;
4063 for(
int c=0; c<noCrops; c++){
4077 ifstream ifile1(
"rotationMax.txt", ios::in);
4078 ifstream ifile2(
"rotationMin.txt", ios::in);
4081 if ( !ifile1.is_open() ) {
4082 cout <<
"Cannot open input file " <<
"rotationMax.txt" << endl;
4086 }
else if(!ifile2.is_open() ){
4087 cout <<
"Cannot open input file " <<
"rotationMin.txt" << endl;
4102 string farm_type, soil_type, farm_size;
4103 ifile1>>farm_type>>soil_type>>farm_size;
4104 ifile2>>farm_type>>soil_type>>farm_size;
4125 rot_max =
"rotationMax_almass.txt";
4126 rot_min =
"rotationMin_almass.txt";
4129 rot_max =
"rotationMax.txt";
4130 rot_min =
"rotationMin.txt";
4133 ifstream ifile1(rot_max.c_str(), ios::in);
4134 ifstream ifile2(rot_min.c_str(), ios::in);
4139 if ( !ifile1.is_open() ) {
4140 cout <<
"Cannot open input file with rotation max" << endl;
4144 }
else if(!ifile2.is_open() ){
4145 cout <<
"Cannot open input file with rotation min" << endl;
4151 int noCrops, noCrops1=0;
4154 if(noCrops!=noCrops1){
4155 g_msg->
Warn(
WARN_FILE,
"FarmManager::ReadCropsData_perSoilType_almass():"" Numbers of crops differ between input files! ",
" " );
4160 for(
int c=0; c<noCrops; c++){
4168 string farm_type, soil_type, farm_size;
4169 ifile1>>farm_type>>soil_type>>farm_size;
4170 ifile2>>farm_type>>soil_type>>farm_size;
4171 for(
int c=0; c<noCrops; c++){
4187 ifstream ifile1(
"winterMax.txt", ios::in);
4190 if ( !ifile1.is_open() ) {
4191 cout <<
"Cannot open input file " <<
"winterMax.txt" << endl;
4215 ifstream ifile(
"livestock_parameters.txt", ios::in);
4217 if ( !ifile.is_open() ) {
4218 cout <<
"Cannot open input file " <<
"livestock_parameters.txt" << endl;
4251 if ( !ifile1.is_open() ) {
4262 for(
int i=0; i<no_years; i++){
4280 if ( str ==
"Pig" )
return toof_Pig;
4282 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateFarmCodes():"" Unknown Farm type Code ", str.c_str() );
4291 if ( str ==
"Sand" )
return tos_Sand;
4292 if ( str ==
"Clay" )
return tos_Clay;
4294 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateSoilCodes():"" Unknown Soil type Code ", str.c_str() );
4305 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateFarmSizeCodes():"" Unknown Farm Size Code ", str.c_str() );
4314 if ( str ==
"DCow")
return toa_DCow;
4320 if ( str ==
"Goat")
return toa_Goat;
4321 if ( str ==
"So")
return toa_So;
4324 if ( str ==
"Deer")
return toa_Deer;
4325 if ( str ==
"Mink")
return toa_Mink;
4326 if ( str ==
"EHen")
return toa_EHen;
4327 if ( str ==
"MHen")
return toa_MHen;
4330 if ( str ==
"Duck")
return toa_Duck;
4334 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateAnimalsCodes():"" Unknown Animal type Code ", str.c_str() );
4343 if ( str ==
"Oats")
return toc_Oats;
4347 if ( str ==
"WRye")
return toc_WRye;
4352 if ( str ==
"Peas")
return toc_Peas;
4375 if ( str ==
"Veg")
return toc_Veg;
4383 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateCropCodes():"" Unknown Crop type Code ", str.c_str() );
4410 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateParametersCodes():"" Unknown Parameter Code ", str.c_str() );
4422 g_msg->
Warn(
WARN_FILE,
"FarmManager::TranslateLivestockParametersCodes():"" Unknown Livestock Parameter Code ", str.c_str() );
4431 if ( str ==
"m_n" )
return tocv_N;
4432 if ( str ==
"m_nt" )
return tocv_Nt;
4434 if ( str ==
"m_BIFi" )
return tocv_BIFi;
4435 if ( str ==
"m_BI" )
return tocv_BI;
4443 if ( str ==
"m_GM" )
return tocv_GM;
4447 g_msg->
Warn(
WARN_FILE,
"FarmManager::TTypesOfCropVariables():"" Unknown crop variable Code ", str.c_str() );
4474 ofstream ofile(
"CropDistribution.txt", ios::out);
4485 ofile <<
"Year" <<
'\t';
4490 ofile <<
"0" <<
'\t';
4506 ofstream ofile (a_fileName.c_str(), ios::out);
4507 ofile <<
"Farm no" <<
'\t';
4517 for (
int i=0; i<(int)
m_farms.size(); i++){
4520 opf = dynamic_cast<OptimisingFarm*>(
m_farms[i]);
4522 ofile << no <<
'\t';
4524 for(
int j = 0; j < size; j++){
4525 double var_to_print = -1;
4535 var_to_print = crop ->
m_n;
4538 var_to_print = crop ->
m_nt;
4544 var_to_print = crop ->
m_BIFi;
4547 var_to_print = crop ->
m_BI;
4562 var_to_print = crop ->
m_resp;
4571 var_to_print = crop ->
m_GM;
4577 g_msg->
Warn(
WARN_BUG,
"FarmManager::PrintOutput(): ""Unknown crop variable type! ",
"" );
4580 ofile << var_to_print <<
'\t';
4593 for(
int i=0; i<(int)
m_farms.size(); i++){
4598 opf = dynamic_cast<OptimisingFarm*>(
m_farms[i]);
4600 for(
int j=0; j<size; j++) {
4613 (*pm_output_file) <<
"Farm no \t";
4616 (*pm_output_file) <<
"mainGoal \t" <<
"totalArea \t" <<
"totalIncome \t" <<
"totalCosts \t" <<
"totalProfit \t";
4617 (*pm_output_file) <<
"FodderDemand \t" <<
"FodderDemand_bef \t" <<
"FodderTrade \t" <<
"FodderGrown \t" ;
4618 (*pm_output_file) <<
"Nanim \t" <<
"totalNanim \t" <<
"totalNt \t" <<
"totalN \t" ;
4619 (*pm_output_file) <<
"totalBI \t" <<
"totalBIHerb \t" <<
"totalBIFi \t" ;
4620 (*pm_output_file) <<
"totalGrooming \t" <<
"totalHoeing \t" <<
"totalWeeding \t";
4621 (*pm_output_file) << endl;
4628 ifstream ifile(
"crops_lookup.txt", ios::in);
4630 if ( !ifile.is_open() ) {
4631 cout <<
"Cannot open input file " <<
"crops_lookup.txt" << endl;
4664 for(
int i=0; i<(int)
m_farms.size(); i++){
4666 opf_i = dynamic_cast<OptimisingFarm*>(
m_farms[i]);
4671 for(
int i=0; i<(int)
m_farms.size(); i++){
4673 opf_i = dynamic_cast<OptimisingFarm*>(
m_farms[i]);
4678 for(
int k = 0; k<(int)
m_farms.size(); k++) {
4680 opf_k = dynamic_cast<OptimisingFarm*>(
m_farms[k]);
4686 if(abs(x - xb) <= par && abs(y - yb) <= par && farm_no_i!=farm_no_k){
4703 ofstream ofile (
"Neighbours.txt", ios::out);
4704 ofile <<
"Farm no" << endl;
4707 for(
int i=0; i<(int)
m_farms.size(); i++){
4710 opf_i = dynamic_cast<OptimisingFarm*>(
m_farms[i]);
4723 ofstream ofile (
"Decision_modes_counts.txt", ios::out);
4724 ofile <<
"Farm_no\t" <<
"imitation\t" <<
"social comparison\t" <<
"repeat\t"<<
"deliberation\t"<<endl;
4727 for(
int i=0; i<(int)
m_farms.size(); i++){
4730 opf_i = dynamic_cast<OptimisingFarm*>(
m_farms[i]);
4732 for(
int j=0; j<4; j++){
4746 double BIherb_sum=0;
4749 double fertilizer_sum=0;
4750 double fertilizer_trade_sum=0;
4758 ofstream ofile (
"CropAreasTotal_and_Average.txt", ios::out);
4761 ofile <<
"CropName\t" <<
"Total\t" <<
"Average\t" <<
"Area_%\t"<< endl;
4772 ofstream ofile5 (
"CropAreas_plant_farms.txt", ios::out);
4773 ofile5 <<
"CropName\t" <<
"Area_%\t" << endl;
4781 ofstream ofile6 (
"CropAreas_pig_farms.txt", ios::out);
4782 ofile6 <<
"CropName\t" <<
"Area_%\t" << endl;
4790 ofstream ofile7 (
"CropAreas_cattle_farms.txt", ios::out);
4791 ofile7 <<
"CropName\t" <<
"Area_%\t" << endl;
4799 ofstream ofile8 (
"CropAreas_other_farms.txt", ios::out);
4800 ofile8 <<
"CropName\t" <<
"Area_%\t" << endl;
4811 ofstream ofile1 (
"PesticideTotals.txt", ios::out);
4812 ofile1 <<
"CropName\t" <<
"BIherb\t" <<
"BIfi\t" <<
"BI\t" ;
4813 ofile1 <<
"BIherb_yr\t" <<
"BIfi_yr\t" <<
"BI_yr\t";
4814 ofile1 <<
"BIherb_ha\t" <<
"BIfi_ha\t" <<
"BI_ha\t";
4838 ofile1 <<
"0\t" <<
"0\t" <<
"0\t" ;
4844 ofstream ofile2 (
"FertilizerTotals.txt", ios::out);
4845 ofile2 <<
"CropName\t" <<
"Fertilizer\t" <<
"Fertilizer_yr\t" <<
"Fertilizer_ha\t" << endl;
4863 ifstream ifile(
"crop_results_stages.txt", ios::in);
4865 if ( !ifile.is_open() ) {
4866 cout <<
"Cannot open input file " <<
"crop_results_stages.txt" << endl;
4873 for(
int c=0; c<no_crops; c++){
4877 for(
int stage=0; stage<2; stage++){
4882 for(
int a=0; a<no_crops; a++){
4890 for(
int s=0; s<2; s++){
4894 for(
int st=0; st<2; st++){
4895 for(
int b=0; b<no_crops; b++){
4897 sums[st] += sq_diff;
4901 ofstream ofile3 (
"Result_summary.txt", ios::out);
4902 ofile3 <<
"BIherb\t" <<
"BIfi\t" <<
"BI\t" <<
"Fert\t" <<
"Fert_trade\t" ;
4903 ofile3 <<
"Sum of sq. diff: Baseline\t" <<
"Sum of sq. diff: Original\t";
4910 for(
int sta=0; sta<2; sta++){
4911 ofile3 << sums[sta] <<
'\t';
4916 ofstream ofile4 (
"Output.txt", ios::out);
4919 double BIdiffabs = abs(BIdiff_percent);
4920 double fert_diff_percent = ((fertilizer_sum/
totalOptFarmsArea/no_years/140.07)-1) * 100;
4921 double fertdiffabs = abs(fert_diff_percent);
4923 ofile4 <<
'\t' << BI_sum/
totalOptFarmsArea/no_years <<
'\t' << BIdiff_percent <<
'\t'<< BIdiffabs <<
'\t';
4924 ofile4 << fertilizer_sum/
totalOptFarmsArea/no_years <<
'\t' << fert_diff_percent <<
'\t' << fertdiffabs <<
'\t';
4925 ofile4 << sums[0] <<
'\t';
4926 ofile4 << 0.2 * abs(BIdiff_percent) + 0.2 * abs(fert_diff_percent) + 0.6 * sums[0] << endl;
4930 ofstream ofile9 (
"Output_crop_areas_percent.txt", ios::out);
4945 vector<TTypesOfVegetation> new_rotation;
4951 new_rotation.push_back(tov);
4956 for(
int i=0; i<(int)
m_farms.size(); i++){
4959 opf = dynamic_cast<OptimisingFarm*>(
m_farms[i]);
4973 int number_opt_farms=0;
4974 vector <OptimisingFarm*> opt_farms;
4975 vector <OptimisingFarm*> opt_farms_copy;
4976 for(
int i=0; i<(int)
m_farms.size(); i++){
4980 opt_farms.push_back(opf);
4983 opt_farms_copy = opt_farms;
4986 int number_profit = (int) (profit_proportion/100 * number_opt_farms);
4987 int number_yield = (int) (yield_proportion/100 * number_opt_farms + 0.5);
4988 int number_env = (int) (env_proportion/100 * number_opt_farms + 0.5);
4995 int index_for_farm=0;
4998 for(
int j=jj; j<number_profit; j++){
5000 index_for_farm = dis(gen);
5001 opt_farms_copy[index_for_farm]->Set_main_goal(
tofg_profit);
5002 opt_farms_copy.erase(opt_farms_copy.begin() + index_for_farm);
5008 for(
int j = jj; j<number_yield + number_profit; j++){
5010 index_for_farm = dis1(gen);
5011 opt_farms_copy[index_for_farm]->Set_main_goal(
tofg_yield);
5012 opt_farms_copy.erase(opt_farms_copy.begin() + index_for_farm);
5018 int loop_limit = (number_env + number_profit + number_yield > number_opt_farms)? number_opt_farms : number_env + number_profit + number_yield;
5019 for(
int j=jj; j<loop_limit; j++){
5021 index_for_farm = dis2(gen);
5023 opt_farms_copy.erase(opt_farms_copy.begin() + index_for_farm);
5027 if((
int)opt_farms_copy.size()>0){
5028 for(
int p=(
int)opt_farms_copy.size(); p>0; p--){
5041 for(
int i=0; i<(int)vector.size(); i++){
5090 g_msg->
Warn(
WARN_BUG,
"almass_no from farms_data doesn't match any of the numbers from farmrefs file",
"" );
5139 for(
int i=0; i<(int)
m_fields.size(); i++){
5140 if(
m_fields[i]->GetRotIndex() != -4){
5191 for(
int i=0; i<size; i++){
5206 for(j=0; j<livestocknum; j += (
toa_Foobar+1)){
5213 g_msg->
Warn(
WARN_BUG,
"Farm's almass_no doesn't match any of the numbers within the livestock numbers vector",
"" );
5216 int index2 = index + 1 + i;
5221 p_lvs =
new Livestock(livestock_type, number);
5229 for(
int i=0; i<no_crops; i++){
5233 for(j=0; j<croparea; j+=(no_crops+1)){
5241 g_msg->
Warn(
WARN_BUG,
"Farm's almass_no doesn't match any of the numbers within the crop areas vector",
"" );
5244 int index2= index + 1 + i;
5337 int sum_centroidx = 0;
5338 int sum_centroidy = 0;
5339 int no_fields = (int)
m_fields.size();
5340 for (
int i=0; i<no_fields; i++){
5341 sum_centroidx +=
m_fields[i]->GetCentroidX();
5342 sum_centroidy +=
m_fields[i]->GetCentroidY();
5355 if (BIherb > 0)
return true;
5367 if (BIfi > 0)
return true;
5390 for(
int a=0; ok==
false && neighbours_copy.size()>0; a++){
5391 srand ((
unsigned)time(NULL));
5392 int neighbour = rand() % (no_farmers-a);
5401 neighbours_copy.erase(neighbours_copy.begin() + neighbour);
5410 neighbours_copy.erase(neighbours_copy.begin() + neighbour);
5420 neighbours_copy.erase(neighbours_copy.begin() + neighbour);
5429 neighbours_copy.erase(neighbours_copy.begin() + neighbour);
5439 for(
int a=0; ok==
false && neighbours_copy.size()>0; a++){
5440 srand ((
unsigned)time(NULL));
5441 int neighbour = rand() % (no_farmers-a);
5447 neighbours_copy.erase(neighbours_copy.begin() + neighbour);
5456 char errornum[ 20 ];
5458 g_msg->
Warn(
WARN_BUG,
"No farm with a matching farm type to imitate: ", errornum );
5495 double sum_of_sat_levels=0;
5496 for(
int i=0; i<5; i++){
5551 int value_for_satisfaction = 1;
5583 for (
int i=0; i < n; ++i) {
5600 for (
int i=0; i < n; ++i) {
5630 for (
int i=0; i< (int)
m_crops.size(); i++) {
5648 string str_AUKey=
"AUKey";
5649 string str_Nusable=
"Nusable";
5659 double NanimUsable = number*AUKey*Nusable*100;
5675 string str_FUuKey=
"FUuKey";
5685 double FUdemand=FUuKey*number;
5742 std::random_device rd;
5743 std::mt19937 gen(rd());
5745 double random_no = dis(gen);
5747 if(random_no > 0.1){
5801 for (
int i=0; i< (int)
m_crops.size(); i++){
5888 if(CGG1area!= CGG2area){
5889 double area_sum = CGG1area + CGG2area;
5894 if(GS1area!=GS2area){
5895 double area_sum = GS1area + GS2area;
5928 double n1=-(beta1/beta2)*0.5;
5934 a_crop->
m_n = nNorm;
5939 double nt1= 0.5*(priceNt/(benefit*beta2) - beta1/beta2) -
m_Nanim;
5948 if(p>=0){a_crop->
m_nt = p;}
5949 else{a_crop->
m_nt = 0;}
5950 a_crop->
m_n = nNorm;
5955 else {a_crop->
m_n = nNorm;}
5962 else {a_crop->
m_n = nNorm;}
5970 double n1=-(beta1/beta2)*0.5;
5976 a_crop->
m_n = nNorm;
5984 a_crop->
m_n = nNorm;
5994 else {a_crop->
m_n = nNorm;}
6007 a_crop->
m_n = nNorm;
6015 a_crop->
m_n = nNorm;
6025 else {a_crop->
m_n = nNorm;}
6042 double ntotal=a_crop->
m_n;
6043 double resp1=alfa + beta1*ntotal + beta2*pow(ntotal,2);
6069 double resp1=a_crop->
m_resp;
6072 double BIHerbMax = betaHerb/alfaHerb;
6073 double gainHerb = 0;
6077 gainHerb = benefit*resp1*alfaHerb/100 + priceG*alfaG + priceH*alfaH + priceW*alfaW;
6078 BIHerb = (gainHerb>priceHerb)? BIHerbMax : 0;
6085 gainHerb = benefit*resp1*alfaHerb/100 + priceG*alfaG + priceH*alfaH + priceW*alfaW;
6093 double BIFiMax = betaFi/alfaFi;
6097 gainFi = benefit*resp1*alfaFi/100;
6098 BIFi = (gainFi > priceFi) ? BIFiMax : 0;
6102 a_crop->
m_BIFi = BIFiMax;
6105 gainFi = benefit*resp1*alfaFi/100;
6117 double BIFi = a_crop->
m_BIFi;
6119 double BI = BIFi+BIHerb;
6147 PotatoesIndustry->
m_BIHerb = 1.41; PotatoesIndustry->
m_BIFi = 9.28; PotatoesIndustry->
m_BI = 10.69;
6167 double grooming, hoeing, weeding =0;
6168 double g = betaG - BIHerb*alfaG;
6169 double h = betaH - BIHerb*alfaH;
6170 double w = betaW - BIHerb*alfaW;
6171 double BIHerbCorr = BIHerb;
6175 if(alfaG!=0) BIHerbCorr=betaG/alfaG;
6180 if(betaH/alfaH < BIHerbCorr) BIHerbCorr=betaH/alfaH;
6185 if(betaW/alfaW < BIHerbCorr) BIHerbCorr = betaW/alfaW;
6193 if(BIHerbCorr < BIHerb){
6213 double BIFi=a_crop->
m_BIFi;
6215 double lossHerb = betaHerb - alfaHerb*BIHerb;
6218 double lossFi = betaFi - alfaFi*BIFi;
6221 double totalLoss = lossHerb + lossFi;
6239 double resp = a_crop->
m_resp;
6241 double BIFi = a_crop->
m_BIFi;
6246 double nt = a_crop->
m_nt;
6249 double income_ha = benefit*resp*(1-totalLoss/100)+subsidy;
6250 double costs_ha = BIHerb*priceHerb + BIFi*priceFi + grooming*priceG + hoeing*priceH + weeding*priceW + nt*priceNt + priceLM;
6251 double profit = income_ha - costs_ha;
6261 a_crop->
m_GM = subsidy-costs_ha;
6266 a_crop->
m_GM = profit;
6316 double areaPercent=0;
6335 double base_prob = 0;
6342 std::random_device rd;
6344 std::mt19937 engine(rd());
6345 double random_number = dis(engine);
6346 if(base_prob == 1) random_number = 0;
6347 double area_1 = base_prob * (1 + 0.2 * random_number) * (100 -
m_assigned);
6348 areaPercent = ( area_1 <= rotationMax)? area_1 : rotationMax;
6353 areaPercent = (rotationMax-minArea <= 100-
m_assigned)? rotationMax : (100 -
m_assigned+minArea);
6361 else {areaPercent = minArea;}
6364 double areaVar=areaPercent-minArea;
6502 double diff = areaWWheat - (areaWRape + areaSRape + areaOats + areaPeas);
6521 double GM_WWheat = wWheat->
m_GM;
6527 if(areaRC < rotationMaxRC){
6529 bool stopInnerLoop =
false;
6535 if(GM_RC + GM_WWheat < 2*GM_var){
6539 if(areaWWheat - areaMin >= diff){
6540 if(rotationMaxVC - areaVC >= diff){
6544 stopInnerLoop =
true;
6547 areaWWheat -= rotationMaxVC - areaVC;
6548 diff -= (rotationMaxVC - areaVC);
6549 areaVC = rotationMaxVC;
6553 if(rotationMaxVC - areaVC >= areaWWheat - areaMin){
6554 areaVC += areaWWheat - areaMin;
6555 diff -= (areaWWheat - areaMin);
6556 areaWWheat = areaMin;
6557 stopInnerLoop =
true;
6560 areaWWheat -= rotationMaxVC - areaVC;
6561 diff -= (rotationMaxVC - areaVC);
6562 areaVC = rotationMaxVC;
6571 if(areaWWheat - areaMin >= diff/2){
6572 if(rotationMaxRC - areaRC >= diff/2){
6574 areaWWheat -= diff/2;
6576 stopInnerLoop =
true;
6579 areaWWheat -= rotationMaxRC - areaRC;
6580 diff -= 2 * (rotationMaxRC - areaRC);
6581 areaRC = rotationMaxRC;
6582 stopInnerLoop =
true;
6586 if(rotationMaxRC - areaRC >= areaWWheat - areaMin){
6587 areaRC += areaWWheat - areaMin;
6588 diff -= 2 * (areaWWheat - areaMin);
6589 areaWWheat = areaMin;
6590 stopInnerLoop =
true;
6593 areaWWheat -= rotationMaxRC - areaRC;
6594 diff -= 2 * (rotationMaxRC - areaRC);
6595 areaRC = rotationMaxRC;
6596 stopInnerLoop =
true;
6608 if(areaWWheat==areaMin && diff > 0){
6614 double toCut = diff - diff1;
6617 ofstream ofile(
"Restrictions.txt",ios::app);
6618 ofile <<
m_almass_no <<
'\t' <<
"winter rotation1 restriction broken, WWheat area at 0. Diff is: " << diff << endl;
6626 if(diff > 0 && areaWWheat - areaMin >= diff){
6669 double diff = areaWWheat - (areaWRape + areaSRape + areaOats + areaPeas);
6689 double GM_WWheat = wWheat->
m_GM;
6695 double areaBeforeRC = areaRC;
6696 if(areaRC < rotationMaxRC){
6698 bool stopInnerLoop =
false;
6704 if(GM_RC + GM_WWheat < 2 * GM_var){
6708 double areaBefore = areaVC;
6709 if(areaWWheat - areaMin >= diff){
6710 if(rotationMaxVC - areaVC >= diff){
6714 stopInnerLoop =
true;
6717 areaWWheat -= rotationMaxVC - areaVC;
6718 diff -= (rotationMaxVC - areaVC);
6719 areaVC = rotationMaxVC;
6723 if(rotationMaxVC - areaVC >= areaWWheat - areaMin){
6724 areaVC += (areaWWheat - areaMin);
6725 diff -= (areaWWheat - areaMin);
6726 areaWWheat = areaMin;
6730 areaWWheat -= rotationMaxVC - areaVC;
6731 diff -= (rotationMaxVC - areaVC);
6732 areaVC = rotationMaxVC;
6737 if(areaVC > areaBefore){
6744 double FUha = resp * (1-loss/100) * FUKey;
6745 double changeFU = (areaVC - areaBefore) *
m_totalArea/100 * FUha;
6754 if(areaWWheat - areaMin >= diff/2){
6755 if(rotationMaxRC - areaRC >= diff/2){
6757 areaWWheat -= diff/2;
6759 stopInnerLoop =
true;
6762 areaWWheat -= rotationMaxRC - areaRC;
6763 diff -= 2 * (rotationMaxRC - areaRC);
6764 areaRC = rotationMaxRC;
6765 stopInnerLoop =
true;
6769 if(rotationMaxRC - areaRC >= areaWWheat - areaMin){
6770 areaRC += areaWWheat - areaMin;
6771 diff -= 2 * (areaWWheat - areaMin);
6772 areaWWheat = areaMin;
6773 stopInnerLoop =
true;
6776 areaWWheat -= rotationMaxRC - areaRC;
6777 diff -= 2 * (rotationMaxRC - areaRC);
6778 areaRC = rotationMaxRC;
6779 stopInnerLoop =
true;
6787 if(areaRC>areaBeforeRC){
6794 double FUha = resp * (1-loss/100) * FUKey;
6795 double changeFU = (areaRC - areaBeforeRC) *
m_totalArea/100 * FUha;
6806 if(areaWWheat==areaMin && diff>0){
6807 double diff1 = diff;
6813 double toCut = diff-diff1;
6816 ofstream ofile(
"Restrictions.txt",ios::app);
6817 ofile <<
m_almass_no <<
'\t' <<
"winter rotation1 restriction broken. Animal farm. WWheat area at 0. Diff is: " << diff << endl;
6825 if(diff>0 && areaWWheat-areaMin >= diff){
6868 double areaWCerealSil = 0;
6874 double sum = areaWBarley + areaWWheat + areaWRye + areaWRape + areaWCerealSil;
6877 if(sum > winterMax){
6896 double diff = sum - winterMax;
6897 double diffBefore = diff;
6919 ofstream ofile(
"Restrictions.txt",ios::app);
6920 ofile <<
m_almass_no <<
'\t' <<
"winter crops restriction broken, non-animal farm. Diff is: " << diff << endl;
6925 double toIncrease = diffBefore - diff;
6963 double areaWCerealSil = 0;
6969 double sum = areaWBarley + areaWWheat + areaWRye + areaWRape + areaWCerealSil;
6972 if(sum > winterMax){
6973 double diff = sum - winterMax;
6974 double diffBefore = diff;
7014 ofstream ofile(
"Restrictions.txt",ios::app);
7015 ofile <<
m_almass_no <<
'\t' <<
"winter crops restriction broken, Animal farm. Diff is: " << diff << endl;
7020 double toIncrease = diffBefore - diff;
7032 double areaBefore = area;
7037 if(areaBefore > area){
7044 double FUha = resp * (1-loss/100) * FUKey;
7045 double changeFU = (areaBefore - area) *
m_totalArea/100 * FUha;
7074 double diff = areaGClover + areaGSeed - areaSBarley;
7095 for(
int i=(
int)
m_cattleCrops.size()-1; i>=0 && diff>0; i--){
7098 double areaCCBefore = areaCC;
7099 if(areaCC > areaMinCC){
7100 bool cCropAtMin =
false;
7105 if(GM_SBarley + GM_CC > 2*GM_var){
7111 double areaVarBefore = areaVar;
7113 if(areaCC - areaMinCC >= diff){
7114 if(areaMaxVar - areaVar >= diff){
7121 diff -= (areaMaxVar - areaVar);
7122 areaCC -= (areaMaxVar - areaVar);
7123 areaVar = areaMaxVar;
7127 if(areaMaxVar - areaVar >= areaCC - areaMinCC){
7128 diff -= areaCC - areaMinCC;
7129 areaVar += areaCC - areaMinCC;
7134 diff -= areaMaxVar - areaVar;
7135 areaCC -= areaMaxVar - areaVar;
7136 areaVar = areaMaxVar;
7146 if(areaVar > areaVarBefore){
7153 double FUha = resp * (1-loss/100) * FUKey;
7154 double changeFU = (areaVar - areaVarBefore) *
m_totalArea/100 * FUha;
7160 if(areaCC < areaCCBefore){
7167 double FUha = resp * (1-loss/100) * FUKey;
7168 double changeFU = (areaCCBefore - areaCC) *
m_totalArea/100 * FUha;
7188 double SBarleyAvailableArea = areaSBarleyMax-areaSBarley;
7189 double areaSBarleyBefore = areaSBarley;
7191 double available = 0;
7195 available += (area - areaMin);
7198 if(areaSBarley < areaSBarleyMax){
7199 if(SBarleyAvailableArea >= diff/2){
7200 if(available >= diff/2){
7201 areaSBarley += diff/2;
7207 areaSBarley += available;
7208 diff -= 2 * available;
7211 if(SBarleyAvailableArea >= diff){
7212 areaSBarley += diff;
7217 double toDecrease = areaSBarleyMax - areaSBarley;
7218 areaSBarley = areaSBarleyMax;
7222 ofstream ofile(
"Restrictions.txt",ios::app);
7223 ofile <<
m_almass_no <<
'\t' <<
"cattle restriction: broken after N 3.2" << endl;
7230 if(available >= SBarleyAvailableArea){
7231 areaSBarley = areaSBarleyMax;
7232 diff -= 2 * SBarleyAvailableArea;
7233 available -= SBarleyAvailableArea;
7236 double diffBefore = diff;
7237 if(available >= diff){
7245 double toDecrease = available;
7248 ofstream ofile(
"Restrictions.txt",ios::out);
7249 ofile <<
m_almass_no <<
'\t' <<
"cattle restriction: broken after Y 3.1" << endl;
7254 areaSBarley += available;
7256 diff -= 2 * available;
7257 double toDecrease = areaSBarleyMax - areaSBarley;
7258 areaSBarley = areaSBarleyMax;
7262 ofstream ofile(
"Restrictions.txt",ios::out);
7263 ofile <<
m_almass_no <<
'\t' <<
"cattle restriction: broken after N 3.1" << endl;
7271 double resp = sBarley->
m_resp;
7274 double FUha = resp * (1-loss/100) * FUKey;
7275 double changeFU = (areaSBarley - areaSBarleyBefore) *
m_totalArea/100 * FUha;
7281 if(available >= diff){
7282 double diffBefore = diff;
7289 double toIncrease = available;
7292 ofstream ofile(
"Restrictions.txt",ios::out);
7293 ofile <<
m_almass_no <<
'\t' <<
"cattle restriction: broken after N 1" << endl;
7315 double diff = areaCGG/2 - areaSBarley;
7327 double new_area_sbarley = areaSBarley;
7328 double new_area_cgg = areaCGG;
7333 available += areaVariableCrop;
7336 if(areaCGG/2 *3 <= available){
7337 new_area_sbarley = areaCGG/2;
7338 double area_to_decrease = new_area_sbarley - areaSBarley;
7342 new_area_cgg = available/3 * 2;
7343 new_area_sbarley = available/3;
7344 double current_sbarley_and_grasses = areaSBarley + areaCGG;
7345 double other_crops_area = available - current_sbarley_and_grasses;
7346 if(current_sbarley_and_grasses < available){
7353 double resp = sBarley->
m_resp;
7357 double FUha = resp * (1-loss/100) * FUKey;
7358 double changeFU = (new_area_sbarley - areaSBarley) *
m_totalArea/100 * FUha;
7366 FUha = resp * (1-loss/100) * FUKey;
7367 changeFU = (areaCGG - new_area_cgg) *
m_totalArea/100 * FUha;
7394 if(area_WB < area_WR){
7408 available += areaVariableCrop;
7411 double new_area_wbarley = area_WB;
7412 double new_area_wrape = area_WR;
7414 if(2 * area_WR <= available){
7415 new_area_wbarley = area_WR;
7416 double area_to_decrease = new_area_wbarley - area_WB;
7420 new_area_wrape = available/2;
7421 new_area_wbarley = available/2;
7422 double current_wbarley_and_wrape = area_WB + area_WR;
7423 double other_crops_area = available - current_wbarley_and_wrape;
7424 if(current_wbarley_and_wrape < available){
7431 double winter_crops=0;
7432 for(
unsigned j=0; j<
m_crops.size(); j++){
7435 winter_crops +=
m_crops[j]->m_areaPercent;
7446 for(
unsigned j=0; j<
m_crops.size(); j++){
7449 winter_crops +=
m_crops[j]->m_areaPercent;
7454 if(winter_crops > winterMax){
7455 double diff = winter_crops - winterMax;
7463 new_area_wrape -= diff/2;
7464 new_area_wbarley -= diff/2;
7473 double resp = wBarley->
m_resp;
7477 double FUha = resp * (1-loss/100) * FUKey;
7478 double changeFU = (new_area_wbarley - area_WB) *
m_totalArea/100 * FUha;
7498 double fodderFromFixed=0;
7501 if(area_percent!=0){
7508 double FU = area*resp*(1-loss/100)*FUKey;
7509 fodderFromFixed += FU;
7513 double fodderFromMinAreas=0;
7516 if(areaMinPercent!=0){
7523 double FU = area*resp*(1-loss/100)*FUKey;
7524 fodderFromMinAreas += FU;
7544 double areaAssignedToFodder=0;
7549 available += areaVariableCrop;
7556 double areaBefore = area;
7560 double FUha = resp * (1-loss/100) * FUKey;
7563 if(percNeeded <= rotationMax - area){
7564 if(percNeeded <= available){
7566 available -= percNeeded;
7574 if(rotationMax-area >= available){
7579 available -= rotationMax-area;
7584 double Funits = FUha * (area-areaBefore) *
m_totalArea/100;
7588 areaAssignedToFodder += (area-areaBefore);
7595 g_msg->
Warn(
WARN_BUG,
"AnimalFarm::determineMinFodder(): impossible to cover the min. fodder prod., farm no: ", index );
7600 vector<CropSort>grownVarCrops_key;
7603 grownVarCrops_key.push_back(gc);
7607 if(areaAssignedToFodder>0){
7611 g_msg->
Warn(
WARN_BUG,
"AnimalFarm::determineMinFodder(): not enough space to grow the min. fodder, farm no.: ", index );
7656 if(areaFodder < rotationMax){
7658 bool assigningFinished =
false;
7661 double minGM = 1000000;
7666 if(savings > minGM){
7672 double FUha = resp*(1-loss/100)*FUKey;
7676 if(percNeeded <= rotationMax - areaFodder){
7677 if(percNeeded <= areaVariable){
7678 areaFodder += percNeeded;
7681 areaVariable -= percNeeded;
7682 assigningFinished =
true;
7685 areaFodder += areaVariable;
7692 if(rotationMax - areaFodder <= areaVariable){
7693 areaVariable -= rotationMax-areaFodder;
7696 areaFodder = rotationMax;
7697 assigningFinished =
true;
7701 areaFodder += areaVariable;
7709 double areaPer = areaMin + areaVariable;
7717 assigningFinished =
true;
7720 }
while (assigningFinished==
false && v>=0);
7724 if(assigningFinished==
false){
7741 if(areaFakeCrop > 0){
7763 for(
int c=0; c< (int)
m_crops.size(); c++){
7766 g_msg->
Warn(
WARN_FILE,
"OptimisingFarm::findCropByName():" "Unknown Code Identificator", crop_name.c_str() );
7771 for(
int c=0; c< (int)
m_crops.size(); c++){
7774 g_msg->
Warn(
WARN_FILE,
"OptimisingFarm::findCropByName_almass():" "Unknown Code Identificator", crop_name.c_str() );
7779 for(
int c=0; c< (int)
m_crops.size(); c++){
7780 if(
m_crops[c]->m_cropType_almass == a_tov_type)
return m_crops[c];
7782 char error_num[ 20 ];
7783 sprintf( error_num,
"%d", a_tov_type);
7784 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::findCropByName_almass():" "Unknown Code Identificator", error_num );
7793 for (
int i=0; i<(int)cropsToSort.size(); i++){
7794 cropsToSort[i].key = cropsToSort[i].crop->m_GM;
7797 else if (sortKey==
"Savings"){
7798 for (
int i=0; i<(int)cropsToSort.size(); i++){
7799 cropsToSort[i].key = cropsToSort[i].crop->m_savings;
7803 for (
int i=0; i<(int)cropsToSort.size(); i++){
7804 cropsToSort[i].key = cropsToSort[i].crop->m_GM_Savings;
7808 sort(cropsToSort.begin(), cropsToSort.end(),
reverseSort());
7814 std::vector<CropSort>helper;
7815 helper.push_back(listToRandomize[0]);
7817 for(
int i=1; i<(int)listToRandomize.size(); i++){
7818 double key_current, key_previous;
7820 key_current=listToRandomize[i].crop->m_GM;
7821 key_previous=listToRandomize[i-1].crop->m_GM;
7823 else if (key==
"Savings"){
7824 key_current=listToRandomize[i].crop->m_savings;
7825 key_previous=listToRandomize[i-1].crop->m_savings;
7827 else if(key==
"GM_Savings"){
7828 key_current=listToRandomize[i].crop->m_GM_Savings;
7829 key_previous=listToRandomize[i-1].crop->m_GM_Savings;
7832 key_current=key_previous=0;
7833 g_msg->
Warn(
WARN_FILE,
"OptimisingFarm::randomizeCropList():" "Unknown sorting key identificator", key.c_str() );
7837 if(key_current==key_previous){
7838 helper.push_back(listToRandomize[i]);
7841 std::random_shuffle(helper.begin(), helper.end());
7845 for(
int j=(
int)helper.size()-1; j>=0; j--){
7846 listToRandomize[i-1-j]=helper[j];
7849 helper.push_back(listToRandomize[i]);
7857 for(
int i=0; howMuchToIncrease>0 && i<(int)cropsToIncrease.size(); i++){
7858 double area = cropsToIncrease[i].crop->m_areaPercent;
7859 double rotationMax = cropsToIncrease[i].crop->m_rotationMax;
7860 double rotMinCrop = cropsToIncrease[i].crop->m_rotationMin;
7861 if(area + howMuchToIncrease <= rotationMax){
7862 area += howMuchToIncrease;
7863 howMuchToIncrease = 0;
7866 howMuchToIncrease -= rotationMax-area;
7869 cropsToIncrease[i].crop->m_areaPercent = area;
7870 cropsToIncrease[i].crop->m_areaVariable = area - rotMinCrop;
7879 for(
int i=0; howMuchToIncrease>0 && i<(int)cropsToIncrease.size(); i++){
7880 double area = cropsToIncrease[i].crop->m_areaPercent;
7881 double areaBefore = area;
7882 double rotationMax = cropsToIncrease[i].crop->m_rotationMax;
7883 double rotMinCrop = cropsToIncrease[i].crop->m_rotationMin;
7884 if(area + howMuchToIncrease <= rotationMax){
7885 area += howMuchToIncrease;
7886 howMuchToIncrease = 0;
7889 howMuchToIncrease -= rotationMax-area;
7892 cropsToIncrease[i].crop->m_areaPercent = area;
7893 cropsToIncrease[i].crop->m_areaVariable = area - rotMinCrop;
7896 if(area > areaBefore){
7900 double resp = cropsToIncrease[i].crop->m_resp;
7901 double loss = cropsToIncrease[i].crop->m_totalLoss;
7903 double FUha = resp * (1-loss/100) * FUKey;
7904 double changeFU = (area-areaBefore) *
m_totalArea/100 * FUha;
7915 for(
int j=(
int)cropsToDecrease.size()-1; howMuchToDecrease>0 && j>=0; j--){
7916 double areaCrop = cropsToDecrease[j].crop->m_areaPercent;
7917 double rotMinCrop = cropsToDecrease[j].crop->m_rotationMin;
7918 if(areaCrop - howMuchToDecrease >= rotMinCrop){
7919 areaCrop -= howMuchToDecrease;
7920 howMuchToDecrease = 0;
7923 howMuchToDecrease -= areaCrop - rotMinCrop;
7924 areaCrop = rotMinCrop;
7926 cropsToDecrease[j].crop->m_areaPercent = areaCrop;
7927 cropsToDecrease[j].crop->m_areaVariable = areaCrop - rotMinCrop;
7936 for(
int j=(
int)cropsToDecrease.size()-1; howMuchToDecrease>0 && j>=0; j--){
7937 double areaCrop = cropsToDecrease[j].crop->m_areaPercent;
7938 double areaBefore = areaCrop;
7939 double rotMinCrop = cropsToDecrease[j].crop->m_rotationMin;
7940 if(areaCrop - howMuchToDecrease >= rotMinCrop){
7941 areaCrop -= howMuchToDecrease;
7942 howMuchToDecrease = 0;
7945 howMuchToDecrease -= areaCrop - rotMinCrop;
7946 areaCrop = rotMinCrop;
7948 cropsToDecrease[j].crop->m_areaPercent = areaCrop;
7949 cropsToDecrease[j].crop->m_areaVariable = areaCrop - rotMinCrop;
7951 if(areaCrop < areaBefore){
7955 double resp = cropsToDecrease[j].crop->m_resp;
7956 double loss = cropsToDecrease[j].crop->m_totalLoss;
7958 double FUha = resp * (1-loss/100) * FUKey;
7959 double changeFU = (areaBefore - areaCrop) *
m_totalArea/100 * FUha;
7970 for(
int i=0; i<(int)allCrops.size(); i++){
7971 double areaPercent = allCrops[i]->m_areaPercent;
7972 double area_ha = (areaPercent==0) ? 0 : (areaPercent/100 *
m_totalArea);
7973 allCrops[i]->m_area_ha = area_ha;
7981 double totalAmount = 0;
7982 for (
int i=0; i<(int)
m_crops.size(); i++){
7983 double area_ha =
m_crops[i]->m_area_ha;
7985 double value_per_ha;
7988 value_per_ha =
m_crops[i] ->m_areaPercent;
7991 value_per_ha =
m_crops[i] ->m_area_ha;
7994 value_per_ha =
m_crops[i] ->m_n;
7997 value_per_ha =
m_crops[i] ->m_nt;
8000 value_per_ha =
m_crops[i] ->m_BIHerb;
8003 value_per_ha =
m_crops[i] ->m_BIFi;
8006 value_per_ha =
m_crops[i] ->m_BI;
8009 value_per_ha =
m_crops[i] ->m_grooming;
8012 value_per_ha =
m_crops[i] ->m_hoeing;
8015 value_per_ha =
m_crops[i] ->m_weeding;
8018 value_per_ha =
m_crops[i] ->m_totalLoss;
8021 value_per_ha =
m_crops[i] ->m_resp;
8024 value_per_ha =
m_crops[i] ->m_income_ha;
8027 value_per_ha =
m_crops[i] ->m_costs_ha;
8030 value_per_ha =
m_crops[i] ->m_GM;
8033 value_per_ha =
m_crops[i] ->m_savings;
8036 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::total(): ""Unknown crop variable type! ",
"" );
8039 totalAmount += value_per_ha * area_ha;
8057 (*ap_output_file) << endl;
8063 double area_to_check = 0.0;
8064 for(
int i=0; i<(int)
m_crops.size(); i++) {
8065 area_to_check +=
m_crops[i]->m_areaPercent;
8068 if(area_to_check > 100.0001 || area_to_check < 99.999){
8069 ofstream ofile(
"Check_if_area_is_100%.txt",ios::app);
8070 ofile <<
m_almass_no <<
'\t' <<
"Farms area is not equal to 100%. The sum of crops areaPercent is: " << area_to_check << endl;
8080 for(
int i = 0; i < (int)
m_crops.size(); i++){
8081 if(
m_crops[i]->m_areaPercent > 0){
8207 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Translate_crops_to_almass(): ""Unknown crop type! ",
"" );
8220 vector<AlmassCrop>crops_almass_aggregated;
8223 for(
int i = 0; i < size; i++){
8228 for(
int p = 0; p < i; p++){
8234 for(
int j = i+1; j < size; j++){
8240 crops_almass_aggregated.push_back(crop);
8275 for(
int i = 0; i < (int)
m_crops.size(); i++){
8276 if(
m_crops[i]->m_areaPercent > 0){
8314 double new_area = area_cgg;
8319 if(area_sb < area_cgg){
8320 new_area = (area_sb + 2*area_cgg)/3;
8327 new_area = area_cgg*2/3;
8381 if(pct<0.5) pct+=0.5;
8398 (*ap_output_file) << i <<
'\t' << crop << endl;
8400 (*ap_output_file) << endl;
8421 int no_rotational = 0;
8438 if(pct<0.5) pct+=0.5;
8452 vector<TTypesOfVegetation>all_crops;
8453 vector<MakeRotation>rotation;
8454 rotation.resize(100);
8465 int area_scaled = (int)(100 * area / area_rot_int + 0.5);
8473 if(SBarley_area < CGG1_area){
8474 if(SBarley_area == 0){
8478 int new_area = (int)((CGG1_area * 2 + SBarley_area)/3 + 0.5);
8491 for(
int j = 0; j<area; j++){
8498 vector<TTypesOfVegetation>all_crops_helper;
8500 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8502 all_crops_helper.push_back(all_crops[i]);
8503 all_crops.erase(all_crops.begin() + i);
8507 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8509 all_crops_helper.push_back(all_crops[i]);
8510 all_crops.erase(all_crops.begin() + i);
8513 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8515 all_crops_helper.push_back(all_crops[i]);
8516 all_crops.erase(all_crops.begin() + i);
8519 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8521 all_crops_helper.push_back(all_crops[i]);
8522 all_crops.erase(all_crops.begin() + i);
8525 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8527 all_crops_helper.push_back(all_crops[i]);
8528 all_crops.erase(all_crops.begin() + i);
8531 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8533 all_crops_helper.push_back(all_crops[i]);
8534 all_crops.erase(all_crops.begin() + i);
8537 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8539 all_crops_helper.push_back(all_crops[i]);
8540 all_crops.erase(all_crops.begin() + i);
8543 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8545 all_crops_helper.push_back(all_crops[i]);
8546 all_crops.erase(all_crops.begin() + i);
8549 for(
int i = 0; i<(int)all_crops.size(); i++){
8551 all_crops_helper.push_back(all_crops[i]);
8552 all_crops.erase(all_crops.begin() + i);
8555 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8557 all_crops_helper.push_back(all_crops[i]);
8558 all_crops.erase(all_crops.begin() + i);
8561 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8563 all_crops_helper.push_back(all_crops[i]);
8564 all_crops.erase(all_crops.begin() + i);
8567 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8569 all_crops_helper.push_back(all_crops[i]);
8570 all_crops.erase(all_crops.begin() + i);
8573 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8575 all_crops_helper.push_back(all_crops[i]);
8576 all_crops.erase(all_crops.begin() + i);
8579 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8581 all_crops_helper.push_back(all_crops[i]);
8582 all_crops.erase(all_crops.begin() + i);
8586 for(
int i = (
int)all_crops.size()-1; i>=0; i--){
8588 all_crops_helper.push_back(all_crops[i]);
8589 all_crops.erase(all_crops.begin() + i);
8594 for(
int i = 0; i<(int)all_crops.size(); i++){
8595 all_crops_helper.push_back(all_crops[i]);
8599 if(all_crops_helper.size()!=100){
8600 if(all_crops_helper.size()>100){
8601 for(
int i = (
int)all_crops_helper.size(); i>100; i--){
8602 all_crops_helper.erase(all_crops_helper.end()-1);
8606 for(
int i = (
int)all_crops_helper.size(); i<100; i++){
8614 all_crops = all_crops_helper;
8618 for(
int i = 0; i<(int)rotation.size(); i++){
8625 for(
int i = 0; i < (int)all_crops.size(); i++){
8632 int step=no_rotational;
8635 for(
int j = pp; count<101 && test==
false; j=j+step){
8637 if (crop_index ==
tov_SpringBarley && sb_area > (100/step)) step = (int)(100/sb_area + 0.5);
8643 if(!(rotation[j].taken)){
8647 crop_before = (j==0) ? rotation[99].Tov : rotation[j-1].Tov;
8648 crop_after = (j==99) ? rotation[0].Tov : rotation[j+1].Tov;
8653 if(lookup_before==-1 || lookup_after==-1){
8655 sprintf( index,
"%d", crop_index);
8656 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 );
8660 if(lookup_before==1 && lookup_after==1){
8661 rotation[j].Tov = all_crops[i];
8662 rotation[j].taken =
true;
8677 for(
int r=0; r<(int)rotation.size() && test==
false; r++){
8681 crop_before = rotation[r].Tov;
8682 crop_after = (r==99) ? rotation[0].Tov : rotation[r+1].Tov;
8686 if(lookup_before==1 && lookup_after==1){
8688 rotation.insert(rotation.begin() + r+1, crop);
8694 for(
int p=(
int)rotation.size()-1; p>=0; p--){
8696 rotation.erase(rotation.begin() + p);
8698 crop_before = (p==0) ? rotation[99].Tov : rotation[p-1].Tov;
8699 crop_after = (p==100) ? rotation[0].Tov : rotation[p].Tov;
8700 int crop_after_position = (p==100) ? 0 : p;
8706 int crop_before2_position = 0;
8709 while(lookup_before!=1){
8718 sprintf( index,
"%d", problem_crop);
8719 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Make_rotations(): The following crop was changed to spring barley: ", index );
8723 crop_index = crop_after;
8725 for(
int t=0; t<(int)rotation.size() && test2==
false; t++){
8726 crop_before1 = rotation[t].Tov;
8727 crop_after1 = (t==99) ? rotation[0].Tov : rotation[t+1].Tov;
8731 if(lookup_before1==1 && lookup_after1==1){
8735 for(
int s=crop_after_position; s!=t+1; s++){
8748 rotation.insert(rotation.begin() + t+1, crop);
8751 if(t+1 > crop_after_position){
8752 rotation.erase(rotation.begin() + crop_after_position);
8753 crop_before2 = (crop_after_position==0) ? rotation[99].Tov : rotation[crop_after_position-1].Tov;
8754 crop_before2_position = (crop_after_position==0) ? 99 : crop_after_position-1;
8755 crop_after = (crop_after_position==99) ? rotation[0].Tov : rotation[crop_after_position].Tov;
8756 crop_after_position = (crop_after_position==99) ? 0 : crop_after_position;
8760 rotation.erase(rotation.begin() + crop_after_position + 1);
8761 crop_before2 = (crop_after_position==0) ? rotation[99].Tov : rotation[crop_after_position].Tov;
8762 crop_before2_position = (crop_after_position==0) ? 99 : crop_after_position;
8763 crop_after = (crop_after_position==99) ? rotation[0].Tov : rotation[crop_after_position+1].Tov;
8764 crop_after_position = (crop_after_position==99) ? 0 : crop_after_position+1;
8784 sprintf( index,
"%d", crop_index);
8786 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Make_rotations(): The following tov type cannot be assigned a place in the rotation: ", index );
8795 for(
int i=0; i<100; i++){
8814 vector<TTypesOfVegetation> veg_type;
8827 for(
int i=0; i<(int)
m_fields.size(); i++){
8831 double biomass=0;
double area=0;
double yield_loss_pest=0;
double no_herb_app=0;
double no_fi_app=0;
8832 double unit_loss_herb=0;
double unit_loss_fi=0;
8833 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;
8834 double yield_exp=0;
double yield_ratio=0;
double income_exp=0;
double costs_exp=0;
double profit_exp=0;
8835 double sellingPrice=0;
double priceHerb=0;
double priceFi=0;
double priceLM=0;
double priceH=0;
double priceW=0;
double priceG=0;
double subsidy=0;
8836 double no_missed_herb_app, no_missed_fi_app = 0;
8837 double fert_applied=0;
double fert_opt=0;
double fert_trade=0;
double beta1=0;
double beta2=0;
double alfaH=0;
double alfaFI=0;
8838 double yield_factor = 0;
8841 int cropDataStorage_index=-1;
8845 cropDataStorage_index = 1;
8849 cropDataStorage_index = 0;
8850 if(crop_data.
taken==
false){
8851 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::ActualProfit(): There is no crop data in the fields m_CropDataStorage",
"" );
8862 bool do_accounting =
true;
8863 if(cropDataStorage_index==0){
8869 do_accounting =
false;
8874 area = crop_data.
area * 0.0001;
8879 unit_loss_herb = betaH/100/2;
8880 unit_loss_fi = alfaFI/100;
8885 unit_loss_herb = alfaH/100;
8886 unit_loss_fi = alfaFI/100;
8891 std::random_device rd;
8892 std::normal_distribution<double> dist(1, 0.2);
8893 std::mt19937 engine(rd());
8894 double r_number_1 = dist(engine);
8895 double r_number_2 = dist(engine);
8901 yield_loss_pest = no_missed_herb_app * unit_loss_herb * r_number_1 + no_missed_fi_app * unit_loss_fi * r_number_2;
8917 yield_ha = (biomass==-1)? dd : biomass;
8918 yield_ha *= yield_factor;
8920 yield_ha -= (1 - fert_applied/fert_opt) * (beta1 * fert_opt + beta2 * fert_opt*fert_opt);
8922 yield_ha *= (1-yield_loss_pest);
8967 income_ha = yield_ha * sellingPrice + subsidy;
8968 income = income_ha * area;
8971 costs_ha = no_herb_app*priceHerb + no_fi_app*priceFi + grooming*priceG + hoeing*priceH + weeding*priceW + fert_trade*priceNt+ priceLM;
8972 costs = costs_ha * area;
8975 profit_ha = income_ha - costs_ha;
8976 profit = profit_ha * area;
8981 yield_ratio = yield_ha/yield_exp;
9004 if (fodder) income_exp = subsidy;
9005 else income_exp = (sellingPrice_lastyr*resp*(1-totalLoss/100)+subsidy)*area;
9008 profit_exp = income_exp - costs_exp;
9019 g_msg->
Warn(
"OptimisingFarm::ActualProfit(): There was no accounting for tov: ", crop);
9027 int index_for_croptotals=0;
9029 for(
int k = 0; k<size; k++){
9031 if(crop_type == crop){
9032 index_for_croptotals = k;
9062 ofstream ofile (
"Economic_figures.txt", ios::app);
9067 ofile << endl <<endl;
9081 min_need_satisfaction1 = 100;
9082 min_need_satisfaction2 = 100;
9122 double avrg_animals_no = 0;
9185 crop_to_grow = current_crop;
9195 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): rot crops vector is empty! Farm no: ", index );
9222 bool other_crop_than_cgg =
false;
9226 other_crop_than_cgg =
true;
9230 if (!other_crop_than_cgg){
9235 bool Sb_inserted=
false;
9239 vector<int>probability_line;
9240 probability_line.push_back(0);
9244 probability_line.push_back(area + (
int)probability_line[probability_line.size() - 1]);
9249 std::random_device rd;
9250 std::mt19937 gen(rd());
9251 int last_number = probability_line[(int)probability_line.size() - 1];
9253 double crop_index = 0;
9257 bool crop_found =
false;
9258 for(
int c = 0; !crop_found; c++){
9259 crop_index = dis(gen);
9261 for(
int j=0; j < (int)probability_line.size(); j++){
9262 if(j==(
int)probability_line.size()-1) {
9265 sprintf( index,
"%d", (
int) crop_index);
9266 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): no crops left, index drawn is ", index );
9271 sprintf( index,
"%d", (
int) crop_index);
9272 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): index not found in the prob. line", index );
9276 if(crop_index >= probability_line[j] && crop_index < probability_line[j+1]) {
9279 sprintf( index,
"%d", j);
9280 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): index out of a range", index );
9291 if(lookup_before==-1){
9293 sprintf( index,
"%d", current_crop);
9294 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 );
9297 if(lookup_before==1){
9299 bool WRape_grown =
false;
9302 for(
int w=0; w<(int)
m_fields.size(); w++){
9310 if(diff <= 20 && !WRape_grown){
9323 if(c==1000 && !crop_found){
9325 probability_line.clear();
9326 probability_line.push_back(0);
9330 probability_line.push_back(area + (
int)probability_line[probability_line.size() - 1]);
9333 last_number = probability_line[(int)probability_line.size() - 1];
9339 sprintf( index,
"%d", current_crop);
9340 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 );
9357 sprintf( index,
"%d", current_crop);
9358 g_msg->
Warn(
WARN_BUG,
"OptimisingFarm::Match_crop_to_field(): m_rotational_crops_copy is empty, the crop chosen is: ", index );
9369 int position_in_mrotation=-1;
9372 for(
int c=0; c< (int)
m_rotation.size(); c++){
9374 position_in_mrotation=c;
9379 if(position_in_mrotation==-1){
9380 char error_num[ 20 ];
9381 sprintf( error_num,
"%d", crop_to_grow );
9382 g_msg->
Warn(
WARN_FILE,
"OptimisingFarm::Match_crop_to_field(): ""Unknown vegetation type:", error_num );
9386 if(position_in_mrotation!=0){
9403 for (
int i = 0; i < nf; i++ )
9405 if (
m_fields[ i ]->GetOpenness() >= a_openness )
9407 p_list->push_back(
m_fields[i]->GetPoly());