From 5e09e20f406d328fdb7fdfb03599e7676a295770 Mon Sep 17 00:00:00 2001 From: Roslyn Henry <roslyn.henry@ed.ac.uk> Date: Thu, 17 Dec 2020 08:55:22 +0000 Subject: [PATCH] Fix for shock method. --- src/ac/ed/lurg/country/CountryAgent.java | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index ef7f7e6a..7eaca36e 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -251,13 +251,13 @@ public class CountryAgent extends AbstractCountryAgent { double totalProduction = getTotalProduction(); double shockMagnitude = 0.0; - Map<CropType, CropUsageData> cropUsages = previousGamsRasterOutput.getCropUsageData(); - for (CropType crop : CropType.getImportedTypes()) { - - if(cropUsages.get(crop).getProductionExpected() != 0) - shockMagnitude += (cropUsages.get(crop).getProductionShock() /cropUsages.get(crop).getProductionExpected()) * (cropUsages.get(crop).getProductionExpected()/totalProduction); - } + for (Map.Entry<CropType, CropUsageData> entry : previousGamsRasterOutput.getCropUsageData().entrySet()) { + CropUsageData cropUsage = entry.getValue(); + CropType crop = entry.getKey(); + if(crop.isImportedCrop() && cropUsage.getProductionExpected() != 0) + shockMagnitude += (cropUsage.getProductionShock() /cropUsage.getProductionExpected()) * (cropUsage.getProductionExpected()/totalProduction); + } demandManager.updateGdpLossesFromShock(country, currentTimestep.getYear(), shockMagnitude); } @@ -271,9 +271,13 @@ public class CountryAgent extends AbstractCountryAgent { public double getTotalProduction() { double totalProduction = 0; - for (CropType crop : CropType.getImportedTypes()) { //assuming pasture and set aside not part of agricultural value, valid or not? - totalProduction += previousGamsRasterOutput.getCropUsageData().get(crop).getProductionExpected(); - } + + for (Map.Entry<CropType, CropUsageData> entry : previousGamsRasterOutput.getCropUsageData().entrySet()) { + CropUsageData cropUsage = entry.getValue(); + CropType crop = entry.getKey(); + if(crop.isImportedCrop()) //assuming pasture and set aside not part of agricultural value, valid or not? + totalProduction += cropUsage.getProductionExpected(); + } return totalProduction; } -- GitLab