diff --git a/src/ac/ed/lurg/country/CountryAgent.java b/src/ac/ed/lurg/country/CountryAgent.java index c0a79f62ab3e14144ce05bb0a5a9e4d075282a50..8d05fd3308b7e24d200924b0cbed909c557e100f 100644 --- a/src/ac/ed/lurg/country/CountryAgent.java +++ b/src/ac/ed/lurg/country/CountryAgent.java @@ -9,6 +9,7 @@ import ac.ed.lurg.country.gams.GamsCountryInput; import ac.ed.lurg.country.gams.GamsInput; import ac.ed.lurg.country.gams.GamsLandUseOptimiser; import ac.ed.lurg.country.gams.GamsOutput; +import ac.ed.lurg.landuse.CropAreas; import ac.ed.lurg.types.CropType; import ac.ed.lurg.utils.LogWriter; import ac.ed.lurg.yield.YieldResponses; @@ -81,15 +82,15 @@ public class CountryAgent { return null; // this should be from LPJ data } - public Map<Integer, Map<CropType, Double>> getPreviousCropArea() { - Map<CropType, Double> previousCropAreas = new HashMap<CropType, Double>(); + public Map<Integer, CropAreas> getPreviousCropArea() { + CropAreas previousCropAreas = new CropAreas(); int previousTimestep = currentTimestep==0 ? 0 : currentTimestep-1; CropAreas cd = cropAreasTimeseries.get(previousTimestep); for (CropType crop : CropType.getAllItems()) - previousCropAreas.put(crop, cd.getCropArea(crop)); + previousCropAreas.setCropArea(crop, cd.getCropArea(crop)); - Map<Integer, Map<CropType, Double>> returnMap = new HashMap<Integer, Map<CropType, Double>>(); + Map<Integer, CropAreas> returnMap = new HashMap<Integer, CropAreas>(); for (int i= 1; i<=ModelConfig.NUM_LOCATIONS_PER_COUNTRY; i++) returnMap.put(i, previousCropAreas); diff --git a/src/ac/ed/lurg/country/CountryAgentCreator.java b/src/ac/ed/lurg/country/CountryAgentCreator.java index fd1fa684d0780ef2958935783289033e9676d03b..3200c2e110f0a3dc6001235fef907dee836db20c 100644 --- a/src/ac/ed/lurg/country/CountryAgentCreator.java +++ b/src/ac/ed/lurg/country/CountryAgentCreator.java @@ -7,6 +7,7 @@ import java.util.HashSet; import ac.ed.lurg.ModelConfig; import ac.ed.lurg.ModelContext; +import ac.ed.lurg.landuse.CropAreas; import ac.ed.lurg.types.CropType; import ac.ed.lurg.types.LandCoverType; import ac.ed.lurg.utils.LogWriter; @@ -62,8 +63,8 @@ public class CountryAgentCreator { initialLandCover.setLandCoverArea(LandCoverType.PASTURE, pastureArea); CropAreas initialCropData = new CropAreas(); - initialCropData.addCropArea(CropType.CEREALS, arableArea, Double.NaN); // at the moment can substitute freely between arable crops so this is ok-ish - initialCropData.addCropArea(CropType.MEAT_OR_PASTURE, pastureArea, Double.NaN); + initialCropData.setCropArea(CropType.CEREALS, arableArea); // at the moment can substitute freely between arable crops so this is ok-ish + initialCropData.setCropArea(CropType.MEAT_OR_PASTURE, pastureArea); CountryAgent ca = new CountryAgent(modelContext, Country.get(countryName), initialCropData, initialLandCover); diff --git a/src/ac/ed/lurg/country/CropAreas.java b/src/ac/ed/lurg/country/CropAreas.java deleted file mode 100644 index 1d6c996c813a0391d7f302d908858180bb6f7c3a..0000000000000000000000000000000000000000 --- a/src/ac/ed/lurg/country/CropAreas.java +++ /dev/null @@ -1,33 +0,0 @@ -package ac.ed.lurg.country; - -import java.util.HashMap; -import java.util.Map; - -import ac.ed.lurg.landuse.LandUseDataPoint; -import ac.ed.lurg.types.CropType; - -/* - * Data for one year and country, but it does not know which one - */ -public class CropAreas { - - private Map<CropType, LandUseDataPoint> cropAreas = new HashMap<CropType, LandUseDataPoint>(); - - public double getCropArea(CropType c) { - LandUseDataPoint lu = cropAreas.get(c); - - if (lu != null) - return lu.getArea(); - else - return 0; - } - - public void addCropArea(CropType c, double area, double intensity) { - LandUseDataPoint lu = new LandUseDataPoint(area, 0, 0, intensity); - cropAreas.put(c, lu); - } - - public int size() { - return cropAreas.size(); - } -} diff --git a/src/ac/ed/lurg/country/gams/GamsInput.java b/src/ac/ed/lurg/country/gams/GamsInput.java index 787b991032b1c82a1226a2ed354e5a7b1de41bba..f60adfdef28ea8ab86ac3f7f8d5c1b90c5be6d95 100644 --- a/src/ac/ed/lurg/country/gams/GamsInput.java +++ b/src/ac/ed/lurg/country/gams/GamsInput.java @@ -2,16 +2,16 @@ package ac.ed.lurg.country.gams; import java.util.Map; -import ac.ed.lurg.types.CropType; +import ac.ed.lurg.landuse.CropAreas; import ac.ed.lurg.yield.YieldResponses; public class GamsInput { private Map<Integer, ? extends YieldResponses> yields; - private Map<Integer, Map<CropType, Double>> previousCropArea; + private Map<Integer, ? extends CropAreas> previousCropArea; private GamsCountryInput countryInput; - public GamsInput(Map<Integer, ? extends YieldResponses> yields, Map<Integer, Map<CropType, Double>> previousCropArea, GamsCountryInput countryInput) { + public GamsInput(Map<Integer, ? extends YieldResponses> yields, Map<Integer, ? extends CropAreas> previousCropArea, GamsCountryInput countryInput) { super(); this.yields = yields; this.previousCropArea = previousCropArea; @@ -21,7 +21,7 @@ public class GamsInput { public Map<Integer, ? extends YieldResponses> getYields() { return yields; } - public Map<Integer, Map<CropType, Double>> getPreviousCropArea() { + public Map<Integer, ? extends CropAreas> getPreviousCropArea() { return previousCropArea; } diff --git a/src/ac/ed/lurg/country/gams/GamsLandUseOptimiser.java b/src/ac/ed/lurg/country/gams/GamsLandUseOptimiser.java index ad0ff148459c719dae9abd32f7a982c2c4460366..c30f97434e576a97697c940b960e896561be1e08 100644 --- a/src/ac/ed/lurg/country/gams/GamsLandUseOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsLandUseOptimiser.java @@ -7,8 +7,9 @@ import java.util.Map.Entry; import java.util.Vector; import ac.ed.lurg.ModelConfig; -import ac.ed.lurg.landuse.LandUseDataPoint; -import ac.ed.lurg.landuse.LandUse; +import ac.ed.lurg.landuse.CropAreas; +import ac.ed.lurg.landuse.Intensities; +import ac.ed.lurg.landuse.Intensity; import ac.ed.lurg.types.CropType; import ac.ed.lurg.utils.LogWriter; import ac.ed.lurg.yield.YieldResponses; @@ -128,7 +129,8 @@ public class GamsLandUseOptimiser { double totalArea = 0; double area, fertIntensity, irrigIntensity, otherIntensity, feedAmount, netImport; - Map<Integer, LandUse> landuses = new HashMap<Integer, LandUse>(); + Map<Integer, Intensities> intensities = new HashMap<Integer, Intensities>(); + Map<Integer, CropAreas> cropAreas = new HashMap<Integer, CropAreas>(); Map<CropType, Double> feedAmounts = new HashMap<CropType, Double>(); Map<CropType, Double> netImports = new HashMap<CropType, Double>(); @@ -154,14 +156,20 @@ public class GamsLandUseOptimiser { LogWriter.println(String.format("\t location %s:\tarea= %.1f,\tfert= %.3f,\tirrg= %.3f,\tintensity= %.3f", locationName, area, fertIntensity, irrigIntensity, otherIntensity)); - LandUse luItem = landuses.get(locId); - if (luItem == null) { - luItem = new LandUse(); - landuses.put(locId, luItem); + Intensities intensityItem = intensities.get(locId); + if (intensityItem == null) { + intensityItem = new Intensities(); + intensities.put(locId, intensityItem); } + intensityItem.setIntensity(cropType, new Intensity(fertIntensity, irrigIntensity, otherIntensity)); - LandUseDataPoint landUse = new LandUseDataPoint(area, fertIntensity, irrigIntensity, otherIntensity); - luItem.setLandUses(cropType, landUse); + CropAreas areaItem = cropAreas.get(locId); + if (areaItem == null) { + areaItem = new CropAreas(); + cropAreas.put(locId, areaItem); + } + areaItem.setCropArea(cropType, area); + totalArea += area; } @@ -169,7 +177,7 @@ public class GamsLandUseOptimiser { LogWriter.println(String.format("\nTotal area= %.1f", totalArea)); //cleanup(ws.workingDirectory()); - GamsOutput results = new GamsOutput(modelStatus, landuses, feedAmounts, netImports); + GamsOutput results = new GamsOutput(modelStatus, intensities, cropAreas, feedAmounts, netImports); return results ; } @@ -184,17 +192,18 @@ public class GamsLandUseOptimiser { } } - private void addLocationMapParm(GAMSParameter parm, Map<Integer, Map<CropType, Double>> locationItemMap) { - for (Map.Entry<Integer, Map<CropType, Double>> cropsForALocation : locationItemMap.entrySet()) { + private void addLocationMapParm(GAMSParameter parm, Map<Integer, ? extends CropAreas> locationItemMap) { + for (Map.Entry<Integer, ? extends CropAreas> cropsForALocation : locationItemMap.entrySet()) { Integer locationId = cropsForALocation.getKey(); - Map<CropType, Double> itemMap = cropsForALocation.getValue(); + CropAreas itemMap = cropsForALocation.getValue(); - for (Map.Entry<CropType, Double> entry : itemMap.entrySet()) { - LogWriter.println(String.format(" %15s,\t %.1f", entry.getKey().getGamsName(), entry.getValue())); + for (CropType cropType : CropType.values()) { + double d = itemMap.getCropArea(cropType); + LogWriter.println(String.format(" %15s,\t %.1f", cropType.getGamsName(), d)); Vector<String> v = new Vector<String>(); - v.add(entry.getKey().getGamsName()); + v.add(cropType.getGamsName()); v.add(Integer.toString(locationId)); - parm.addRecord(v).setValue(entry.getValue()); + parm.addRecord(v).setValue(d); } } } diff --git a/src/ac/ed/lurg/country/gams/GamsOutput.java b/src/ac/ed/lurg/country/gams/GamsOutput.java index ed1fe9406a3f0bd1d61def5d912ab5339cb0ccbc..b5956d83307602113b20fb4671f61da34f7762f5 100644 --- a/src/ac/ed/lurg/country/gams/GamsOutput.java +++ b/src/ac/ed/lurg/country/gams/GamsOutput.java @@ -2,21 +2,27 @@ package ac.ed.lurg.country.gams; import java.util.Map; -import ac.ed.lurg.landuse.LandUse; +import ac.ed.lurg.landuse.CropAreas; +import ac.ed.lurg.landuse.Intensities; import ac.ed.lurg.types.CropType; public class GamsOutput { int status; - Map<Integer, LandUse> landuses; // data mapped from id (not raster) - + Map<Integer, Intensities> intensities; // data mapped from id (not raster) + Map<Integer, CropAreas> cropAreas; Map<CropType, Double> feedAmounts; Map<CropType, Double> netImports; - public GamsOutput(int status, Map<Integer, LandUse> landuses, Map<CropType, Double> feedAmounts, Map<CropType, Double> netImports) { + public GamsOutput(int status, + Map<Integer, Intensities> intensities, + Map<Integer, CropAreas> cropAreas, + Map<CropType, Double> feedAmounts, + Map<CropType, Double> netImports) { super(); this.status = status; - this.landuses = landuses; + this.intensities = intensities; + this.cropAreas = cropAreas; this.feedAmounts = feedAmounts; this.netImports = netImports; } @@ -24,8 +30,11 @@ public class GamsOutput { public int getStatus() { return status; } - public Map<Integer, LandUse> getLanduses() { - return landuses; + public Map<Integer, Intensities> getIntensities() { + return intensities; + } + public Map<Integer, CropAreas> getCropAreas() { + return cropAreas; } public Map<CropType, Double> getFeedAmounts() { return feedAmounts; diff --git a/src/ac/ed/lurg/country/gams/GamsRasterInput.java b/src/ac/ed/lurg/country/gams/GamsRasterInput.java index a2a7fdc3dd2ca657d31ae6a1a5ad423b29b56847..2e0d3891afc17903b91fe007111900574f4811c6 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterInput.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterInput.java @@ -1,20 +1,21 @@ package ac.ed.lurg.country.gams; -import ac.ed.lurg.landuse.LandUse; +import ac.ed.lurg.landuse.CropAreas; +import ac.ed.lurg.landuse.Intensities; import ac.ed.lurg.yield.YieldRaster; import ac.sac.raster.RasterSet; public class GamsRasterInput { private YieldRaster yields; - private RasterSet<LandUse> previousLandUse; + private RasterSet<CropAreas> previousCropAreas; private GamsCountryInput countryInput; public GamsRasterInput(YieldRaster yields, - RasterSet<LandUse> previousLandUse, GamsCountryInput countryInput) { + RasterSet<CropAreas> previousCropAreas, GamsCountryInput countryInput) { super(); this.yields = yields; - this.previousLandUse = previousLandUse; + this.previousCropAreas = previousCropAreas; this.countryInput = countryInput; } @@ -22,8 +23,8 @@ public class GamsRasterInput { return yields; } - public RasterSet<LandUse> getPreviousLandUse() { - return previousLandUse; + public RasterSet<CropAreas> getPreviousCropAreas() { + return previousCropAreas; } public GamsCountryInput getCountryInput() { diff --git a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java index 39bea1589949454847b00c220fe1863a19862490..7d8d42214df15c9a9bf7d52afbd6c4490bad37de 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterOptimiser.java @@ -3,10 +3,14 @@ package ac.ed.lurg.country.gams; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Set; +import ac.ed.lurg.landuse.CropAreas; +import ac.ed.lurg.landuse.Intensities; import ac.ed.lurg.types.CropType; import ac.ed.lurg.types.YieldType; import ac.ed.lurg.utils.LogWriter; @@ -14,10 +18,12 @@ import ac.ed.lurg.yield.AveragingYieldResponses; import ac.ed.lurg.yield.YieldRaster; import ac.ed.lurg.yield.YieldResponses; import ac.sac.raster.RasterKey; +import ac.sac.raster.RasterSet; public class GamsRasterOptimiser { private GamsRasterInput rasterInputData; + private Map<Integer, Set<RasterKey>> mapping; public GamsRasterOptimiser(GamsRasterInput rasterInputData) { this.rasterInputData = rasterInputData; @@ -25,55 +31,97 @@ public class GamsRasterOptimiser { public GamsRasterOutput run() { // workout similar areas - Map<Integer, AveragingYieldResponses> mapping = findSimilarAreas(rasterInputData.getYields()); - Map<Integer, Map<CropType, Double>> dummy = null; - - // create GamsInput using mapping - GamsInput gamsInput = new GamsInput(mapping, dummy, rasterInputData.getCountryInput()); + GamsInput gamsInput = convertFromRaster(rasterInputData); // run optimizer GamsLandUseOptimiser opti = new GamsLandUseOptimiser(gamsInput); GamsOutput gamsOutput = opti.run(); // map results back to raster + return convertToRaster(gamsInput, gamsOutput); + } + + private GamsRasterOutput convertToRaster(GamsInput gamsInput, GamsOutput gamsOutput) { + // intensities - constant over single category? + RasterSet<Intensities> intensityRaster = new RasterSet<Intensities>(); + + for (Map.Entry<Integer, Intensities> entry : gamsOutput.getIntensities().entrySet()) { + for (RasterKey key : mapping.get(entry.getKey())) { + intensityRaster.put(key, entry.getValue()); + } + } + RasterSet<CropAreas> areaRaster = new RasterSet<CropAreas>(); + + // crop areas - need some allocation process + return null; } + - - private Map<Integer, AveragingYieldResponses> findSimilarAreas(YieldRaster yieldRaster) { + private GamsInput convertFromRaster(GamsRasterInput rasterInputData) { // as a first attempt only going to look at pasture and cereal yields, assuming other yields will be correlated to one or the other. + YieldRaster yieldRaster = rasterInputData.getYields(); + RasterSet<CropAreas> cropAreaRaster = rasterInputData.getPreviousCropAreas(); + List<Double> cerealDivisions = getDivisions(yieldRaster, CropType.CEREALS, 2); List<Double> pastureDivisions = getDivisions(yieldRaster, CropType.MEAT_OR_PASTURE, 2); int numCerealCats = (1+cerealDivisions.size()); - LogWriter.println("Found " + numCerealCats * (1+pastureDivisions.size()) + " categories"); - - Map<Integer, AveragingYieldResponses> aggregatedData = new HashMap<Integer, AveragingYieldResponses>(); + LogWriter.println("Making " + numCerealCats * (1+pastureDivisions.size()) + " categories"); + Map<Integer, AveragingYieldResponses> aggregatedYield = new HashMap<Integer, AveragingYieldResponses>(); + Map<Integer, CropAreas> aggregatedAreas = new HashMap<Integer, CropAreas>(); + mapping = new HashMap<Integer, Set<RasterKey>>(); + for (Entry<RasterKey, YieldResponses> entry : yieldRaster.entrySet()) { YieldResponses yresp = entry.getValue(); + CropAreas cropAreas = cropAreaRaster.get(entry.getKey()); int cerealCat = findCategory(cerealDivisions, yresp.getYieldMax(CropType.CEREALS)); int pastureCat = findCategory(pastureDivisions, yresp.getYieldMax(CropType.MEAT_OR_PASTURE)); int id = cerealCat + pastureCat * numCerealCats; - AveragingYieldResponses avgYResp = aggregatedData.get(id); - if (avgYResp == null) { - avgYResp = new AveragingYieldResponses(); - aggregatedData.put(id, avgYResp); - } - - avgYResp.addMapping(entry.getKey()); + AveragingYieldResponses avgYResp = getAverageYieldsForLocation(aggregatedYield, id); + CropAreas aggAreas = getAggregatedAreaForLocation(aggregatedAreas, id); + getMappingForLocation(mapping, id).add(entry.getKey()); for (CropType crop : CropType.values()) { for (YieldType yieldType : YieldType.values()) { avgYResp.setYield(yieldType, crop, yresp.getYield(yieldType, crop)); } + aggAreas.setCropArea(crop, aggAreas.getCropArea(crop) + cropAreas.getCropArea(crop)); } } - - return aggregatedData; + + return new GamsInput(aggregatedYield, aggregatedAreas, rasterInputData.getCountryInput()); + } + + private Set<RasterKey> getMappingForLocation(Map<Integer, Set<RasterKey>> mapping, int id) { + Set<RasterKey> keys = mapping.get(id); + if (keys == null) { + keys = new HashSet<RasterKey>(); + mapping.put(id, keys); + } + return keys; + } + + private CropAreas getAggregatedAreaForLocation(Map<Integer, CropAreas> aggregatedAreas, int id) { + CropAreas aggAreas = aggregatedAreas.get(id); + if (aggAreas == null) { + aggAreas = new CropAreas(); + aggregatedAreas.put(id, aggAreas); + } + return aggAreas; + } + + private AveragingYieldResponses getAverageYieldsForLocation(Map<Integer, AveragingYieldResponses> aggregatedYield, int id) { + AveragingYieldResponses avgYResp = aggregatedYield.get(id); + if (avgYResp == null) { + avgYResp = new AveragingYieldResponses(); + aggregatedYield.put(id, avgYResp); + } + return avgYResp; } private int findCategory(List<Double> divisions, double yield) { diff --git a/src/ac/ed/lurg/country/gams/GamsRasterOutput.java b/src/ac/ed/lurg/country/gams/GamsRasterOutput.java index d29d37d69c5cbf510f5da702fd5682a264e5f91a..d5f7c61cd2a5323f51be9db80d3a042d883ca8de 100644 --- a/src/ac/ed/lurg/country/gams/GamsRasterOutput.java +++ b/src/ac/ed/lurg/country/gams/GamsRasterOutput.java @@ -2,22 +2,25 @@ package ac.ed.lurg.country.gams; import java.util.Map; -import ac.ed.lurg.landuse.LandUse; +import ac.ed.lurg.landuse.CropAreas; +import ac.ed.lurg.landuse.Intensities; import ac.ed.lurg.types.CropType; import ac.sac.raster.RasterSet; public class GamsRasterOutput { int status; - RasterSet<LandUse> landuses; - + RasterSet<Intensities> intensityRaster; + RasterSet<CropAreas> cropAreaRaster; Map<CropType, Double> feedAmounts; Map<CropType, Double> netImports; - public GamsRasterOutput(int status, RasterSet<LandUse> landuses, Map<CropType, Double> feedAmounts, Map<CropType, Double> netImports) { + public GamsRasterOutput(int status, RasterSet<Intensities> intensityRaster, RasterSet<CropAreas> cropAreaRaster, + Map<CropType, Double> feedAmounts, Map<CropType, Double> netImports) { super(); this.status = status; - this.landuses = landuses; + this.intensityRaster = intensityRaster; + this.cropAreaRaster = cropAreaRaster; this.feedAmounts = feedAmounts; this.netImports = netImports; } @@ -25,8 +28,11 @@ public class GamsRasterOutput { public int getStatus() { return status; } - public RasterSet<LandUse> getLanduses() { - return landuses; + public RasterSet<Intensities> getIntensityRaster() { + return intensityRaster; + } + public RasterSet<CropAreas> getCropAreaRaster() { + return cropAreaRaster; } public Map<CropType, Double> getFeedAmounts() { return feedAmounts; diff --git a/src/ac/ed/lurg/country/gams/GamsTest.java b/src/ac/ed/lurg/country/gams/GamsTest.java index c72ca4b3c95f437cb19cb54b50489a8ca512b243..f6b5a4f6ba6e1d19f1e7ab00be9e8d4641ff3404 100644 --- a/src/ac/ed/lurg/country/gams/GamsTest.java +++ b/src/ac/ed/lurg/country/gams/GamsTest.java @@ -4,6 +4,7 @@ import java.util.HashMap; import java.util.Map; import ac.ed.lurg.ModelConfig; +import ac.ed.lurg.landuse.CropAreas; import ac.ed.lurg.types.CropType; import ac.ed.lurg.types.YieldType; import ac.ed.lurg.yield.YieldResponses; @@ -58,18 +59,18 @@ public class GamsTest { return returnMap; } - public Map<Integer, Map<CropType, Double>> getPreviousCropArea() { - Map<CropType, Double> dummyMap = new HashMap<CropType, Double>(); - dummyMap.put(CropType.CEREALS, 9.0); - dummyMap.put(CropType.FRUIT, 5.0); - dummyMap.put(CropType.OILCROPS, 10.0); - dummyMap.put(CropType.STARCHY_ROOTS, 5.0); - dummyMap.put(CropType.PULSES, 20.0); - dummyMap.put(CropType.VEGETABLES, 20.0); - dummyMap.put(CropType.MEAT_OR_PASTURE, 80.0); - dummyMap.put(CropType.TREENUTS, 5.0); + public Map<Integer, CropAreas> getPreviousCropArea() { + CropAreas dummyMap = new CropAreas(); + dummyMap.setCropArea(CropType.CEREALS, 9.0); + dummyMap.setCropArea(CropType.FRUIT, 5.0); + dummyMap.setCropArea(CropType.OILCROPS, 10.0); + dummyMap.setCropArea(CropType.STARCHY_ROOTS, 5.0); + dummyMap.setCropArea(CropType.PULSES, 20.0); + dummyMap.setCropArea(CropType.VEGETABLES, 20.0); + dummyMap.setCropArea(CropType.MEAT_OR_PASTURE, 80.0); + dummyMap.setCropArea(CropType.TREENUTS, 5.0); - Map<Integer, Map<CropType, Double>> returnMap = new HashMap<Integer, Map<CropType, Double>>(); + Map<Integer, CropAreas> returnMap = new HashMap<Integer, CropAreas>(); for (int i= 1; i<=ModelConfig.NUM_LOCATIONS_PER_COUNTRY; i++) returnMap.put(i, dummyMap); diff --git a/src/ac/ed/lurg/landuse/CropAreas.java b/src/ac/ed/lurg/landuse/CropAreas.java new file mode 100644 index 0000000000000000000000000000000000000000..ea90b32791373e332bdb03f4034cb4f835877e08 --- /dev/null +++ b/src/ac/ed/lurg/landuse/CropAreas.java @@ -0,0 +1,32 @@ +package ac.ed.lurg.landuse; + +import java.util.HashMap; +import java.util.Map; + +import ac.ed.lurg.types.CropType; +import ac.sac.raster.RasterItem; + +/* + * Data for one year and country, but it does not know which one + */ +public class CropAreas implements RasterItem { + + private Map<CropType, Double> cropAreas = new HashMap<CropType, Double>(); + + public double getCropArea(CropType c) { + Double lu = cropAreas.get(c); + + if (lu != null) + return lu; + else + return 0; + } + + public void setCropArea(CropType c, double area) { + cropAreas.put(c, area); + } + + public int size() { + return cropAreas.size(); + } +} diff --git a/src/ac/ed/lurg/landuse/Intensities.java b/src/ac/ed/lurg/landuse/Intensities.java new file mode 100644 index 0000000000000000000000000000000000000000..218c6e10212c75c5943fcc1be7fad0b1adc36088 --- /dev/null +++ b/src/ac/ed/lurg/landuse/Intensities.java @@ -0,0 +1,20 @@ +package ac.ed.lurg.landuse; + +import java.util.HashMap; +import java.util.Map; + +import ac.ed.lurg.types.CropType; +import ac.sac.raster.RasterItem; + +public class Intensities implements RasterItem { + + Map<CropType, Intensity> intensityMap = new HashMap<CropType, Intensity>(); + + public Intensity getLandUses(CropType crop) { + return intensityMap.get(crop); + } + + public void setIntensity(CropType crop, Intensity intensityData) { + intensityMap.put(crop, intensityData); + } +} diff --git a/src/ac/ed/lurg/landuse/Intensity.java b/src/ac/ed/lurg/landuse/Intensity.java new file mode 100644 index 0000000000000000000000000000000000000000..daa20a8a75fcbed765d11fde3e4eedf8372a95b3 --- /dev/null +++ b/src/ac/ed/lurg/landuse/Intensity.java @@ -0,0 +1,26 @@ +package ac.ed.lurg.landuse; + +public class Intensity { + double fertiliserIntensity; + double irrigationIntensity; + double otherIntensity; + + public Intensity(double fertiliserIntensity, double irrigationIntensity, double otherIntensity) { + super(); + this.fertiliserIntensity = fertiliserIntensity; + this.irrigationIntensity = irrigationIntensity; + this.otherIntensity = otherIntensity; + } + + public double getFertiliserIntensity() { + return fertiliserIntensity; + } + + public double getIrrigationIntensity() { + return irrigationIntensity; + } + + public double getOtherIntensity() { + return otherIntensity; + } +} diff --git a/src/ac/ed/lurg/landuse/LandUse.java b/src/ac/ed/lurg/landuse/LandUse.java deleted file mode 100644 index 792b20bd76381562d30471c98adc647300ae6330..0000000000000000000000000000000000000000 --- a/src/ac/ed/lurg/landuse/LandUse.java +++ /dev/null @@ -1,50 +0,0 @@ -package ac.ed.lurg.landuse; - -import java.util.HashMap; -import java.util.Map; - -import ac.ed.lurg.types.CropType; -import ac.sac.raster.RasterItem; - -public class LandUse implements RasterItem { - - Map<CropType, LandUseDataPoint> landUses = new HashMap<CropType, LandUseDataPoint>(); - - public LandUseDataPoint getLandUses(CropType crop) { - return landUses.get(crop); - } - - public void setLandUses(CropType crop, LandUseDataPoint landUse) { - landUses.put(crop, landUse); - } - - public void setLandUses(Map<CropType, LandUseDataPoint> landUses) { - this.landUses = landUses; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result - + ((landUses == null) ? 0 : landUses.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - LandUse other = (LandUse) obj; - if (landUses == null) { - if (other.landUses != null) - return false; - } else if (!landUses.equals(other.landUses)) - return false; - return true; - } -} diff --git a/src/ac/ed/lurg/landuse/LandUseDataPoint.java b/src/ac/ed/lurg/landuse/LandUseDataPoint.java deleted file mode 100644 index 8e093bd5387cc6e627512c666fb320fa677368a0..0000000000000000000000000000000000000000 --- a/src/ac/ed/lurg/landuse/LandUseDataPoint.java +++ /dev/null @@ -1,72 +0,0 @@ -package ac.ed.lurg.landuse; - -public class LandUseDataPoint { - double area; - double fertiliserIntensity; - double irrigationIntensity; - double otherIntensity; - - public LandUseDataPoint(double area, double fertiliserIntensity, double irrigationIntensity, double otherIntensity) { - super(); - this.area = area; - this.fertiliserIntensity = fertiliserIntensity; - this.irrigationIntensity = irrigationIntensity; - this.otherIntensity = otherIntensity; - } - - public double getArea() { - return area; - } - - public double getFertiliserIntensity() { - return fertiliserIntensity; - } - - public double getIrrigationIntensity() { - return irrigationIntensity; - } - - public double getOtherIntensity() { - return otherIntensity; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - long temp; - temp = Double.doubleToLongBits(area); - result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(fertiliserIntensity); - result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(irrigationIntensity); - result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(otherIntensity); - result = prime * result + (int) (temp ^ (temp >>> 32)); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - LandUseDataPoint other = (LandUseDataPoint) obj; - if (Double.doubleToLongBits(area) != Double - .doubleToLongBits(other.area)) - return false; - if (Double.doubleToLongBits(fertiliserIntensity) != Double - .doubleToLongBits(other.fertiliserIntensity)) - return false; - if (Double.doubleToLongBits(irrigationIntensity) != Double - .doubleToLongBits(other.irrigationIntensity)) - return false; - if (Double.doubleToLongBits(otherIntensity) != Double - .doubleToLongBits(other.otherIntensity)) - return false; - return true; - } -} diff --git a/src/ac/ed/lurg/landuse/LandUseSet.java b/src/ac/ed/lurg/landuse/LandUseSet.java deleted file mode 100644 index 7e7fa475a9a9d8dc216633496c5d9239f2388783..0000000000000000000000000000000000000000 --- a/src/ac/ed/lurg/landuse/LandUseSet.java +++ /dev/null @@ -1,12 +0,0 @@ -package ac.ed.lurg.landuse; - -import ac.sac.raster.RasterSet; - -public class LandUseSet extends RasterSet<LandUse> { - - private static final long serialVersionUID = -2682317143041974233L; - - protected LandUse createRasterData() { - return new LandUse(); - } -} diff --git a/src/ac/ed/lurg/yield/AveragingYieldResponses.java b/src/ac/ed/lurg/yield/AveragingYieldResponses.java index 9d34d694db8c3ca1191aa7ec6679fe924533e1c0..0a5f857f15aad3bb27317b8c8fc2b6cad0c206ec 100644 --- a/src/ac/ed/lurg/yield/AveragingYieldResponses.java +++ b/src/ac/ed/lurg/yield/AveragingYieldResponses.java @@ -1,14 +1,8 @@ package ac.ed.lurg.yield; -import java.util.Collection; -import java.util.HashSet; - import ac.ed.lurg.types.CropType; -import ac.sac.raster.RasterKey; public class AveragingYieldResponses extends YieldResponses { - - private Collection<RasterKey> rasterKeys = new HashSet<RasterKey>(); @Override YieldResponse getYieldResponseForCrop(CropType crop) { @@ -19,12 +13,4 @@ public class AveragingYieldResponses extends YieldResponses { } return yresp; } - - public void addMapping(RasterKey key) { - rasterKeys.add(key); - } - - public Collection<RasterKey> getRasterKeys() { - return rasterKeys; - } }