Skip to content
Snippets Groups Projects
Commit 16f66571 authored by Peter Alexander's avatar Peter Alexander
Browse files

Rebase elastic demand projections

parent afa42328
No related branches found
No related tags found
No related merge requests found
......@@ -35,7 +35,7 @@ $gdxin %gdx_prices_and_gdp%
$load p=price, m=gdp_pc
$gdxin
display p;
display p, m;
w.up(j) = 1;
......
......@@ -380,5 +380,5 @@ public class ModelConfig {
public static final boolean USE_CRAFTY_COUNTRIES = getBooleanProperty("USE_CRAFTY_COUNTRIES", false);
public static final String CRAFTY_PRODUCTION_DIR = getProperty("CRAFTY_PRODUCTION_DIR", OUTPUT_DIR + File.separator + "crafty");
public static final double NON_FOOD_PRICE = getDoubleProperty("NON_FOOD_PRICE", 60.0);
public static final double NON_FOOD_PRICE = getDoubleProperty("NON_FOOD_PRICE", 0.06);
}
......@@ -67,7 +67,7 @@ public class GamsDemandOptimiser {
CommodityType comm = entry.getKey();
Vector<String> v = new Vector<String>();
v.add(comm.getGamsName());
double priceComm = entry.getValue();
double priceComm = entry.getValue() * 1000;
LogWriter.println(String.format("%s: \tprice= %.4f", comm.getGamsName(), priceComm));
setGamsParamValue(priceP.addRecord(v), priceComm, 4);
}
......
......@@ -11,8 +11,8 @@ import ac.ed.lurg.utils.LogWriter;
public abstract class AbstractSSPDemandManager extends AbstractDemandManager {
private SspManager sspManager;
private String ssp_scenario;
protected SspManager sspManager;
protected String ssp_scenario;
protected BaseConsumpManager baseConsumpManager;
public AbstractSSPDemandManager(String ssp_scenario, BaseConsumpManager baseConsumpManager, CompositeCountryManager compositeCountryManager) {
......@@ -24,25 +24,23 @@ public abstract class AbstractSSPDemandManager extends AbstractDemandManager {
@Override
Map<CommodityType, Double> getFoodDemand(SingleCountry c, int year, Map<CommodityType, Double> prices) {
SspData baseSspData = sspManager.get(ssp_scenario, ModelConfig.BASE_YEAR, c);
SspData sd = sspManager.get(ssp_scenario, year, c);
Map<CommodityType, Double> foodDemandMap = new HashMap<CommodityType, Double>();
if (baseSspData == null || sd == null) {
LogWriter.printlnWarning(String.format("No baseSspData or ssp for %s, baseYr:%d, year:%d, %s, base:%s, sd:%s. Skipping", ssp_scenario, ModelConfig.BASE_YEAR, year, c.getCountryName(), baseSspData, sd));
if (sd == null) {
LogWriter.printlnWarning(String.format("No ssp for %s, baseYr:%d, year:%d, %s, sd:%s. Skipping", ssp_scenario, ModelConfig.BASE_YEAR, year, c.getCountryName(), sd));
return foodDemandMap;
}
double gdpPcYear;
if((ModelConfig.CONSTANT_DIET_HIGH_INCOME & c.getIncomeGroup().toLowerCase().contains("high")) ||
(ModelConfig.CONSTANT_DIET_LOW_INCOME & !c.getIncomeGroup().toLowerCase().contains("high")))
gdpPcYear = baseSspData.getGdpPc();
gdpPcYear = sspManager.get(ssp_scenario, ModelConfig.BASE_YEAR, c).getGdpPc();
else gdpPcYear= sd.getGdpPc();
LogWriter.println("Got ssp data for " + c.getCountryName() + " of " + sd);
foodDemandMap = getFoodDemandMap(c, baseSspData.getGdpPc(), gdpPcYear * ModelConfig.SSP_GDP_PC_FACTOR,
sd.getPopulation() * ModelConfig.SSP_POPULATION_FACTOR, prices);
foodDemandMap = getFoodDemandMap(c, gdpPcYear * ModelConfig.SSP_GDP_PC_FACTOR, sd.getPopulation() * ModelConfig.SSP_POPULATION_FACTOR, prices);
if(!ModelConfig.SHOCKS_POSSIBLE){
return foodDemandMap;
......@@ -60,5 +58,5 @@ public abstract class AbstractSSPDemandManager extends AbstractDemandManager {
return projectedCpc;
}
abstract Map<CommodityType, Double> getFoodDemandMap(SingleCountry c, double baseGdpPc, double gdpPc, double population, Map<CommodityType, Double> prices);
abstract Map<CommodityType, Double> getFoodDemandMap(SingleCountry c, double gdpPc, double population, Map<CommodityType, Double> prices);
}
......@@ -19,9 +19,11 @@ public class DemandManagerSSP extends AbstractSSPDemandManager {
}
@Override
Map<CommodityType, Double> getFoodDemandMap(SingleCountry c, double baseGdpPc, double gdpPc, double population, Map<CommodityType, Double> prices) {
Map<CommodityType, Double> getFoodDemandMap(SingleCountry c, double gdpPc, double population, Map<CommodityType, Double> prices) {
Map<CommodityType, Double> aFoodDemandMap = new HashMap<CommodityType, Double>();
SspData baseSspData = sspManager.get(ssp_scenario, ModelConfig.BASE_YEAR, c);
double baseGdpPc = baseSspData.getGdpPc();
for (CommodityType commodity : CommodityType.getAllFoodItems()) {
ModelFitType fitType = commodity.isAnimalProduct() ? ModelConfig.DEMAND_ANIMAL_PROD_FIT : ModelConfig.DEMAND_NON_ANIMAL_PROD_FIT;
DemandCurve dc = demandCurveManager.get(commodity, fitType);
......
......@@ -3,36 +3,47 @@ package ac.ed.lurg.demand;
import java.util.HashMap;
import java.util.Map;
import ac.ed.lurg.ModelConfig;
import ac.ed.lurg.country.CompositeCountryManager;
import ac.ed.lurg.country.SingleCountry;
import ac.ed.lurg.country.gams.GamsDemandOptimiser;
import ac.ed.lurg.types.CommodityType;
public class ElasticDemandManager extends AbstractSSPDemandManager {
private Map<CommodityType, Double> baseExpCpc;
protected Map<SingleCountry, Map<CommodityType, Double>> baseCpcCache = new HashMap<SingleCountry, Map<CommodityType, Double>>();
public ElasticDemandManager(String ssp_scenario, BaseConsumpManager baseConsumpManager, CompositeCountryManager compositeCountryManager) {
super(ssp_scenario, baseConsumpManager, compositeCountryManager);
}
@Override
Map<CommodityType, Double> getFoodDemandMap(SingleCountry c, double baseGdpPc, double gdpPc, double population, Map<CommodityType, Double> prices) {
Map<CommodityType, Double> aFoodPc = new GamsDemandOptimiser(c, gdpPc, prices).getDemandPc();
Map<CommodityType, Double> aFood = new HashMap<CommodityType, Double>();
Map<CommodityType, Double> getFoodDemandMap(SingleCountry c, double gdpPc, double population, Map<CommodityType, Double> prices) {
// Do the projection
Map<CommodityType, Double> foodPc = new GamsDemandOptimiser(c, gdpPc, prices).getDemandPc();
Map<CommodityType, Double> foodDemands = new HashMap<CommodityType, Double>();
SspData baseSspData = sspManager.get(ssp_scenario, ModelConfig.BASE_YEAR, c);
double baseGdpPc = baseSspData.getGdp();
Map<CommodityType, Double> baseExpCpcMap = baseCpcCache.get(c);
if (baseExpCpcMap == null) { // we should only do this in the first year
baseCpcCache.put(c, foodPc);
baseExpCpcMap = foodPc;
}
for (Map.Entry<CommodityType, Double> entry : aFoodPc.entrySet()) {
for (Map.Entry<CommodityType, Double> entry : foodPc.entrySet()) {
CommodityType commodity = entry.getKey();
double newExpCpc = entry.getValue();
//TODO double baseExpCpc = dc.getProjectConsumptionPc(baseGdpPc);
double baseExpCpc = Double.NaN;
double baseExpCpc = baseExpCpcMap.get(commodity);
double baseCpc = baseConsumpManager.get(c, commodity);
double cpc = rebaseConsumption(baseGdpPc, baseCpc, baseExpCpc, gdpPc, newExpCpc);
double d = cpc * population;
aFood.put(commodity, d);
foodDemands.put(commodity, d);
}
return aFood;
return foodDemands;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment