diff --git a/src/ac/ed/lurg/InternationalMarket.java b/src/ac/ed/lurg/InternationalMarket.java index 262531cd66ebfac5540a576256e05a9d5514b708..36e807fe416d177fd173493d97e7c7e17301fa14 100644 --- a/src/ac/ed/lurg/InternationalMarket.java +++ b/src/ac/ed/lurg/InternationalMarket.java @@ -9,6 +9,7 @@ import java.util.Map.Entry; import ac.ed.lurg.country.AbstractCountryAgent; import ac.ed.lurg.country.GlobalPrice; +import ac.ed.lurg.country.StockReader; import ac.ed.lurg.landuse.CropUsageData; import ac.ed.lurg.types.CropToDoubleMap; import ac.ed.lurg.types.CropType; @@ -19,11 +20,11 @@ public class InternationalMarket { private Map<CropType, GlobalPrice> worldPrices = new HashMap<CropType, GlobalPrice>(); public InternationalMarket() { - //Map<CropType, Double> stockLevel = getInitialStockLevels(); + Map<CropType, Double> stockLevel = getInitialStockLevels(); for (CropType crop : CropType.getImportedTypes()) { - //Double stock = stockLevel.get(crop); - worldPrices.put(crop, GlobalPrice.createInitial(crop.getInitialPrice())); + Double initialStock = stockLevel.get(crop); + worldPrices.put(crop, GlobalPrice.createInitial(crop.getInitialPrice(), initialStock)); } } @@ -31,11 +32,11 @@ public class InternationalMarket { return worldPrices; } -/* private Map<CropType, Double> getInitialStockLevels() { + private Map<CropType, Double> getInitialStockLevels() { Map<CropType, Double> initialStockLevels = new StockReader().read(); initialStockLevels.put(CropType.ENERGY_CROPS, 0.0); return initialStockLevels; - } */ + } void determineInternationalTrade(Collection<AbstractCountryAgent> countryAgents, double gen2EcDDemand, Timestep timestep) { CropToDoubleMap totalImportCommodities = new CropToDoubleMap(); diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index 2f1bb7617ea5ee2485c7a67da37c3d0c4ad9e16c..749ccce1f90611d29da187b2171c75433c585389 100755 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -343,6 +343,8 @@ public class ModelConfig { public static final double MARKET_LAMBA = getDoubleProperty("MARKET_LAMBA", 0.4); // controls international market price adjustment rate public static final boolean PRICE_UPDATE_BY_MARKET_IMBALANCE = getBooleanProperty("PRICE_UPDATE_BY_MARKET_IMBALANCE", false);; + public static final double MAX_PRICE_INCREASE = getDoubleProperty("MAX_PRICE_INCREASE", 1.5); + public static final double MAX_PRICE_DECREASE = getDoubleProperty("MAX_PRICE_DECREASE", .75); public static final double STOCK_TARGET_RATE = getDoubleProperty("STOCK_TARGET_RATE", 0.05); public static final int DEMAND_RECALC_MAX_ITERATIONS = getIntProperty("DEMAND_RECALC_MAX_ITERATIONS", 0); // 0 is original behaviour diff --git a/src/ac/ed/lurg/country/GlobalPrice.java b/src/ac/ed/lurg/country/GlobalPrice.java index aee2d8f81cb664e2785eb71d1347501a4c4a18d1..3848361056a0f5890b6f5c64e3d1c83c926fe2b7 100644 --- a/src/ac/ed/lurg/country/GlobalPrice.java +++ b/src/ac/ed/lurg/country/GlobalPrice.java @@ -12,18 +12,20 @@ public class GlobalPrice { private double exportAmountBeforeLoss; private double transportLosses; private double stockLevel; + private double stockTarget; - private GlobalPrice(int timestepId, double exportPrice, double stockLevel, double importAmount, double exportAmountBeforeLoss, double transportLosses) { + private GlobalPrice(int timestepId, double exportPrice, double stockLevel, double stockTarget, double importAmount, double exportAmountBeforeLoss, double transportLosses) { this.timestepId = timestepId; this.exportPrice = exportPrice; this.stockLevel = stockLevel; + this.stockTarget = stockTarget; this.importAmount = importAmount; this.exportAmountBeforeLoss = exportAmountBeforeLoss; this.transportLosses = transportLosses; } - public static GlobalPrice createInitial(double exportPrice) { - return new GlobalPrice(ModelConfig.START_TIMESTEP-1, exportPrice, Double.NaN, Double.NaN, Double.NaN, Double.NaN); + public static GlobalPrice createInitial(double exportPrice, double intitalStock) { + return new GlobalPrice(ModelConfig.START_TIMESTEP-1, exportPrice, intitalStock, intitalStock, Double.NaN, Double.NaN, Double.NaN); } public double getExportPrice(){ @@ -65,9 +67,6 @@ public class GlobalPrice { public GlobalPrice createWithUpdatedMarketPrices(double newImports, double newExportAmountBeforeLoss, Timestep timestep, double production) { - if (Double.isNaN(stockLevel)) - stockLevel = ModelConfig.STOCK_TARGET_RATE * production; // set stock initially to target level, this is pretty horrible and should really be done on construction but don't easily have production value at that point - double transportLossRate = (!ModelConfig.SHOCKS_POSSIBLE) ? ModelConfig.TRANSPORT_LOSSES : ModelConfig.getParameter(Parameter.TRANSPORT_LOSSES, timestep.getYear()); double newTransportLosses = newExportAmountBeforeLoss * transportLossRate; double exportsAfterTransportLosses = newExportAmountBeforeLoss - newTransportLosses; @@ -95,25 +94,24 @@ public class GlobalPrice { LogWriter.println(String.format("Price update market imbalance: adjustment= %.4f, imports %.1f, exports %.1f", adjustment, newImports, getExportsAfterTransportLosses())); } else { - double stockTarget = ModelConfig.STOCK_TARGET_RATE * production; double ratio = (stockTarget - updatedStock) / stockTarget; if (ratio >= 0) { adjustment = 1 + ModelConfig.MARKET_LAMBA * ratio/(1 - ratio*ratio); - if (adjustment > 3 || ratio > 1) - adjustment = 3; // default to max up change + if (adjustment > ModelConfig.MAX_PRICE_INCREASE || ratio > 1) + adjustment = ModelConfig.MAX_PRICE_INCREASE; // default to max up change } else { adjustment = 1 / ( 1 - ModelConfig.MARKET_LAMBA * ratio/(1 - ratio*ratio)); - if (adjustment < 0.1 || ratio < -1) - adjustment = 0.1; // default to max down change + if (adjustment < ModelConfig.MAX_PRICE_DECREASE || ratio < -1) + adjustment = ModelConfig.MAX_PRICE_DECREASE; // default to max down change } LogWriter.println(String.format("Price update from stock target: adjustment= %.4f, ratio= %.4f", adjustment, ratio)); } newPrice = exportPrice * adjustment * financialSpeculationMultiplier; - return new GlobalPrice(timestep.getTimestep(), newPrice, updatedStock, newImports, newExportAmountBeforeLoss, newTransportLosses); + return new GlobalPrice(timestep.getTimestep(), newPrice, updatedStock, stockTarget, newImports, newExportAmountBeforeLoss, newTransportLosses); } else { LogWriter.printlnError(String.format("Price for not updated (still %s), as no imports and no exports for it", exportPrice));