diff --git a/GAMS/elasticDemand.gms b/GAMS/elasticDemand.gms index 1433cc305b11873572cfe8f2bcaaf16b0f6365d5..e3f43c0436e7407322486798ac2b2cac4201b0a1 100644 --- a/GAMS/elasticDemand.gms +++ b/GAMS/elasticDemand.gms @@ -69,10 +69,9 @@ model MAIDADS_Sim "MAIDADS model for simulation" / MAIDADS_Sim.optfile = 1; option cns=path; -u = 0; -SubsistenceC(j) = (delta(j)+tau(j)*exp(omega*u))/(1+exp(omega*u)); -DiscretionaryC(i)$p(i) = [(alpha(i)+beta(i)*exp(u))/(1+exp(u))]/p(i)* - [m-sum(j,p(j)*SubsistenceC(j))]; +u = 0; +SubsistenceC(j) = 0.05; +DiscretionaryC(i)$p(i) = 0.05; DiscretionaryC.LO(i) = 1E-11; SubsistenceC.LO(j) = 0; w(j) = (SubsistenceC(j)+DiscretionaryC(j))*p(j)/m; diff --git a/debug_config.properties b/debug_config.properties index 0afa48b9196f68c7d1c7059ee4cdec1e02dabfc5..29b8ba623bdd2a858969821c450eb93838ca8d4b 100644 --- a/debug_config.properties +++ b/debug_config.properties @@ -2,14 +2,14 @@ BASE_DIR=.. YIELD_DIR=/Users/peteralexander/Documents/LURG/LPJ/LPJGPLUM_expt1.1_2006-2100_PLUM6xtra_20180412171654/rcp60 -DEBUG_LIMIT_COUNTRIES=true +DEBUG_LIMIT_COUNTRIES=false DEBUG_COUNTRY_NAME=China IS_CALIBRATION_RUN = true GENERATE_NEW_YIELD_CLUSTERS = false NUM_YIELD_CLUSTERS=8000 -END_TIMESTEP=1 +END_TIMESTEP=0 TIMESTEP_SIZE=1 INTERPOLATE_OUTPUT_YEARS = false diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index bf07a732b49ba4ce24992429d89d4ad22036c596..c899a92c3806a12c098549819271d6fafa2587f4 100644 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -183,15 +183,15 @@ public class ModelConfig { public static final String YIELD_FILENAME = getProperty("YIELD_FILENAME", "yieldPH.out"); public static final boolean PASTURE_FERT_RESPONSE_FROM_LPJ = getBooleanProperty("PASTURE_FERT_RESPONSE_FROM_LPJ", false);; - public static final double CALIB_FACTOR_CEREAL_C3 = getDoubleProperty("CALIB_FACTOR_CEREAL_C3", 1.077); - public static final double CALIB_FACTOR_CEREAL_C4 = getDoubleProperty("CALIB_FACTOR_CEREAL_C4", 0.685); + public static final double CALIB_FACTOR_CEREAL_C3 = getDoubleProperty("CALIB_FACTOR_CEREAL_C3", 1.046); + public static final double CALIB_FACTOR_CEREAL_C4 = getDoubleProperty("CALIB_FACTOR_CEREAL_C4", 0.654); public static final double CALIB_FACTOR_MISCANTHUS = getDoubleProperty("CALIB_FACTOR_MISCANTHUS", 2.148); - public static final double CALIB_FACTOR_RICE = getDoubleProperty("CALIB_FACTOR_RICE", 0.991); - public static final double CALIB_FACTOR_OILCROPS = getDoubleProperty("CALIB_FACTOR_OILCROPS", 0.608); - public static final double CALIB_FACTOR_PULSES = getDoubleProperty("CALIB_FACTOR_PULSES", 0.865); - public static final double CALIB_FACTOR_STARCHY_ROOTS = getDoubleProperty("CALIB_FACTOR_STARCHY_ROOTS", 4.856); - public static final double CALIB_FACTOR_FRUITVEG = getDoubleProperty("CALIB_FACTOR_FRUITVEG", 9.0); - public static final double CALIB_FACTOR_SUGAR = getDoubleProperty("CALIB_FACTOR_SUGAR", 4.0); + public static final double CALIB_FACTOR_RICE = getDoubleProperty("CALIB_FACTOR_RICE", 0.972); + public static final double CALIB_FACTOR_OILCROPS = getDoubleProperty("CALIB_FACTOR_OILCROPS", 0.578); + public static final double CALIB_FACTOR_PULSES = getDoubleProperty("CALIB_FACTOR_PULSES", 0.686); + public static final double CALIB_FACTOR_STARCHY_ROOTS = getDoubleProperty("CALIB_FACTOR_STARCHY_ROOTS", 3.526); + public static final double CALIB_FACTOR_FRUITVEG = getDoubleProperty("CALIB_FACTOR_FRUITVEG", 4.560); + public static final double CALIB_FACTOR_SUGAR = getDoubleProperty("CALIB_FACTOR_SUGAR", 11.909); public static final double INITIAL_PRICE_SHIFT = getDoubleProperty("INITIAL_PRICE_SHIFT", 1.0); public static final double INITAL_PRICE_WHEAT = getDoubleProperty("INITAL_PRICE_WHEAT", 0.157 * ModelConfig.INITIAL_PRICE_SHIFT); diff --git a/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java b/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java index 71199e5fcc9d604b00eed8cff2bf5f8661437194..17e3650ccb9b9814608f0a495bf9685f9c22c768 100644 --- a/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java @@ -24,11 +24,13 @@ public class GamsDemandOptimiser { private SingleCountry country; private double gdpPc; private Map<CommodityType, Double> prices; + private double usaGdpPc; - public GamsDemandOptimiser(SingleCountry country, double gdpPc, Map<CommodityType, Double> prices) { + public GamsDemandOptimiser(SingleCountry country, double gdpPc, Map<CommodityType, Double> prices, double usaGdpPc) { this.country = country; this.gdpPc = gdpPc; this.prices = prices; + this.usaGdpPc = usaGdpPc; } public Map<CommodityType, Double> getDemandPc() { @@ -63,14 +65,19 @@ public class GamsDemandOptimiser { LogWriter.println("\nPrice"); GAMSParameter priceP = inDB.addParameter("price", 1); + for (Map.Entry<CommodityType, Double> entry : prices.entrySet()) { CommodityType comm = entry.getKey(); Vector<String> v = new Vector<String>(); v.add(comm.getGamsName()); - double priceComm = (!comm.equals(CommodityType.NONFOOD)) ? entry.getValue() * 1000 / comm.getkcalPerT()*2000*365 : entry.getValue() * 1000; - //price per calorie of commodity x per year assuming 2000 kcal a day for whole year + + double priceComm; + if (comm == CommodityType.NONFOOD) + priceComm = 45.376+53.036*gdpPc/usaGdpPc; + else + priceComm = entry.getValue() * 1000 / comm.getkcalPerT()*2000*365; //price per calorie of commodity x per year assuming 2000 kcal a day for whole year - LogWriter.println(String.format("%s: \tprice= %.4f", comm.getGamsName(), priceComm)); + LogWriter.println(String.format("%14s: price= %.4f", comm.getGamsName(), priceComm)); setGamsParamValue(priceP.addRecord(v), priceComm, 4); } } @@ -98,13 +105,16 @@ public class GamsDemandOptimiser { LogWriter.println(String.format("Can't find commodity from Gams demand, so ignoring: " + commodityName)); else { //gams is calculating demand in number of 2000 kcal servings per day so * by 2000 and * 365 to get kcal per year - double demandPc = commodity.equals(CommodityType.NONFOOD) ? rec.getValue() : rec.getValue()*2000*365*1/commodity.getkcalPerT(); - - LogWriter.println("country " + country + " calories per day " + rec.getValue()*2000); - LogWriter.println(String.format("%s:\t demandPc= %.3f", commodityName, demandPc)); + double demandGams = rec.getValue(); - if (!commodity.equals(CommodityType.NONFOOD)) // we don't want to consider non-food + if (commodity == CommodityType.NONFOOD) { // we don't want to consider non-food, so not added to demandMap + LogWriter.println(String.format("%14s: demand(gams)= %.3f", commodityName, demandGams)); + } + else { + double demandPc = rec.getValue()*2000*365*1/commodity.getkcalPerT(); + LogWriter.println(String.format("%14s: demand(gams)= %.3f, demand(kcal)=%.1f, demand(plum)= %.3f", commodityName, demandGams, demandGams*2000, demandPc)); demandMap.put(commodity, demandPc); + } } } diff --git a/src/ac/ed/lurg/demand/AbstractSSPDemandManager.java b/src/ac/ed/lurg/demand/AbstractSSPDemandManager.java index fba1b407dc7a1ca72b3fdaf0292f3acbce802ca8..6afe752da2c828d231eaafb16a380f7bbb197f01 100644 --- a/src/ac/ed/lurg/demand/AbstractSSPDemandManager.java +++ b/src/ac/ed/lurg/demand/AbstractSSPDemandManager.java @@ -5,6 +5,7 @@ import java.util.Map; import ac.ed.lurg.ModelConfig; import ac.ed.lurg.country.CompositeCountryManager; +import ac.ed.lurg.country.CountryManager; import ac.ed.lurg.country.SingleCountry; import ac.ed.lurg.types.CommodityType; import ac.ed.lurg.utils.LogWriter; @@ -14,12 +15,14 @@ public abstract class AbstractSSPDemandManager extends AbstractDemandManager { protected SspManager sspManager; protected String ssp_scenario; protected BaseConsumpManager baseConsumpManager; + private SingleCountry usa; public AbstractSSPDemandManager(String ssp_scenario, BaseConsumpManager baseConsumpManager, CompositeCountryManager compositeCountryManager) { super(compositeCountryManager); this.ssp_scenario = ssp_scenario; this.baseConsumpManager = baseConsumpManager; sspManager = new SspManager(); + usa = CountryManager.getForName("United States of America"); } @Override @@ -39,8 +42,10 @@ public abstract class AbstractSSPDemandManager extends AbstractDemandManager { else gdpPcYear= sd.getGdpPc(); + SspData usaSd = sspManager.get(ssp_scenario, year, usa); + LogWriter.println("Got ssp data for " + c.getCountryName() + " of " + sd); - foodDemandMap = getFoodDemandMap(c, 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, usaSd.getGdpPc()); if(!ModelConfig.SHOCKS_POSSIBLE){ return foodDemandMap; @@ -58,5 +63,5 @@ public abstract class AbstractSSPDemandManager extends AbstractDemandManager { return projectedCpc; } - abstract Map<CommodityType, Double> getFoodDemandMap(SingleCountry c, double gdpPc, double population, Map<CommodityType, Double> prices); + abstract Map<CommodityType, Double> getFoodDemandMap(SingleCountry c, double gdpPc, double population, Map<CommodityType, Double> prices, double usaGdpPc); } diff --git a/src/ac/ed/lurg/demand/DemandManagerSSP.java b/src/ac/ed/lurg/demand/DemandManagerSSP.java index f043562787db82f077206f54a0273fc4edf44566..41f5c3192717555f5e56f22d24dc462c72a3ad12 100644 --- a/src/ac/ed/lurg/demand/DemandManagerSSP.java +++ b/src/ac/ed/lurg/demand/DemandManagerSSP.java @@ -19,7 +19,7 @@ public class DemandManagerSSP extends AbstractSSPDemandManager { } @Override - Map<CommodityType, Double> getFoodDemandMap(SingleCountry c, double gdpPc, double population, Map<CommodityType, Double> prices) { + Map<CommodityType, Double> getFoodDemandMap(SingleCountry c, double gdpPc, double population, Map<CommodityType, Double> prices, double usaGdpPc) { Map<CommodityType, Double> aFoodDemandMap = new HashMap<CommodityType, Double>(); SspData baseSspData = sspManager.get(ssp_scenario, ModelConfig.BASE_YEAR, c); double baseGdpPc = baseSspData.getGdpPc(); diff --git a/src/ac/ed/lurg/demand/ElasticDemandManager.java b/src/ac/ed/lurg/demand/ElasticDemandManager.java index 62eb3f18ed93b7589c203d1d3d7a9cfdb2959d67..5c63ca71278680a14c1190dd0a9a8f478e59b62e 100644 --- a/src/ac/ed/lurg/demand/ElasticDemandManager.java +++ b/src/ac/ed/lurg/demand/ElasticDemandManager.java @@ -12,16 +12,16 @@ import ac.ed.lurg.types.CommodityType; public class ElasticDemandManager extends AbstractSSPDemandManager { 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 gdpPc, double population, Map<CommodityType, Double> prices) { + Map<CommodityType, Double> getFoodDemandMap(SingleCountry c, double gdpPc, double population, Map<CommodityType, Double> prices, double usaGdpPc) { // Do the projection - Map<CommodityType, Double> foodPc = new GamsDemandOptimiser(c, gdpPc, prices).getDemandPc(); + Map<CommodityType, Double> foodPc = new GamsDemandOptimiser(c, gdpPc, prices, usaGdpPc).getDemandPc(); Map<CommodityType, Double> foodDemands = new HashMap<CommodityType, Double>(); SspData baseSspData = sspManager.get(ssp_scenario, ModelConfig.BASE_YEAR, c); diff --git a/src/ac/ed/lurg/yield/LPJCropTypes.java b/src/ac/ed/lurg/yield/LPJCropTypes.java index 019a686a46c080d6891a7bf99dc9986900ed49d7..d5a2ade18dc48b2ae4bf4f89a3277ff607118ff2 100644 --- a/src/ac/ed/lurg/yield/LPJCropTypes.java +++ b/src/ac/ed/lurg/yield/LPJCropTypes.java @@ -10,7 +10,7 @@ public enum LPJCropTypes { OILCROPS("Oilcrops"), STARCHY_ROOTS("StarchyRoots"), FRUITVEG("Oilcrops"), - SUGAR("CerealsC3"), + SUGAR("Oilcrops"), PASTURE_C3("PC3G"), PASTURE_C4("PC4G");