From 2a9360e24eeb1a723532ec045fa1170859de6975 Mon Sep 17 00:00:00 2001
From: Peter Alexander <peter@blackhillock.co.uk>
Date: Fri, 18 Sep 2015 23:05:08 +0100
Subject: [PATCH] Stop changes in import during calibration

---
 src/ac/ed/lurg/ModelMain.java                     | 4 ++--
 src/ac/ed/lurg/country/GlobalPrice.java           | 2 +-
 src/ac/ed/lurg/country/gams/GamsCountryInput.java | 4 ++--
 3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java
index b3d01442..3ab05cdf 100644
--- a/src/ac/ed/lurg/ModelMain.java
+++ b/src/ac/ed/lurg/ModelMain.java
@@ -162,7 +162,7 @@ public class ModelMain {
 
 			double imports = totalImportCommodities.get(crop);
 			double exports = totalExportCommodities.get(crop) * (1.0-ModelConfig.TRANSPORT_LOSSES);
-			GlobalPrice adjustedPrice = prevPrice.updateMarketPrices(imports, exports);
+			GlobalPrice adjustedPrice = prevPrice.createWithUpdatedMarketPrices(imports, exports);
 			LogWriter.println(String.format("Price for %s updated from %s (imports amount %.0f, exports amount %.0f) to %s ", crop.getGamsName(), prevPrice, imports, exports, adjustedPrice));
 			prevWorldPrices.put(crop, adjustedPrice);
 		}
@@ -218,7 +218,7 @@ public class ModelMain {
 	
 	private void writeGlobalMarketFile(Timestep timestep) {
 		try {
-			StringBuffer sbHeadings = new StringBuffer("Year, Crop, Imports (Mt), Exports (Mt), import price, export price");
+			StringBuffer sbHeadings = new StringBuffer("Year, Crop, Imports (Mt), Exports (Mt), New import price, New export price");
 			BufferedWriter outputFile = getFileWriter(timestep, ModelConfig.PRICES_OUTPUT_FILE, sbHeadings.toString());
 
 			for (CropType crop : CropType.getImportedTypes() ) {
diff --git a/src/ac/ed/lurg/country/GlobalPrice.java b/src/ac/ed/lurg/country/GlobalPrice.java
index 7f5eafaa..61758314 100644
--- a/src/ac/ed/lurg/country/GlobalPrice.java
+++ b/src/ac/ed/lurg/country/GlobalPrice.java
@@ -35,7 +35,7 @@ public class GlobalPrice {
 		return exportAmount;
 	}
 
-	public GlobalPrice updateMarketPrices(double imports, double exports) {
+	public GlobalPrice createWithUpdatedMarketPrices(double imports, double exports) {
 		if (imports > 0 || exports > 0) {
 			double ratio;
 
diff --git a/src/ac/ed/lurg/country/gams/GamsCountryInput.java b/src/ac/ed/lurg/country/gams/GamsCountryInput.java
index eed98aa4..431a3992 100644
--- a/src/ac/ed/lurg/country/gams/GamsCountryInput.java
+++ b/src/ac/ed/lurg/country/gams/GamsCountryInput.java
@@ -44,7 +44,7 @@ public class GamsCountryInput {
 	public static GamsCountryInput createInput(CompositeCountry country, Map<CommodityType, Double> projectedDemand, Map<CropType, GlobalPrice> worldPrices,
 			Map<CropType, Double> baseNetImport, Map<CropType, Double> maxOfProdOrSupply, Map<CropType, Double> cropAdjustments, boolean calibrateToObserved) {
 			
-		double allowedImportChange = ModelConfig.MAX_IMPORT_CHANGE;
+		double allowedImportChange = calibrateToObserved ? 0.0 : ModelConfig.MAX_IMPORT_CHANGE;		
 		Map<CropType, ImportExportConstraint> importConstraints = new HashMap<CropType, ImportExportConstraint>();
 		
 		for (Map.Entry<CropType, Double> entry : baseNetImport.entrySet()) {
@@ -52,7 +52,7 @@ public class GamsCountryInput {
 			double change = allowedImportChange * maxOfProdOrSupply.get(c);
 			importConstraints.put(c, new ImportExportConstraint(entry.getValue() - change, entry.getValue() + change));
 		}
-		
+
 		return new GamsCountryInput(country, projectedDemand, worldPrices, importConstraints, cropAdjustments, calibrateToObserved);
 	}
 	
-- 
GitLab