From c33d227d4f6287b58d350812a063e406e4dc1bea Mon Sep 17 00:00:00 2001 From: Peter Alexander <peter@blackhillock.co.uk> Date: Thu, 17 Sep 2015 21:56:49 +0100 Subject: [PATCH] Fix for setting irrigation constraint --- src/ac/ed/lurg/ModelConfig.java | 6 ++++-- .../ed/lurg/country/gams/GamsLocationOptimiser.java | 4 ++-- .../ed/lurg/country/gams/GamsRasterOptimiser.java | 13 ++++++++----- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/ac/ed/lurg/ModelConfig.java b/src/ac/ed/lurg/ModelConfig.java index 59019ffa..399813cf 100644 --- a/src/ac/ed/lurg/ModelConfig.java +++ b/src/ac/ed/lurg/ModelConfig.java @@ -148,7 +148,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.1); + public static final double IRRIG_COST_SCALE_FACTOR = getDoubleProperty("IRRIG_COST_SCALE_FACTOR", 0.02); 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 @@ -157,5 +157,7 @@ public class ModelConfig { public static final int NUM_PASTURE_CATEGORIES = getIntProperty("NUM_PASTURE_CATEGORIES", 1); public static final boolean DEBUG_LIMIT_COUNTRIES = getBooleanProperty("DEBUG_LIMIT_COUNTRIES", false); - public static final double DEFAULT_MAX_IRRIGATION_RATE = getDoubleProperty("DEFAULT_MAX_IRRIGATION_RATE", 50.0); // should need this but some areas crops don't have a value, but was causing them to be selected + public static final double PASTURE_MAX_IRRIGATION_RATE = getDoubleProperty("DEFAULT_MAX_IRRIGATION_RATE", 50.0); // should need this but some areas crops don't have a value, but was causing them to be selected + public static int NUM_CALIBRATION_ITERATIONS = 10; + } \ No newline at end of file diff --git a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java index 06ee659b..f2049682 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java @@ -121,9 +121,9 @@ public class GamsLocationOptimiser { IrrigationItem irrigCostItem = entry.getValue(); double irrigCost = irrigCostItem.getIrrigCost(); double irrigConstraint = irrigCostItem.getIrrigConstraint(); - if (DEBUG) LogWriter.println(String.format(" %d \t %.1f,\t %.1f", locationId, irrigCost, irrigConstraint)); + if (DEBUG) LogWriter.println(String.format(" %d \t %.3f,\t %.1f", locationId, irrigCost, irrigConstraint)); irrigCostP.addRecord(Integer.toString(locationId)).setValue(irrigCost); - irrigConstraintP.addRecord(Integer.toString(locationId)).setValue(irrigCost); + irrigConstraintP.addRecord(Integer.toString(locationId)).setValue(irrigConstraint); } if (DEBUG) LogWriter.println("\nDemand"); diff --git a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java index ef8ffcd5..9985cbe6 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java @@ -65,7 +65,7 @@ public class GamsRasterOptimiser { LogWriter.println("baseCropland=" + baseCropland + ", basePasture=" + basePasture); - for (int i=0; i<10; i++) { + for (int i=0; i<ModelConfig.NUM_CALIBRATION_ITERATIONS; i++) { GamsLocationInput newInput = GamsLocationInput.createWithNewAdjustments(gamsInput, cropAdjustments); GamsLocationOptimiser opti= new GamsLocationOptimiser(newInput); @@ -354,12 +354,15 @@ public class GamsRasterOptimiser { // Crops yields and area fractions for (CropType crop : CropType.getNonMeatTypes()) { - if (irrigItem!= null) { + if (irrigItem!= null) { double irrigMax = irrigItem.getMaxIrrigAmount(crop); - + if (irrigMax == 0.0) { - LogWriter.printlnError("Can't find irrig max amount for col:" + key.getCol() + ", row:" + key.getRow() + ", x:" + yieldRaster.getXCoordin(key) + ", y:" + yieldRaster.getYCoordin(key) + ", crop:" + crop); - irrigMax = ModelConfig.DEFAULT_MAX_IRRIGATION_RATE; + if (CropType.PASTURE == crop) + irrigMax = ModelConfig.PASTURE_MAX_IRRIGATION_RATE; + else { + LogWriter.printlnError("Can't find irrig max amount for col:" + key.getCol() + ", row:" + key.getRow() + ", x:" + yieldRaster.getXCoordin(key) + ", y:" + yieldRaster.getYCoordin(key) + ", crop:" + crop); + } } aggIrig.setMaxIrrigAmount(crop, aggregateMean(aggIrig.getMaxIrrigAmount(crop), suitableAreaSoFar, irrigMax, suitableAreaThisTime)); -- GitLab