diff --git a/src/ac/ed/lurg/country/AbstractCountryAgent.java b/src/ac/ed/lurg/country/AbstractCountryAgent.java index 2a2a2cc38a0505e9414d8debdd6ad3da9f68a3a7..25283e15cc991770a59c9ab3ec1559c51968cf5a 100644 --- a/src/ac/ed/lurg/country/AbstractCountryAgent.java +++ b/src/ac/ed/lurg/country/AbstractCountryAgent.java @@ -18,7 +18,7 @@ public abstract class AbstractCountryAgent { protected Map<CropType, Double> tradeBarriers; protected Map<CommodityType, Double> currentProjectedDemand; protected Map<CropType, CountryPrice> currentCountryPrices; - private Map<CommodityType, Map<CropType, Double>> baseDemandFact; + protected Map<CommodityType, Map<CropType, Double>> baseDemandFact; protected Timestep currentTimestep; protected Map<CommodityType, Map<CropType, Double>> currentMinDemandFract; @@ -78,15 +78,7 @@ public abstract class AbstractCountryAgent { return prices; } - private double getCommPriceFromCropPrice(CommodityType commodity) { - double commPricePlum = 0; - Map<CropType, Double> demandFract = baseDemandFact.get(commodity); - - for (CropType crop : commodity.getCropTypes()) { - commPricePlum += currentCountryPrices.get(crop).getImportPrice() * demandFract.get(crop); // weight price by base demand of each cereal crop - } - return commPricePlum; - } + protected abstract double getCommPriceFromCropPrice(CommodityType commodity); public Map<CommodityType, Double> getCurrentProjectedDemand() { return currentProjectedDemand; diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index 0179740982e19d0d3ea2e4872cb66c82f426c230..06736d5c22b9fe93de0bab0b776ae90282185aaf 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -207,6 +207,24 @@ public class CountryAgent extends AbstractCountryAgent { return input; } + + @Override + protected double getCommPriceFromCropPrice(CommodityType commodity) { + double commPricePlum = 0; + Map<CropType, Double> demandFract = baseDemandFact.get(commodity); + Map<CropType, CropUsageData> cropUsageMap = previousGamsRasterOutput.getCropUsageData(); + + for (CropType crop : commodity.getCropTypes()) { + CropUsageData cropUsageData = cropUsageMap.get(crop); + + double weighting = Math.max(0, cropUsageData.getShockedNetImports()/(cropUsageData.getProductionExpected()+cropUsageData.getNetImportsExpected())); + double newImportPrice = currentCountryPrices.get(crop).getImportPrice()*weighting + currentCountryPrices.get(crop).getExportPrice()*(1-weighting); + + commPricePlum += newImportPrice * demandFract.get(crop); // weight price by base demand of each cereal crop + } + + return commPricePlum; + } public RasterSet<LandUseItem> getLandUses() { return previousGamsRasterOutput.getLandUses(); diff --git a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java index cbdb684cb47e302863c547ebd7a3b8534bf40170..7ab4740c38afd86c010352f50332dd9e4df4e94b 100644 --- a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java +++ b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java @@ -9,14 +9,15 @@ import ac.ed.lurg.country.CompositeCountry; import ac.ed.lurg.country.GlobalPrice; import ac.ed.lurg.demand.AbstractDemandManager; import ac.ed.lurg.landuse.CropUsageData; +import ac.ed.lurg.types.CommodityType; import ac.ed.lurg.types.CropType; -/** +/** * Country agent that is interface over data transferred to and from CRAFTY. - * Need to configure country mapping to that there is + * Need to configure country mapping to that there is * */ public class CraftyCountryAgent extends AbstractCountryAgent { - + private Map<CropType, CropUsageData> cropUsageData; public CraftyCountryAgent(AbstractDemandManager demandManager,CompositeCountry country, Map<CropType, Double> tradeBarriers) { @@ -35,7 +36,18 @@ public class CraftyCountryAgent extends AbstractCountryAgent { CropUsageData cropusage = new CropUsageData(entry.getValue()); cropUsageData.put(entry.getKey(), cropusage); } - + updateNetImportsFromProdAndDemand(currentProjectedDemand, currentMinDemandFract, cropUsageData); } + + @Override + protected double getCommPriceFromCropPrice(CommodityType commodity) { + double commPricePlum = 0; + Map<CropType, Double> demandFract = baseDemandFact.get(commodity); + + for (CropType crop : commodity.getCropTypes()) { + commPricePlum += currentCountryPrices.get(crop).getImportPrice() * demandFract.get(crop); // weight price by base demand of each cereal crop + } + return commPricePlum; + } } \ No newline at end of file