diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index 399813cf9136d33357fd785b283eba541cb720f2..c59ff35ceecd46c0c67351cc16651712452e20fa 100644 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -119,6 +119,7 @@ public class ModelConfig { // Output public static final String LAND_COVER_OUTPUT_FILE = OUTPUT_DIR + File.separator + "lc.txt"; public static final String PRICES_OUTPUT_FILE = OUTPUT_DIR + File.separator + "prices.txt"; + public static final String DEMAND_OUTPUT_FILE = OUTPUT_DIR + File.separator + "demand.txt"; public static final boolean OUTPUT_FOR_LPJG = getBooleanProperty("OUTPUT_FOR_LPJG", true); public static final boolean INTERPOLATE_OUTPUT_YEARS = getBooleanProperty("INTERPOLATE_OUTPUT_YEARS", true); @@ -139,7 +140,7 @@ public class ModelConfig { public static final double MAX_IMPORT_CHANGE = getDoubleProperty("MAX_IMPORT_CHANGE", 0.1); public static final double PASTURE_HARVEST_FRACTION = getDoubleProperty("PASTURE_HARVEST_FRACTION", 0.5); - public static final double MEAT_EFFICIENCY = getDoubleProperty("MEAT_EFFICIENCY", 0.5); + public static final double MEAT_EFFICIENCY = getDoubleProperty("MEAT_EFFICIENCY", 1.0); public static final double IRRIGIATION_EFFICIENCY = getDoubleProperty("IRRIGIATION_EFFICIENCY", 0.5); public static final double LAND_CHANGE_COST = getDoubleProperty("LAND_CHANGE_COST", 2.0); public static final double MIN_FEED_RATE = getDoubleProperty("MIN_FEED_RATE", 0.15); @@ -148,7 +149,7 @@ public class ModelConfig { public static final double MARKET_LAMBA = getDoubleProperty("MARKET_LAMBA", 0.3); // controls international market price adjustment rate public static final double POPULATION_AGGREG_LIMIT = getDoubleProperty("POPULATION_AGGREG_LIMIT", 40.0); // in millions, smaller countries are aggregated on a regional basis - public static final double IRRIG_COST_SCALE_FACTOR = getDoubleProperty("IRRIG_COST_SCALE_FACTOR", 0.02); + public static final double IRRIG_COST_SCALE_FACTOR = getDoubleProperty("IRRIG_COST_SCALE_FACTOR", 0.05); public static final double FERTILISER_MAX_COST = getDoubleProperty("FERTILISER_MAX_COST", 2.5); public static final double TRANSPORT_LOSSES = getDoubleProperty("TRANSPORT_LOSSES", 0.15); // in international trade public static final double TRADE_BARRIER_FACTOR = getDoubleProperty("TRADE_BARRIER_FACTOR", 1.2); // price factor in international trade, transport cost and real trade barriers diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java index 5c0320de972c41cdfe45f23c48b6dac24c69af4a..b3d0144271bd9509da89dc889c3c4c14b0d1eec7 100644 --- a/src/ac/ed/lurg/ModelMain.java +++ b/src/ac/ed/lurg/ModelMain.java @@ -29,6 +29,7 @@ import ac.ed.lurg.landuse.LandCoverItem; import ac.ed.lurg.landuse.LandCoverReader; import ac.ed.lurg.landuse.LandUseItem; import ac.ed.lurg.output.LpjgOutputer; +import ac.ed.lurg.types.CommodityType; import ac.ed.lurg.types.CropToDoubleMap; import ac.ed.lurg.types.CropType; import ac.ed.lurg.types.LandCoverType; @@ -225,6 +226,8 @@ public class ModelMain { sbData.append(String.format("%d, %s", timestep.getYear(), crop.getGamsName())); sbData.append(String.format(", %.1f, %.1f", prevWorldPrices.get(crop).getImportAmount(), prevWorldPrices.get(crop).getExportAmount())); sbData.append(String.format(", %.3f, %.3f", prevWorldPrices.get(crop).getImportPrice(), prevWorldPrices.get(crop).getExportPrice())); + + outputFile.write(sbData.toString()); outputFile.newLine(); } @@ -235,12 +238,41 @@ public class ModelMain { LogWriter.print(e); } } + + private void writeDemandFile(Timestep timestep) { + try { + StringBuffer sbHeadings = new StringBuffer("Year, Commodity, Amount (Mt)"); + BufferedWriter outputFile = getFileWriter(timestep, ModelConfig.DEMAND_OUTPUT_FILE, sbHeadings.toString()); + + for (CommodityType comm : CommodityType.getAllItems() ) { + double demandAmount = 0; + + for (CountryAgent country : countryAgents) { + Double d = country.getCurrentProjectedDemand().get(comm); + if (d != null) + demandAmount += d.doubleValue(); + } + StringBuffer sbData = new StringBuffer(); + sbData.append(String.format("%d, %s", timestep.getYear(), comm.getGamsName())); + sbData.append(String.format(", %.1f", demandAmount)); + + outputFile.write(sbData.toString()); + outputFile.newLine(); + } + outputFile.close(); + } + catch (IOException e) { + LogWriter.print(e); + } + } + private void outputTimestepResults(Timestep timestep, RasterSet<LandUseItem> landUseRaster, RasterSet<IntegerRasterItem> locationIdRaster, YieldRaster yieldSurfaces) { writeLandCoverFile(timestep, landUseRaster); writeGlobalMarketFile(timestep); + writeDemandFile(timestep); if (ModelConfig.OUTPUT_FOR_LPJG) { for (int outputYear : timestep.getYearsFromLast()) { @@ -303,7 +335,7 @@ public class ModelMain { // DEBUG code if (ModelConfig.DEBUG_LIMIT_COUNTRIES) { - if (!(cc.getName().equals("United States of Americaxx") || cc.getName().equals("United Kingdom") || cc.getName().equals("Russian Federationxx") || cc.getName().equals("South Asia_otherxx")) ) { + if (!(cc.getName().equals("United States of America") || cc.getName().equals("Chinaxx") || cc.getName().equals("Russian Federationxx") || cc.getName().equals("South Asia_otherxx")) ) { continue; } } @@ -340,6 +372,7 @@ public class ModelMain { } private RasterSet<IrrigationItem> getIrrigationData(Timestep timestep, YieldRaster yieldSurfaces) { + double needToUseTimeStepForMaxData; RasterSet<IrrigationItem> irigData = new RasterSet<IrrigationItem>(desiredProjection) { private static final long serialVersionUID = 8393130687550888654L; diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index ac107029fde1a0a455d23e9b6178ce9bcd9e107a..cfbb34c761c1649443506e864a9ac0715c3e1d16 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -28,7 +28,8 @@ public class CountryAgent { private Map<Timestep, GamsRasterOutput> resultsTimeseries = new HashMap<Timestep, GamsRasterOutput>(); private Timestep currentTimestep; private YieldRaster countryYieldSurfaces; - + private Map<CommodityType, Double> currentProjectedDemand; + public CountryAgent(DemandManager demandManager, CompositeCountry country, RasterSet<LandCoverItem> initialLC, Map<CropType, CropUsageData> cropUsageData) { @@ -64,9 +65,9 @@ public class CountryAgent { this.countryYieldSurfaces = countryYieldSurfaces; // get projected demand - Map<CommodityType, Double> projectedDemand = demandManager.getDemand(country, timestep.getYear()); + currentProjectedDemand = demandManager.getDemand(country, timestep.getYear()); - if (projectedDemand.size() == 0) { + if (currentProjectedDemand.size() == 0) { LogWriter.printlnError("No demand for country " + country + " so skipping it"); } else if (countryYieldSurfaces.size() == 0 ) { @@ -74,7 +75,7 @@ public class CountryAgent { } else { // optimize areas and intensity - GamsRasterInput input = getGamsRasterInput(projectedDemand, worldPrices, irrigData); + GamsRasterInput input = getGamsRasterInput(currentProjectedDemand, worldPrices, irrigData); GamsRasterOptimiser opti = new GamsRasterOptimiser(input); LogWriter.println("Running " + country.getName() + ", currentTimestep " + currentTimestep); @@ -85,6 +86,10 @@ public class CountryAgent { return null; } + + public Map<CommodityType, Double> getCurrentProjectedDemand() { + return currentProjectedDemand; + } private GamsRasterInput getGamsRasterInput(Map<CommodityType, Double> projectedDemand, Map<CropType, GlobalPrice> worldPrices, RasterSet<IrrigationItem> irrigData) {