diff --git a/GAMS/IntExtOpt.gms b/GAMS/IntExtOpt.gms index b7566b86dbc9ead4a976b9c496285cb79f8beae8..595b76f9c136f576d4001594950a2101e54f0f59 100644 --- a/GAMS/IntExtOpt.gms +++ b/GAMS/IntExtOpt.gms @@ -15,6 +15,10 @@ PARAMETER previousFertIntensity(crop, location); PARAMETER previousIrrigIntensity(crop, location); PARAMETER previousOtherIntensity(crop, location); + PARAMETER previousRuminantFeed(crop); + PARAMETER previousMonogastricFeed(crop); + PARAMETER previousImportAmount(all_types); + PARAMETER previousExportAmount(all_types); PARAMETER yieldNone(crop, location) yield in t per ha; PARAMETER yieldFertOnly(crop, location) yield in t per ha; PARAMETER yieldIrrigOnly(crop, location) yield in t per ha; @@ -46,7 +50,7 @@ *$gdxin "/Users/peteralexander/Documents/R_Workspace/UNPLUM/temp/GamsTmp/t1.gdx" $gdxin %gdxincname% $load location, suitableLandArea, demand, agriExpansionCost, cropIncCost, pastureIncCost, cropDecCost, pastureDecCost -$load previousArea, previousFertIntensity, previousIrrigIntensity, previousOtherIntensity +$load previousArea, previousFertIntensity, previousIrrigIntensity, previousOtherIntensity, previousRuminantFeed, previousMonogastricFeed, previousImportAmount, previousExportAmount $load yieldNone, yieldFertOnly, yieldIrrigOnly, yieldBoth $load fertParam, irrigParam, otherIParam, exportPrices, importPrices, maxNetImport, minNetImport, unhandledCropArea $load meatEfficency, otherICost, irrigCost, irrigMaxRate, irrigConstraint, fertiliserUnitCost, domesticPriceMarkup @@ -141,16 +145,10 @@ $gdxin YIELD_EQ(crop, location) .. yield(crop, location) =E= ( yieldNone(crop, location) + -* (yieldFertOnly(crop, location) - yieldNone(crop, location)) * ((fertI(crop, location) + delta) ** fertParam(crop, location)) + -* (yieldIrrigOnly(crop, location) - yieldNone(crop, location)) * ((irrigI(crop, location) + delta) ** irrigParam(crop, location)) + -* (yieldBoth(crop, location) + yieldNone(crop, location) - yieldFertOnly(crop, location) - yieldIrrigOnly(crop, location)) * -* ((fertI(crop, location) + delta) ** fertParam(crop, location)) * ((irrigI(crop, location) + delta) ** irrigParam(crop, location)) - (yieldFertOnly(crop, location) - yieldNone(crop, location)) * (1 - exp(-fertParam(crop, location)*fertI(crop, location))) + (yieldIrrigOnly(crop, location) - yieldNone(crop, location)) * (1 - exp(-irrigParam(crop, location)*irrigI(crop, location))) + (yieldBoth(crop, location) + yieldNone(crop, location) - yieldFertOnly(crop, location) - yieldIrrigOnly(crop, location)) * (1 - exp(-fertParam(crop, location)*fertI(crop, location))) * (1 - exp(-irrigParam(crop, location)*irrigI(crop, location))) - ) * (1 - exp(-otherIntensity(crop, location)*otherIParam)); NET_SUPPLY_EQ(crop) .. net_supply(crop) =E= sum(location, area(crop, location) * yield(crop, location)) - feedAmount(crop) + importAmount(crop) - exportAmount(crop); @@ -208,23 +206,19 @@ $gdxin MODEL LAND_USE /ALL/ ; - importAmount.L(import_crop)$((maxNetImport(import_crop) + minNetImport(import_crop)) gt 0) = (maxNetImport(import_crop) + minNetImport(import_crop)) / 2; - exportAmount.L(import_crop)$((maxNetImport(import_crop) + minNetImport(import_crop)) lt 0) = -(maxNetImport(import_crop) + minNetImport(import_crop)) / 2; - fertI.L(crop, location) = previousFertIntensity(crop, location); irrigI.L(crop, location) = previousIrrigIntensity(crop, location); otherIntensity.L(crop, location) = previousOtherIntensity(crop, location); - area.L(crop, location) = previousArea(crop, location) - - display suitableLandArea; - + area.L(crop, location) = previousArea(crop, location); + ruminantFeed.L(feed_crop) = previousRuminantFeed(feed_crop); + monogastricFeed.L(feed_crop) = previousMonogastricFeed(feed_crop); + importAmount.L(all_types) = previousImportAmount(all_types); + exportAmount.L(all_types) = previousExportAmount(all_types); + SOLVE LAND_USE USING NLP MINIMIZING total_cost; - - display previousFertIntensity; - - display agriLandExpansion.l, previousArea, irrigMaxRate, irrigI.l, area.l, cropIncrease.l, cropDecrease.l, pastureIncrease.l, pastureDecrease.l; -* display area.l, net_supply.l, demand, feedAmount.l, yield.l, importAmount.l, exportAmount.l, unitCost.l, exportPrices, maxNetImport, minNetImport; - display otherIntensity.l, fertI.l, irrigI.l; + + display agriLandExpansion.L, previousArea, irrigMaxRate, otherIntensity.L, fertI.L, irrigI.L, area.L, cropIncrease.L, cropDecrease.L, pastureIncrease.L, pastureDecrease.L; +* display suitableLandArea, area.l, net_supply.l, demand, feedAmount.l, yield.l, importAmount.l, exportAmount.l, unitCost.l, exportPrices, maxNetImport, minNetImport; * Calculate summary information used in Java process parameter totalProd(all_types); @@ -248,12 +242,6 @@ $gdxin netImportCost(import_crop) = importAmount.l(import_crop) * importPrices(import_crop) - exportAmount.l(import_crop) * exportPrices(import_crop); netImportAmount(import_crop) = importAmount.l(import_crop) - exportAmount.l(import_crop); - -* feedCost(feed_crop)$(netImportAmount(feed_crop) gt 0) = (totalProdCost(feed_crop) + netImportCost(feed_crop)) * feedAmount.l(feed_crop) / (totalProd(feed_crop) + netImportAmount(feed_crop)); -* feedCost(feed_crop)$(netImportAmount(feed_crop) le 0 and totalProd(feed_crop) gt 0) = totalProdCost(feed_crop) * feedAmount.l(feed_crop) / totalProd(feed_crop); -* totalProdCost('meat') = sum(feed_crop, feedCost(feed_crop)); - -* display totalProdCost, totalProd, netImportCost Scalar ms 'model status', ss 'solve status'; ms=LAND_USE.modelstat; diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index 586809c882261226ddb706f5ac482514d8206d18..ce8f387ea11c498ce6b586add65d036a8172c9cc 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -170,7 +170,7 @@ public class CountryAgent { // constraining each country to only export twice the energy crops that it's proportion of global cropland implies, as a rough constraint, really constraint comes price - GamsCountryInput countryLevelInputs = new GamsCountryInput(country, currentProjectedDemand, currentCountryPrices, importConstraints); + GamsCountryInput countryLevelInputs = new GamsCountryInput(country, currentProjectedDemand, currentCountryPrices, importConstraints, previousGamsRasterOutput.getCropUsageData()); GamsRasterInput input = new GamsRasterInput(currentTimestep, countryYieldSurfaces, previousGamsRasterOutput.getLandUses(), irrigData, countryLevelInputs); return input; diff --git a/src/ac/ed/lurg/country/gams/GamsCountryInput.java b/src/ac/ed/lurg/country/gams/GamsCountryInput.java index ea480c26010dd5677696d6386dffa550702ae66d..ccd1179d62b9d694a8b0a10fa2cf6fa98fee0e8f 100644 --- a/src/ac/ed/lurg/country/gams/GamsCountryInput.java +++ b/src/ac/ed/lurg/country/gams/GamsCountryInput.java @@ -7,6 +7,7 @@ import ac.ed.lurg.ModelConfig; import ac.ed.lurg.country.CompositeCountry; import ac.ed.lurg.country.CountryPrice; import ac.ed.lurg.country.ImportExportConstraint; +import ac.ed.lurg.landuse.CropUsageData; import ac.ed.lurg.types.CommodityType; import ac.ed.lurg.types.CropType; @@ -16,18 +17,20 @@ public class GamsCountryInput { private Map<CommodityType, Double> projectedDemand; private Map<CropType, ImportExportConstraint> importConstraints; private Map<CropType, CountryPrice> countryPrices; - + private Map<CropType, CropUsageData> previousCropUsageData; + public GamsCountryInput(CompositeCountry country, Map<CommodityType, Double> projectedDemand, Map<CropType, CountryPrice> countryPrices, - Map<CropType, ImportExportConstraint> importConstraints) { + Map<CropType, ImportExportConstraint> importConstraints, Map<CropType, CropUsageData> previousCropUsageData) { super(); this.country = country; this.projectedDemand = projectedDemand; this.importConstraints = importConstraints; this.countryPrices = countryPrices; + this.previousCropUsageData = previousCropUsageData; } public GamsCountryInput(GamsCountryInput gamsInput) { - this(gamsInput.country, gamsInput.projectedDemand, gamsInput.countryPrices,gamsInput.importConstraints); + this(gamsInput.country, gamsInput.projectedDemand, gamsInput.countryPrices, gamsInput.importConstraints, gamsInput.previousCropUsageData); } public CompositeCountry getCountry() { @@ -45,6 +48,10 @@ public class GamsCountryInput { public Map<CropType, ImportExportConstraint> getImportConstraints() { return importConstraints; } + + public Map<CropType, CropUsageData> getPreviousCropUsageData() { + return previousCropUsageData; + } public double getMeatEfficiency() { return ModelConfig.MEAT_EFFICIENCY; // this is already handled by the feed conversion efficiency for each animal product diff --git a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java index af97ad52a0c3e37536e6c6888784d3cf21280ff8..cbfa7486c48a83d05b5791dfb059144569585189 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationOptimiser.java @@ -88,6 +88,12 @@ public class GamsLocationOptimiser { GAMSParameter prevFertIP = inDB.addParameter("previousFertIntensity", 2); GAMSParameter prevIrrigIP = inDB.addParameter("previousIrrigIntensity", 2); GAMSParameter prevOtherIP = inDB.addParameter("previousOtherIntensity", 2); + + GAMSParameter previousRuminantFeedP = inDB.addParameter("previousRuminantFeed", 1); + GAMSParameter previousMonogastricFeedP = inDB.addParameter("previousMonogastricFeed", 1); + GAMSParameter previousImportAmountP = inDB.addParameter("previousImportAmount", 1); + GAMSParameter previousExportAmountP = inDB.addParameter("previousExportAmount", 1); + GAMSParameter landP = inDB.addParameter("suitableLandArea", 1); GAMSParameter agriExpansionCostP = inDB.addParameter("agriExpansionCost", 1); @@ -204,25 +210,38 @@ public class GamsLocationOptimiser { } } - if (DEBUG) LogWriter.println("\nImport-export, min net imports, max net imports, global import price, global export price"); + if (DEBUG) LogWriter.println("\nImport-export, min net imports, max net imports, global import price, global export price, imports, exports, ruminantFeed, monogastricFeed"); GAMSParameter minImportP = inDB.addParameter("minNetImport", 1); GAMSParameter maxImportP = inDB.addParameter("maxNetImport", 1); GAMSParameter importPriceP = inDB.addParameter("importPrices", 1); GAMSParameter exportPriceP = inDB.addParameter("exportPrices", 1); - - for (CropType crop : CropType.getImportedTypes()) { + + for (CropType crop : CropType.getImportedTypes()) { ImportExportConstraint iec = countryInput.getImportConstraints().get(crop); CountryPrice gp = countryInput.getCountryPrices().get(crop); double minNetImport = iec.getMinNetImport(); double maxNetImport = iec.getMaxNetImport(); double importPrice = gp.getImportPrice(); double exportPrice = gp.getExportPrice(); + CropUsageData cu = countryInput.getPreviousCropUsageData().get(crop); + double netImports = cu.getNetImports(); + double imports = netImports>0 ? netImports : 0; + double exports = netImports<0 ? -netImports : 0; + + double ruminantFeed = cu.getRuminantFeed(); + double monogastricFeed = cu.getMonogastricFeed(); + + if (DEBUG) LogWriter.println(String.format(" %15s, \t %5.1f, \t %5.1f, \t %5.3f, \t %5.3f, \t %5.1f, \t %5.1f, \t %5.1f, \t %5.1f", + crop.getGamsName(), minNetImport, maxNetImport, importPrice, exportPrice, imports, exports, ruminantFeed, monogastricFeed)); - if (DEBUG) LogWriter.println(String.format(" %15s, \t %5.1f, \t %5.1f, \t %5.3f, \t %5.3f", crop.getGamsName(), minNetImport, maxNetImport, importPrice, exportPrice)); setGamsParamValue(minImportP.addRecord(crop.getGamsName()), minNetImport, 3); setGamsParamValue(maxImportP.addRecord(crop.getGamsName()), maxNetImport, 3); setGamsParamValue(importPriceP.addRecord(crop.getGamsName()), importPrice, 3); setGamsParamValue(exportPriceP.addRecord(crop.getGamsName()), exportPrice, 3); + setGamsParamValue(previousImportAmountP.addRecord(crop.getGamsName()), imports, 3); + setGamsParamValue(previousExportAmountP.addRecord(crop.getGamsName()), exports, 3); + setGamsParamValue(previousRuminantFeedP.addRecord(crop.getGamsName()), ruminantFeed, 3); + setGamsParamValue(previousMonogastricFeedP.addRecord(crop.getGamsName()), monogastricFeed, 3); } LogWriter.print("\n"); @@ -268,11 +287,11 @@ public class GamsLocationOptimiser { GAMSVariable varFertIntensities = outDB.getVariable("fertI"); GAMSVariable varIrrigIntensities = outDB.getVariable("irrigI"); GAMSVariable varOtherIntensities = outDB.getVariable("otherIntensity"); - GAMSVariable varFeedAmount = outDB.getVariable("feedAmount"); + GAMSVariable varRuminantFeed = outDB.getVariable("ruminantFeed"); + GAMSVariable varMonogastricFeed = outDB.getVariable("monogastricFeed"); GAMSParameter parmNetImports = outDB.getParameter("netImportAmount"); GAMSVariable varYields = outDB.getVariable("yield"); GAMSVariable varUnitEnergies = outDB.getVariable("unitCost"); -// GAMSParameter parmCropAdj = outDB.getParameter("cropAdj"); GAMSParameter parmProd = outDB.getParameter("totalProd"); GAMSParameter parmProdCost = outDB.getParameter("totalProdCost"); GAMSParameter parmCroplandArea = outDB.getParameter("totalCropland"); @@ -280,8 +299,8 @@ public class GamsLocationOptimiser { double totalCropArea = 0; double totalPastureArea = 0; - double area, fertIntensity, irrigIntensity, otherIntensity = Double.NaN, feedAmount, netImport, yield, unitCost, prod, prodCost; - + double area, fertIntensity, irrigIntensity, otherIntensity = Double.NaN, ruminantFeed, monogastricFeed, netImport, yield, unitCost, prod, prodCost; + final LazyHashMap<Integer, LandUseItem> landUses = new LazyHashMap<Integer, LandUseItem>() { protected LandUseItem createValue() { return new LandUseItem(); } }; @@ -305,14 +324,15 @@ public class GamsLocationOptimiser { CropType cropType = CropType.getForGamsName(itemName); if (!cropUsageData.containsKey(cropType)) { // then we must not have seen this crop type before, so need to do all non location specific stuff - feedAmount = varFeedAmount.findRecord(itemName).getLevel(); + ruminantFeed = cropType.isFeedCrop() ? varRuminantFeed.findRecord(itemName).getLevel() : 0; + monogastricFeed = cropType.isFeedCrop() ? varMonogastricFeed.findRecord(itemName).getLevel() : 0; netImport = cropType.isImportedCrop() ? getParmValue(parmNetImports, itemName) : 0; prod = getParmValue(parmProd, itemName); prodCost = getParmValue(parmProdCost, itemName); double totalArea = getParmValue(parmTotalArea, itemName); - cropUsageData.put(cropType, new CropUsageData(feedAmount, netImport, prod, prodCost)); - if (DEBUG) LogWriter.println(String.format("\n%s:\tarea= %.1f,\tfeedAmount= %.1f,\tnetImports= %.3f,\tprod= %.3f,\tprodCost= %.3f,\tprodCostRate= %.3f", itemName, totalArea, feedAmount, netImport, prod, prodCost, prodCost/prod)); + cropUsageData.put(cropType, new CropUsageData(ruminantFeed, monogastricFeed, netImport, prod, prodCost)); + if (DEBUG) LogWriter.println(String.format("\n%s:\tarea= %.1f,\tfeedAmount= %.1f,\tnetImports= %.3f,\tprod= %.3f,\tprodCost= %.3f,\tprodCostRate= %.3f", itemName, totalArea, ruminantFeed+monogastricFeed, netImport, prod, prodCost, prodCost/prod)); } LandUseItem landUseItem = landUses.lazyGet(locId); @@ -341,7 +361,7 @@ public class GamsLocationOptimiser { prod = getParmValue(parmProd, meatTypes.getGamsName()); // prodCost = getParmValue(parmProdCost, meatTypes.getGamsName()); currently not calculated in GAMS correctly, not sure it's needed - cropUsageData.put(meatTypes, new CropUsageData(0.0, netImport, prod, Double.NaN)); + cropUsageData.put(meatTypes, new CropUsageData(0.0, 0.0, netImport, prod, Double.NaN)); if (DEBUG) LogWriter.println(String.format("\n%s:\t\t\t\t\tnetImports= %.3f,\tprod= %.3f", meatTypes.getGamsName(), netImport, prod)); } LogWriter.println(String.format("\n%s %s: Total area= %.1f (crop=%.1f, pasture %.1f)", diff --git a/src/ac/ed/lurg/country/gams/GamsLocationOutput.java b/src/ac/ed/lurg/country/gams/GamsLocationOutput.java index a57334ce7c538d79783b4d734501bfb9b8c36a94..7cf0f795cf8f262abee0e3681b3b7dc036b68062 100644 --- a/src/ac/ed/lurg/country/gams/GamsLocationOutput.java +++ b/src/ac/ed/lurg/country/gams/GamsLocationOutput.java @@ -34,9 +34,4 @@ public class GamsLocationOutput { public Map<CropType, CropUsageData> getCommoditiesData() { return cropUsageData; } - - public Map<CropType, Double> getCropAdjustments() { - return cropAdjustments; - } - } diff --git a/src/ac/ed/lurg/country/gams/GamsLocationTest.java b/src/ac/ed/lurg/country/gams/GamsLocationTest.java deleted file mode 100644 index e2099deb5c02894589b44a58fc473c79f2018559..0000000000000000000000000000000000000000 --- a/src/ac/ed/lurg/country/gams/GamsLocationTest.java +++ /dev/null @@ -1,155 +0,0 @@ -package ac.ed.lurg.country.gams; - -import java.util.HashMap; -import java.util.Map; - -import ac.ed.lurg.Timestep; -import ac.ed.lurg.country.CompositeCountry; -import ac.ed.lurg.country.CountryPrice; -import ac.ed.lurg.landuse.LandUseItem; -import ac.ed.lurg.landuse.IrrigationItem; -import ac.ed.lurg.types.CommodityType; -import ac.ed.lurg.types.CropType; -import ac.ed.lurg.types.LandCoverType; -import ac.ed.lurg.types.YieldType; -import ac.ed.lurg.yield.YieldResponsesItem; - -public class GamsLocationTest { - public static final int NUM_LOCATIONS_PER_COUNTRY = 3; - - public static void main(String[] args) { - GamsLocationTest aGamsTest = new GamsLocationTest(); - aGamsTest.run(); - } - - private void run() { - GamsCountryInput countryLevelInputs = new GamsCountryInput(new CompositeCountry("Test"), getProjectedDemand(), getCountryPrices(), null); - GamsLocationInput gamsInput = new GamsLocationInput(new Timestep(0), getYields(), getPreviousArea(), getIrrigationCosts(), countryLevelInputs); - - GamsLocationOptimiser opti = new GamsLocationOptimiser(gamsInput); - opti.run(); - } - - Map<CommodityType, Double> getProjectedDemand() { - Map<CommodityType, Double> dummyMap = new HashMap<CommodityType, Double>(); - dummyMap.put(CommodityType.CEREALS, 300.0); - dummyMap.put(CommodityType.OILCROPS, 50.0); - dummyMap.put(CommodityType.PULSES, 60.0); - dummyMap.put(CommodityType.STARCHY_ROOTS, 150.0); - dummyMap.put(CommodityType.MONOGASTRICS, 480.0); - return dummyMap; - } - - Map<CropType, CountryPrice> getCountryPrices() { - - Map<CropType, CountryPrice> dummyTradeMap = new HashMap<CropType, CountryPrice>(); - - dummyTradeMap.put(CropType.WHEAT, createCountryPrice(0.15,0.15)); - dummyTradeMap.put(CropType.MAIZE, createCountryPrice(0.15,0.15)); - dummyTradeMap.put(CropType.RICE, createCountryPrice(0.4,0.4)); - dummyTradeMap.put(CropType.OILCROPS, createCountryPrice(0.4,0.4)); - dummyTradeMap.put(CropType.PULSES, createCountryPrice(0.2,0.2)); - dummyTradeMap.put(CropType.STARCHY_ROOTS, createCountryPrice(0.1,0.1)); - dummyTradeMap.put(CropType.MONOGASTRICS, createCountryPrice(0.2,0.2)); - - return dummyTradeMap; - } - - CountryPrice createCountryPrice(double imports, double exports){ - - return new CountryPrice(imports,exports); - - } - - Map<Integer, YieldResponsesItem> getYields() { - - YieldResponsesItem yresp = getYieldRespItem(1, 1); - Map<Integer, YieldResponsesItem> returnMap = new HashMap<Integer, YieldResponsesItem>(); - - for (int i= 1; i<=NUM_LOCATIONS_PER_COUNTRY; i++) - returnMap.put(i, yresp); - - return returnMap; - } - - YieldResponsesItem getYieldRespItem(double base, double pastureFactor) { - YieldResponsesItem yresp = new YieldResponsesItem(); - - for (CropType crop : CropType.getAllItems()) { - double factor = base; - if (CropType.PASTURE == crop) - factor = base * pastureFactor; - - yresp.setYield(YieldType.NO_FERT_NO_IRRIG, crop, factor); - yresp.setYield(YieldType.FERT_MID_NO_IRRIG, crop, factor*2.2); - yresp.setYield(YieldType.FERT_MAX_NO_IRRIG, crop, factor*3); -// yresp.setYield(YieldType.IRRIG_MID_ONLY, crop, factor*1.8); - yresp.setYield(YieldType.NO_FERT_IRRIG_MAX, crop, factor*2); - yresp.setYield(YieldType.FERT_MAX_IRRIG_MAX, crop, factor*4); - } - return yresp; - } - - private Map<Integer, IrrigationItem> getIrrigationCosts() { - Map<Integer, IrrigationItem> returnMap = new HashMap<Integer, IrrigationItem>(); - - for (int i= 1; i<=NUM_LOCATIONS_PER_COUNTRY; i++) { - IrrigationItem dummyIrrigCost = new IrrigationItem(); - dummyIrrigCost.setIrrigCost(Math.random()); - returnMap.put(i, dummyIrrigCost); - } - - return returnMap; - } - - private Map<Integer, LandUseItem> getPreviousArea() { - LandUseItem dummyMap = getAreaItem(0,0); - Map<Integer, LandUseItem> returnMap = new HashMap<Integer, LandUseItem>(); - - for (int i= 1; i<=NUM_LOCATIONS_PER_COUNTRY; i++) - returnMap.put(i, dummyMap); - - return returnMap; - } - - LandUseItem getAreaItem(double cereal, double pasture) { - LandUseItem dummyMap = new LandUseItem(); - - dummyMap.setCropFraction(CropType.WHEAT, 0.2); - dummyMap.setCropFraction(CropType.MAIZE, 0.2); - dummyMap.setCropFraction(CropType.RICE, 0.1); - dummyMap.setCropFraction(CropType.OILCROPS, 0.1); - dummyMap.setCropFraction(CropType.PULSES, 0.1); - dummyMap.setCropFraction(CropType.STARCHY_ROOTS, 0.1); - - dummyMap.setLandCoverArea(LandCoverType.PASTURE, pasture); - dummyMap.setLandCoverArea(LandCoverType.CROPLAND, cereal); - dummyMap.setLandCoverArea(LandCoverType.MANAGED_FOREST, 200 - pasture - cereal); - dummyMap.setLandCoverArea(LandCoverType.OTHER_NATURAL, 30); - return dummyMap; - } - - Map<CropType, Double> getWorldInputEnergy() { - Map<CropType, Double> dummyMap = new HashMap<CropType, Double>(); - dummyMap.put(CropType.WHEAT, 0.4); - dummyMap.put(CropType.MAIZE, 0.4); - dummyMap.put(CropType.RICE, 1.0); - dummyMap.put(CropType.OILCROPS, 10.0); - dummyMap.put(CropType.PULSES, 20.0); - dummyMap.put(CropType.STARCHY_ROOTS, 5.0); - dummyMap.put(CropType.PASTURE, 80.0); - return dummyMap; - } - - Map<CropType, Double> getBaseNetImport() { - Map<CropType, Double> dummyMap = new HashMap<CropType, Double>(); - dummyMap.put(CropType.WHEAT, 24.0); - dummyMap.put(CropType.MAIZE, 5.0); - dummyMap.put(CropType.OILCROPS, 5.0); - dummyMap.put(CropType.OILCROPS, 10.0); - dummyMap.put(CropType.PULSES, 20.0); - dummyMap.put(CropType.STARCHY_ROOTS, 5.0); - dummyMap.put(CropType.PASTURE, 5.0); - return dummyMap; - } -} diff --git a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java index 7c8999929edbbf75098494ce90aa0bc8c407ae14..a9659cffe79d279bdfddc9f12d2e162c01edfe92 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java @@ -49,7 +49,7 @@ public class GamsRasterOptimiser { private GamsRasterOutput convertToRaster(GamsLocationInput gamsInput, GamsLocationOutput gamsOutput) { RasterSet<LandUseItem> newIntensityRaster = allocAreas(gamsInput.getPreviousLandUse(), gamsOutput); - return new GamsRasterOutput(gamsOutput.getStatus(), newIntensityRaster, gamsOutput.getCommoditiesData(), gamsOutput.getCropAdjustments()); + return new GamsRasterOutput(gamsOutput.getStatus(), newIntensityRaster, gamsOutput.getCommoditiesData()); } private RasterSet<LandUseItem> createWithSameLandCovers(RasterSet<LandUseItem> toCopy) { diff --git a/src/ac/ed/lurg/country/gams/GamsRasterOutput.java b/src/ac/ed/lurg/country/gams/GamsRasterOutput.java index 5034f74893389db1aa5a47823373a30a9da1f440..05ad2abb9f1fc8dd0390058fbddad80cb9540c0d 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterOutput.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterOutput.java @@ -10,11 +10,8 @@ import ac.sac.raster.RasterSet; public class GamsRasterOutput { private int status; - private RasterSet<LandUseItem> landUses; - private Map<CropType, CropUsageData> cropUsageData; - private Map<CropType, Double> cropAdjustments; public GamsRasterOutput(RasterSet<LandUseItem> landUses, Map<CropType, CropUsageData> cropUsageData) { super(); @@ -22,11 +19,9 @@ public class GamsRasterOutput { this.cropUsageData = cropUsageData; } - public GamsRasterOutput(int status, RasterSet<LandUseItem> intensityRaster, Map<CropType, CropUsageData> cropUsageData, - Map<CropType, Double> cropAdjustments) { + public GamsRasterOutput(int status, RasterSet<LandUseItem> intensityRaster, Map<CropType, CropUsageData> cropUsageData) { this(intensityRaster, cropUsageData); this.status = status; - this.cropAdjustments = cropAdjustments; } public int getStatus() { @@ -40,8 +35,4 @@ public class GamsRasterOutput { public Map<CropType, CropUsageData> getCropUsageData() { return cropUsageData; } - - public Map<CropType, Double> getCropAdjustments() { - return cropAdjustments; - } } diff --git a/src/ac/ed/lurg/country/gams/GamsRasterTest.java b/src/ac/ed/lurg/country/gams/GamsRasterTest.java deleted file mode 100644 index 399923029aaf7e25fc699a9d2630c43399ee6e40..0000000000000000000000000000000000000000 --- a/src/ac/ed/lurg/country/gams/GamsRasterTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package ac.ed.lurg.country.gams; - -import ac.ed.lurg.Timestep; -import ac.ed.lurg.country.CompositeCountry; -import ac.ed.lurg.landuse.LandUseItem; -import ac.ed.lurg.landuse.IrrigationItem; -import ac.ed.lurg.utils.LogWriter; -import ac.ed.lurg.yield.YieldRaster; -import ac.ed.lurg.yield.YieldResponsesItem; -import ac.sac.raster.RasterKey; -import ac.sac.raster.RasterSet; - -public class GamsRasterTest extends GamsLocationTest { - - public static void main(String[] args) { - GamsRasterTest aGamsRasterTest = new GamsRasterTest(); - aGamsRasterTest.run(); - } - - private void run() { - GamsCountryInput countryLevelInputs = new GamsCountryInput(new CompositeCountry("Test"), getProjectedDemand(), getCountryPrices(), null); - GamsRasterInput input = new GamsRasterInput(new Timestep(0), getYieldRaster(), getPreviousAreaRaster(), getIrrigationCost(), countryLevelInputs); - - GamsRasterOptimiser opti = new GamsRasterOptimiser(input, null); - GamsRasterOutput output = opti.run(); - LogWriter.println(output.toString()); - } - - private static final int X_RANGE = 3; - private static final int Y_RANGE = 3; - - public YieldRaster getYieldRaster() { - YieldRaster testYieldRaster= new YieldRaster(null); - - for (int i = 0; i<X_RANGE; i++) { - for (int j = 0; j<Y_RANGE; j++) { - RasterKey key = new RasterKey(i,j); - YieldResponsesItem yresp; - if (i==2 && j==2) - yresp = getYieldRespItem(0.5*i + 0.3*j, 0.7); - else - yresp = getYieldRespItem(2.0/(i+1) + 0.3*j, 1.2); - testYieldRaster.put(key, yresp); - } - } - - return testYieldRaster; - } - - public RasterSet<IrrigationItem> getIrrigationCost() { - RasterSet<IrrigationItem> testIrrigationCostRaster= new RasterSet<IrrigationItem>(null); - - for (int i = 0; i<X_RANGE; i++) { - for (int j = 0; j<Y_RANGE; j++) { - RasterKey key = new RasterKey(i,j); - IrrigationItem item = new IrrigationItem(); - item.setIrrigCost(1.0/(1+i)); - testIrrigationCostRaster.put(key, item); - } - } - - return testIrrigationCostRaster; - } - - - public RasterSet<LandUseItem> getPreviousAreaRaster() { - RasterSet<LandUseItem> testAreaRaster= new RasterSet<LandUseItem>(null); - - for (int i = 0; i<X_RANGE; i++) { - for (int j = 0; j<Y_RANGE; j++) { - RasterKey key = new RasterKey(i,j); - LandUseItem areaItem = getAreaItem(i * 20, j * 30); - testAreaRaster.put(key, areaItem); - } - } - - return testAreaRaster; - } -} diff --git a/src/ac/ed/lurg/landuse/CropUsageData.java b/src/ac/ed/lurg/landuse/CropUsageData.java index dd77197bda552688023949b31fd6a7b44def6f0b..279804d121857f78ec105e4bb989ac5d1e18595d 100644 --- a/src/ac/ed/lurg/landuse/CropUsageData.java +++ b/src/ac/ed/lurg/landuse/CropUsageData.java @@ -2,21 +2,27 @@ package ac.ed.lurg.landuse; public class CropUsageData { - private double feedAmount; + private double ruminantFeed; + private double monogastricFeed; private double netImports; private double prod; private double prodCost; - public CropUsageData(double feedAmount, double netImports, double prod, double prodCost) { + public CropUsageData(double ruminantFeed, double monogastricFeed, double netImports, double prod, double prodCost) { super(); - this.feedAmount = feedAmount; + this.ruminantFeed = ruminantFeed; + this.monogastricFeed = monogastricFeed; this.netImports = netImports; this.prod = prod; this.prodCost = prodCost; } - - public double getFeedAmount() { - return feedAmount; + + public double getRuminantFeed() { + return ruminantFeed; + } + + public double getMonogastricFeed() { + return monogastricFeed; } public double getNetImports() { diff --git a/src/ac/ed/lurg/landuse/CropUsageReader.java b/src/ac/ed/lurg/landuse/CropUsageReader.java index efbdb1b8a02acfd5b0ea9d357e56022d4c4e0620..f5ec7b4bee4c68de47d710f8c4cf6ce27a07f824 100644 --- a/src/ac/ed/lurg/landuse/CropUsageReader.java +++ b/src/ac/ed/lurg/landuse/CropUsageReader.java @@ -32,7 +32,7 @@ public class CropUsageReader { LazyHashMap<CompositeCountry, Map<CropType, CropUsageData>> commodityMap = new LazyHashMap<CompositeCountry, Map<CropType, CropUsageData>>() { protected Map<CropType, CropUsageData> createValue() { Map<CropType, CropUsageData> countryData = new HashMap<CropType, CropUsageData>(); - countryData.put(CropType.ENERGY_CROPS, new CropUsageData(Double.NaN, 0.0, Double.NaN, Double.NaN)); // 2nd generation energy crops not in FAO data, so adding zero values. + countryData.put(CropType.ENERGY_CROPS, new CropUsageData(Double.NaN, Double.NaN, 0.0, Double.NaN, Double.NaN)); // 2nd generation energy crops not in FAO data, so adding zero values. return countryData; } }; @@ -67,7 +67,7 @@ public class CropUsageReader { netImports += oldData.getNetImports(); } - CropUsageData newData = new CropUsageData(Double.NaN, netImports, Double.NaN, Double.NaN); + CropUsageData newData = new CropUsageData(Double.NaN, Double.NaN, netImports, Double.NaN, Double.NaN); countryData.put(crop, newData); } fitReader.close(); diff --git a/src/ac/ed/lurg/types/CropType.java b/src/ac/ed/lurg/types/CropType.java index c73fa528a5b6ad9f0b968d7a4c50cc406d575e1e..5fc70bf5c51a47facfcfd68faa536f7b74336781 100644 --- a/src/ac/ed/lurg/types/CropType.java +++ b/src/ac/ed/lurg/types/CropType.java @@ -11,37 +11,33 @@ import ac.ed.lurg.utils.LogWriter; public enum CropType { - WHEAT("WheatBarleyOats", "wheat", ModelConfig.CALIB_FACTOR_WHEAT), - MAIZE("MaizeMilletSorghum", "maize", ModelConfig.CALIB_FACTOR_MAIZE), - RICE("Rice (Paddy Equivalent)", "rice", ModelConfig.CALIB_FACTOR_RICE), -// TROPICAL_CEREALS("TropicalCereals", "tropicalCereals"), - OILCROPS("Oilcrops", "oilcrops", ModelConfig.CALIB_FACTOR_OILCROPS), -// SOYBEAN("Soyabeans", "soybean"), - PULSES("Pulses", "pulses", ModelConfig.CALIB_FACTOR_PULSES), - STARCHY_ROOTS("Starchy Roots", "starchyRoots", ModelConfig.CALIB_FACTOR_STARCHY_ROOTS), - ENERGY_CROPS("Energy crops", "energycrops", Double.NaN), // no calibration factor as difference depending on whether SRC or Miscanthus - MONOGASTRICS("Monogastrics", "monogastrics", true, true), - RUMINANTS("Ruminants", "ruminants", true, true), - PASTURE("pasture", "pasture", false, false); // confusing having a land cover and a crop type. Needed here for yields (but not used for cropland area fractions). + WHEAT("WheatBarleyOats", "wheat", ModelConfig.CALIB_FACTOR_WHEAT, true, false, true), + MAIZE("MaizeMilletSorghum", "maize", ModelConfig.CALIB_FACTOR_MAIZE, true, false, true), + RICE("Rice (Paddy Equivalent)", "rice", ModelConfig.CALIB_FACTOR_RICE, true, false, false), + OILCROPS("Oilcrops", "oilcrops", ModelConfig.CALIB_FACTOR_OILCROPS, true, false, true), + PULSES("Pulses", "pulses", ModelConfig.CALIB_FACTOR_PULSES, true, false, false), + STARCHY_ROOTS("Starchy Roots", "starchyRoots", ModelConfig.CALIB_FACTOR_STARCHY_ROOTS, true, false, false), + ENERGY_CROPS("Energy crops", "energycrops", Double.NaN, true, false, false), // no calibration factor as difference depending on whether SRC or Miscanthus + MONOGASTRICS("Monogastrics", "monogastrics", 1.0, true, true, false), + RUMINANTS("Ruminants", "ruminants", 1.0, true, true, false), + PASTURE("pasture", "pasture", 1.0, false, false, true); // confusing having a land cover and a crop type. Needed here for yields (but not used for cropland area fractions). private String faoName; private String gamsName; private boolean importedCrop; private boolean isMeat; - private double calibrationFactor = 1.0; + private boolean isFeedCrop; + private double calibrationFactor; private static Collection<CropType> importedCrops; - private CropType (String faoName, String gamsName, boolean importedCrop, boolean isMeat) { + private CropType (String faoName, String gamsName, double calibrationFactor, boolean importedCrop, boolean isMeat, boolean isFeedCrop) { this.faoName = faoName; this.gamsName = gamsName; + this.calibrationFactor = calibrationFactor; this.importedCrop = importedCrop; this.isMeat = isMeat; - } - - private CropType (String faoName, String gamsName, double calibrationFactor) { - this(faoName, gamsName, true, false); - this.calibrationFactor = calibrationFactor; + this.isFeedCrop = isFeedCrop; } public static Collection<CropType> getCropsLessPasture() { @@ -136,4 +132,8 @@ public enum CropType { public double getCalibrationFactor() { return calibrationFactor; } + + public boolean isFeedCrop() { + return isFeedCrop; + } }