diff --git a/data/sims/globalShock.csv b/data/sims/globalShock.csv index 1ac9988dd3c6b5e44ad73d0fed0504d6f144957d..1f5efd5483acb6753ea9032b6dcd86bd43c7b8d4 100644 --- a/data/sims/globalShock.csv +++ b/data/sims/globalShock.csv @@ -1,16 +1,16 @@ -Ensemble,Scenario,AGRI_LAND_EXPANSION_COST_FACTOR,ANNUAL_MAX_IMPORT_CHANGE,BIOENERGY_DEMAND_SHIFT,CROP_TO_PASTURE_COST_FACTOR,FERTILISER_COST_PER_T,INITIAL_PRICE_SHIFT,IRRIG_COST_SCALE_FACTOR,IRRIGATION_EFFICIENCY,LAND_CHANGE_COST,MARKET_LAMBA,MEAT_EFFICIENCY,MIN_NATURAL_RATE,OTHER_INTENSITY_COST,PASTURE_HARVEST_FRACTION,SSP_GDP_PC_FACTOR,SSP_POPULATION_FACTOR,SSP_SCENARIO,TECHNOLOGY_CHANGE_ANNUAL_RATE,TRADE_BARRIER_MULTIPLIER,TRANSPORT_COST,RCP,SHOCKS_POSSIBLE,APPLY_EXPORT_TAXES,EXPORT_TAX_RATE,EXPORT_TAX_THRESHOLD,YIELD_DIR_TOP,BIOENERGY_DEMAND_SCENARIO -shocks/noShocks,s1,1,0.02,1,1,1.6,1,0.00035,0.5,0.2,0.4,1,0.1,0.7,0.5,1,1,SSP2_v9_130325,0.002,1,0.05,rcp45,FALSE,FALSE,1,0.1,rcp45,SSP2_RCP45 -shocks/noShocks,s2,1.08270938702243,0.0187532681030967,1.05,0.9,1.72467318969033,0.9,0.000392014778383574,0.491729061297757,0.189688362297416,0.45,0.995864530648878,0.12174185522096,0.679221135051611,0.55,0.95,1.05,SSP2_v9_130325,0.00158753449189663,1.08270938702243,0.0458442270103222,rcp45,FALSE,FALSE,1.25,0.125,rcp45,SSP2_RCP45 -shocks/noShocks,s3,0.91729061297757,0.0212467318969033,0.95,1.1,1.47532681030967,1.1,0.000307985221616426,0.508270938702243,0.210311637702584,0.35,1.00413546935112,0.0782581447790401,0.720778864948389,0.45,1.05,0.95,SSP2_v9_130325,0.00241246550810337,0.91729061297757,0.0541557729896778,rcp45,FALSE,FALSE,0.75,0.075,rcp45,SSP2_RCP45 -shocks/noShocks,s4,0.960874657414893,0.0194097808551165,1.025,0.85,1.81153483560056,1.15,0.000279015531982238,0.503912534258511,0.182453074797474,0.475,0.998043732870745,0.110368611745326,0.664744194066573,0.475,1.025,0.925,SSP2_v9_130325,0.00180496552244993,0.960874657414893,0.0570511611866855,rcp45,FALSE,FALSE,1.375,0.0875,rcp45,SSP2_RCP45 -shocks/noShocks,s5,1.14060088096457,0.0221153483560056,0.925,1.05,1.54097808551165,0.95,0.000369925055308764,0.485939911903543,0.204875861938752,0.375,1.00703004404823,0.0637597348849639,0.709836985748058,0.575,0.925,1.025,SSP2_v9_130325,0.00270187700810103,1.14060088096457,0.0480326028503884,rcp45,FALSE,FALSE,0.875,0.1375,rcp45,SSP2_RCP45 -shocks/noTax,s1,1,0.02,1,1,1.6,1,0.00035,0.5,0.2,0.4,1,0.1,0.7,0.5,1,1,SSP2_v9_130325,0.002,1,0.05,rcp45,TRUE,FALSE,1,0.1,rcp45,SSP2_RCP45 -shocks/noTax,s2,1.08270938702243,0.0187532681030967,1.05,0.9,1.72467318969033,0.9,0.000392014778383574,0.491729061297757,0.189688362297416,0.45,0.995864530648878,0.12174185522096,0.679221135051611,0.55,0.95,1.05,SSP2_v9_130325,0.00158753449189663,1.08270938702243,0.0458442270103222,rcp45,TRUE,FALSE,1.25,0.125,rcp45,SSP2_RCP45 -shocks/noTax,s3,0.91729061297757,0.0212467318969033,0.95,1.1,1.47532681030967,1.1,0.000307985221616426,0.508270938702243,0.210311637702584,0.35,1.00413546935112,0.0782581447790401,0.720778864948389,0.45,1.05,0.95,SSP2_v9_130325,0.00241246550810337,0.91729061297757,0.0541557729896778,rcp45,TRUE,FALSE,0.75,0.075,rcp45,SSP2_RCP45 -shocks/noTax,s4,0.960874657414893,0.0194097808551165,1.025,0.85,1.81153483560056,1.15,0.000279015531982238,0.503912534258511,0.182453074797474,0.475,0.998043732870745,0.110368611745326,0.664744194066573,0.475,1.025,0.925,SSP2_v9_130325,0.00180496552244993,0.960874657414893,0.0570511611866855,rcp45,TRUE,FALSE,1.375,0.0875,rcp45,SSP2_RCP45 -shocks/noTax,s5,1.14060088096457,0.0221153483560056,0.925,1.05,1.54097808551165,0.95,0.000369925055308764,0.485939911903543,0.204875861938752,0.375,1.00703004404823,0.0637597348849639,0.709836985748058,0.575,0.925,1.025,SSP2_v9_130325,0.00270187700810103,1.14060088096457,0.0480326028503884,rcp45,TRUE,FALSE,0.875,0.1375,rcp45,SSP2_RCP45 -shocks/withTax,s1,1,0.02,1,1,1.6,1,0.00035,0.5,0.2,0.4,1,0.1,0.7,0.5,1,1,SSP2_v9_130325,0.002,1,0.05,rcp45,TRUE,TRUE,1,0.1,rcp45,SSP2_RCP45 -shocks/withTax,s2,1.08270938702243,0.0187532681030967,1.05,0.9,1.72467318969033,0.9,0.000392014778383574,0.491729061297757,0.189688362297416,0.45,0.995864530648878,0.12174185522096,0.679221135051611,0.55,0.95,1.05,SSP2_v9_130325,0.00158753449189663,1.08270938702243,0.0458442270103222,rcp45,TRUE,TRUE,1.25,0.125,rcp45,SSP2_RCP45 -shocks/withTax,s3,0.91729061297757,0.0212467318969033,0.95,1.1,1.47532681030967,1.1,0.000307985221616426,0.508270938702243,0.210311637702584,0.35,1.00413546935112,0.0782581447790401,0.720778864948389,0.45,1.05,0.95,SSP2_v9_130325,0.00241246550810337,0.91729061297757,0.0541557729896778,rcp45,TRUE,TRUE,0.75,0.075,rcp45,SSP2_RCP45 -shocks/withTax,s4,0.960874657414893,0.0194097808551165,1.025,0.85,1.81153483560056,1.15,0.000279015531982238,0.503912534258511,0.182453074797474,0.475,0.998043732870745,0.110368611745326,0.664744194066573,0.475,1.025,0.925,SSP2_v9_130325,0.00180496552244993,0.960874657414893,0.0570511611866855,rcp45,TRUE,TRUE,1.375,0.0875,rcp45,SSP2_RCP45 -shocks/withTax,s5,1.14060088096457,0.0221153483560056,0.925,1.05,1.54097808551165,0.95,0.000369925055308764,0.485939911903543,0.204875861938752,0.375,1.00703004404823,0.0637597348849639,0.709836985748058,0.575,0.925,1.025,SSP2_v9_130325,0.00270187700810103,1.14060088096457,0.0480326028503884,rcp45,TRUE,TRUE,0.875,0.1375,rcp45,SSP2_RCP45 +Ensemble,Scenario,AGRI_LAND_EXPANSION_COST_FACTOR,ANNUAL_MAX_IMPORT_CHANGE,BIOENERGY_DEMAND_SHIFT,CROP_TO_PASTURE_COST_FACTOR,FERTILISER_COST_PER_T,INITIAL_PRICE_SHIFT,IRRIG_COST_SCALE_FACTOR,IRRIGATION_EFFICIENCY,LAND_CHANGE_COST,MARKET_LAMBA,MEAT_EFFICIENCY,MIN_NATURAL_RATE,OTHER_INTENSITY_COST,PASTURE_HARVEST_FRACTION,SSP_GDP_PC_FACTOR,SSP_POPULATION_FACTOR,SSP_SCENARIO,TECHNOLOGY_CHANGE_ANNUAL_RATE,TRADE_BARRIER_MULTIPLIER,TRANSPORT_COST,RCP,SHOCKS_POSSIBLE,APPLY_EXPORT_TAXES,EXPORT_TAX_RATE,EXPORT_TAX_THRESHOLD,PRICE_CALCULATION,YIELD_DIR_TOP,BIOENERGY_DEMAND_SCENARIO +shocks/noShocks,s1,1,0.02,1,1,1.6,1,0.00035,0.5,0.2,0.4,1,0.1,0.7,0.5,1,1,SSP2_v9_130325,0.002,1,0.05,rcp45,FALSE,FALSE,1,0.1,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/noShocks,s2,1.08270938702243,0.0187532681030967,1.05,0.9,1.72467318969033,0.9,0.000392014778383574,0.491729061297757,0.189688362297416,0.45,0.995864530648878,0.12174185522096,0.679221135051611,0.55,0.95,1.05,SSP2_v9_130325,0.00158753449189663,1.08270938702243,0.0458442270103222,rcp45,FALSE,FALSE,1.25,0.125,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/noShocks,s3,0.91729061297757,0.0212467318969033,0.95,1.1,1.47532681030967,1.1,0.000307985221616426,0.508270938702243,0.210311637702584,0.35,1.00413546935112,0.0782581447790401,0.720778864948389,0.45,1.05,0.95,SSP2_v9_130325,0.00241246550810337,0.91729061297757,0.0541557729896778,rcp45,FALSE,FALSE,0.75,0.075,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/noShocks,s4,0.960874657414893,0.0194097808551165,1.025,0.85,1.81153483560056,1.15,0.000279015531982238,0.503912534258511,0.182453074797474,0.475,0.998043732870745,0.110368611745326,0.664744194066573,0.475,1.025,0.925,SSP2_v9_130325,0.00180496552244993,0.960874657414893,0.0570511611866855,rcp45,FALSE,FALSE,1.375,0.0875,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/noShocks,s5,1.14060088096457,0.0221153483560056,0.925,1.05,1.54097808551165,0.95,0.000369925055308764,0.485939911903543,0.204875861938752,0.375,1.00703004404823,0.0637597348849639,0.709836985748058,0.575,0.925,1.025,SSP2_v9_130325,0.00270187700810103,1.14060088096457,0.0480326028503884,rcp45,FALSE,FALSE,0.875,0.1375,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/noTax,s1,1,0.02,1,1,1.6,1,0.00035,0.5,0.2,0.4,1,0.1,0.7,0.5,1,1,SSP2_v9_130325,0.002,1,0.05,rcp45,TRUE,FALSE,1,0.1,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/noTax,s2,1.08270938702243,0.0187532681030967,1.05,0.9,1.72467318969033,0.9,0.000392014778383574,0.491729061297757,0.189688362297416,0.45,0.995864530648878,0.12174185522096,0.679221135051611,0.55,0.95,1.05,SSP2_v9_130325,0.00158753449189663,1.08270938702243,0.0458442270103222,rcp45,TRUE,FALSE,1.25,0.125,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/noTax,s3,0.91729061297757,0.0212467318969033,0.95,1.1,1.47532681030967,1.1,0.000307985221616426,0.508270938702243,0.210311637702584,0.35,1.00413546935112,0.0782581447790401,0.720778864948389,0.45,1.05,0.95,SSP2_v9_130325,0.00241246550810337,0.91729061297757,0.0541557729896778,rcp45,TRUE,FALSE,0.75,0.075,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/noTax,s4,0.960874657414893,0.0194097808551165,1.025,0.85,1.81153483560056,1.15,0.000279015531982238,0.503912534258511,0.182453074797474,0.475,0.998043732870745,0.110368611745326,0.664744194066573,0.475,1.025,0.925,SSP2_v9_130325,0.00180496552244993,0.960874657414893,0.0570511611866855,rcp45,TRUE,FALSE,1.375,0.0875,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/noTax,s5,1.14060088096457,0.0221153483560056,0.925,1.05,1.54097808551165,0.95,0.000369925055308764,0.485939911903543,0.204875861938752,0.375,1.00703004404823,0.0637597348849639,0.709836985748058,0.575,0.925,1.025,SSP2_v9_130325,0.00270187700810103,1.14060088096457,0.0480326028503884,rcp45,TRUE,FALSE,0.875,0.1375,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/withTax,s1,1,0.02,1,1,1.6,1,0.00035,0.5,0.2,0.4,1,0.1,0.7,0.5,1,1,SSP2_v9_130325,0.002,1,0.05,rcp45,TRUE,TRUE,1,0.1,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/withTax,s2,1.08270938702243,0.0187532681030967,1.05,0.9,1.72467318969033,0.9,0.000392014778383574,0.491729061297757,0.189688362297416,0.45,0.995864530648878,0.12174185522096,0.679221135051611,0.55,0.95,1.05,SSP2_v9_130325,0.00158753449189663,1.08270938702243,0.0458442270103222,rcp45,TRUE,TRUE,1.25,0.125,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/withTax,s3,0.91729061297757,0.0212467318969033,0.95,1.1,1.47532681030967,1.1,0.000307985221616426,0.508270938702243,0.210311637702584,0.35,1.00413546935112,0.0782581447790401,0.720778864948389,0.45,1.05,0.95,SSP2_v9_130325,0.00241246550810337,0.91729061297757,0.0541557729896778,rcp45,TRUE,TRUE,0.75,0.075,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/withTax,s4,0.960874657414893,0.0194097808551165,1.025,0.85,1.81153483560056,1.15,0.000279015531982238,0.503912534258511,0.182453074797474,0.475,0.998043732870745,0.110368611745326,0.664744194066573,0.475,1.025,0.925,SSP2_v9_130325,0.00180496552244993,0.960874657414893,0.0570511611866855,rcp45,TRUE,TRUE,1.375,0.0875,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 +shocks/withTax,s5,1.14060088096457,0.0221153483560056,0.925,1.05,1.54097808551165,0.95,0.000369925055308764,0.485939911903543,0.204875861938752,0.375,1.00703004404823,0.0637597348849639,0.709836985748058,0.575,0.925,1.025,SSP2_v9_130325,0.00270187700810103,1.14060088096457,0.0480326028503884,rcp45,TRUE,TRUE,0.875,0.1375,weightedExportOrProductionCosts,rcp45,SSP2_RCP45 diff --git a/data/sims/globalShock_params.csv b/data/sims/globalShock_params.csv index a40a576fb12d1d103dc1d8d256ee0c07499122d6..42b2a42244bccf620dc6a8af15a6f9a0d5a56463 100644 --- a/data/sims/globalShock_params.csv +++ b/data/sims/globalShock_params.csv @@ -26,6 +26,7 @@ noShocks,SHOCKS_POSSIBLE,value,,,,,,FALSE noShocks,APPLY_EXPORT_TAXES,value,,,,,,FALSE noShocks,EXPORT_TAX_RATE,unif,0.5,1.5,,,, noShocks,EXPORT_TAX_THRESHOLD,unif,0.05,0.15,,,, +noShocks,PRICE_CALCULATION,value,,,,,,weightedExportOrProductionCosts noTax,AGRI_LAND_EXPANSION_COST_FACTOR,beta,0,2,0.8,1,1.2, noTax,ANNUAL_MAX_IMPORT_CHANGE,beta,0.008,0.032,0.017,0.02,0.023, noTax,BIOENERGY_DEMAND_SHIFT,unif,0.9,1.1,,,, @@ -53,6 +54,7 @@ noTax,SHOCKS_POSSIBLE,value,,,,,,TRUE noTax,APPLY_EXPORT_TAXES,value,,,,,,FALSE noTax,EXPORT_TAX_RATE,unif,0.5,1.5,,,, noTax,EXPORT_TAX_THRESHOLD,unif,0.05,0.15,,,, +noTax,PRICE_CALCULATION,value,,,,,,weightedExportOrProductionCosts withTax,AGRI_LAND_EXPANSION_COST_FACTOR,beta,0,2,0.8,1,1.2, withTax,ANNUAL_MAX_IMPORT_CHANGE,beta,0.008,0.032,0.017,0.02,0.023, withTax,BIOENERGY_DEMAND_SHIFT,unif,0.9,1.1,,,, @@ -79,4 +81,5 @@ withTax,YIELD_DIR_TOP,value,,,,,,ssp2 withTax,SHOCKS_POSSIBLE,value,,,,,,TRUE withTax,APPLY_EXPORT_TAXES,value,,,,,,TRUE withTax,EXPORT_TAX_RATE,unif,0.5,1.5,,,, -withTax,EXPORT_TAX_THRESHOLD,unif,0.05,0.15,,,, \ No newline at end of file +withTax,EXPORT_TAX_THRESHOLD,unif,0.05,0.15,,,, +withTax,PRICE_CALCULATION,value,,,,,,weightedExportOrProductionCosts \ No newline at end of file diff --git a/src/ac/ed/lurg/country/AbstractCountryAgent.java b/src/ac/ed/lurg/country/AbstractCountryAgent.java index 895a60e66ad95f5dc02b57c4feff98e22b5ce8ac..d2170d57c5b61aa47864ea928d5a6c4e1e81e0f8 100644 --- a/src/ac/ed/lurg/country/AbstractCountryAgent.java +++ b/src/ac/ed/lurg/country/AbstractCountryAgent.java @@ -18,13 +18,12 @@ public abstract class AbstractCountryAgent { protected Map<CropType, Double> tradeBarriers; protected Map<CommodityType, Double> currentProjectedDemand; protected Map<CropType, CountryPrice> currentCountryPrices; + private Map<CropType, CountryPrice> previousCountryPrices; protected Map<CommodityType, Map<CropType, Double>> baseDemandFact; protected Timestep currentTimestep; protected Map<CommodityType, Map<CropType, Double>> currentMinDemandFract; protected double currentGen2EcDemand; - private double exportTaxRate; - private Map<CropType, Double> previousProducerCropPrices; - protected Map<CropType, Double> currentProducerCropPrices; + protected double exportTaxRate; public AbstractCountryAgent(AbstractDemandManager demandManager,CompositeCountry country, Map<CropType, Double> tradeBarriers) { @@ -49,37 +48,28 @@ public abstract class AbstractCountryAgent { for (CropType c : CropType.getImportedTypes()) { GlobalPrice worldPrice = worldPrices.get(c); Double tb = tradeBarriers.get(c); - LogWriter.println(worldPrice + " " + c); - double exportPrice = worldPrice.getExportPrice(); - exportPrice /= (1 + exportTaxRate); - - CountryPrice prices = new CountryPrice(worldPrice.getCountryImportPrice(tb==null ? 0 : tb, currentTimestep), exportPrice); + CountryPrice prices = createCountryPrices(c, worldPrice.getCountryImportPrice(tb==null ? 0 : tb, currentTimestep), worldPrice.getExportPrice()); countryPrices.put(c, prices); } - + currentCountryPrices = countryPrices; } protected void savePreviousProducerCropPrices() { - previousProducerCropPrices = currentProducerCropPrices; + previousCountryPrices = currentCountryPrices; } - protected void calculateProducerCropPrices() { - currentProducerCropPrices = getProducerCropPrices(); - LogWriter.println("calculateProducerCropPrices " + country + " " + currentTimestep + " prices now " + currentProducerCropPrices); - } - protected void calculateExportTax() { exportTaxRate = 0; - if (previousProducerCropPrices != null) { + if (previousCountryPrices != null) { for (CropType crop : CommodityType.CEREALS.getCropTypes()) { - double newPrice = currentProducerCropPrices.get(crop); - double oldPrice = previousProducerCropPrices.get(crop); + double newPrice = currentCountryPrices.get(crop).getConsumerPrice(); + double oldPrice = previousCountryPrices.get(crop).getConsumerPrice(); double priceChangeRate = (newPrice - oldPrice)/ oldPrice; if (priceChangeRate > ModelConfig.EXPORT_TAX_THRESHOLD) { exportTaxRate = ModelConfig.EXPORT_TAX_RATE; - LogWriter.println(String.format("calculateExportTax: Price Spike, %s, %d, %s, %.2f, %.6f, %.6f", country, currentTimestep.getTimestep(), crop, priceChangeRate*100, newPrice, oldPrice)); + LogWriter.println(String.format("\ncalculateExportTax: Price Spike, %s, %d, %s, %.2f, %.6f, %.6f\n", country, currentTimestep.getTimestep(), crop, priceChangeRate*100, newPrice, oldPrice)); break; } else @@ -90,7 +80,7 @@ public abstract class AbstractCountryAgent { LogWriter.println(String.format("calculateExportTax %s: exportTax is now %s", country, exportTaxRate)); } - protected abstract Map<CropType, Double> getProducerCropPrices(); + abstract protected CountryPrice createCountryPrices(CropType crop, double importPrice, double exportPrice); private void calculateDemand(boolean outputGamsDemand) { Map<CommodityType, Double> producerPrices = getProducerCommodityPrices(); @@ -99,8 +89,8 @@ public abstract class AbstractCountryAgent { } protected void calculateCountryPricesAndDemand(Map<CropType, GlobalPrice> worldPrices, boolean outputGamsDemand) { + LogWriter.println("\ncalculateCountryPricesAndDemand for " + country + " "+ currentTimestep.getTimestep()); calculateCountryPrices(worldPrices); - calculateProducerCropPrices(); calculateDemand(outputGamsDemand); } diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index 51eb93e89b376f0db30680f688f5913e6c24cf99..f4b5aefb594a9504445e6aa523380c48fa8879fc 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -208,52 +208,25 @@ public class CountryAgent extends AbstractCountryAgent { Map<CropType, Double> demandFract = baseDemandFact.get(commodity); for (CropType crop : commodity.getCropTypes()) { - double newCropPrice = currentProducerCropPrices.get(crop); - commPricePlum += newCropPrice * demandFract.get(crop); // weight price by base demand of each cereal crop + double consumerCropPrice = currentCountryPrices.get(crop).getConsumerPrice(); + commPricePlum += consumerCropPrice * demandFract.get(crop); // weight price by base demand of each cereal crop } return commPricePlum; } @Override - protected Map<CropType, Double> getProducerCropPrices() { - Map<CropType, Double> cropPrices = new HashMap<CropType, Double>(); + protected CountryPrice createCountryPrices(CropType crop, double importPrice, double exportPrice) { Map<CropType, CropUsageData> cropUsageMap = previousGamsRasterOutput.getCropUsageData(); - - for (CropType crop : CropType.getImportedTypes()) { - - CropUsageData cropUsageData = cropUsageMap.get(crop); - double weighting = Math.max(0, cropUsageData.getShockedNetImports()/(cropUsageData.getProductionExpected()+cropUsageData.getNetImportsExpected())); - - double importPrice = currentCountryPrices.get(crop).getImportPrice(); - double exportPrice = currentCountryPrices.get(crop).getExportPrice(); - double prodCost = cropUsageData.getProdCostRate(); - double exportOrProdCost = Double.isNaN(prodCost) || prodCost <= 0.0 ? exportPrice : prodCost; - double newCropPrice; - - switch (ModelConfig.PRICE_CALCULATION) { - case IMPORTONLY: - newCropPrice = importPrice; - break; - case WEIGHTEDIMPEXP: - newCropPrice = importPrice*weighting + exportPrice*(1-weighting); - break; - case WEIGHTEDINCLPRODCOSTS: - newCropPrice = importPrice*weighting + exportOrProdCost*(1-weighting); - break; - default: - newCropPrice = importPrice; - LogWriter.printlnWarning("Warning, price calculation type not set, using only import price as default " + newCropPrice); - break; - } - - LogWriter.println(String.format(" Crop %s: import %.4f, export %.4f, prodcost %.4f, newCropPrice %.4f", crop, importPrice, exportPrice, prodCost, newCropPrice)); - cropPrices.put(crop, newCropPrice); - } - - return cropPrices; + CropUsageData cropUsageData = cropUsageMap.get(crop); + + double weighting = Math.max(0, cropUsageData.getShockedNetImports()/(cropUsageData.getProductionExpected()+cropUsageData.getShockedNetImports())); + double prodCost = cropUsageData.getProdCostRate(); + CountryPrice cp = new CountryPrice(crop, importPrice, exportPrice, prodCost, weighting, exportTaxRate); + LogWriter.println("Created " + cp); + return cp; } - + public void shockGDP() { double totalProduction = getTotalProduction(); diff --git a/src/ac/ed/lurg/country/CountryPrice.java b/src/ac/ed/lurg/country/CountryPrice.java index 7639ff30288cd4a96d16bbd185365076a99ca639..385312488383245afe4e216e7a6cc624d8b87e1e 100644 --- a/src/ac/ed/lurg/country/CountryPrice.java +++ b/src/ac/ed/lurg/country/CountryPrice.java @@ -1,16 +1,27 @@ package ac.ed.lurg.country; +import ac.ed.lurg.ModelConfig; +import ac.ed.lurg.types.CropType; +import ac.ed.lurg.utils.LogWriter; + public class CountryPrice { - double importPrice; - double exportPrice; + private CropType crop; + private double importPrice; + private double exportPrice; + private double exportTaxRate; + private double prodCost; + private double consumerPriceweighting; - public CountryPrice(double importPrice, double exportPrice){ - - this.importPrice = importPrice; - this.exportPrice = exportPrice; + public CountryPrice(CropType crop, double importPrice, double exportPrice, double prodCost, double weighting, double exportTaxRate){ + this.crop = crop; + this.importPrice = importPrice; + this.exportPrice = exportPrice; + this.prodCost = prodCost; + this.consumerPriceweighting = weighting; + this.exportTaxRate = exportTaxRate; } - + public double getImportPrice() { return importPrice; } @@ -19,9 +30,41 @@ public class CountryPrice { return exportPrice; } + public double getConsumerPrice() { + double exportOrProdCost = Double.isNaN(prodCost) || prodCost <= 0.0 ? exportPrice : prodCost; + double consumerPrice; + + switch (ModelConfig.PRICE_CALCULATION) { + case IMPORTONLY: + consumerPrice = importPrice; + break; + case WEIGHTEDIMPEXP: + consumerPrice = importPrice*consumerPriceweighting + exportPrice*(1-consumerPriceweighting); + break; + case WEIGHTEDINCLPRODCOSTS: + consumerPrice = importPrice*consumerPriceweighting + exportOrProdCost*(1-consumerPriceweighting); + break; + default: + consumerPrice = importPrice; + LogWriter.printlnWarning("Warning, price calculation type not set, using only import price as default " + consumerPrice); + break; + } + + LogWriter.println(String.format(" Crop %s: import %.4f, export %.4f, prodcost %.4f, newCropPrice %.4f", crop, importPrice, exportPrice, prodCost, consumerPrice)); + return consumerPrice; + } + + public double getProducerNetExportPrice() { + if (ModelConfig.APPLY_EXPORT_TAXES) + return exportPrice / (1 + exportTaxRate); + else + return exportPrice; + } + @Override public String toString() { - return "CountryPrice [importPrice=" + importPrice + ", exportPrice=" + exportPrice + "]"; + return "CountryPrice [crop=" + crop + ", importPrice=" + importPrice + ", exportPrice=" + exportPrice + + ", exportTaxRate=" + exportTaxRate + ", prodCost=" + prodCost + ", consumerPriceweighting="+ consumerPriceweighting + "]"; } } diff --git a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java index 1155495029b354f5bf0f2c80d73ece038ab59e8a..fbc10bb0c23fcff975d378145d42af9c0886a282 100644 --- a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java +++ b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java @@ -1,8 +1,10 @@ package ac.ed.lurg.country.crafty; import java.util.Map; + import ac.ed.lurg.country.AbstractCountryAgent; import ac.ed.lurg.country.CompositeCountry; +import ac.ed.lurg.country.CountryPrice; import ac.ed.lurg.country.GlobalPrice; import ac.ed.lurg.demand.AbstractDemandManager; import ac.ed.lurg.landuse.CropUsageData; @@ -43,7 +45,7 @@ public class CraftyCountryAgent extends AbstractCountryAgent { } @Override - protected Map<CropType, Double> getProducerCropPrices() { + protected CountryPrice createCountryPrices(CropType crop, double importPrice, double exportPrice) { // TODO Auto-generated method stub return null; } diff --git a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java index 21567125833e8a2cc529285e7c5e86dd6749e57a..63186d04f3766d17602fce8186e0726191d6e465 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java @@ -272,7 +272,7 @@ public class GamsLocationOptimiser { double minTrade = iec.getMinConstraint(); double maxTrade = iec.getMaxConstraint(); double importPrice = gp.getImportPrice(); - double exportPrice = gp.getExportPrice(); + double exportPrice = gp.getProducerNetExportPrice(); CropUsageData cu = countryInput.getPreviousCropUsageData().get(crop); double netImports = cu.getNetImportsExpected();