From 5e294afa4801ca839da380453ac0ef78ac29c1ef Mon Sep 17 00:00:00 2001
From: alexanpe <devnull@localhost>
Date: Wed, 13 Mar 2019 18:22:10 +0000
Subject: [PATCH] Changes to demand output file

---
 debug_config.properties                             |  2 +-
 .../ed/lurg/country/gams/GamsDemandOptimiser.java   |  2 +-
 src/ac/ed/lurg/demand/ElasticDemandManager.java     | 13 +++++++------
 3 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/debug_config.properties b/debug_config.properties
index 69f55b1b..5d5b0704 100644
--- a/debug_config.properties
+++ b/debug_config.properties
@@ -9,7 +9,7 @@ IS_CALIBRATION_RUN = false
 GENERATE_NEW_YIELD_CLUSTERS = false
 NUM_YIELD_CLUSTERS=8000
 
-END_TIMESTEP=0
+END_TIMESTEP=18
 TIMESTEP_SIZE=5
 
 INTERPOLATE_OUTPUT_YEARS = false
diff --git a/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java b/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java
index f64f0186..ef347485 100644
--- a/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java
+++ b/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java
@@ -104,7 +104,7 @@ public class GamsDemandOptimiser {
 	private GamsDemandOutput handleResults(GAMSDatabase outDB) {
 		int modelStatus = (int) outDB.getParameter("ms").findRecord().getValue();
 		String status = GAMSGlobals.ModelStat.lookup(modelStatus).toString();
-		LogWriter.println(String.format("\nDemamd %s: Modelstatus %s, Solvestatus %s", inputData.getCountry(),
+		LogWriter.println(String.format("\nDemamd %s %d: Modelstatus %s, Solvestatus %s", inputData.getCountry(), inputData.getYear(),
 				status,	GAMSGlobals.SolveStat.lookup((int) outDB.getParameter("ss").findRecord().getValue()) ));
 		
 		GAMSVariable varU = outDB.getVariable("u");
diff --git a/src/ac/ed/lurg/demand/ElasticDemandManager.java b/src/ac/ed/lurg/demand/ElasticDemandManager.java
index ad27844b..e0d466cc 100644
--- a/src/ac/ed/lurg/demand/ElasticDemandManager.java
+++ b/src/ac/ed/lurg/demand/ElasticDemandManager.java
@@ -77,13 +77,13 @@ public class ElasticDemandManager extends AbstractSSPDemandManager {
 			foodDemands.put(commodity, d);
 		}
 
-		writeGamsDemandOutputs(inputData, gamsOutput, foodDemands);
+		writeGamsDemandOutputs(inputData, gamsOutput, foodDemands, population);
 
 		return foodDemands;
 	}
 
 	private String getDamsDemandOutputsHeader() {
-		StringBuffer sbHeader = new StringBuffer("country,year,gdpPc");
+		StringBuffer sbHeader = new StringBuffer("country,year,gdpPc,population");
 
 		for (CommodityType commodity : CommodityType.values())
 			sbHeader.append(",price_" + commodity.getGamsName());
@@ -102,9 +102,10 @@ public class ElasticDemandManager extends AbstractSSPDemandManager {
 		return sbHeader.toString();
 	}
 
-	private void writeGamsDemandOutputs(GamsDemandInput inputData, GamsDemandOutput gamsOutput, Map<CommodityType, Double> foodDemands) {
+	private void writeGamsDemandOutputs(GamsDemandInput inputData, GamsDemandOutput gamsOutput, Map<CommodityType, Double> foodDemands, double population) {
 		try {
-			StringBuffer sbData = new StringBuffer(String.format("%s,%d,%.2f", inputData.getCountry(), inputData.getYear(),inputData.getGdpPc()));
+			Map<CommodityType, Double> plumDemands = gamsOutput.getPlumDemands();
+			StringBuffer sbData = new StringBuffer(String.format("%s,%d,%.2f,%.6f", inputData.getCountry(), inputData.getYear(),inputData.getGdpPc(), population));
 
 			for (CommodityType commodity : CommodityType.values())
 				sbData.append(String.format(",%.4f", inputData.getPrices().get(commodity)));
@@ -116,9 +117,9 @@ public class ElasticDemandManager extends AbstractSSPDemandManager {
 			for (CommodityType commodity : CommodityType.values())
 				sbData.append(String.format(",%.4f", gamsOutput.getGamsDemands(commodity).getDiscretionary()));
 			for (CommodityType commodity : CommodityType.getAllFoodItems())
-				sbData.append(String.format(",%.4f", gamsOutput.getPlumDemands().get(commodity)));
+				sbData.append(String.format(",%.4f", plumDemands.get(commodity)));
 			for (CommodityType commodity : CommodityType.getAllFoodItems())
-				sbData.append(String.format(",%.4f", foodDemands.get(commodity)));
+				sbData.append(String.format(",%.4f", foodDemands.get(commodity)/population));
 
 			outputFile.write(sbData.toString());
 			outputFile.newLine();
-- 
GitLab