diff --git a/debug_config.properties b/debug_config.properties index 1b2a6f3461ce037b51973c35f48f6bbc4ebb667a..34fd146f5e5d3e9ee2c032c66b48ad534840b458 100644 --- a/debug_config.properties +++ b/debug_config.properties @@ -6,11 +6,11 @@ YIELD_FILENAME=yield.out DEBUG_LIMIT_COUNTRIES=false DEBUG_COUNTRY_NAME=Mongolia -IS_CALIBRATION_RUN = true -GENERATE_NEW_YIELD_CLUSTERS = true +IS_CALIBRATION_RUN = false +GENERATE_NEW_YIELD_CLUSTERS = false NUM_YIELD_CLUSTERS=8000 -END_TIMESTEP=0 +END_TIMESTEP=1 TIMESTEP_SIZE=10 INTERPOLATE_OUTPUT_YEARS = false @@ -25,5 +25,6 @@ PRICE_ELASTIC_DEMAND=true GAMS_COUNTRY_TO_SAVE=Brazil SSP_SCENARIO=SSP2_v9_130325 -MARKET_ADJ_PRICE=false -DONT_REBASE_DEMAND=false \ No newline at end of file +DONT_REBASE_DEMAND=false + +DEMAND_RECALC_MAX_ITERATIONS=0 \ No newline at end of file diff --git a/src/ac/ed/lurg/InternationalMarket.java b/src/ac/ed/lurg/InternationalMarket.java index 8315add3c592f3b5fbbdfb1bbbe9116677ee0aeb..3c329fd61d1a3383803588de7004125a80c6dbeb 100644 --- a/src/ac/ed/lurg/InternationalMarket.java +++ b/src/ac/ed/lurg/InternationalMarket.java @@ -56,8 +56,6 @@ public class InternationalMarket { else totalExportCommodities.incrementValue(c, -countryNetImports); } - - } // energycrops are a special case where demand in global and exogenously specified @@ -72,7 +70,7 @@ public class InternationalMarket { double previousStockLevel = stockLevel.get(crop); double transportLossRate=(!ModelConfig.SHOCKS_POSSIBLE) ? ModelConfig.TRANSPORT_LOSSES : ModelConfig.getParameter(Parameter.TRANSPORT_LOSSES, timestep.getYear()); GlobalPrice adjustedPrice = prevPrice.createWithUpdatedMarketPrices(imports, exportsBeforeTransportLosses, exportsBeforeTransportLosses * transportLossRate, (ModelConfig.MARKET_ADJ_PRICE), timestep); - LogWriter.println( String.format("Price for %s updated from %s (imports amount %.0f, exports amount %.0f) to %s ", + LogWriter.println( String.format("Price for %s updated from %s (imports amount %.1f, exports amount %.1f) to %s ", crop.getGamsName(), prevPrice, imports, adjustedPrice.getExportsAfterTransportLosses(), adjustedPrice)); worldPrices.put(crop, adjustedPrice); double updatedStockLevel = previousStockLevel + adjustedPrice.getStockChange(); @@ -95,4 +93,28 @@ public class InternationalMarket { outputFile.newLine(); } } + +/* public double findMaxPriceDiff(Map<CropType, Double> previousExportPrices) { + if (previousExportPrices == null) + return Double.MAX_VALUE; + + double maxSoFar = 0; + CropType crop = null; + + for (Entry<CropType, GlobalPrice> entry : worldPrices.entrySet()) { + Double previousP = previousExportPrices.get(entry.getKey()); + + if (previousP == null) + return Double.MAX_VALUE; + + double diffThisTime = Math.abs(previousP - entry.getValue().getExportPrice()); + if (diffThisTime > maxSoFar) { + maxSoFar = diffThisTime; + crop = entry.getKey(); + } + } + + LogWriter.println("findMaxPriceDiff: found " + maxSoFar + " for " + crop); + return maxSoFar; + } */ } diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index 0e61741ef57370b0520e87e9d257c8f4ad9ce891..e7207624674d1e37e65ed871f49d71e2a22bdf6e 100755 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -341,6 +341,7 @@ public class ModelConfig { public static final double SUGAR_SUB_PROPORTION = getDoubleProperty("SUGAR_SUB_PROPORTION", 0.1); public static final double MARKET_LAMBA = getDoubleProperty("MARKET_LAMBA", 0.4); // controls international market price adjustment rate + public static final int DEMAND_RECALC_MAX_ITERATIONS = getIntProperty("DEMAND_RECALC_MAX_ITERATIONS", 0); // 0 is original behaviour public static final double POPULATION_AGGREG_LIMIT = getDoubleProperty("POPULATION_AGGREG_LIMIT", 30.0); // in millions, smaller countries are aggregated on a regional basis public static final boolean PREDEFINED_COUNTRY_GROUPING = getBooleanProperty("PREDEFINED_COUNTRY_GROUPING", true); @@ -393,4 +394,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"); + } diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java index af3bbfe7bac314baa610345c87b134530d4e49f7..6f1cd5bc06533247c048f84c9a5d6b437211434c 100644 --- a/src/ac/ed/lurg/ModelMain.java +++ b/src/ac/ed/lurg/ModelMain.java @@ -130,9 +130,16 @@ public class ModelMain { double gen2EcDDemand = demandManager.getSecondGenBioenergyDemand(ModelConfig.IS_CALIBRATION_RUN ? new Timestep(1) : timestep); double gen2Increase = (gen2EcDDemand>previousGen2EcDDemand) ? gen2EcDDemand - previousGen2EcDDemand : 0.0; - countryAgents.processTimestepForAll(timestep, yieldSurfaces, currentIrrigationData, gen2Increase); - + countryAgents.determineProductionForAll(timestep, yieldSurfaces, currentIrrigationData, gen2Increase); internationalMarket.determineInternationalTrade(countryAgents.getAll(), gen2EcDDemand, timestep); + + // loop for iterations. Could check within a tolerance using internationalMarket.findMaxPriceDiff, not doing so as doesn't find a solution due to inelastic consumption + for (int i=0; i < ModelConfig.DEMAND_RECALC_MAX_ITERATIONS; i++) { + LogWriter.println("\n++ Re-estimating prices and demand " + i); + countryAgents.recalculateDemandForAll(); // recalculate demand from new prices + countryAgents.updateNetImportsForAll(); // calculate imports and exports + internationalMarket.determineInternationalTrade(countryAgents.getAll(), gen2EcDDemand, timestep); // calculate prices + } // output results outputTimestepResults(timestep, globalLandUseRaster); diff --git a/src/ac/ed/lurg/country/AbstractCountryAgent.java b/src/ac/ed/lurg/country/AbstractCountryAgent.java index 33d81da774f648e9c4093b17e55496bbc95f6425..2a2a2cc38a0505e9414d8debdd6ad3da9f68a3a7 100644 --- a/src/ac/ed/lurg/country/AbstractCountryAgent.java +++ b/src/ac/ed/lurg/country/AbstractCountryAgent.java @@ -17,9 +17,11 @@ public abstract class AbstractCountryAgent { protected CompositeCountry country; protected Map<CropType, Double> tradeBarriers; protected Map<CommodityType, Double> currentProjectedDemand; - private Map<CropType, CountryPrice> currentCountryPrices; + protected Map<CropType, CountryPrice> currentCountryPrices; private Map<CommodityType, Map<CropType, Double>> baseDemandFact; - + protected Timestep currentTimestep; + protected Map<CommodityType, Map<CropType, Double>> currentMinDemandFract; + public AbstractCountryAgent(AbstractDemandManager demandManager,CompositeCountry country, Map<CropType, Double> tradeBarriers) { this.demandManager = demandManager; @@ -32,29 +34,36 @@ public abstract class AbstractCountryAgent { return country; } - protected Map<CropType, CountryPrice> calculateCountryPrices(Map<CropType, GlobalPrice> worldPrices, Timestep timestep){ + protected void setCurrentTimestep(Timestep timestep) { + currentTimestep = timestep; + currentMinDemandFract = getMinDemandFraction(); + } + + private void calculateCountryPrices(Map<CropType, GlobalPrice> worldPrices){ Map<CropType, CountryPrice> countryPrices = new HashMap <CropType, CountryPrice>(); for (CropType c : CropType.getImportedTypes()) { GlobalPrice worldPrice = worldPrices.get(c); Double tb = tradeBarriers.get(c); LogWriter.println(worldPrice + " " + c); - CountryPrice prices = new CountryPrice(worldPrice.getCountryImportPrice(tb==null ? 0 : tb, timestep), worldPrice.getExportPrice()); + CountryPrice prices = new CountryPrice(worldPrice.getCountryImportPrice(tb==null ? 0 : tb, currentTimestep), worldPrice.getExportPrice()); countryPrices.put(c, prices); } currentCountryPrices = countryPrices; - return currentCountryPrices; } - protected Map<CommodityType, Double> calculateDemand(Timestep timestep) { - Map<CommodityType, Double> producerPrices = getProducerCommodityPrices(timestep); - - currentProjectedDemand = demandManager.getDemand(country, timestep.getYear(), producerPrices); - return currentProjectedDemand; + private void calculateDemand() { + Map<CommodityType, Double> producerPrices = getProducerCommodityPrices(); + currentProjectedDemand = demandManager.getDemand(country, currentTimestep.getYear(), producerPrices); + } + + protected void calculateCountryPricesAndDemand(Map<CropType, GlobalPrice> worldPrices) { + calculateCountryPrices(worldPrices); + calculateDemand(); } - private Map<CommodityType, Double> getProducerCommodityPrices(Timestep timestep) { + private Map<CommodityType, Double> getProducerCommodityPrices() { if (!ModelConfig.PRICE_ELASTIC_DEMAND) return null; @@ -87,11 +96,11 @@ public abstract class AbstractCountryAgent { return currentCountryPrices; } - protected Map<CommodityType, Map<CropType, Double>> getMinDemandFraction(Timestep timestep) { + private Map<CommodityType, Map<CropType, Double>> getMinDemandFraction() { 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; + : (currentTimestep.getTimestep() - ModelConfig.DEMAND_FRACT_CHANGE_START_STEP) * ModelConfig.TIMESTEP_SIZE; for (CommodityType comm : baseDemandFact.keySet()) { if (comm == CommodityType.CEREALS || comm == CommodityType.OILCROPSPULSES) { diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index 3fff02ae45e1e66903eb4e253e4254b8334e4135..0179740982e19d0d3ea2e4872cb66c82f426c230 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -13,7 +13,6 @@ import java.util.Map; import java.util.Map.Entry; import ac.ed.lurg.ModelConfig; -import ac.ed.lurg.Timestep; import ac.ed.lurg.country.gams.GamsCountryInput; import ac.ed.lurg.country.gams.GamsRasterInput; import ac.ed.lurg.country.gams.GamsRasterOptimiser; @@ -38,7 +37,6 @@ import ac.sac.raster.RasterSet; public class CountryAgent extends AbstractCountryAgent { private GamsRasterOutput previousGamsRasterOutput; - private Timestep currentTimestep; private RasterSet<IntegerRasterItem> yieldClusters; private double animalFeedFromOtherSources; private Map<CropType, Double> subsidyRates; @@ -101,24 +99,21 @@ public class CountryAgent extends AbstractCountryAgent { return mapping; } - public GamsRasterOutput determineProduction(Timestep timestep, YieldRaster countryYieldSurfaces, RasterSet<IrrigationItem> irrigData, + public GamsRasterOutput determineProduction(YieldRaster countryYieldSurfaces, RasterSet<IrrigationItem> irrigData, Map<CropType, GlobalPrice> worldPrices, double globalGen2EcIncrease) { - currentTimestep = timestep; - calculateCountryPrices(worldPrices, currentTimestep); - - // get projected demand - Map<CommodityType, Double> projectedDemand = calculateDemand(timestep); + // project demand + calculateCountryPricesAndDemand(worldPrices); if (saveGamsGdxFiles && ModelConfig.PRICE_ELASTIC_DEMAND) saveGDXFile("demand"); if (currentTimestep.isInitialTimestep()) { - double totalAnimalProductDemand = projectedDemand.get(CommodityType.MONOGASTRICS) + projectedDemand.get(CommodityType.RUMINANTS); + double totalAnimalProductDemand = currentProjectedDemand.get(CommodityType.MONOGASTRICS) + currentProjectedDemand.get(CommodityType.RUMINANTS); animalFeedFromOtherSources = totalAnimalProductDemand * ModelConfig.ANIMAL_FEED_FROM_OTHER_SOURCES_RATE; } - if (projectedDemand.size() == 0) { + if (currentProjectedDemand.size() == 0) { LogWriter.printlnError("No demand for country " + country + " so skipping it"); } else if (countryYieldSurfaces.size() == 0 ) { @@ -137,12 +132,6 @@ public class CountryAgent extends AbstractCountryAgent { GamsRasterOutput result = opti.run(); - // No longer need this as even profit max calcs imports in GAMS now - // if (!ModelConfig.ORIG_LEAST_COST_MIN) { - // GamsCountryInput countryInput = input.getCountryInput(); - // updateNetImportsFromProdAndDemand(countryInput.getProjectedDemand(), countryInput.getMinDemandFractions(), result.getCropUsageData()); - // } - if (saveGamsGdxFiles) saveGDXFile("landuse"); @@ -153,6 +142,10 @@ public class CountryAgent extends AbstractCountryAgent { throw new RuntimeException("Skipping optimisation of country " + country); } + public void updateNetImportsFromProdAndDemand() { + updateNetImportsFromProdAndDemand(currentProjectedDemand, currentMinDemandFract, previousGamsRasterOutput.getCropUsageData()); + } + private void saveGDXFile(String ext) { // some hacky code for debug purposes that keeps each gams gdx file try { @@ -208,10 +201,8 @@ public class CountryAgent extends AbstractCountryAgent { importConstraints.put(crop, new TradeConstraint(baseTrade - changeDown, baseTrade + changeUp)); } - Map<CommodityType, Map<CropType, Double>> minDemandFract = getMinDemandFraction(currentTimestep); - - GamsCountryInput countryLevelInputs = new GamsCountryInput(country, getCurrentProjectedDemand(), getCurrentCountryPrices(), importConstraints, - previousGamsRasterOutput.getCropUsageData(), minDemandFract, animalFeedFromOtherSources, subsidyRates); + GamsCountryInput countryLevelInputs = new GamsCountryInput(country, currentProjectedDemand, currentCountryPrices, importConstraints, + previousGamsRasterOutput.getCropUsageData(), currentMinDemandFract, animalFeedFromOtherSources, subsidyRates); GamsRasterInput input = new GamsRasterInput(currentTimestep, countryYieldSurfaces, previousGamsRasterOutput.getLandUses(), irrigData, countryLevelInputs); return input; diff --git a/src/ac/ed/lurg/country/CountryAgentManager.java b/src/ac/ed/lurg/country/CountryAgentManager.java index 3c59266712c3800427b72d0b7068906098dee646..273bd8b4755d69d6a3a732320d057fe7566acb59 100644 --- a/src/ac/ed/lurg/country/CountryAgentManager.java +++ b/src/ac/ed/lurg/country/CountryAgentManager.java @@ -92,11 +92,32 @@ public class CountryAgentManager { return countryAgents; } - public void processTimestepForAll(Timestep timestep, YieldRaster yieldSurfaces, IrrigationRasterSet currentIrrigationData, double gen2Increase) { + public void determineProductionForAll(Timestep timestep, YieldRaster yieldSurfaces, IrrigationRasterSet currentIrrigationData, double gen2Increase) { + + for (AbstractCountryAgent aca : countryAgents) { + aca.setCurrentTimestep(timestep); + } for (CountryAgent ca : gamsCountryAgents) { LogWriter.println("Country " + ca.getCountry()); - doGamsAgentTimestep(timestep, ca, yieldSurfaces, currentIrrigationData, gen2Increase); + Collection<RasterKey> countryKeys = countryBoundaryRaster.getKeysFor(ca.getCountry()); + YieldRaster countryYieldSurfaces = yieldSurfaces.createSubsetForKeys(countryKeys); + RasterSet<IrrigationItem> irrigData = currentIrrigationData.createSubsetForKeys(countryKeys); + + try { + ca.determineProduction(countryYieldSurfaces, irrigData, internationalMarket.getWorldPrices(), gen2Increase); + + // update global rasters + globalLandUseRaster.putAll(ca.getLandUses()); + + // if first timestep and calibration get the clustering info, which doesn't change through time + if (ModelConfig.GENERATE_NEW_YIELD_CLUSTERS && timestep.isInitialTimestep()) + clusterIdRaster.putAll(ca.getYieldClusters()); + + } catch (Exception e) { + LogWriter.printlnError("Exception processing " + ca.getCountry() + " will continue with other countries"); + LogWriter.print(e); + } } if (craftyCountryAgents.size() > 0) { @@ -104,25 +125,15 @@ public class CountryAgentManager { } } - private void doGamsAgentTimestep(Timestep timestep, CountryAgent ca, YieldRaster yieldSurfaces, IrrigationRasterSet currentIrrigationData, double gen2Increase) { - Collection<RasterKey> countryKeys = countryBoundaryRaster.getKeysFor(ca.getCountry()); - YieldRaster countryYieldSurfaces = yieldSurfaces.createSubsetForKeys(countryKeys); - RasterSet<IrrigationItem> irrigData = currentIrrigationData.createSubsetForKeys(countryKeys); - - // do the optimization - try { - ca.determineProduction(timestep, countryYieldSurfaces, irrigData, internationalMarket.getWorldPrices(), gen2Increase); - - // update global rasters - globalLandUseRaster.putAll(ca.getLandUses()); + public void updateNetImportsForAll() { + for (CountryAgent ca : gamsCountryAgents) { + ca.updateNetImportsFromProdAndDemand(); + } + } - // if first timestep and calibration get the clustering info, which doesn't change through time - if (ModelConfig.GENERATE_NEW_YIELD_CLUSTERS && timestep.isInitialTimestep()) - clusterIdRaster.putAll(ca.getYieldClusters()); - - } catch (Exception e) { - LogWriter.printlnError("Exception processing " + ca.getCountry() + " will continue with other countries"); - LogWriter.print(e); + public void recalculateDemandForAll() { + for (CountryAgent ca : gamsCountryAgents) { + ca.calculateCountryPricesAndDemand(internationalMarket.getWorldPrices()); } } } \ No newline at end of file diff --git a/src/ac/ed/lurg/country/GlobalPrice.java b/src/ac/ed/lurg/country/GlobalPrice.java index dcbc92894a3a8cc6e0f4370bb8cd1650dd6df111..213afeb00caab66ad26fb4db985877b93dbc24f7 100644 --- a/src/ac/ed/lurg/country/GlobalPrice.java +++ b/src/ac/ed/lurg/country/GlobalPrice.java @@ -81,7 +81,7 @@ public class GlobalPrice { @Override public String toString() { - return String.format("export=%.3f", exportPrice); + return String.format("exportPrice=%.6f", exportPrice); } public double getStockChange() { diff --git a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java index 66c0881b54ca9c1326795be803e64cf0557238a7..cbdb684cb47e302863c547ebd7a3b8534bf40170 100644 --- a/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java +++ b/src/ac/ed/lurg/country/crafty/CraftyCountryAgent.java @@ -4,7 +4,6 @@ import java.util.HashMap; import java.util.Map; import java.util.Map.Entry; -import ac.ed.lurg.Timestep; import ac.ed.lurg.country.AbstractCountryAgent; import ac.ed.lurg.country.CompositeCountry; import ac.ed.lurg.country.GlobalPrice; @@ -28,9 +27,8 @@ public class CraftyCountryAgent extends AbstractCountryAgent { return cropUsageData; } - public void updateProduction(Timestep timestep, Map<CropType, Double> cropProduction, Map<CropType, GlobalPrice> worldPrices) { - calculateDemand(timestep); - calculateCountryPrices(worldPrices, timestep); + public void updateProduction(Map<CropType, Double> cropProduction, Map<CropType, GlobalPrice> worldPrices) { + calculateCountryPricesAndDemand(worldPrices); cropUsageData = new HashMap<CropType, CropUsageData>(); for (Entry<CropType, Double> entry : cropProduction.entrySet()) { @@ -38,6 +36,6 @@ public class CraftyCountryAgent extends AbstractCountryAgent { cropUsageData.put(entry.getKey(), cropusage); } - updateNetImportsFromProdAndDemand(currentProjectedDemand, getMinDemandFraction(timestep), cropUsageData); + updateNetImportsFromProdAndDemand(currentProjectedDemand, currentMinDemandFract, cropUsageData); } } \ No newline at end of file diff --git a/src/ac/ed/lurg/country/crafty/CraftyProdManager.java b/src/ac/ed/lurg/country/crafty/CraftyProdManager.java index af3cf49422d19e3da306e3b5f2f37a0cff707fe8..1a4414bce1b8e6100e3abdf309522c5e1d25d46d 100644 --- a/src/ac/ed/lurg/country/crafty/CraftyProdManager.java +++ b/src/ac/ed/lurg/country/crafty/CraftyProdManager.java @@ -66,7 +66,7 @@ public class CraftyProdManager { if (cropProduction.size() < CropType.getImportedTypes().size()) { // Don't need setaside or pasture, which aren't imported either LogWriter.printlnError("Not all crops present in Crafty production for country: " + cca.getCountry() + " only " + cropProduction.size()); } - cca.updateProduction(timestep, cropProduction, worldPrices); + cca.updateProduction(cropProduction, worldPrices); } catch (Exception e) { LogWriter.println("Problem getting Crafty data for: " + cca.getCountry()); diff --git a/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java b/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java index af99e4c4e440e8931f2bdd49028098fd68a41b2a..516c0fe30441c440e7cdba5de6eaba466852bc61 100755 --- a/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsDemandOptimiser.java @@ -109,7 +109,7 @@ public class GamsDemandOptimiser { private GamsDemandOutput handleResults(GAMSDatabase outDB) { int modelStatus = (int) outDB.getParameter("ms").findRecord().getValue(); String status = GAMSGlobals.ModelStat.lookup(modelStatus).toString(); - LogWriter.println(String.format("\nDemamd %s: Modelstatus (%d) %s, Solvestatus %s", inputData.getCountry(), + LogWriter.println(String.format("\nDemand %s: Modelstatus (%d) %s, Solvestatus %s", inputData.getCountry(), modelStatus, status, GAMSGlobals.SolveStat.lookup((int) outDB.getParameter("ss").findRecord().getValue()) )); GAMSVariable varU = outDB.getVariable("u"); diff --git a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java index b08f26f1a4e0dbfa248a3e516953f8e5dbdc0ca3..d78210d1914c317305ddbfecdf002ce92283b1e2 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java @@ -180,7 +180,7 @@ public class GamsLocationOptimiser { if (DEBUG) LogWriter.println("\nDemand: " + inputData.getCountryInput().getCountry() + " " + inputData.getTimestep().getYear()); GamsCountryInput countryInput = inputData.getCountryInput(); - addCommodityMapParm(inDB.addParameter("demand", 1), countryInput.getProjectedDemand(), 4); + addCommodityMapParm(inDB.addParameter("demand", 1), countryInput.getProjectedDemand(), -1); GAMSParameter minCerealFracP = inDB.addParameter("minDemandPerCereal", 1); GAMSParameter minOilcropsFracP = inDB.addParameter("minDemandPerOilcrop", 1); @@ -324,7 +324,7 @@ public class GamsLocationOptimiser { } private double setGamsParamValue(GAMSParameterRecord param, double val, int places) { - double dOut = Math.round(val * Math.pow(10,places)) / Math.pow(10,places); + double dOut = places >= 0 ? Math.round(val * Math.pow(10,places)) / Math.pow(10,places) : val; param.setValue(dOut); return dOut; } diff --git a/src/ac/ed/lurg/demand/AbstractDemandManager.java b/src/ac/ed/lurg/demand/AbstractDemandManager.java index a265b5c54c48174927247d8b530d178ac19a8c37..ce2ce7fd6f87603f2d815c2d484a97a4d05ef85d 100644 --- a/src/ac/ed/lurg/demand/AbstractDemandManager.java +++ b/src/ac/ed/lurg/demand/AbstractDemandManager.java @@ -60,7 +60,7 @@ public abstract class AbstractDemandManager { return demandMap; } - abstract Map<CommodityType, Double> getFoodDemand(SingleCountry c, int year, Map<CommodityType, Double> prices); + protected abstract Map<CommodityType, Double> getFoodDemand(SingleCountry c, int year, Map<CommodityType, Double> prices); public double getSecondGenBioenergyDemand(Timestep timestep) { int year = ModelConfig.CHANGE_DEMAND_YEAR ? timestep.getYear() : ModelConfig.BASE_YEAR; @@ -87,7 +87,7 @@ public abstract class AbstractDemandManager { return cerealFractionsManager.getBaseDemandFracts(cc); } - public Map<CommodityType, Double> dietaryAdjustment(Map<CommodityType, Double> originalFoodDemandMap, int year, Map<CommodityType, Double> kcalPerT) { + protected Map<CommodityType, Double> dietaryAdjustment(Map<CommodityType, Double> originalFoodDemandMap, int year, Map<CommodityType, Double> kcalPerT) { double monoDemandAdj = (!ModelConfig.SHOCKS_POSSIBLE) ? 0.0 : ModelConfig.getParameter(Parameter.MONOGASTRIC_CHANGE_ANNUAL_RATE, year); double rumDemandAdj = (!ModelConfig.SHOCKS_POSSIBLE) ? 0.0 : ModelConfig.getParameter(Parameter.RUMINANT_CHANGE_ANNUAL_RATE, year); diff --git a/src/ac/ed/lurg/demand/AbstractSSPDemandManager.java b/src/ac/ed/lurg/demand/AbstractSSPDemandManager.java index 28eca99ff85d4fd1811a3db9f5e9c14b4a24877a..6aadbbeec739d805566cd463f4e698b55ce24e7e 100644 --- a/src/ac/ed/lurg/demand/AbstractSSPDemandManager.java +++ b/src/ac/ed/lurg/demand/AbstractSSPDemandManager.java @@ -28,7 +28,7 @@ public abstract class AbstractSSPDemandManager extends AbstractDemandManager { } @Override - Map<CommodityType, Double> getFoodDemand(SingleCountry c, int year, Map<CommodityType, Double> prices) { + protected Map<CommodityType, Double> getFoodDemand(SingleCountry c, int year, Map<CommodityType, Double> prices) { SspData sd = sspManager.get(ssp_scenario, year, c); Map<CommodityType, Double> foodDemandMap = new HashMap<CommodityType, Double>(); diff --git a/src/ac/ed/lurg/demand/DemandManagerFromFile.java b/src/ac/ed/lurg/demand/DemandManagerFromFile.java index 1c69ff1f036b0a8f6f1900bb55874b6ee734e3b6..765730b9dfce9139cf3b8e1b7271eb0249b70371 100644 --- a/src/ac/ed/lurg/demand/DemandManagerFromFile.java +++ b/src/ac/ed/lurg/demand/DemandManagerFromFile.java @@ -21,7 +21,7 @@ public class DemandManagerFromFile extends AbstractDemandManager { } @Override - Map<CommodityType, Double> getFoodDemand(SingleCountry c, int year, Map<CommodityType, Double> prices) { + protected Map<CommodityType, Double> getFoodDemand(SingleCountry c, int year, Map<CommodityType, Double> prices) { Map<CommodityType, Double> foodDemandMap = new HashMap<CommodityType, Double>(); for (CommodityType commodity : CommodityType.getAllFoodItems()) {