diff --git a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java index 878f10c98a02c11ca06926abb1018d66677c8b1f..dcad192299baccdcd131b7ecdd5a7ee0d96c510a 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java @@ -73,7 +73,31 @@ public class GamsRasterOptimiser { CropToDouble cropChangeTotals = newAreaAggItem.getCropChanges(prevAreaAggItem); // if (DEBUG) LogWriter.println("Processing location id " + locId); + + double pastureChange = cropChangeTotals.get(CropType.PASTURE); + double croplandChange = cropChangeTotals.getCroplandTotal(); + double prevForestToNaturalFraction = prevAreaAggItem.getForestToNaturalFraction(); + + double pastureFromCrop = 0; + double pastureFromNatural = 0; + double cropFromNatural = 0; + + if (pastureChange > 0 && croplandChange < 0) { + pastureFromCrop = Math.min(pastureChange, -croplandChange); + pastureFromNatural = (pastureChange > -croplandChange) ? 0 : pastureChange+croplandChange; + } + else if (pastureChange < 0 && croplandChange > 0) { + pastureFromCrop = -Math.min(-pastureChange, croplandChange); + cropFromNatural = (croplandChange > -pastureChange) ? 0 : -(pastureChange+croplandChange); + } + else { + pastureFromNatural = pastureChange; + cropFromNatural = croplandChange; + } + + // allocAllAreasForAgg(newAreaRaster, prevAreaRaster, keys, pastureFromNatural); + double shortfall = allocAllAreasForAgg(newAreaRaster, prevAreaRaster, keys, cropChangeTotals); if (shortfall > 0.00001) LogWriter.printlnError("This should never happen, due to GAMS constraint. Not able to incorporate all changes, as not enough forest or natural areas left: " + shortfall); @@ -180,8 +204,8 @@ public class GamsRasterOptimiser { RasterSet<IrrigationCostItem> irrigCostRaster = rasterInputData.getIrrigationCost(); { - // YieldResponsesItem yresp = yieldRaster.getFromCoordinates(-118.0, -33.0); - // LogWriter.printlnError("Test key2: " + yresp.getYieldMax(CropType.CEREALS) + ", " + yresp.getYieldFertOnly(CropType.CEREALS) + ", " + yresp.getYieldIrrigOnly(CropType.CEREALS)); + // YieldResponsesItem yresp = yieldRaster.get(new RasterKey(40,38));//getFromCoordinates(-118.0, -33.0); + // LogWriter.printlnError("Test key2: " + yresp.getYieldMax(CropType.WHEAT) + ", " + yresp.getYieldFertOnly(CropType.WHEAT) + ", " + yresp.getYieldIrrigOnly(CropType.WHEAT)); } // look for inconsistencies diff --git a/src/ac/ed/lurg/landuse/AreasItem.java b/src/ac/ed/lurg/landuse/AreasItem.java index b2a084ecb2cc730f2f7c219150b68934b64330c6..9b85996b69eaa8cb0590f8515450732383c103be 100644 --- a/src/ac/ed/lurg/landuse/AreasItem.java +++ b/src/ac/ed/lurg/landuse/AreasItem.java @@ -47,6 +47,14 @@ public class AreasItem implements RasterItem { double d = getTotalCropIncPastureArea() + getLandCoverArea(LandDataType.FOREST) + getLandCoverArea(LandDataType.OTHER_NATURAL); return d; } + + public double getForestToNaturalFraction() { + double forest = getLandCoverArea(LandDataType.FOREST); + double natural = forest + getLandCoverArea(LandDataType.OTHER_NATURAL); + double d = forest / natural; + return d; + } + public CropToDouble getCropChanges(AreasItem prevAreaAggItem) { CropToDouble changes = new CropToDouble(); diff --git a/src/ac/ed/lurg/types/CropToDouble.java b/src/ac/ed/lurg/types/CropToDouble.java index ada35b775403ca10267564c9d6bc1e2d11475e0a..b8f1176c012e2640a04ed240db4ca229c69b91a7 100644 --- a/src/ac/ed/lurg/types/CropToDouble.java +++ b/src/ac/ed/lurg/types/CropToDouble.java @@ -22,4 +22,13 @@ public class CropToDouble extends HashMap<CropType, Double> { return total; } + + public double getCroplandTotal() { + double total = 0; + for (CropType c : CropType.getCropsLessPasture()) + total += get(c); + + return total; + + } } diff --git a/src/ac/ed/lurg/types/CropType.java b/src/ac/ed/lurg/types/CropType.java index 8ed5b07ea27fcf78b668c91c817e6d8bfcfed7dd..85c13bb3753091239101d46313a8c26f643be0d1 100644 --- a/src/ac/ed/lurg/types/CropType.java +++ b/src/ac/ed/lurg/types/CropType.java @@ -17,7 +17,7 @@ public enum CropType { SOYBEAN("Soyabeans", "soybean"), PULSES("Pulses + (Total)", "pulses"), STARCHY_ROOTS("Starchy Roots + (Total)", "starchyRoots"), - MEAT("meatmilkeggs", "meat", false, true), + MEAT("meatmilkeggs", "meat", true, true), PASTURE("pasture", "pasture", false, false); private String faoName; @@ -36,6 +36,16 @@ public enum CropType { this(faoName, gamsName, true, false); } + public static Collection<CropType> getCropsLessPasture() { + Collection<CropType> comms = new HashSet<CropType>(); + + for (CropType c : values()) + if (c.importedCrop || !c.isMeat) + comms.add(c); + + return comms; + } + public static Collection<CropType> getImportedTypes() { Collection<CropType> comms = new HashSet<CropType>();