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

Fix issue with ruminants going to zero for profit max constrained by...

Fix issue with ruminants going to zero for profit max constrained by production (rather than net prod)
parent 9757d061
No related branches found
No related tags found
No related merge requests found
...@@ -143,8 +143,8 @@ $gdxin ...@@ -143,8 +143,8 @@ $gdxin
MAX_OTHER_INTENSITY_CONSTRAINT(crop, location) MAX_OTHER_INTENSITY_CONSTRAINT(crop, location)
SETASIDE_AREA_CALC(location) SETASIDE_AREA_CALC(location)
TOTAL_LAND_CHANGE_CONSTRAINT(location) constraint on suitable land use TOTAL_LAND_CHANGE_CONSTRAINT(location) constraint on suitable land use
CROP_MAX_PROD_CONSTRAINT(crop) constraint on max production for crops CROP_MAX_PROD_CONSTRAINT(crop_less_pasture) constraint on max production for crops
CROP_MIN_PROD_CONSTRAINT(crop) constraint on min production for crops CROP_MIN_PROD_CONSTRAINT(crop_less_pasture) constraint on min production for crops
ANIMAL_MAX_PROD_CONSTRAINT(animal_product) constraint on max production for animal product ANIMAL_MAX_PROD_CONSTRAINT(animal_product) constraint on max production for animal product
ANIMAL_MIN_PROD_CONSTRAINT(animal_product) constraint on min production for animal products ANIMAL_MIN_PROD_CONSTRAINT(animal_product) constraint on min production for animal products
IRRIGATION_CONSTRAINT(location) constraint no water usage IRRIGATION_CONSTRAINT(location) constraint no water usage
...@@ -155,6 +155,7 @@ $gdxin ...@@ -155,6 +155,7 @@ $gdxin
PASTURE_DECREASE_CONV_CALC(location) PASTURE_DECREASE_CONV_CALC(location)
PASTURE_TOTAL_CHANGE_CONSTRAINT(location) PASTURE_TOTAL_CHANGE_CONSTRAINT(location)
LAND_RATE_CHANGE_CONSTRAINT_INCREASE LAND_RATE_CHANGE_CONSTRAINT_INCREASE
PASTURE_FEED_CONSTRAINT
PROFIT_EQ total profit objective function; PROFIT_EQ total profit objective function;
UNIT_COST_EQ(crop, location) .. unitCost(crop, location) =E= ( baseCost(crop) + UNIT_COST_EQ(crop, location) .. unitCost(crop, location) =E= ( baseCost(crop) +
...@@ -193,8 +194,9 @@ $gdxin ...@@ -193,8 +194,9 @@ $gdxin
TOTAL_LAND_CHANGE_CONSTRAINT(location) .. suitableLandArea(location) =G= sum(crop_less_pasture, area(crop_less_pasture, location)) / (1.0 - unhandledCropRate) + area('pasture', location); TOTAL_LAND_CHANGE_CONSTRAINT(location) .. suitableLandArea(location) =G= sum(crop_less_pasture, area(crop_less_pasture, location)) / (1.0 - unhandledCropRate) + area('pasture', location);
SETASIDE_AREA_CALC(location) .. area('setaside', location) =E= sum(crop_less_pasture, area(crop_less_pasture, location)) * setAsideRate; SETASIDE_AREA_CALC(location) .. area('setaside', location) =E= sum(crop_less_pasture, area(crop_less_pasture, location)) * setAsideRate;
CROP_MAX_PROD_CONSTRAINT(crop) .. production(crop) =L= maxProduction(crop); CROP_MAX_PROD_CONSTRAINT(crop_less_pasture) .. production(crop_less_pasture) =L= maxProduction(crop_less_pasture);
CROP_MIN_PROD_CONSTRAINT(crop) .. production(crop) =G= minProduction(crop); CROP_MIN_PROD_CONSTRAINT(crop_less_pasture) .. production(crop_less_pasture) =G= minProduction(crop_less_pasture);
PASTURE_FEED_CONSTRAINT .. production('pasture') =E= ruminantFeed('pasture');
ANIMAL_MAX_PROD_CONSTRAINT(animal_product) .. production(animal_product) =L= maxProduction(animal_product); ANIMAL_MAX_PROD_CONSTRAINT(animal_product) .. production(animal_product) =L= maxProduction(animal_product);
ANIMAL_MIN_PROD_CONSTRAINT(animal_product) .. production(animal_product) =G= minProduction(animal_product); ANIMAL_MIN_PROD_CONSTRAINT(animal_product) .. production(animal_product) =G= minProduction(animal_product);
......
...@@ -175,26 +175,24 @@ public class CountryAgent { ...@@ -175,26 +175,24 @@ public class CountryAgent {
totalExcessProd += netImportsFromMinDemand; totalExcessProd += netImportsFromMinDemand;
} }
double additionalNetImportsRequired = demand - totalProd - totalmportFromMD; double additionalNetImportsRequired = demand - totalProd - totalmportFromMD;
LogWriter.println("additionalNetImportsRequired is " + additionalNetImportsRequired);
for (CropType crop : commodity.getCropTypes()) { for (CropType crop : commodity.getCropTypes()) {
double netImportsMD = netImportsFromMinDemands.get(crop); double netImportsMD = netImportsFromMinDemands.get(crop);
double netImports=0; double netImports=0;
if (additionalNetImportsRequired > 0) { // overall importing if (additionalNetImportsRequired > 0) { // overall need to import more
if (minCerealFracts.containsKey(crop)) if (minCerealFracts.containsKey(crop))
netImports = netImportsMD + minCerealFracts.get(crop) * additionalNetImportsRequired; // divide required imports by minCerealFracts netImports = netImportsMD + minCerealFracts.get(crop) * additionalNetImportsRequired; // divide required additional imports by minCerealFracts
} }
else { // overall exporting else { // overall need to export more
if (netImportsMD > 0) if (netImportsMD > 0)
netImports = netImportsMD; // still import what we need for minimum fraction netImports = netImportsMD; // still import what we need for minimum fraction
else{ else if(netImportsMD < 0)
if(netImportsMD != 0)
netImports = netImportsMD / totalExcessProd * additionalNetImportsRequired; // divide exports by production in excess of minimum demand netImports = netImportsMD / totalExcessProd * additionalNetImportsRequired; // divide exports by production in excess of minimum demand
else }
netImports = 0;
}
}
CropUsageData cropUsage = cropUsages.get(crop); CropUsageData cropUsage = cropUsages.get(crop);
LogWriter.println("Updating cereal " + crop + " to " + netImports); LogWriter.println("Updating cereal net imports " + crop + " to " + netImports);
cropUsage.updateNetImports(netImports); cropUsage.updateNetImports(netImports);
} }
} }
...@@ -204,7 +202,7 @@ public class CountryAgent { ...@@ -204,7 +202,7 @@ public class CountryAgent {
CropUsageData cropUsage = cropUsages.get(crop); CropUsageData cropUsage = cropUsages.get(crop);
double prod = cropUsage.getProduction() *(1-crop.getSeedAndWasteRate()) - cropUsage.getMonogastricFeed() - cropUsage.getRuminantFeed(); double prod = cropUsage.getProduction() *(1-crop.getSeedAndWasteRate()) - cropUsage.getMonogastricFeed() - cropUsage.getRuminantFeed();
double netImports = demand - prod; double netImports = demand - prod;
LogWriter.println("Updating net imports single commodity/crop" + commodity + "/" + crop + " to " + netImports); LogWriter.println("Updating net imports " + crop + " to " + netImports);
cropUsage.updateNetImports(netImports); cropUsage.updateNetImports(netImports);
} }
} }
......
...@@ -440,7 +440,7 @@ public class GamsLocationOptimiser { ...@@ -440,7 +440,7 @@ public class GamsLocationOptimiser {
prodCost = getParmValue(parmProdCost, meatTypes.getGamsName()); prodCost = getParmValue(parmProdCost, meatTypes.getGamsName());
cropUsageData.put(meatTypes, new CropUsageData(0.0, 0.0, netImport, netImportCost, prod, prodCost, Double.NaN)); cropUsageData.put(meatTypes, new CropUsageData(0.0, 0.0, netImport, netImportCost, prod, prodCost, Double.NaN));
if (DEBUG) LogWriter.println(String.format("\n%s:\t\t\t\t\tnetImports= %.3f,tnetImportCost= %.3f,\tprod= %.3f,\tprodCost= %.3f", meatTypes.getGamsName(), netImport, netImportCost, prod, prodCost)); if (DEBUG) LogWriter.println(String.format("\n%s:\t\t\t\t\tnetImports= %.3f,\tnetImportCost= %.3f,\tprod= %.3f,\tprodCost= %.3f", meatTypes.getGamsName(), netImport, netImportCost, prod, prodCost));
} }
LogWriter.println(String.format("\n%s %s: Total area= %.1f (crop=%.1f, pasture %.1f)", LogWriter.println(String.format("\n%s %s: Total area= %.1f (crop=%.1f, pasture %.1f)",
inputData.getCountryInput().getCountry(), inputData.getTimestep().getYear(), inputData.getCountryInput().getCountry(), inputData.getTimestep().getYear(),
......
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