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

Output demand to file

parent d81fd3e4
No related branches found
No related tags found
No related merge requests found
...@@ -119,6 +119,7 @@ public class ModelConfig { ...@@ -119,6 +119,7 @@ public class ModelConfig {
// Output // Output
public static final String LAND_COVER_OUTPUT_FILE = OUTPUT_DIR + File.separator + "lc.txt"; 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 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 OUTPUT_FOR_LPJG = getBooleanProperty("OUTPUT_FOR_LPJG", true);
public static final boolean INTERPOLATE_OUTPUT_YEARS = getBooleanProperty("INTERPOLATE_OUTPUT_YEARS", true); public static final boolean INTERPOLATE_OUTPUT_YEARS = getBooleanProperty("INTERPOLATE_OUTPUT_YEARS", true);
...@@ -139,7 +140,7 @@ public class ModelConfig { ...@@ -139,7 +140,7 @@ public class ModelConfig {
public static final double MAX_IMPORT_CHANGE = getDoubleProperty("MAX_IMPORT_CHANGE", 0.1); 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 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 IRRIGIATION_EFFICIENCY = getDoubleProperty("IRRIGIATION_EFFICIENCY", 0.5);
public static final double LAND_CHANGE_COST = getDoubleProperty("LAND_CHANGE_COST", 2.0); 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); public static final double MIN_FEED_RATE = getDoubleProperty("MIN_FEED_RATE", 0.15);
...@@ -148,7 +149,7 @@ public class ModelConfig { ...@@ -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 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 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 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 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 public static final double TRADE_BARRIER_FACTOR = getDoubleProperty("TRADE_BARRIER_FACTOR", 1.2); // price factor in international trade, transport cost and real trade barriers
......
...@@ -29,6 +29,7 @@ import ac.ed.lurg.landuse.LandCoverItem; ...@@ -29,6 +29,7 @@ import ac.ed.lurg.landuse.LandCoverItem;
import ac.ed.lurg.landuse.LandCoverReader; import ac.ed.lurg.landuse.LandCoverReader;
import ac.ed.lurg.landuse.LandUseItem; import ac.ed.lurg.landuse.LandUseItem;
import ac.ed.lurg.output.LpjgOutputer; import ac.ed.lurg.output.LpjgOutputer;
import ac.ed.lurg.types.CommodityType;
import ac.ed.lurg.types.CropToDoubleMap; import ac.ed.lurg.types.CropToDoubleMap;
import ac.ed.lurg.types.CropType; import ac.ed.lurg.types.CropType;
import ac.ed.lurg.types.LandCoverType; import ac.ed.lurg.types.LandCoverType;
...@@ -225,6 +226,8 @@ public class ModelMain { ...@@ -225,6 +226,8 @@ public class ModelMain {
sbData.append(String.format("%d, %s", timestep.getYear(), crop.getGamsName())); 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(", %.1f, %.1f", prevWorldPrices.get(crop).getImportAmount(), prevWorldPrices.get(crop).getExportAmount()));
sbData.append(String.format(", %.3f, %.3f", prevWorldPrices.get(crop).getImportPrice(), prevWorldPrices.get(crop).getExportPrice())); sbData.append(String.format(", %.3f, %.3f", prevWorldPrices.get(crop).getImportPrice(), prevWorldPrices.get(crop).getExportPrice()));
outputFile.write(sbData.toString()); outputFile.write(sbData.toString());
outputFile.newLine(); outputFile.newLine();
} }
...@@ -235,12 +238,41 @@ public class ModelMain { ...@@ -235,12 +238,41 @@ public class ModelMain {
LogWriter.print(e); 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) { private void outputTimestepResults(Timestep timestep, RasterSet<LandUseItem> landUseRaster, RasterSet<IntegerRasterItem> locationIdRaster, YieldRaster yieldSurfaces) {
writeLandCoverFile(timestep, landUseRaster); writeLandCoverFile(timestep, landUseRaster);
writeGlobalMarketFile(timestep); writeGlobalMarketFile(timestep);
writeDemandFile(timestep);
if (ModelConfig.OUTPUT_FOR_LPJG) { if (ModelConfig.OUTPUT_FOR_LPJG) {
for (int outputYear : timestep.getYearsFromLast()) { for (int outputYear : timestep.getYearsFromLast()) {
...@@ -303,7 +335,7 @@ public class ModelMain { ...@@ -303,7 +335,7 @@ public class ModelMain {
// DEBUG code // DEBUG code
if (ModelConfig.DEBUG_LIMIT_COUNTRIES) { 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; continue;
} }
} }
...@@ -340,6 +372,7 @@ public class ModelMain { ...@@ -340,6 +372,7 @@ public class ModelMain {
} }
private RasterSet<IrrigationItem> getIrrigationData(Timestep timestep, YieldRaster yieldSurfaces) { private RasterSet<IrrigationItem> getIrrigationData(Timestep timestep, YieldRaster yieldSurfaces) {
double needToUseTimeStepForMaxData;
RasterSet<IrrigationItem> irigData = new RasterSet<IrrigationItem>(desiredProjection) { RasterSet<IrrigationItem> irigData = new RasterSet<IrrigationItem>(desiredProjection) {
private static final long serialVersionUID = 8393130687550888654L; private static final long serialVersionUID = 8393130687550888654L;
......
...@@ -28,7 +28,8 @@ public class CountryAgent { ...@@ -28,7 +28,8 @@ public class CountryAgent {
private Map<Timestep, GamsRasterOutput> resultsTimeseries = new HashMap<Timestep, GamsRasterOutput>(); private Map<Timestep, GamsRasterOutput> resultsTimeseries = new HashMap<Timestep, GamsRasterOutput>();
private Timestep currentTimestep; private Timestep currentTimestep;
private YieldRaster countryYieldSurfaces; private YieldRaster countryYieldSurfaces;
private Map<CommodityType, Double> currentProjectedDemand;
public CountryAgent(DemandManager demandManager, CompositeCountry country, RasterSet<LandCoverItem> initialLC, public CountryAgent(DemandManager demandManager, CompositeCountry country, RasterSet<LandCoverItem> initialLC,
Map<CropType, CropUsageData> cropUsageData) { Map<CropType, CropUsageData> cropUsageData) {
...@@ -64,9 +65,9 @@ public class CountryAgent { ...@@ -64,9 +65,9 @@ public class CountryAgent {
this.countryYieldSurfaces = countryYieldSurfaces; this.countryYieldSurfaces = countryYieldSurfaces;
// get projected demand // 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"); LogWriter.printlnError("No demand for country " + country + " so skipping it");
} }
else if (countryYieldSurfaces.size() == 0 ) { else if (countryYieldSurfaces.size() == 0 ) {
...@@ -74,7 +75,7 @@ public class CountryAgent { ...@@ -74,7 +75,7 @@ public class CountryAgent {
} }
else { else {
// optimize areas and intensity // optimize areas and intensity
GamsRasterInput input = getGamsRasterInput(projectedDemand, worldPrices, irrigData); GamsRasterInput input = getGamsRasterInput(currentProjectedDemand, worldPrices, irrigData);
GamsRasterOptimiser opti = new GamsRasterOptimiser(input); GamsRasterOptimiser opti = new GamsRasterOptimiser(input);
LogWriter.println("Running " + country.getName() + ", currentTimestep " + currentTimestep); LogWriter.println("Running " + country.getName() + ", currentTimestep " + currentTimestep);
...@@ -85,6 +86,10 @@ public class CountryAgent { ...@@ -85,6 +86,10 @@ public class CountryAgent {
return null; return null;
} }
public Map<CommodityType, Double> getCurrentProjectedDemand() {
return currentProjectedDemand;
}
private GamsRasterInput getGamsRasterInput(Map<CommodityType, Double> projectedDemand, Map<CropType, GlobalPrice> worldPrices, RasterSet<IrrigationItem> irrigData) { private GamsRasterInput getGamsRasterInput(Map<CommodityType, Double> projectedDemand, Map<CropType, GlobalPrice> worldPrices, RasterSet<IrrigationItem> irrigData) {
......
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