From 523e84ba4a4a1f19e39206383c52db773a4fe9c3 Mon Sep 17 00:00:00 2001 From: Bart Arendarczyk <s1924442@ed.ac.uk> Date: Thu, 4 May 2023 14:38:01 +0100 Subject: [PATCH] Slight changes to trade constraints. --- src/ac/ed/lurg/country/CountryAgent.java | 8 ++++---- src/ac/ed/lurg/country/GlobalPrice.java | 15 ++++----------- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index 5f557b17..ecebc608 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -178,7 +178,7 @@ public class CountryAgent extends AbstractCountryAgent { if (crop.isImportedCrop()) { changeUp = cropPrice.getTradeChangeUp(maxOfProdOrSupply); - changeDown = cropPrice.getTradeChangeDown(maxOfProdOrSupply, crop.getStockToUseRatio()); + //changeDown = cropPrice.getTradeChangeDown(maxOfProdOrSupply, crop.getStockToUseRatio()); if (changeUp < 0) { // need to reduce imports to avoid negative stocks baseTrade += changeUp; @@ -225,7 +225,7 @@ public class CountryAgent extends AbstractCountryAgent { } else { double maxOfProdOrSupply = carbonUsageData.getCarbonCredits() + Math.max(baseTrade, 0); changeUp = globalCarbonPrice.getTradeChangeUp(maxOfProdOrSupply); - changeDown = globalCarbonPrice.getTradeChangeDown(maxOfProdOrSupply, ModelConfig.DEFAULT_STOCK_USE_RATIO); + changeDown = maxOfProdOrSupply * ModelConfig.MAX_IMPORT_CHANGE; if (changeUp < 0) { // need to reduce imports to avoid negative stocks baseTrade += changeUp; @@ -260,7 +260,7 @@ public class CountryAgent extends AbstractCountryAgent { changeUp = changeDown = 0.0; } else { changeUp = woodPrice.getTradeChangeUp(maxOfProdOrSupply); - changeDown = woodPrice.getTradeChangeDown(maxOfProdOrSupply, ModelConfig.DEFAULT_STOCK_USE_RATIO); + changeDown = maxOfProdOrSupply * ModelConfig.MAX_IMPORT_CHANGE; if (changeUp < 0) { // need to reduce imports to avoid negative stocks baseTrade += changeUp; @@ -290,7 +290,7 @@ public class CountryAgent extends AbstractCountryAgent { double prodCost = cropUsageData.getProdCostRate(); Double tb = tradeBarriers.get(crop); double tradeBarrier = tb==null ? 0 : tb; - double exportTaxRateForCrop = CommodityType.CEREALS.getCropTypes().contains(crop) ? exportTaxRate : 0.0; + double exportTaxRateForCrop = CommodityType.CEREALS_STARCHY_ROOTS.getCropTypes().contains(crop) ? exportTaxRate : 0.0; CountryPrice cp = new CountryPrice(crop, worldPrice, tradeBarrier, prodCost, weighting, exportTaxRateForCrop); return cp; } diff --git a/src/ac/ed/lurg/country/GlobalPrice.java b/src/ac/ed/lurg/country/GlobalPrice.java index a8719fd7..7263e879 100644 --- a/src/ac/ed/lurg/country/GlobalPrice.java +++ b/src/ac/ed/lurg/country/GlobalPrice.java @@ -119,8 +119,9 @@ public class GlobalPrice implements Serializable { // Adjust price based on stock change adjustment = 1 - lambda * stockChange / production; - // If below target stock and stocks not already increasing, nudge prices to increase stock. - if (updatedStock < targetStock & stockChange < 0) { + // If below target stock and stocks not already increasing, nudge prices up to increase stock. + // If above target stock and stocks not already decreasing, nudge prices down to decrease stock. + if ((updatedStock < targetStock & stockChange < 0 & stockChange < prevStockChange) | (updatedStock > targetStock & stockChange > 0 & stockChange > prevStockChange)) { adjustment *= 1 - 0.5 * ModelConfig.MARKET_LAMBDA * (updatedStock - targetStock) / production; } } @@ -195,15 +196,7 @@ public class GlobalPrice implements Serializable { maxOfProdOrSupply += 0.05 * production / CountryManager.getInstance().getCountryCount(); double supplyFraction = maxOfProdOrSupply / (production * 1.05); // ensures stocks don't go below zero even if no exports - return (0.95 * stockLevel - (importAmount - getExportsAfterTransportLosses())) * supplyFraction; - } - - public double getTradeChangeDown(double maxOfProdOrSupply, double targetStockUseRatio) { - // plus 5% of global production divided by number of countries in case country has 0 supply - maxOfProdOrSupply += 0.05 * production / CountryManager.getInstance().getCountryCount(); - double supplyFraction = maxOfProdOrSupply / (production * 1.05); - // Allow exports to increase until stocks 50% above target stock level - return Math.max(targetStockUseRatio * production * 1.5 - stockLevel, 0) * supplyFraction; + return (0.9 * stockLevel - (importAmount - getExportsAfterTransportLosses())) * supplyFraction; } } \ No newline at end of file -- GitLab