diff --git a/src/ac/ed/lurg/country/AbstractCountryAgent.java b/src/ac/ed/lurg/country/AbstractCountryAgent.java index 2a2a2cc38a0505e9414d8debdd6ad3da9f68a3a7..ac9bd99fbab52a08c661f891f30e46837880c327 100644 --- a/src/ac/ed/lurg/country/AbstractCountryAgent.java +++ b/src/ac/ed/lurg/country/AbstractCountryAgent.java @@ -39,19 +39,7 @@ public abstract class AbstractCountryAgent { currentMinDemandFract = getMinDemandFraction(); } - private void calculateCountryPrices(Map<CropType, GlobalPrice> worldPrices){ - Map<CropType, CountryPrice> countryPrices = new HashMap <CropType, CountryPrice>(); - - for (CropType c : CropType.getImportedTypes()) { - GlobalPrice worldPrice = worldPrices.get(c); - Double tb = tradeBarriers.get(c); - LogWriter.println(worldPrice + " " + c); - CountryPrice prices = new CountryPrice(worldPrice.getCountryImportPrice(tb==null ? 0 : tb, currentTimestep), worldPrice.getExportPrice()); - countryPrices.put(c, prices); - } - - currentCountryPrices = countryPrices; - } + protected abstract void calculateCountryPrices(Map<CropType, GlobalPrice> worldPrices); private void calculateDemand() { Map<CommodityType, Double> producerPrices = getProducerCommodityPrices(); diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index 0179740982e19d0d3ea2e4872cb66c82f426c230..192c5278e289b3c7650128d173d4450d6750babd 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -59,6 +59,34 @@ public class CountryAgent extends AbstractCountryAgent { public RasterSet<IntegerRasterItem> getYieldClusters() { return yieldClusters; } + + @Override + protected void calculateCountryPrices(Map<CropType, GlobalPrice> worldPrices) { + Map<CropType, CountryPrice> countryPrices = new HashMap <CropType, CountryPrice>(); + + Map<CropType, CropUsageData> cropUsageMap = previousGamsRasterOutput.getCropUsageData(); + + for (CropType c : CropType.getImportedTypes()) { + GlobalPrice worldPrice = worldPrices.get(c); + Double tb = tradeBarriers.get(c); + CropUsageData cropUsageData = cropUsageMap.get(c); + LogWriter.println(worldPrice + " " + c); + double importsPostShock = cropUsageData.getShockedNetImports(); + double productionPostShock = cropUsageData.getProductionExpected()-cropUsageData.getProductionShock(); + double weighting = importsPostShock/(productionPostShock+importsPostShock); + + double importPrice = worldPrice.getCountryImportPrice(tb==null ? 0 : tb, currentTimestep) * weighting; + double exportPrice = worldPrice.getExportPrice() * (1-weighting); + + double newImportPrice = importPrice + exportPrice; + + CountryPrice prices = new CountryPrice(newImportPrice, worldPrice.getExportPrice()); + countryPrices.put(c, prices); + } + + currentCountryPrices = countryPrices; + + } private RasterSet<IntegerRasterItem> calcYieldClusters(RasterSet<IrrigationItem> irrigData, YieldRaster countryYieldSurfaces) { diff --git a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java index cbdb684cb47e302863c547ebd7a3b8534bf40170..e81408fa84d32cb5f03f13ee5bb5bc58d2e28937 100644 --- a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java +++ b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java @@ -6,10 +6,14 @@ import java.util.Map.Entry; 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.country.SingleCountry; import ac.ed.lurg.demand.AbstractDemandManager; import ac.ed.lurg.landuse.CropUsageData; +import ac.ed.lurg.types.CommodityType; import ac.ed.lurg.types.CropType; +import ac.ed.lurg.utils.LogWriter; /** * Country agent that is interface over data transferred to and from CRAFTY. @@ -38,4 +42,20 @@ public class CraftyCountryAgent extends AbstractCountryAgent { updateNetImportsFromProdAndDemand(currentProjectedDemand, currentMinDemandFract, cropUsageData); } + + @Override + protected void calculateCountryPrices(Map<CropType, GlobalPrice> worldPrices) { + Map<CropType, CountryPrice> countryPrices = new HashMap <CropType, CountryPrice>(); + + for (CropType c : CropType.getImportedTypes()) { + GlobalPrice worldPrice = worldPrices.get(c); + Double tb = tradeBarriers.get(c); + LogWriter.println(worldPrice + " " + c); + CountryPrice prices = new CountryPrice(worldPrice.getCountryImportPrice(tb==null ? 0 : tb, currentTimestep), worldPrice.getExportPrice()); + countryPrices.put(c, prices); + } + + currentCountryPrices = countryPrices; + + } } \ No newline at end of file