Skip to content
Snippets Groups Projects
Commit d106c5c5 authored by Peter Alexander's avatar Peter Alexander
Browse files

no message

parent 59737d6c
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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();
......
......@@ -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;
}
}
......@@ -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>();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment