From 9c2e4925e293ad8119a4f78acbfd4294a7158765 Mon Sep 17 00:00:00 2001 From: Peter Alexander <> Date: Mon, 17 Jan 2022 10:18:21 +0000 Subject: [PATCH] More debug change for tax --- .../ed/lurg/country/AbstractCountryAgent.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/ac/ed/lurg/country/AbstractCountryAgent.java b/src/ac/ed/lurg/country/AbstractCountryAgent.java index 2fee1dab..895a60e6 100644 --- a/src/ac/ed/lurg/country/AbstractCountryAgent.java +++ b/src/ac/ed/lurg/country/AbstractCountryAgent.java @@ -22,7 +22,7 @@ public abstract class AbstractCountryAgent { protected Timestep currentTimestep; protected Map<CommodityType, Map<CropType, Double>> currentMinDemandFract; protected double currentGen2EcDemand; - private double exportTax; + private double exportTaxRate; private Map<CropType, Double> previousProducerCropPrices; protected Map<CropType, Double> currentProducerCropPrices; @@ -51,7 +51,7 @@ public abstract class AbstractCountryAgent { Double tb = tradeBarriers.get(c); LogWriter.println(worldPrice + " " + c); double exportPrice = worldPrice.getExportPrice(); - exportPrice *= (1 - exportTax); + exportPrice /= (1 + exportTaxRate); CountryPrice prices = new CountryPrice(worldPrice.getCountryImportPrice(tb==null ? 0 : tb, currentTimestep), exportPrice); countryPrices.put(c, prices); @@ -65,30 +65,29 @@ public abstract class AbstractCountryAgent { } protected void calculateProducerCropPrices() { - LogWriter.println("calculateProducerCropPrices " + country + " " + currentTimestep); currentProducerCropPrices = getProducerCropPrices(); LogWriter.println("calculateProducerCropPrices " + country + " " + currentTimestep + " prices now " + currentProducerCropPrices); } protected void calculateExportTax() { - exportTax = 0; + exportTaxRate = 0; if (previousProducerCropPrices != null) { for (CropType crop : CommodityType.CEREALS.getCropTypes()) { double newPrice = currentProducerCropPrices.get(crop); double oldPrice = previousProducerCropPrices.get(crop); - if ((newPrice - oldPrice)/ oldPrice > ModelConfig.EXPORT_TAX_THRESHOLD) { - exportTax = ModelConfig.EXPORT_TAX_RATE; - LogWriter.println(String.format("calculateExportTax: Price Spike: %s: Price increased beyond threshold for %s, newPrice=%.4f, oldPrice=%.4f", country, crop, newPrice, oldPrice)); + 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)); break; } - else { - LogWriter.println(String.format("calculateExportTax: %s: Price change below threshold for %s, newPrice=%.4f, oldPrice=%.4f", country, crop, newPrice, oldPrice)); - } + else + LogWriter.println(String.format("calculateExportTax: Price change below threshold, %s, %d, %s, %.2f, %.6f, %.6f", country, currentTimestep.getTimestep(), crop, priceChangeRate*100, newPrice, oldPrice)); } } - LogWriter.println(String.format("calculateExportTax %s: exportTax is now %s", country, exportTax)); + LogWriter.println(String.format("calculateExportTax %s: exportTax is now %s", country, exportTaxRate)); } protected abstract Map<CropType, Double> getProducerCropPrices(); -- GitLab