From 201fef6a5b11a0094885a6a88f1dd40aa7bdb98f Mon Sep 17 00:00:00 2001
From: Peter Alexander <>
Date: Sun, 16 Jan 2022 22:06:30 +0000
Subject: [PATCH] Debug changes for export tax

---
 src/ac/ed/lurg/ModelMain.java                    | 2 --
 src/ac/ed/lurg/country/AbstractCountryAgent.java | 4 ++++
 src/ac/ed/lurg/country/CountryAgent.java         | 4 +++-
 src/ac/ed/lurg/country/CountryAgentManager.java  | 6 ------
 4 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java
index 06e11cdb..5d41efae 100644
--- a/src/ac/ed/lurg/ModelMain.java
+++ b/src/ac/ed/lurg/ModelMain.java
@@ -123,8 +123,6 @@ public class ModelMain {
 		
 		YieldRaster yieldSurfaces = getYieldSurfaces(timestep); // this will wait for the marker file from LPJ if configured to do so
 		getUpdateIrrigationData(timestep, yieldSurfaces); // updating currentIrrigationData
-
-		countryAgents.savePreviousProducerCropPricesForAll();
 		
 		// When running half earth we can to alter protected areas data at a point in time
 		if(ModelConfig.HALFEARTH && ModelConfig.FORCE_PROTECTED_AREAS_START_YEAR == timestep.getYear() && !ModelConfig.IS_CALIBRATION_RUN) {
diff --git a/src/ac/ed/lurg/country/AbstractCountryAgent.java b/src/ac/ed/lurg/country/AbstractCountryAgent.java
index f5af8f01..2fee1dab 100644
--- a/src/ac/ed/lurg/country/AbstractCountryAgent.java
+++ b/src/ac/ed/lurg/country/AbstractCountryAgent.java
@@ -67,6 +67,7 @@ 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() {
@@ -81,6 +82,9 @@ public abstract class AbstractCountryAgent {
 					LogWriter.println(String.format("calculateExportTax: Price Spike: %s: Price increased beyond threshold for %s, newPrice=%.4f, oldPrice=%.4f", country, crop, newPrice, oldPrice));
 					break;
 				}
+				else {
+					LogWriter.println(String.format("calculateExportTax: %s: Price change below threshold for %s, newPrice=%.4f, oldPrice=%.4f", country, crop, newPrice, oldPrice));
+				}
 			}
 		}
 
diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java
index 721d6663..51eb93e8 100644
--- a/src/ac/ed/lurg/country/CountryAgent.java
+++ b/src/ac/ed/lurg/country/CountryAgent.java
@@ -107,8 +107,10 @@ public class CountryAgent extends AbstractCountryAgent {
 		// project demand
 		calculateCountryPricesAndDemand(worldPrices, false);
 		
-		if (ModelConfig.APPLY_EXPORT_TAXES && !ModelConfig.IS_CALIBRATION_RUN)
+		if (ModelConfig.APPLY_EXPORT_TAXES && !ModelConfig.IS_CALIBRATION_RUN) {
 			calculateExportTax();
+			savePreviousProducerCropPrices();
+		}
 		
 		if (saveGamsGdxFiles && ModelConfig.PRICE_ELASTIC_DEMAND)
 			saveGDXFile("demand");
diff --git a/src/ac/ed/lurg/country/CountryAgentManager.java b/src/ac/ed/lurg/country/CountryAgentManager.java
index 569e76b1..7a9abf49 100644
--- a/src/ac/ed/lurg/country/CountryAgentManager.java
+++ b/src/ac/ed/lurg/country/CountryAgentManager.java
@@ -145,12 +145,6 @@ public class CountryAgentManager {
 		}
 	}
 	
-	public void savePreviousProducerCropPricesForAll() {
-		for (CountryAgent ca : gamsCountryAgents) {
-			ca.savePreviousProducerCropPrices();
-		}
-	}
-	
 	public void serializeCropUsageForAll() {
 		Map<CompositeCountry, Map<CropType, CropUsageData>> cropUsageDataMap = new HashMap<CompositeCountry, Map<CropType, CropUsageData>>();
 		for (CountryAgent ca : gamsCountryAgents) {
-- 
GitLab