diff --git a/GAMS/IntExtOpt.gms b/GAMS/IntExtOpt.gms index ea7633f87f066438767b97df30803a5a4d549555..66115fcbe8f6b23038aba9ccf55c34d6efc315df 100644 --- a/GAMS/IntExtOpt.gms +++ b/GAMS/IntExtOpt.gms @@ -142,7 +142,7 @@ $gdxin POSITIVE VARIABLE cropArea, fertI, irrigI, otherIntensity, ruminantFeed, monogastricFeed, importAmount, exportAmount, agriLandExpansion, cropIncrease, cropDecrease, pastureDecrease, pastureIncrease, totalFeedDM, - landCoverArea, landCoverChange, woodHarvest, carbonFlux; + landCoverArea, landCoverChange, woodHarvest; EQUATIONS UNIT_COST_EQ(crop, location) cost per area @@ -244,7 +244,7 @@ $gdxin LAND_COVER_CHANGE_CONSTRAINT(land_cover, location) .. sum(land_cover_after, landCoverChange(land_cover, land_cover_after, location)) =L= previousLandCoverArea(land_cover, location); -* TOTAL_LAND_COVER_CONSTRAINT(location) .. sum(land_cover, landCoverArea(land_cover, location)) =E= suitableArea(location); +* TOTAL_LAND_COVER_CONSTRAINT(location) .. sum(land_cover, landCoverArea(land_cover, location)) =E= suitableLandArea(location); WOOD_HARVEST_CALC(location) .. woodHarvest(location) =E= sum((land_cover_before, land_cover_after), landCoverChange(land_cover_before, land_cover_after, location) * woodYield(land_cover_before, land_cover_after, location)); diff --git a/src/ac/ed/lurg/ModelMain.java b/src/ac/ed/lurg/ModelMain.java index e01d8ac4f9a04483df989dcf3d4951d88ad8b396..0ae21ecd9aa272646cfa9533a2a4374b68c5f2bb 100644 --- a/src/ac/ed/lurg/ModelMain.java +++ b/src/ac/ed/lurg/ModelMain.java @@ -633,12 +633,14 @@ public class ModelMain { for (Map.Entry<RasterKey, LandCoverItem> entry : initialLC.entrySet()) landUseRaster.put(entry.getKey(), new LandUseItem(entry.getValue())); + /* // Set initial GAMS land covers for (LandUseItem item : landUseRaster.values()) { item.setLandCoverArea(LandCoverType.TIMBER_FOREST, item.getLandCoverArea(LandCoverType.MANAGED_FOREST)); item.setLandCoverArea(LandCoverType.CARBON_FOREST, 0.0); item.setLandCoverArea(LandCoverType.NATURAL, item.getLandCoverArea(LandCoverType.OTHER_NATURAL) + item.getLandCoverArea(LandCoverType.UNMANAGED_FOREST)); } + */ return landUseRaster; } diff --git a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java index 616dc301fae2324dda673c220955bb110009a29f..c8278cd1edb441c57b019633487e6b0ade414875 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java @@ -173,7 +173,7 @@ public class GamsLocationOptimiser { Vector<String> v = new Vector<String>(); v.add(lc.getName()); v.add(locString); - setGamsParamValue(prevLandCoverP.addRecord(v), landUseItem.getLandCoverArea(lc), 3); + setGamsParamValue(prevLandCoverP.addRecord(v), landUseItem.getUnprotectedLandCoverArea(lc), 3); } } @@ -415,7 +415,7 @@ public class GamsLocationOptimiser { if (modelStatus != ModelStat.OPTIMAL_LOCAL) LogWriter.printlnError("Critical!!! Land use incorrectly solved. " + contextString); - GAMSVariable varAreas = outDB.getVariable("area"); + GAMSVariable varAreas = outDB.getVariable("cropArea"); GAMSVariable varFertIntensities = outDB.getVariable("fertI"); GAMSVariable varIrrigIntensities = outDB.getVariable("irrigI"); GAMSVariable varOtherIntensities = outDB.getVariable("otherIntensity"); @@ -549,6 +549,33 @@ public class GamsLocationOptimiser { double change = rec.getLevel(); + if (landCoverChange.containsKey(locId)) { + Map<LandCoverType, Map<LandCoverType, Double>> locMap = landCoverChange.get(locId); + + if (locMap.containsKey(LandCoverType.getForName(fromLC))) { + locMap.get(LandCoverType.getForName(fromLC)).put(LandCoverType.getForName(toLC), change); + } + else { + Map<LandCoverType, Double> toMap = new HashMap<LandCoverType, Double>(); + toMap.put(LandCoverType.getForName(toLC), change); + + //Map<LandCoverType, Map<LandCoverType, Double>> fromMap = new HashMap<LandCoverType, Map<LandCoverType, Double>>(); + //fromMap.put(LandCoverType.getForName(fromLC), toMap); + + landCoverChange.get(locId).put(LandCoverType.getForName(fromLC), toMap); + } + } + else { + Map<LandCoverType, Double> toMap = new HashMap<LandCoverType, Double>(); + toMap.put(LandCoverType.getForName(toLC), change); + + Map<LandCoverType, Map<LandCoverType, Double>> fromMap = new HashMap<LandCoverType, Map<LandCoverType, Double>>(); + fromMap.put(LandCoverType.getForName(fromLC), toMap); + + landCoverChange.put(locId, fromMap); + } + + /* Map<LandCoverType, Double> toMap = new HashMap<LandCoverType, Double>(); toMap.put(LandCoverType.getForName(toLC), change); @@ -556,7 +583,7 @@ public class GamsLocationOptimiser { fromMap.put(LandCoverType.getForName(fromLC), toMap); landCoverChange.put(locId, fromMap); - + */ } GamsLocationOutput results = new GamsLocationOutput(modelStatus, landUses, cropUsageData, landCoverChange); diff --git a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java index f5f18ff404be173ab91daeb38c88c4d222bbbff3..a0b8df7d3f78d165b961506af9828c66dc1f4ff9 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java @@ -271,10 +271,7 @@ public class GamsRasterOptimiser { } - - - return newLandUseRaster; } @@ -532,26 +529,44 @@ public class GamsRasterOptimiser { //Suitable areas aggLandUse.setSuitableArea(suitableAreaSoFar + suitableAreaThisTime); - // Land covers ares + + // Land covers areas for (LandCoverType landType : LandCoverType.values()) { - double areaThisTime = landUseItem.getLandCoverArea(landType); - double areaSoFar = aggLandUse.getLandCoverArea(landType); - aggLandUse.setLandCoverArea(landType, areaSoFar + areaThisTime); - } + double areaThisTime = landUseItem.getUnprotectedLandCoverArea(landType); + double areaSoFar = aggLandUse.getUnprotectedLandCoverArea(landType); - /* - // Gams land cover areas - for (GamsLandCoverType landType : GamsLandCoverType.values()) { - double areaThisTime = landUseItem.getGamsLandCoverArea(landType); - double areaSoFar = aggLandUse.getGamsLandCoverArea(landType); - aggLandUse.setGamsLandCoverArea(landType, areaSoFar + areaThisTime); + aggLandUse.setUnprotectedLandCoverArea(landType, areaSoFar + areaThisTime); } - */ + + + } - } - + } + /* + for (Entry<RasterKey, LandUseItem> entry : rasterInputData.getPreviousLandUses().entrySet()) { + LandUseItem landUseItem = entry.getValue(); + RasterKey key = entry.getKey(); + int clusterId = mapping.get(key).getInt(); + LandUseItem aggLandUse = aggregatedAreas.lazyGet(clusterId); + + // Land covers areas + for (LandCoverType landType : LandCoverType.values()) { + double areaThisTime = landUseItem.getUnprotectedLandCoverArea(landType); + double areaSoFar = aggLandUse.getUnprotectedLandCoverArea(landType); + + aggLandUse.setLandCoverArea(landType, areaSoFar + areaThisTime); + } + } + */ +/* + LogWriter.println("potato" + rasterInputData.getCountryInput().getCountry().getName()); + if (rasterInputData.getCountryInput().getCountry().getName().equals("Central America")) { + LogWriter.println("foo"); + } +*/ LogWriter.println("YieldResponsesItem: " + rasterInputData.getCountryInput().getCountry() + ", countFound=" + countFound + ", countMissing=" + countMissing); - + + // for (Map.Entry<Integer, Set<RasterKey>> e : mapping.entrySet()) { // LogWriter.println(e.getKey() + " zone has " + e.getValue().size() + " raster areas"); diff --git a/src/ac/ed/lurg/landuse/LandUseItem.java b/src/ac/ed/lurg/landuse/LandUseItem.java index f30e7b0673d27347d5b07f8c387a8479626e0b42..ad974d34bde721d509f180667b5580c2a7e97c47 100644 --- a/src/ac/ed/lurg/landuse/LandUseItem.java +++ b/src/ac/ed/lurg/landuse/LandUseItem.java @@ -32,6 +32,10 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem>, Serial for (LandCoverType lcType : LandCoverType.values()) landCoverAreas.put(lcType, landCover.getLandCoverArea(lcType)); + landCoverAreas.put(LandCoverType.TIMBER_FOREST, landCover.getLandCoverArea(LandCoverType.MANAGED_FOREST)); + landCoverAreas.put(LandCoverType.CARBON_FOREST, 0.0); + landCoverAreas.put(LandCoverType.NATURAL, landCover.getLandCoverArea(LandCoverType.OTHER_NATURAL) + landCover.getLandCoverArea(LandCoverType.UNMANAGED_FOREST)); + setCropFraction(CropType.WHEAT, 0.5); // random start as don't have better data setCropFraction(CropType.MAIZE, 0.5); setUnavailableArea(landCover.getUnavailableFract()); @@ -296,7 +300,13 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem>, Serial } public double getUnprotectedLandCoverArea(LandCoverType landType) { - return unprotectedAreas.get(landType); + Double d = unprotectedAreas.get(landType); + return d == null ? 0.0 : d; + } + + public void setUnprotectedLandCoverArea(LandCoverType landType, double d) { + unprotectedAreas.put(landType, d); + } private double getProtectedandUnavailable() { @@ -427,6 +437,11 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem>, Serial return total; } + /* + public boolean checkForUnprotected(LandCoverType landCover) { + return unprotectedAreas.containsKey(landCover); + } + */ /* public double getGamsLandCoverArea(GamsLandCoverType landCoverType) { return gamsLandCoverAreas.get(landCoverType);