From 5a5ccb2dfd20dcc2e59058088884675cdac6c65a Mon Sep 17 00:00:00 2001 From: Peter Alexander <peter@blackhillock.co.uk> Date: Sun, 17 Mar 2019 14:15:42 +0000 Subject: [PATCH] Trying to get the feed amount vaguely correct with profit max --- GAMS/LUOpt.gms | 73 +++++++++---------- data/base_demand_fracts.csv | 40 ++++++---- debug_config.properties | 8 +- src/ac/ed/lurg/ModelConfig.java | 2 +- .../ed/lurg/country/AbstractCountryAgent.java | 2 + src/ac/ed/lurg/country/CountryAgent.java | 22 +++--- src/ac/ed/lurg/country/TradeConstraint.java | 19 +++++ .../country/TradeOrProductionConstraint.java | 30 -------- .../lurg/country/gams/GamsCountryInput.java | 20 ++--- .../country/gams/GamsLocationOptimiser.java | 28 +++---- 10 files changed, 116 insertions(+), 128 deletions(-) create mode 100644 src/ac/ed/lurg/country/TradeConstraint.java delete mode 100644 src/ac/ed/lurg/country/TradeOrProductionConstraint.java diff --git a/GAMS/LUOpt.gms b/GAMS/LUOpt.gms index 5b03aa48..e3af85e3 100644 --- a/GAMS/LUOpt.gms +++ b/GAMS/LUOpt.gms @@ -1,11 +1,11 @@ SET all_types / monogastrics, ruminants, cereals, oilcropspulses, wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, pasture, setaside /; - SET crop(all_types) / wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, pasture, setaside /; - SET crop_less_pasture(crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, setaside/; - SET feed_crop(crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots, pasture/; - SET feed_crop_less_pasture(feed_crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots /; - SET traded_commodity(all_types) / monogastrics, ruminants, wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops /; - SET non_traded(all_types) / cereals, oilcropspulses, pasture, setaside /; + SET crop(all_types) / wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, pasture, setaside /; + SET crop_less_pasture(crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, setaside/; + SET feed_crop(crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, pasture/; + SET feed_crop_less_pasture(feed_crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg /; + SET traded_commodity(all_types) / monogastrics, ruminants, wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops /; + SET non_traded(all_types) / cereals, oilcropspulses, pasture, setaside /; SET animal_product(all_types) / monogastrics, ruminants /; SET cereal_crop(crop) / wheat, maize, rice /; @@ -30,8 +30,8 @@ PARAMETER demand(all_types) in t; PARAMETER exportPrices(traded_commodity) prices for exports and domestic farmgate price; PARAMETER importPrices(traded_commodity) prices for imports; - PARAMETER maxProduction(all_types) maximum Production crop based domestic demand and net imports; - PARAMETER minProduction(all_types) minimum Production crop based domestic demand and net imports; + PARAMETER maxNetImport(all_types) maximum Production crop based domestic demand and net imports; + PARAMETER minNetImport(all_types) minimum Production crop based domestic demand and net imports; PARAMETER irrigCost(location) irrigation cost in cost per 1000 Mlitre or Mha for each litre per m2; PARAMETER irrigMaxRate(crop, location) max water application rate irrigation in litre per m2; PARAMETER irrigConstraint(location) max water available for irrigation in litre per m2; @@ -61,7 +61,7 @@ $gdxin %gdxincname% $load location, suitableLandArea, demand, agriExpansionCost, cropIncCost, pastureIncCost, cropDecCost, pastureDecCost $load previousArea, previousFertIntensity, previousIrrigIntensity, previousOtherIntensity, previousRuminantFeed, previousMonogastricFeed, previousImportAmount, previousExportAmount $load yieldNone, yieldFertOnly, yieldIrrigOnly, yieldBoth -$load fertParam, irrigParam, otherIParam, exportPrices, importPrices, maxProduction, minProduction, unhandledCropRate, setAsideRate, maxLandExpansionRate, subsidyRate +$load fertParam, irrigParam, otherIParam, exportPrices, importPrices, maxNetImport, minNetImport, unhandledCropRate, setAsideRate, maxLandExpansionRate, subsidyRate $load meatEfficency, otherICost, irrigCost, irrigMaxRate, irrigConstraint, fertiliserUnitCost, domesticPriceMarkup, minDemandPerCereal, minDemandPerOilcrop, seedAndWasteRate, animalFeedFromOtherSources $gdxin @@ -111,11 +111,11 @@ $gdxin fertI(crop, location) fertilizer intensity for each crop - factor between 0 and 1 irrigI(crop, location) irrigation intensity for each crop - factor between 0 and 1 otherIntensity(crop, location) - ruminantFeed(crop) amount of feed for ruminant animals - Mt - monogastricFeed(crop) amount of feed for monogatric animals - Mt - importForFeed(all_types) imports of crops and meat - not allowed to be negative - Mt - export(traded_commodity) amount of commodities exported - not allowed to be negative - domesticallyProducedFoodSupply(all_types) net domestically produced food after feed use - Mt + ruminantFeed(all_types) amount of feed for ruminant animals - Mt + monogastricFeed(all_types) amount of feed for monogatric animals - Mt + export(traded_commodity) amount of commodities exported + import(all_types) amount of commodities import + netFoodSupply(all_types) net supply in a country for food - Mt domesticallyMetDemand(traded_commodity) amount domestically produced and consumed as food - Mt yield(crop, location) yield per area for each crop - t per ha unitCost(crop, location) cost per area for each crop - cost @@ -130,19 +130,19 @@ $gdxin POSITIVE VARIABLE area, fertI, irrigI, otherIntensity, ruminantFeed, monogastricFeed, production, agriLandExpansion, cropIncrease, cropDecrease, pastureDecrease, pastureIncrease, totalFeedDM, - importForFeed, export, domesticallyProducedFoodSupply, domesticallyMetDemand; + export, import, netFoodSupply, domesticallyMetDemand; EQUATIONS UNIT_COST_EQ(crop, location) cost per area YIELD_EQ(crop, location) yield given chosen intensity DOMESTICALLY_MET_DEMAND_CONSTRAINT1(traded_commodity) constraint on commodity produced and consumed domestically DOMESTICALLY_MET_DEMAND_CONSTRAINT2(traded_commodity) constraint on commodity produced and consumed domestically - EXPORT_CALC(traded_commodity) calc exports for each traded commodity does not go negative for imports + EXPORT_CALC(traded_commodity) calc exports for each traded commodity + IMPORT_CALC(traded_commodity) calc imports for each traded commodity CROP_PROD_EQ(crop) calc total production for crops RUMINANT_PROD_EQ production of ruminant MONOGASTRICS_PROD_EQ production of monogastric - CROP_NET_PROD_EQ(crop) calc net production for crops - ANIMAL_NET_PROD_EQ(animal_product) calc net production for animal products + NET_FOOD_SUPPLY_EQ(all_types) calc net production for crops TOTAL_NON_PASTURE_FEED_DM_CALC calc total feed dry matter not including pasture FEED_MIX_CONSTRAINT(feed_crop_less_pasture) limit amount of feed for each feed crop MAX_FERT_INTENSITY_CONSTRAINT(crop, location) constraint on maximum fertilizer intensity @@ -150,10 +150,8 @@ $gdxin MAX_OTHER_INTENSITY_CONSTRAINT(crop, location) SETASIDE_AREA_CALC(location) TOTAL_LAND_CHANGE_CONSTRAINT(location) constraint on suitable land use - CROP_MAX_PROD_CONSTRAINT(crop_less_pasture) constraint on max production for crops - CROP_MIN_PROD_CONSTRAINT(crop_less_pasture) constraint on min production for crops - ANIMAL_MAX_PROD_CONSTRAINT(animal_product) constraint on max production for animal product - ANIMAL_MIN_PROD_CONSTRAINT(animal_product) constraint on min production for animal products + MAX_NET_IMPORT_CONSTRAINT(traded_commodity) constraint on max net imports + MIN_NET_IMPORT_CONSTRAINT(traded_commodity) constraint on min net imports IRRIGATION_CONSTRAINT(location) constraint no water usage AGRI_LAND_EXPANSION_CALC(location) calc agriLandExpansion CROP_INCREASE_CALC(location) @@ -183,16 +181,16 @@ $gdxin RUMINANT_PROD_EQ .. production('ruminants') =L= meatEfficency*(sum(feed_crop, ruminantFeed(feed_crop) * cropDM(feed_crop)) + ruminantOtherFeed); MONOGASTRICS_PROD_EQ .. production('monogastrics') =L= meatEfficency*(sum(feed_crop_less_pasture, monogastricFeed(feed_crop_less_pasture) * cropDM(feed_crop_less_pasture)) + monogastricOtherFeed); - CROP_NET_PROD_EQ(crop) .. domesticallyProducedFoodSupply(crop) =E= production(crop) * (1 - seedAndWasteRate(crop)) - ruminantFeed(crop) - monogastricFeed(crop) + importForFeed(crop); - ANIMAL_NET_PROD_EQ(animal_product) .. domesticallyProducedFoodSupply(animal_product) =E= production(animal_product) * (1 - seedAndWasteRate(animal_product)); + NET_FOOD_SUPPLY_EQ(all_types) .. netFoodSupply(all_types) =E= production(all_types) * (1 - seedAndWasteRate(all_types)) - ruminantFeed(all_types) - monogastricFeed(all_types) + import(all_types); -* This set of 3 equations used to divide commodities between domestic produced/consumed valued at import prices and those for export valued at export prices - DOMESTICALLY_MET_DEMAND_CONSTRAINT1(traded_commodity) .. domesticallyMetDemand(traded_commodity) =L= domesticallyProducedFoodSupply(traded_commodity); +* This set of 4 equations used to divide commodities between domestic produced/consumed valued at import prices and those for export valued at export prices + DOMESTICALLY_MET_DEMAND_CONSTRAINT1(traded_commodity) .. domesticallyMetDemand(traded_commodity) =L= netFoodSupply(traded_commodity); DOMESTICALLY_MET_DEMAND_CONSTRAINT2(traded_commodity) .. domesticallyMetDemand(traded_commodity) =L= demand(traded_commodity); - EXPORT_CALC(traded_commodity) .. export(traded_commodity) =L= domesticallyProducedFoodSupply(traded_commodity) - domesticallyMetDemand(traded_commodity); + EXPORT_CALC(traded_commodity) .. export(traded_commodity) =L= netFoodSupply(traded_commodity) - domesticallyMetDemand(traded_commodity); + IMPORT_CALC(traded_commodity) .. netFoodSupply(traded_commodity) =G= demand(traded_commodity); TOTAL_NON_PASTURE_FEED_DM_CALC .. totalFeedDM =E= sum(feed_crop_less_pasture, (ruminantFeed(feed_crop_less_pasture) + monogastricFeed(feed_crop_less_pasture)) * cropDM(feed_crop_less_pasture)); - FEED_MIX_CONSTRAINT(feed_crop_less_pasture) .. (ruminantFeed(feed_crop_less_pasture) + monogastricFeed(feed_crop_less_pasture)) * cropDM(feed_crop_less_pasture) =L= totalFeedDM * 0.7; + FEED_MIX_CONSTRAINT(feed_crop_less_pasture) .. (ruminantFeed(feed_crop_less_pasture) + monogastricFeed(feed_crop_less_pasture)) * cropDM(feed_crop_less_pasture) =L= totalFeedDM * 0.6; MAX_FERT_INTENSITY_CONSTRAINT(crop, location) .. fertI(crop, location) =L= 1; MAX_IRRIG_INTENSITY_CONSTRAINT(crop, location) .. irrigI(crop, location) =L= 1; @@ -201,11 +199,10 @@ $gdxin TOTAL_LAND_CHANGE_CONSTRAINT(location) .. suitableLandArea(location) =G= sum(crop_less_pasture, area(crop_less_pasture, location)) / (1.0 - unhandledCropRate) + area('pasture', location); SETASIDE_AREA_CALC(location) .. area('setaside', location) =E= sum(crop_less_pasture, area(crop_less_pasture, location)) * setAsideRate; - CROP_MAX_PROD_CONSTRAINT(crop_less_pasture) .. production(crop_less_pasture) =L= maxProduction(crop_less_pasture); - CROP_MIN_PROD_CONSTRAINT(crop_less_pasture) .. production(crop_less_pasture) =G= minProduction(crop_less_pasture); - PASTURE_FEED_CONSTRAINT .. production('pasture') =E= ruminantFeed('pasture'); - ANIMAL_MAX_PROD_CONSTRAINT(animal_product) .. production(animal_product) =L= maxProduction(animal_product); - ANIMAL_MIN_PROD_CONSTRAINT(animal_product) .. production(animal_product) =G= minProduction(animal_product); + PASTURE_FEED_CONSTRAINT .. production('pasture') =G= ruminantFeed('pasture'); + + MAX_NET_IMPORT_CONSTRAINT(traded_commodity) .. import(traded_commodity) - export(traded_commodity) =L= maxNetImport(traded_commodity); + MIN_NET_IMPORT_CONSTRAINT(traded_commodity) .. import(traded_commodity) - export(traded_commodity) =G= minNetImport(traded_commodity); IRRIGATION_CONSTRAINT(location) .. irrigConstraint(location) * suitableLandArea(location) * (1.0 - unhandledCropRate) =G= sum(crop, irrigMaxRate(crop, location) * irrigI(crop, location) * area(crop, location)); @@ -234,7 +231,7 @@ $gdxin ) ) - - SUM(traded_commodity, importForFeed(traded_commodity) * importPrices(traded_commodity)) + - SUM(traded_commodity, import(traded_commodity) * importPrices(traded_commodity)) ); MODEL LAND_USE /ALL/ ; @@ -244,15 +241,15 @@ $gdxin area.L(crop, location) = previousArea(crop, location); ruminantFeed.L(feed_crop) = previousRuminantFeed(feed_crop); monogastricFeed.L(feed_crop) = previousMonogastricFeed(feed_crop); - importForFeed.L(all_types) = 0; + import.L(traded_commodity) = previousImportAmount(traded_commodity); export.L(traded_commodity) = previousExportAmount(traded_commodity); SOLVE LAND_USE USING NLP MAXIMIZING totalProfit; * display agriLandExpansion.L, previousArea, irrigMaxRate, otherIntensity.L, fertI.L, irrigI.L, area.L, cropIncrease.L, cropDecrease.L, pastureIncrease.L, pastureDecrease.L; * display suitableLandArea, area.l, yield.l, unitCost.l, exportPrices; - display domesticallyProducedFoodSupply.l, demand, domesticallyMetDemand.l, importForFeed.l; - display export.l, production.l, maxProduction, minProduction; + display netFoodSupply.l, demand, domesticallyMetDemand.l; + display export.l, import.l, production.l, maxNetImport, minNetImport; * Calculate summary information used in Java process @@ -271,7 +268,7 @@ $gdxin totalProdCost(crop) = sum(location, unitCost.l(crop, location) * area.l(crop, location)); totalCropland(location) = sum(crop_less_pasture, area.l(crop_less_pasture, location)); totalArea(crop) = sum(location, area.l(crop, location)); - netImportAmount(traded_commodity) = importForFeed.l(traded_commodity) - export.l(traded_commodity); + netImportAmount(traded_commodity) = import.l(traded_commodity) - export.l(traded_commodity); Scalar ms 'model status', ss 'solve status'; ms=LAND_USE.modelstat; diff --git a/data/base_demand_fracts.csv b/data/base_demand_fracts.csv index 3c590e2f..961b493f 100644 --- a/data/base_demand_fracts.csv +++ b/data/base_demand_fracts.csv @@ -126,7 +126,7 @@ Mongolia,Cereals,WheatBarleyOats,0.392417 Montenegro,Cereals,WheatBarleyOats,0.091082 Morocco,Cereals,WheatBarleyOats,6.950021 Mozambique,Cereals,WheatBarleyOats,0.48027 -Myanmar,Cereals,WheatBarleyOats,0.351164 +Myanmar,Cereals,WheatBarleyOats,1.26584557162866 Namibia,Cereals,WheatBarleyOats,0.1262 Nepal,Cereals,WheatBarleyOats,1.389611 Net Food Importing Developing Countries,Cereals,WheatBarleyOats,78.453144 @@ -141,7 +141,7 @@ Northern America,Cereals,WheatBarleyOats,33.437083 Northern Europe,Cereals,WheatBarleyOats,13.613167 Norway,Cereals,WheatBarleyOats,0.645097 Oceania,Cereals,WheatBarleyOats,2.656465 -Oman,Cereals,WheatBarleyOats,0.50776937900122 +Oman,Cereals,WheatBarleyOats,0.209604 Pakistan,Cereals,WheatBarleyOats,20.07921 Panama,Cereals,WheatBarleyOats,0.196152 Paraguay,Cereals,WheatBarleyOats,0.242004 @@ -208,7 +208,9 @@ Yemen,Cereals,WheatBarleyOats,2.760014 Zambia,Cereals,WheatBarleyOats,0.163996 Zimbabwe,Cereals,WheatBarleyOats,0.453568 Libya,Cereals,WheatBarleyOats,1.31097126956357 -Papua New Guinea,Cereals,WheatBarleyOats,0.629823585675712 +Sudan,Cereals,WheatBarleyOats,1.5333379641111 +South Sudan,Cereals,WheatBarleyOats,0.426948541246053 +Somalia,Cereals,WheatBarleyOats,0.406781421407959 Democratic Republic of the Congo,Cereals,WheatBarleyOats,0.691038959410474 Timor-Leste,Cereals,WheatBarleyOats,0.011755 Afghanistan,Cereals,MaizeMilletSorghum,0.0873 @@ -338,7 +340,7 @@ Mongolia,Cereals,MaizeMilletSorghum,0 Montenegro,Cereals,MaizeMilletSorghum,0.000988 Morocco,Cereals,MaizeMilletSorghum,1.190704 Mozambique,Cereals,MaizeMilletSorghum,1.7418 -Myanmar,Cereals,MaizeMilletSorghum,0.249807 +Myanmar,Cereals,MaizeMilletSorghum,0.884494172140235 Namibia,Cereals,MaizeMilletSorghum,0.140749 Nepal,Cereals,MaizeMilletSorghum,1.484332 Net Food Importing Developing Countries,Cereals,MaizeMilletSorghum,58.159378 @@ -353,7 +355,7 @@ Northern America,Cereals,MaizeMilletSorghum,29.702689 Northern Europe,Cereals,MaizeMilletSorghum,1.138397 Norway,Cereals,MaizeMilletSorghum,0.005529 Oceania,Cereals,MaizeMilletSorghum,0.175913 -Oman,Cereals,MaizeMilletSorghum,0.0587958430177354 +Oman,Cereals,MaizeMilletSorghum,0.039892 Pakistan,Cereals,MaizeMilletSorghum,2.860168 Panama,Cereals,MaizeMilletSorghum,0.08997 Paraguay,Cereals,MaizeMilletSorghum,0.467988 @@ -421,7 +423,9 @@ Yemen,Cereals,MaizeMilletSorghum,0.794676 Zambia,Cereals,MaizeMilletSorghum,1.674827 Zimbabwe,Cereals,MaizeMilletSorghum,1.617506 Libya,Cereals,MaizeMilletSorghum,0.0973716319352007 -Papua New Guinea,Cereals,MaizeMilletSorghum,0.0117130927156399 +Sudan,Cereals,MaizeMilletSorghum,3.64268012425896 +South Sudan,Cereals,MaizeMilletSorghum,1.01428191415058 +Somalia,Cereals,MaizeMilletSorghum,0.966371819757027 Democratic Republic of the Congo,Cereals,MaizeMilletSorghum,9.62310189652887 Afghanistan,OilcropsPulses,Oilcrops,0.083876 Africa,OilcropsPulses,Oilcrops,19.576187 @@ -550,7 +554,7 @@ Mongolia,OilcropsPulses,Oilcrops,0.013376 Montenegro,OilcropsPulses,Oilcrops,0.008518 Morocco,OilcropsPulses,Oilcrops,1.252077 Mozambique,OilcropsPulses,Oilcrops,0.579168 -Myanmar,OilcropsPulses,Oilcrops,2.515264 +Myanmar,OilcropsPulses,Oilcrops,4.13929776182578 Namibia,OilcropsPulses,Oilcrops,0.012818 Nepal,OilcropsPulses,Oilcrops,0.394216 Net Food Importing Developing Countries,OilcropsPulses,Oilcrops,23.710884 @@ -565,7 +569,7 @@ Northern America,OilcropsPulses,Oilcrops,15.46324 Northern Europe,OilcropsPulses,Oilcrops,1.809435 Norway,OilcropsPulses,Oilcrops,0.088969 Oceania,OilcropsPulses,Oilcrops,1.83022 -Oman,OilcropsPulses,Oilcrops,0.0537593802409762 +Oman,OilcropsPulses,Oilcrops,0.019556 Pakistan,OilcropsPulses,Oilcrops,3.520063 Panama,OilcropsPulses,Oilcrops,0.056962 Paraguay,OilcropsPulses,Oilcrops,0.223116 @@ -633,7 +637,9 @@ Yemen,OilcropsPulses,Oilcrops,0.057439 Zambia,OilcropsPulses,Oilcrops,0.248531 Zimbabwe,OilcropsPulses,Oilcrops,0.31121 Libya,OilcropsPulses,Oilcrops,0.167110314617429 -Papua New Guinea,OilcropsPulses,Oilcrops,0.86961949806966 +Sudan,OilcropsPulses,Oilcrops,0.994733472591395 +South Sudan,OilcropsPulses,Oilcrops,0.276977427672133 +Somalia,OilcropsPulses,Oilcrops,0.263894265565503 Democratic Republic of the Congo,OilcropsPulses,Oilcrops,1.04157644949363 Afghanistan,OilcropsPulses,Pulses,0.080919 Africa,OilcropsPulses,Pulses,10.458633 @@ -762,7 +768,7 @@ Mongolia,OilcropsPulses,Pulses,0.001387 Montenegro,OilcropsPulses,Pulses,0.003616 Morocco,OilcropsPulses,Pulses,0.223557 Mozambique,OilcropsPulses,Pulses,0.330317 -Myanmar,OilcropsPulses,Pulses,0.807939 +Myanmar,OilcropsPulses,Pulses,0.944132554052644 Namibia,OilcropsPulses,Pulses,0.016749 Nepal,OilcropsPulses,Pulses,0.288435 Net Food Importing Developing Countries,OilcropsPulses,Pulses,12.467568 @@ -777,7 +783,7 @@ Northern America,OilcropsPulses,Pulses,1.406157 Northern Europe,OilcropsPulses,Pulses,0.235764 Norway,OilcropsPulses,Pulses,0.020828 Oceania,OilcropsPulses,Pulses,0.127048 -Oman,OilcropsPulses,Pulses,0.0291890308961707 +Oman,OilcropsPulses,Pulses,0.01291 Pakistan,OilcropsPulses,Pulses,1.126194 Panama,OilcropsPulses,Pulses,0.020079 Paraguay,OilcropsPulses,Pulses,0.056177 @@ -845,7 +851,9 @@ Yemen,OilcropsPulses,Pulses,0.129406 Zambia,OilcropsPulses,Pulses,0.025203 Zimbabwe,OilcropsPulses,Pulses,0.056333 Libya,OilcropsPulses,Pulses,0.0521064832216307 -Papua New Guinea,OilcropsPulses,Pulses,0.0717994269319683 +Sudan,OilcropsPulses,Pulses,0.305185230162028 +South Sudan,OilcropsPulses,Pulses,0.084976953468347 +Somalia,OilcropsPulses,Pulses,0.080963026171463 Democratic Republic of the Congo,OilcropsPulses,Pulses,1.27407015630048 Afghanistan,Cereals,Rice (Paddy Equivalent),0.713046 Africa,Cereals,Rice (Paddy Equivalent),33.758311 @@ -974,7 +982,7 @@ Mongolia,Cereals,Rice (Paddy Equivalent),0.020827 Montenegro,Cereals,Rice (Paddy Equivalent),0.00202 Morocco,Cereals,Rice (Paddy Equivalent),0.028609 Mozambique,Cereals,Rice (Paddy Equivalent),0.796138 -Myanmar,Cereals,Rice (Paddy Equivalent),13.816741 +Myanmar,Cereals,Rice (Paddy Equivalent),23.3927880678706 Namibia,Cereals,Rice (Paddy Equivalent),0.012858 Nepal,Cereals,Rice (Paddy Equivalent),3.531217 Net Food Importing Developing Countries,Cereals,Rice (Paddy Equivalent),99.400694 @@ -989,7 +997,7 @@ Northern America,Cereals,Rice (Paddy Equivalent),4.659713 Northern Europe,Cereals,Rice (Paddy Equivalent),0.909902 Norway,Cereals,Rice (Paddy Equivalent),0.035101 Oceania,Cereals,Rice (Paddy Equivalent),0.571926 -Oman,Cereals,Rice (Paddy Equivalent),0.52943267608964 +Oman,Cereals,Rice (Paddy Equivalent),0.240534 Pakistan,Cereals,Rice (Paddy Equivalent),3.279105 Panama,Cereals,Rice (Paddy Equivalent),0.352758 Paraguay,Cereals,Rice (Paddy Equivalent),0.053911 @@ -1057,5 +1065,7 @@ Yemen,Cereals,Rice (Paddy Equivalent),0.520942 Zambia,Cereals,Rice (Paddy Equivalent),0.054526 Zimbabwe,Cereals,Rice (Paddy Equivalent),0.186916 Libya,Cereals,Rice (Paddy Equivalent),0.0209684541909016 -Papua New Guinea,Cereals,Rice (Paddy Equivalent),0.479153877745502 +Sudan,Cereals,Rice (Paddy Equivalent),0.473795173155122 +South Sudan,Cereals,Rice (Paddy Equivalent),0.131925356811516 +Somalia,Cereals,Rice (Paddy Equivalent),0.125693799086231 Democratic Republic of the Congo,Cereals,Rice (Paddy Equivalent),0.49086320378312 diff --git a/debug_config.properties b/debug_config.properties index 2d5393c8..4aca2c31 100644 --- a/debug_config.properties +++ b/debug_config.properties @@ -1,8 +1,9 @@ BASE_DIR=.. -YIELD_DIR=/Users/peteralexander/Documents/LURG/LPJ/LPJGPLUM_expt1.1_2006-2100_PLUM6xtra_20180412171654/rcp60 +YIELD_DIR=/Users/peteralexander/Documents/LURG/LPJ/LPJGPLUM_remap6p7_20190225/rcp26 +YIELD_FILENAME=yield.out -DEBUG_LIMIT_COUNTRIES=true +DEBUG_LIMIT_COUNTRIES=false DEBUG_COUNTRY_NAME=Brazil IS_CALIBRATION_RUN = true @@ -25,5 +26,4 @@ GAMS_COUNTRY_TO_SAVE=Brazil SSP_SCENARIO=SSP2_v9_130325 MARKET_ADJ_PRICE=false -DONT_REBASE_DEMAND=false -INITAL_PRICE_OILCROPS=0.169 \ No newline at end of file +DONT_REBASE_DEMAND=false \ No newline at end of file diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index 7b19ea46..3eb61b2b 100755 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -201,7 +201,7 @@ public class ModelConfig { public static final double INITAL_PRICE_RICE = getDoubleProperty("INITAL_PRICE_RICE", 0.182 * ModelConfig.INITIAL_PRICE_SHIFT); public static final double INITAL_PRICE_OILCROPS = getDoubleProperty("INITAL_PRICE_OILCROPS", (0.820 * .4 + 0.314 * .6) * 0.3 * ModelConfig.INITIAL_PRICE_SHIFT); public static final double INITAL_PRICE_PULSES = getDoubleProperty("INITAL_PRICE_PULSES", 0.4 * ModelConfig.INITIAL_PRICE_SHIFT); - public static final double INITAL_PRICE_STARCHYROOTS = getDoubleProperty("INITAL_PRICE_STARCHYROOTS", 0.1 * ModelConfig.INITIAL_PRICE_SHIFT); + public static final double INITAL_PRICE_STARCHYROOTS = getDoubleProperty("INITAL_PRICE_STARCHYROOTS", 0.2 * ModelConfig.INITIAL_PRICE_SHIFT); public static final double INITAL_PRICE_MONOGASTRICS = getDoubleProperty("INITAL_PRICE_MONOGASTRICS", 0.4 * 0.5 * ModelConfig.INITIAL_PRICE_SHIFT); // quantities is in feed equivalent term (0.4 is weighted average price per feed, and 0.5 accounts for mark-up for additional processing) public static final double INITAL_PRICE_RUMINANTS = getDoubleProperty("INITAL_PRICE_RUMINANTS", 0.1 * 0.6 * ModelConfig.INITIAL_PRICE_SHIFT); // quantities is in feed equivalent term public static final double INITAL_PRICE_ENERGYCROPS = getDoubleProperty("INITAL_PRICE_ENERGYCROPS", 0.04 * ModelConfig.INITIAL_PRICE_SHIFT); diff --git a/src/ac/ed/lurg/country/AbstractCountryAgent.java b/src/ac/ed/lurg/country/AbstractCountryAgent.java index 0f2bb225..22ef64ec 100644 --- a/src/ac/ed/lurg/country/AbstractCountryAgent.java +++ b/src/ac/ed/lurg/country/AbstractCountryAgent.java @@ -75,6 +75,8 @@ public abstract class AbstractCountryAgent { private double getCommPriceFromCropPrice(CommodityType commodity) { double commPricePlum = 0; Map<CropType, Double> demandFract = baseDemandFact.get(commodity); + if (commodity.equals(CommodityType.OILCROPSPULSES) || commodity.equals(CommodityType.CEREALS)) + LogWriter.println("Got one to debug"); for (CropType crop : commodity.getCropTypes()) { commPricePlum += currentCountryPrices.get(crop).getImportPrice() * demandFract.get(crop); // weight price by base demand of each cereal crop diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index 587af6b6..0d1294cd 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -174,32 +174,28 @@ public class CountryAgent extends AbstractCountryAgent { allowedImportChange = ModelConfig.MAX_IMPORT_CHANGE; // when running is calibration model calibrate (ModelConfig.IS_CALIBRATION_RUN==true) MAX_IMPORT_CHANGE is already 0. } - Map<CropType, TradeOrProductionConstraint> importConstraints = new HashMap<CropType, TradeOrProductionConstraint>(); + Map<CropType, TradeConstraint> importConstraints = new HashMap<CropType, TradeConstraint>(); for (Map.Entry<CropType, CropUsageData> entry : previousGamsRasterOutput.getCropUsageData().entrySet()) { CropUsageData cropUsage = entry.getValue(); CropType crop = entry.getKey(); - double baseTradeOrProd = (ModelConfig.ORIG_LEAST_COST_MIN) ? cropUsage.getNetImports() : cropUsage.getProduction(); + double baseTrade = cropUsage.getNetImports(); double changeUp = 0.0; double changeDown = 0.0; if (allowedImportChange > 0.0) { - double maxOfProdOrSupply = ModelConfig.ORIG_LEAST_COST_MIN ? - (cropUsage.getProduction() + Math.max(baseTradeOrProd, 0)) : - Math.max(cropUsage.getNetImports() + baseTradeOrProd, baseTradeOrProd); //max of supply for food + double maxOfProdOrSupply = cropUsage.getProduction() + Math.max(baseTrade, 0); //max of supply for food - //max of supply overall, needed for when imports are supplying feed and change is zero to allow for production to replace imports - if (maxOfProdOrSupply == 0) maxOfProdOrSupply = Math.max(cropUsage.getNetImports() + cropUsage.getProduction() , cropUsage.getProduction() ); + // max of supply overall, needed for when imports are supplying feed and change is zero to allow for production to replace imports + // CONFUSING NOT SURE IF NEEDED if (maxOfProdOrSupply == 0) maxOfProdOrSupply = Math.max(cropUsage.getNetImports() + cropUsage.getProduction() , cropUsage.getProduction()); changeDown = changeUp = allowedImportChange * maxOfProdOrSupply; - - } if (CropType.ENERGY_CROPS.equals(crop)) { double croplandArea = LandUseItem.getTotalLandCover(previousGamsRasterOutput.getLandUses().values(), LandCoverType.CROPLAND); double ecMaxExport = gen2EcIncrease * croplandArea / 1500.0 * 2; if (ModelConfig.IS_CALIBRATION_RUN) { - baseTradeOrProd = 0.0; + baseTrade = 0.0; ecMaxExport = 0.0; } if (ModelConfig.ORIG_LEAST_COST_MIN) @@ -207,11 +203,11 @@ public class CountryAgent extends AbstractCountryAgent { else changeUp = ecMaxExport; - if (Double.isNaN(baseTradeOrProd)) - baseTradeOrProd=0; + if (Double.isNaN(baseTrade)) + baseTrade=0; } - importConstraints.put(crop, new TradeOrProductionConstraint(baseTradeOrProd - changeDown, baseTradeOrProd + changeUp, ModelConfig.ORIG_LEAST_COST_MIN)); + importConstraints.put(crop, new TradeConstraint(baseTrade - changeDown, baseTrade + changeUp)); } Map<CommodityType, Map<CropType, Double>> minDemandFract = getMinDemandFraction(currentTimestep); diff --git a/src/ac/ed/lurg/country/TradeConstraint.java b/src/ac/ed/lurg/country/TradeConstraint.java new file mode 100644 index 00000000..c314ab0c --- /dev/null +++ b/src/ac/ed/lurg/country/TradeConstraint.java @@ -0,0 +1,19 @@ +package ac.ed.lurg.country; + +public class TradeConstraint { + private double minValue; + private double maxValue; + + public TradeConstraint(double minValue, double maxValue) { + this.minValue = minValue; + this.maxValue = maxValue; + } + + public double getMinConstraint() { + return minValue; + } + + public double getMaxConstraint() { + return maxValue; + } +} diff --git a/src/ac/ed/lurg/country/TradeOrProductionConstraint.java b/src/ac/ed/lurg/country/TradeOrProductionConstraint.java deleted file mode 100644 index 1c8d57c7..00000000 --- a/src/ac/ed/lurg/country/TradeOrProductionConstraint.java +++ /dev/null @@ -1,30 +0,0 @@ -package ac.ed.lurg.country; - -public class TradeOrProductionConstraint { - private double minValue; - private double maxValue; - - public static final String TRADE_CONSTRAINT = "Trade Constraint"; - public static final String PRODUCTION_CONSTRAINT = "Production Constraint"; - - private String constraintType; - - public TradeOrProductionConstraint(double minValue, double maxValue, boolean isTradeConstraint) { - this.minValue = minValue; - this.maxValue = maxValue; - this.constraintType = isTradeConstraint ? TRADE_CONSTRAINT : PRODUCTION_CONSTRAINT; - } - - public double getMinConstraint() { - return minValue; - } - - public double getMaxConstraint() { - return maxValue; - } - - // perhaps we should do this with multiple classes, but since no different behavior let's not go that way for now - public String getConstraintType() { - return constraintType; - } -} diff --git a/src/ac/ed/lurg/country/gams/GamsCountryInput.java b/src/ac/ed/lurg/country/gams/GamsCountryInput.java index ef00c091..b89b7732 100644 --- a/src/ac/ed/lurg/country/gams/GamsCountryInput.java +++ b/src/ac/ed/lurg/country/gams/GamsCountryInput.java @@ -6,7 +6,7 @@ import java.util.Map; import ac.ed.lurg.ModelConfig; import ac.ed.lurg.country.CompositeCountry; import ac.ed.lurg.country.CountryPrice; -import ac.ed.lurg.country.TradeOrProductionConstraint; +import ac.ed.lurg.country.TradeConstraint; import ac.ed.lurg.landuse.CropUsageData; import ac.ed.lurg.types.CommodityType; import ac.ed.lurg.types.CropType; @@ -15,7 +15,7 @@ public class GamsCountryInput { private CompositeCountry country; // not really required but useful for debugging private Map<CommodityType, Double> projectedDemand; - private Map<CropType, TradeOrProductionConstraint> tradeOrProdConstraints; + private Map<CropType, TradeConstraint> tradeConstraints; private Map<CropType, CountryPrice> countryPrices; private Map<CropType, CropUsageData> previousCropUsageData; private Map<CommodityType, Map<CropType, Double>> minDemandFractions; @@ -23,12 +23,12 @@ public class GamsCountryInput { private Map<CropType, Double> subsidyRates; public GamsCountryInput(CompositeCountry country, Map<CommodityType, Double> projectedDemand, Map<CropType, CountryPrice> countryPrices, - Map<CropType, TradeOrProductionConstraint> importConstraints, Map<CropType, CropUsageData> previousCropUsageData, + Map<CropType, TradeConstraint> importConstraints, Map<CropType, CropUsageData> previousCropUsageData, Map<CommodityType, Map<CropType, Double>> minDemandFracts, double animalFeedFromOtherSources, Map<CropType, Double> subsidyRates) { super(); this.country = country; this.projectedDemand = projectedDemand; - this.tradeOrProdConstraints = importConstraints; + this.tradeConstraints = importConstraints; this.countryPrices = countryPrices; this.previousCropUsageData = previousCropUsageData; this.minDemandFractions = minDemandFracts; @@ -48,8 +48,8 @@ public class GamsCountryInput { return countryPrices; } - public Map<CropType, TradeOrProductionConstraint> getTradeOrProductionConstraints() { - return tradeOrProdConstraints; + public Map<CropType, TradeConstraint> getTradeConstraints() { + return tradeConstraints; } public Map<CropType, CropUsageData> getPreviousCropUsageData() { @@ -62,17 +62,17 @@ public class GamsCountryInput { return ModelConfig.MEAT_EFFICIENCY; // this is already handled by the feed conversion efficiency for each animal product } - public Map<CropType, Double> getMinTradeOrProd() { + public Map<CropType, Double> getMinTrade() { Map<CropType, Double> netImport = new HashMap<CropType, Double>(); - for (Map.Entry<CropType, TradeOrProductionConstraint> entry : tradeOrProdConstraints.entrySet()) { + for (Map.Entry<CropType, TradeConstraint> entry : tradeConstraints.entrySet()) { netImport.put(entry.getKey(), entry.getValue().getMinConstraint()); } return netImport; } - public Map<CropType, Double> getMaxTradeOrProd() { + public Map<CropType, Double> getMaxTrade() { Map<CropType, Double> netImport = new HashMap<CropType, Double>(); - for (Map.Entry<CropType, TradeOrProductionConstraint> entry : tradeOrProdConstraints.entrySet()) { + for (Map.Entry<CropType, TradeConstraint> entry : tradeConstraints.entrySet()) { netImport.put(entry.getKey(), entry.getValue().getMaxConstraint()); } return netImport; diff --git a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java index 18e14627..8dbadd4e 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java @@ -21,7 +21,7 @@ import com.gams.api.GAMSWorkspaceInfo; import ac.ed.lurg.ModelConfig; import ac.ed.lurg.country.CountryPrice; -import ac.ed.lurg.country.TradeOrProductionConstraint; +import ac.ed.lurg.country.TradeConstraint; import ac.ed.lurg.landuse.CropUsageData; import ac.ed.lurg.landuse.Intensity; import ac.ed.lurg.landuse.IrrigationItem; @@ -261,26 +261,20 @@ public class GamsLocationOptimiser { if (DEBUG) LogWriter.println("\nImport-export, min trade/prod, max trade/prod, global import price, global export price, imports, exports, ruminantFeed, monogastricFeed, seedAndWasteRate"); - GAMSParameter minTradeOrProdP = null; - GAMSParameter maxTradeOrProdP = null; - if (ModelConfig.ORIG_LEAST_COST_MIN) { - minTradeOrProdP = inDB.addParameter("minNetImport", 1); - maxTradeOrProdP = inDB.addParameter("maxNetImport", 1); - } - else { - minTradeOrProdP = inDB.addParameter("minProduction", 1); - maxTradeOrProdP = inDB.addParameter("maxProduction", 1); - } + GAMSParameter minTradeP = null; + GAMSParameter maxTradeP = null; + minTradeP = inDB.addParameter("minNetImport", 1); + maxTradeP = inDB.addParameter("maxNetImport", 1); GAMSParameter importPriceP = inDB.addParameter("importPrices", 1); GAMSParameter exportPriceP = inDB.addParameter("exportPrices", 1); for (CropType crop : CropType.getImportedTypes()) { - TradeOrProductionConstraint iec = countryInput.getTradeOrProductionConstraints().get(crop); + TradeConstraint iec = countryInput.getTradeConstraints().get(crop); CountryPrice gp = countryInput.getCountryPrices().get(crop); - double minTradeOrProd = iec.getMinConstraint(); - double maxTradeOrProd = iec.getMaxConstraint(); + double minTrade = iec.getMinConstraint(); + double maxTrade = iec.getMaxConstraint(); double importPrice = gp.getImportPrice(); double exportPrice = gp.getExportPrice(); @@ -294,10 +288,10 @@ public class GamsLocationOptimiser { double seedAndWasteRate = crop.getSeedAndWasteRate(); if (DEBUG) LogWriter.println(String.format(" %15s, \t %5.1f, \t %5.1f, \t %5.3f, \t %5.3f, \t %5.1f, \t %5.1f, \t %5.1f, \t %5.1f, \t %5.3f", - crop.getGamsName(), minTradeOrProd, maxTradeOrProd, importPrice, exportPrice, imports, exports, ruminantFeed, monogastricFeed, seedAndWasteRate)); + crop.getGamsName(), minTrade, maxTrade, importPrice, exportPrice, imports, exports, ruminantFeed, monogastricFeed, seedAndWasteRate)); - setGamsParamValue(minTradeOrProdP.addRecord(crop.getGamsName()), minTradeOrProd, 3); - setGamsParamValue(maxTradeOrProdP.addRecord(crop.getGamsName()), maxTradeOrProd, 3); + setGamsParamValue(minTradeP.addRecord(crop.getGamsName()), minTrade, 3); + setGamsParamValue(maxTradeP.addRecord(crop.getGamsName()), maxTrade, 3); setGamsParamValue(importPriceP.addRecord(crop.getGamsName()), importPrice, 3); setGamsParamValue(exportPriceP.addRecord(crop.getGamsName()), exportPrice, 3); setGamsParamValue(previousImportAmountP.addRecord(crop.getGamsName()), imports, 3); -- GitLab