diff --git a/GAMS/LUOpt.gms b/GAMS/LUOpt.gms index d3305c9366bec46b2bf72432b4e915883e3505c3..5b03aa481dce88c8ddbb9a9e1d0605c9cb9ffb43 100644 --- a/GAMS/LUOpt.gms +++ b/GAMS/LUOpt.gms @@ -1,15 +1,16 @@ - SET all_types / monogastrics, ruminants, cereals, wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, pasture, setaside /; + SET all_types / monogastrics, ruminants, cereals, oilcropspulses, wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, pasture, setaside /; - SET crop(all_types) / wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, pasture, setaside /; - SET crop_less_pasture(crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, setaside/; - SET feed_crop(crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots, pasture/; - SET feed_crop_less_pasture(feed_crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots /; - SET traded_commodity(all_types) / monogastrics, ruminants, wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops /; - SET non_traded(all_types) / cereals, pasture, setaside /; + SET crop(all_types) / wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, pasture, setaside /; + SET crop_less_pasture(crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, setaside/; + SET feed_crop(crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots, pasture/; + SET feed_crop_less_pasture(feed_crop) / wheat, maize, rice, oilcrops, pulses, starchyRoots /; + SET traded_commodity(all_types) / monogastrics, ruminants, wheat, maize, rice, oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops /; + SET non_traded(all_types) / cereals, oilcropspulses, pasture, setaside /; SET animal_product(all_types) / monogastrics, ruminants /; - SET cereal_crop(crop) / wheat, maize, rice /; - SET non_cereal_crop(crop) / oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, pasture /; + SET cereal_crop(crop) / wheat, maize, rice /; + SET oilcrop_crop(crop) / oilcrops, pulses /; + SET non_cereal_crop(crop) / oilcrops, pulses, starchyRoots, fruitveg, sugar, energycrops, pasture /; SET location; PARAMETER suitableLandArea(location) areas of land in Mha; PARAMETER previousArea(crop, location) areas for previous timestep in Mha; @@ -35,6 +36,7 @@ PARAMETER irrigMaxRate(crop, location) max water application rate irrigation in litre per m2; PARAMETER irrigConstraint(location) max water available for irrigation in litre per m2; PARAMETER minDemandPerCereal(cereal_crop) min demand for each cereal crop as factor of all cereals; + PARAMETER minDemandPerOilcrop(oilcrop_crop) min demand for each oilcrop and pulse crop as factor of all oilcrops and pulses; PARAMETER seedAndWasteRate(all_types) rate of use for seed and waste combined; PARAMETER subsidyRate(crop) rates of subsidy compared to costs; @@ -60,7 +62,7 @@ $load location, suitableLandArea, demand, agriExpansionCost, cropIncCost, pastur $load previousArea, previousFertIntensity, previousIrrigIntensity, previousOtherIntensity, previousRuminantFeed, previousMonogastricFeed, previousImportAmount, previousExportAmount $load yieldNone, yieldFertOnly, yieldIrrigOnly, yieldBoth $load fertParam, irrigParam, otherIParam, exportPrices, importPrices, maxProduction, minProduction, unhandledCropRate, setAsideRate, maxLandExpansionRate, subsidyRate -$load meatEfficency, otherICost, irrigCost, irrigMaxRate, irrigConstraint, fertiliserUnitCost, domesticPriceMarkup, minDemandPerCereal, seedAndWasteRate, animalFeedFromOtherSources +$load meatEfficency, otherICost, irrigCost, irrigMaxRate, irrigConstraint, fertiliserUnitCost, domesticPriceMarkup, minDemandPerCereal, minDemandPerOilcrop, seedAndWasteRate, animalFeedFromOtherSources $gdxin @@ -71,6 +73,7 @@ $gdxin ruminantOtherFeed = animalFeedFromOtherSources * 0.25; monogastricOtherFeed = animalFeedFromOtherSources * 0.75; demand(cereal_crop) = demand('cereals') * minDemandPerCereal(cereal_crop); + demand(oilcrop_crop) = demand('oilcropspulses') * minDemandPerOilcrop(oilcrop_crop); previousArea(crop_less_pasture, location) = previousArea(crop_less_pasture, location) * (1.0 - unhandledCropRate); @@ -251,6 +254,7 @@ $gdxin display domesticallyProducedFoodSupply.l, demand, domesticallyMetDemand.l, importForFeed.l; display export.l, production.l, maxProduction, minProduction; + * Calculate summary information used in Java process parameter totalProd(all_types); parameter totalProdCost(all_types); diff --git a/data/DemandParameters.gdx b/data/DemandParameters.gdx index ca341df8ea0fde9cdd5220004778655dcb3e2cf2..a99959597817e5d046cac0c0fc4f8ab0f0db03cc 100644 Binary files a/data/DemandParameters.gdx and b/data/DemandParameters.gdx differ diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index 5c662f518b2dca74e17edea0dc90f2bf120b5da7..f6c59a678fa1b1d7dbdb0f4da32e1bedbe33fc59 100644 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -233,7 +233,6 @@ public class ModelConfig { public static final String DOMESTIC_OUTPUT_FILE = OUTPUT_DIR + File.separator + "domestic.txt"; public static final String COUNTRY_DEMAND_FILE = OUTPUT_DIR + File.separator + "countryDemand.txt"; public static final String FOOD_BALANCE_SHEET_FILE = OUTPUT_DIR + File.separator + "fbs.txt"; - public static final String UK_LAND_COVER_OUTPUT_FILE = OUTPUT_DIR + File.separator + "ukLC.txt"; public static final String ANIMAL_NUMBERS_OUTPUT_FILE = OUTPUT_DIR + File.separator + "animals.txt";; public static final boolean OUTPUT_FOR_LPJG = getBooleanProperty("OUTPUT_FOR_LPJG", true); @@ -275,10 +274,10 @@ public class ModelConfig { public static final String SSP_SCENARIO = getProperty("SSP_SCENARIO", "SSP1_v9_130325"); public static final ModelFitType DEMAND_ANIMAL_PROD_FIT = ModelFitType.findByName(getProperty("DEMAND_ANIMAL_PROD_FIT", "loglinear")); public static final ModelFitType DEMAND_NON_ANIMAL_PROD_FIT = ModelFitType.findByName(getProperty("DEMAND_NON_ANIMAL_PROD_FIT", "loglinear")); - public static final double TOTAL_MAX_CEREAL_CHANGE = getDoubleProperty("TOTAL_MAX_CEREAL_CHANGE", 0.5); - public static final double ANNUAL_MAX_CEREAL_CHANGE = getDoubleProperty("ANNUAL_MAX_CEREAL_CHANGE", 0.0); - public static final boolean LIMIT_CEREAL_FRACTION = getBooleanProperty("LIMIT_CEREAL_FRACTION", true); - public static final int CEREAL_CHANGE_START_STEP = getIntProperty("CEREAL_CHANGE_START_STEP", 0); + public static final double TOTAL_MAX_DEMAND_FRACT_CHANGE = getDoubleProperty("TOTAL_MAX_DEMAND_FRACT_CHANGE", 0.5); + public static final double ANNUAL_MAX_DEMAND_FRACT_CHANGE = getDoubleProperty("ANNUAL_MAX_DEMAND_FRACT_CHANGE", 0.0); + public static final boolean LIMIT_DEMAND_FRACTION = getBooleanProperty("LIMIT_DEMAND_FRACTION", true); + public static final int DEMAND_FRACT_CHANGE_START_STEP = getIntProperty("DEMAND_FRACT_CHANGE_START_STEP", 0); public static final double PASTURE_HARVEST_FRACTION = getDoubleProperty("PASTURE_HARVEST_FRACTION", 0.5); public static final double ANIMAL_FEED_FROM_OTHER_SOURCES_RATE = getDoubleProperty("ANIMAL_FEED_FROM_OTHER_SOURCES_RATE", 0.127); // animal nutrition coming from sources other crops modelled diff --git a/src/ac/ed/lurg/country/AbstractCountryAgent.java b/src/ac/ed/lurg/country/AbstractCountryAgent.java index 8ddcc1bc987eae1f3edbc6e41e0b27522dbf1f2e..7426a6bd92aa0590933efeb4bda8222de66ab3c7 100644 --- a/src/ac/ed/lurg/country/AbstractCountryAgent.java +++ b/src/ac/ed/lurg/country/AbstractCountryAgent.java @@ -1,5 +1,7 @@ package ac.ed.lurg.country; +import java.io.BufferedWriter; +import java.io.IOException; import java.util.Collection; import java.util.HashMap; import java.util.Map; @@ -8,9 +10,13 @@ import ac.ed.lurg.ModelConfig; import ac.ed.lurg.Timestep; import ac.ed.lurg.demand.AbstractDemandManager; import ac.ed.lurg.landuse.CropUsageData; +import ac.ed.lurg.landuse.LandUseItem; import ac.ed.lurg.types.CommodityType; import ac.ed.lurg.types.CropType; +import ac.ed.lurg.types.LandCoverType; import ac.ed.lurg.utils.LogWriter; +import ac.sac.raster.RasterKey; +import ac.sac.raster.RasterSet; public abstract class AbstractCountryAgent { @@ -89,25 +95,35 @@ public abstract class AbstractCountryAgent { return currentCountryPrices; } - protected Map<CropType, Double> getMinCerealFraction(Timestep timestep) { - Map<CropType, Double> minCerealFraction = new HashMap<CropType, Double>(); - - int yearsOfChange = ModelConfig.IS_CALIBRATION_RUN ? 0 : (timestep.getTimestep() - ModelConfig.CEREAL_CHANGE_START_STEP) * ModelConfig.TIMESTEP_SIZE; - - for (Map.Entry<CropType, Double> entry : baseDemandFact.get(CommodityType.CEREALS).entrySet()) { - minCerealFraction.put(entry.getKey(), entry.getValue() * Math.max(ModelConfig.TOTAL_MAX_CEREAL_CHANGE, (1- ModelConfig.ANNUAL_MAX_CEREAL_CHANGE * yearsOfChange))); + protected Map<CommodityType, Map<CropType, Double>> getMinDemandFraction(Timestep timestep) { + Map<CommodityType, Map<CropType, Double>> minDemandFraction = new HashMap<CommodityType, Map<CropType, Double>>(); + + int yearsOfChange = ModelConfig.IS_CALIBRATION_RUN ? 0 + : (timestep.getTimestep() - ModelConfig.DEMAND_FRACT_CHANGE_START_STEP) * ModelConfig.TIMESTEP_SIZE; + + for (CommodityType comm : baseDemandFact.keySet()) { + if (comm == CommodityType.CEREALS || comm == CommodityType.OILCROPSPULSES) { + Map<CropType, Double> cropFracts = new HashMap<CropType, Double>(); + for (Map.Entry<CropType, Double> crop : baseDemandFact.get(comm).entrySet()) { + cropFracts.put(crop.getKey(), crop.getValue() * Math.max(ModelConfig.TOTAL_MAX_DEMAND_FRACT_CHANGE, + (1 - ModelConfig.ANNUAL_MAX_DEMAND_FRACT_CHANGE * yearsOfChange))); + } + minDemandFraction.put(comm, cropFracts); + } } - return minCerealFraction; + + return minDemandFraction; } - protected void updateNetImportsFromProdAndDemand(Map<CommodityType, Double> demands, Map<CropType, Double> minCerealFracts, Map<CropType, CropUsageData> cropUsages) { + protected void updateNetImportsFromProdAndDemand(Map<CommodityType, Double> demands, Map<CommodityType, Map<CropType, Double>> minDemandFracts, Map<CropType, CropUsageData> cropUsages) { for (CommodityType commodity : CommodityType.getAllFoodItems()) { - if (commodity != CommodityType.CEREALS && commodity.getCropTypes().size() != 1) - throw new RuntimeException("Not cereal and not 1 to 1 mapping for commodity to crop: " + commodity); // skips cereals which is a special case and handled separately below + + if (commodity != CommodityType.CEREALS && commodity != CommodityType.OILCROPSPULSES && commodity.getCropTypes().size() != 1) + throw new RuntimeException("Not cereal or oilcropspulses and not 1 to 1 mapping for commodity to crop: " + commodity); // skips cereals which is a special case and handled separately below double demand = demands.get(commodity); - if (commodity == CommodityType.CEREALS) { + if (commodity == CommodityType.CEREALS || commodity == CommodityType.OILCROPSPULSES) { Map<CropType, Double> netImportsFromMinDemands = new HashMap<CropType, Double>(); double totalProd = 0, totalmportFromMD = 0, totalExcessProd = 0; @@ -115,9 +131,8 @@ public abstract class AbstractCountryAgent { CropUsageData cropUsage = cropUsages.get(crop); double prod = cropUsage.getProduction() *(1-crop.getSeedAndWasteRate()) - cropUsage.getMonogastricFeed() - cropUsage.getRuminantFeed(); totalProd += prod; - double minFract = minCerealFracts.containsKey(crop) ? minCerealFracts.get(crop) : 0.0; + double minFract = minDemandFracts.get(commodity).containsKey(crop) ? minDemandFracts.get(commodity).get(crop) : 0.0; double netImportsFromMinDemand = minFract * demand - prod; - LogWriter.println("netImportsFromMinDemand " + crop + " to " + netImportsFromMinDemand); netImportsFromMinDemands.put(crop, netImportsFromMinDemand); if (netImportsFromMinDemand > 0) @@ -132,8 +147,8 @@ public abstract class AbstractCountryAgent { double netImportsMD = netImportsFromMinDemands.get(crop); double netImports=0; if (additionalNetImportsRequired > 0) { // overall need to import more - if (minCerealFracts.containsKey(crop)) - netImports = netImportsMD + minCerealFracts.get(crop) * additionalNetImportsRequired; // divide required additional imports by minCerealFracts + if (minDemandFracts.get(commodity).containsKey(crop)) + netImports = netImportsMD + minDemandFracts.get(commodity).get(crop) * additionalNetImportsRequired; // divide required additional imports by minCerealFracts } else { // overall need to export more if (netImportsMD > 0) @@ -143,7 +158,7 @@ public abstract class AbstractCountryAgent { } CropUsageData cropUsage = cropUsages.get(crop); - LogWriter.println("Updating cereal net imports " + crop + " to " + netImports); + LogWriter.println("Updating " + commodity + " net imports " + crop + " to " + netImports); cropUsage.updateNetImports(netImports); } } @@ -161,4 +176,4 @@ public abstract class AbstractCountryAgent { } abstract public Map<CropType, CropUsageData> getCropUsageData(); -} +} \ No newline at end of file diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index ac1c9c42441eb9ae974af49b9d883081e618669f..96cb417655bd24f8ec251581021ce139e15e093b 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -135,7 +135,7 @@ public class CountryAgent extends AbstractCountryAgent { if (!ModelConfig.ORIG_LEAST_COST_MIN) { GamsCountryInput countryInput = input.getCountryInput(); - updateNetImportsFromProdAndDemand(countryInput.getProjectedDemand(), countryInput.getMinCerealFraction(), result.getCropUsageData()); + updateNetImportsFromProdAndDemand(countryInput.getProjectedDemand(), countryInput.getMinDemandFractions(), result.getCropUsageData()); } if (saveGamsGdxFiles) saveGDXFile(); @@ -209,10 +209,10 @@ public class CountryAgent extends AbstractCountryAgent { importConstraints.put(crop, new TradeOrProductionConstraint(baseTradeOrProd - changeDown, baseTradeOrProd + changeUp, ModelConfig.ORIG_LEAST_COST_MIN)); } - Map<CropType, Double> minCerealFract = getMinCerealFraction(currentTimestep); + Map<CommodityType, Map<CropType, Double>> minDemandFract = getMinDemandFraction(currentTimestep); GamsCountryInput countryLevelInputs = new GamsCountryInput(country, getCurrentProjectedDemand(), getCurrentCountryPrices(), importConstraints, - previousGamsRasterOutput.getCropUsageData(), minCerealFract, animalFeedFromOtherSources, subsidyRates); + previousGamsRasterOutput.getCropUsageData(), minDemandFract, animalFeedFromOtherSources, subsidyRates); GamsRasterInput input = new GamsRasterInput(currentTimestep, countryYieldSurfaces, previousGamsRasterOutput.getLandUses(), irrigData, countryLevelInputs); return input; diff --git a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java index 24a99c2b750abc2debc6bb110c3d3d3032cc53c9..66c0881b54ca9c1326795be803e64cf0557238a7 100644 --- a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java +++ b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java @@ -38,6 +38,6 @@ public class CraftyCountryAgent extends AbstractCountryAgent { cropUsageData.put(entry.getKey(), cropusage); } - updateNetImportsFromProdAndDemand(currentProjectedDemand, getMinCerealFraction(timestep), cropUsageData); + updateNetImportsFromProdAndDemand(currentProjectedDemand, getMinDemandFraction(timestep), cropUsageData); } } \ No newline at end of file diff --git a/src/ac/ed/lurg/country/gams/GamsCountryInput.java b/src/ac/ed/lurg/country/gams/GamsCountryInput.java index f53bfa144479965c57083b730dd84508a1c23bff..ef00c0918388a3cddcdb570dc2226b5b5d976f12 100644 --- a/src/ac/ed/lurg/country/gams/GamsCountryInput.java +++ b/src/ac/ed/lurg/country/gams/GamsCountryInput.java @@ -18,20 +18,20 @@ public class GamsCountryInput { private Map<CropType, TradeOrProductionConstraint> tradeOrProdConstraints; private Map<CropType, CountryPrice> countryPrices; private Map<CropType, CropUsageData> previousCropUsageData; - private Map<CropType, Double> minCerealFraction; + private Map<CommodityType, Map<CropType, Double>> minDemandFractions; private double animalFeedFromOtherSources; private Map<CropType, Double> subsidyRates; public GamsCountryInput(CompositeCountry country, Map<CommodityType, Double> projectedDemand, Map<CropType, CountryPrice> countryPrices, - Map<CropType, TradeOrProductionConstraint> importConstraints, Map<CropType, CropUsageData> previousCropUsageData, Map<CropType, Double> minCerealFraction, - double animalFeedFromOtherSources, Map<CropType, Double> subsidyRates) { + Map<CropType, TradeOrProductionConstraint> importConstraints, Map<CropType, CropUsageData> previousCropUsageData, + Map<CommodityType, Map<CropType, Double>> minDemandFracts, double animalFeedFromOtherSources, Map<CropType, Double> subsidyRates) { super(); this.country = country; this.projectedDemand = projectedDemand; this.tradeOrProdConstraints = importConstraints; this.countryPrices = countryPrices; this.previousCropUsageData = previousCropUsageData; - this.minCerealFraction = minCerealFraction; + this.minDemandFractions = minDemandFracts; this.animalFeedFromOtherSources = animalFeedFromOtherSources; this.subsidyRates = subsidyRates; } @@ -78,8 +78,8 @@ public class GamsCountryInput { return netImport; } - public Map<CropType, Double> getMinCerealFraction() { - return minCerealFraction; + public Map<CommodityType, Map<CropType, Double>> getMinDemandFractions() { + return minDemandFractions; } public double getAnimalFeedFromOtherSources() { diff --git a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java index d5b7b05a871bdf06e44775d6354986282ee932fe..82eee8af5108657ba80f73b9f38f1b725d7e0a64 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java @@ -1,6 +1,7 @@ package ac.ed.lurg.country.gams; import java.io.File; +import java.util.Collection; import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; @@ -183,16 +184,31 @@ public class GamsLocationOptimiser { addCommodityMapParm(inDB.addParameter("demand", 1), countryInput.getProjectedDemand(), 4); GAMSParameter minCerealFracP = inDB.addParameter("minDemandPerCereal", 1); - - if (DEBUG) LogWriter.println("\nCereal crop: min fraction of cereals"); - for (Map.Entry<CropType, Double> entry : countryInput.getMinCerealFraction().entrySet()) { - double minCerealFract = ModelConfig.LIMIT_CEREAL_FRACTION ? entry.getValue() : 0.0; - if (!Double.isNaN(minCerealFract)) { - double dOut = setGamsParamValueTruncate(minCerealFracP.addRecord(entry.getKey().getGamsName()), minCerealFract, 4); - if (DEBUG) LogWriter.println(String.format(" %15s,\t %.4f", entry.getKey().getGamsName(), dOut)); + GAMSParameter minOilcropsFracP = inDB.addParameter("minDemandPerOilcrop", 1); + + for (Entry<CommodityType, Map<CropType, Double>> comm : countryInput.getMinDemandFractions().entrySet()) { + for (Map.Entry<CropType, Double> crop : comm.getValue().entrySet()) { + LogWriter.println("commodity " + comm + " crop " + crop + " value" + crop.getValue()); + double minCommFract = ModelConfig.LIMIT_DEMAND_FRACTION ? crop.getValue() : 0.0; + if (!Double.isNaN(minCommFract)) { + double dOut; + if (comm.getKey() == CommodityType.CEREALS){ + LogWriter.println("crop name " + crop.getKey().getGamsName()+ " minCommFract " + minCommFract); + dOut = setGamsParamValueTruncate(minCerealFracP.addRecord(crop.getKey().getGamsName()), + minCommFract, 4); + LogWriter.println("dOut " + dOut); + }else{ + LogWriter.println("crop name " + crop.getKey().getGamsName()+ " minCommFract " + minCommFract); + dOut = setGamsParamValueTruncate(minOilcropsFracP.addRecord(crop.getKey().getGamsName()), + minCommFract, 4); + LogWriter.println("dOut " + dOut); + } + if (DEBUG)LogWriter.println(String.format(" %15s,\t %.4f", crop.getKey().getGamsName(), dOut)); + } + } } - + if (DEBUG) LogWriter.println("\nYield (fert/irrig) None/None, Max/None, None/Max, Max/Max,\t [fert p],\t [irrig p],\t {max irrig}"); GAMSParameter yNoneP = inDB.addParameter("yieldNone", 2); GAMSParameter y_fert = inDB.addParameter("yieldFertOnly", 2); diff --git a/src/ac/ed/lurg/demand/CerealFractionsManager.java b/src/ac/ed/lurg/demand/CerealFractionsManager.java index 268ebe3865dc9e7d6edf2d671f03ddc0983ffd36..2f515e3ccb22c07a87306a56c214b6226da7d2df 100644 --- a/src/ac/ed/lurg/demand/CerealFractionsManager.java +++ b/src/ac/ed/lurg/demand/CerealFractionsManager.java @@ -47,39 +47,39 @@ public class CerealFractionsManager { private Map<CropType, Double> getBaseDemandFracts(CompositeCountry cc, CommodityType commodity) { - Map<CropType, Double> cerealDemandMap = new HashMap<CropType, Double>(); + Map<CropType, Double> commodityDemandMap = new HashMap<CropType, Double>(); for (SingleCountry c : compositeCountryManager.getAllForCompositeCountry(cc)) { - Map<CropType, Double> singleCMap = getCerealFraction(c, commodity); + Map<CropType, Double> singleCMap = getCommodityFraction(c, commodity); for (CropType crop : CropType.getAllItems()) { Double newDemandD = singleCMap.get(crop); - Double prevDemandD = cerealDemandMap.get(crop); + Double prevDemandD = commodityDemandMap.get(crop); double newDemand = getDoubleOrZero(newDemandD) + getDoubleOrZero(prevDemandD); - if (newDemand> 0) cerealDemandMap.put(crop, newDemand); + if (newDemand> 0) commodityDemandMap.put(crop, newDemand); } } - double totalCerealDemand = 0; - for (Double d : cerealDemandMap.values()) - totalCerealDemand += getDoubleOrZero(d); + double totalCommodityDemand = 0; + for (Double d : commodityDemandMap.values()) + totalCommodityDemand += getDoubleOrZero(d); - Map<CropType, Double> cerealFractionMap = new HashMap<CropType, Double>(); - for (Entry<CropType, Double> entry : cerealDemandMap.entrySet()) { - cerealFractionMap.put(entry.getKey(), getDoubleOrZero(entry.getValue())/totalCerealDemand); + Map<CropType, Double> commodityFractionMap = new HashMap<CropType, Double>(); + for (Entry<CropType, Double> entry : commodityDemandMap.entrySet()) { + commodityFractionMap.put(entry.getKey(), getDoubleOrZero(entry.getValue())/totalCommodityDemand); } - return cerealFractionMap; + return commodityFractionMap; } private double getDoubleOrZero(Double d) { return (d==null ? 0.0 : d.doubleValue()); } - private Map<CropType, Double> getCerealFraction(SingleCountry c, CommodityType commodity) { + private Map<CropType, Double> getCommodityFraction(SingleCountry c, CommodityType commodity) { Map<CropType, Double> foodDemandMap = new HashMap<CropType, Double>(); - for (CropType crop : CommodityType.CEREALS.getCropTypes()) { + for (CropType crop : commodity.getCropTypes()) { Map<String, String> queryMap = new HashMap<String, String>(); queryMap.put("Country", c.getCountryName()); queryMap.put("Item", crop.getFaoName()); @@ -87,12 +87,12 @@ public class CerealFractionsManager { try { Map<String, String> row = cerealFractionReader.querySingle(queryMap); - String cerealS = row.get("food"); - Double cerealAmt = Double.valueOf(cerealS); - foodDemandMap.put(crop, cerealAmt); - } - catch (Exception e) { - LogWriter.println("Problem finding cereal demand: " + crop.getFaoName() + ", " + c.getCountryName()); + String commodityS = row.get("food"); + Double commodityAmt = Double.valueOf(commodityS); + foodDemandMap.put(crop, commodityAmt); + } catch (Exception e) { + LogWriter.println("Problem finding " + commodity.getGamsName() + " demand: " + crop.getFaoName() + ", " + + c.getCountryName()); } } return foodDemandMap; diff --git a/src/ac/ed/lurg/types/CommodityType.java b/src/ac/ed/lurg/types/CommodityType.java index 73df628f841f2849f4d617d1dd07cb3a50af1ef2..7beae3734aa14ff1fba7ac7963f2e416f9140e14 100644 --- a/src/ac/ed/lurg/types/CommodityType.java +++ b/src/ac/ed/lurg/types/CommodityType.java @@ -11,7 +11,7 @@ import ac.ed.lurg.ModelConfig; public enum CommodityType { CEREALS("Cereals", "cereals", false, new CropType[]{CropType.WHEAT, CropType.MAIZE, CropType.RICE}, 0.0115335812,ModelConfig.CEREALS_SUB_PROPORTION), - OILCROPSPULSES("OilcropsPulses", "oilcropspulses", false, new CropType[]{CropType.OILCROPS}, 0.0243500061,ModelConfig.OILCROPSPULSES_SUB_PROPORTION), + OILCROPSPULSES("OilcropsPulses", "oilcropspulses", false, new CropType[]{CropType.OILCROPS, CropType.PULSES}, 0.0243500061,ModelConfig.OILCROPSPULSES_SUB_PROPORTION), STARCHY_ROOTS("Starchy Roots", "starchyRoots", false, new CropType[]{CropType.STARCHY_ROOTS}, 0.0034561229,ModelConfig.STARCHY_ROOTS_SUB_PROPORTION), MONOGASTRICS("Monogastrics", "monogastrics", true, new CropType[]{CropType.MONOGASTRICS}, 0.0019100435, Double.NaN), RUMINANTS("Ruminants", "ruminants", true, new CropType[]{CropType.RUMINANTS}, 0.0009951162, Double.NaN),