diff --git a/src/ac/ed/lurg/demand/ElasticDemandManager.java b/src/ac/ed/lurg/demand/ElasticDemandManager.java index eca6b8d87f9eebe4719c4bab89d12e2ccff64cba..f5fbece8b307b4877c4ab6eedefc3b615fcc6a01 100755 --- a/src/ac/ed/lurg/demand/ElasticDemandManager.java +++ b/src/ac/ed/lurg/demand/ElasticDemandManager.java @@ -96,6 +96,28 @@ public class ElasticDemandManager extends AbstractSSPDemandManager { double d = cpcAdj * population; foodDemands.put(commodity, d); } + + double foodSpend = 0; + for (CommodityType commodity : CommodityType.getAllFoodItems()) { + double consumerPrice = consumerPrices.get(commodity); + double rebasedDemand = foodDemands.get(commodity); + double caloriesPerT = kcalPerT.get(commodity); + + foodSpend += consumerPrice*rebasedDemand/population/365/2000*caloriesPerT; + } + + LogWriter.println("foodSpend " + foodSpend + " budget " + gdpPc*ModelConfig.MAX_INCOME_PROPORTION_FOOD_SPEND); + + if(foodSpend > gdpPc*ModelConfig.MAX_INCOME_PROPORTION_FOOD_SPEND) { + double overspend= 1/(foodSpend/(gdpPc*ModelConfig.MAX_INCOME_PROPORTION_FOOD_SPEND)); + LogWriter.println("overspend " + overspend); + for (Map.Entry<CommodityType, Double> entry : foodPc.entrySet()) { + CommodityType commodity = entry.getKey(); + double rebasedDemand = foodDemands.get(commodity); + double affordableDemand = rebasedDemand*overspend; + foodDemands.put(commodity, affordableDemand); + } + } if (outputGamsDemand) writeGamsDemandOutputs(inputData, gamsOutput, foodDemands, population);