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

Refactoring to simplify setting of import/export prices

parent 44489609
No related branches found
No related tags found
No related merge requests found
...@@ -19,8 +19,8 @@ ...@@ -19,8 +19,8 @@
PARAMETER fertParam(crop, location) yield response to fertilizer parameter; PARAMETER fertParam(crop, location) yield response to fertilizer parameter;
PARAMETER irrigParam(crop, location) yield response to irrigation parameter; PARAMETER irrigParam(crop, location) yield response to irrigation parameter;
PARAMETER demand(all_types) in t; PARAMETER demand(all_types) in t;
PARAMETER worldExportPrices(import_crop) prices for exports; PARAMETER exportPrices(import_crop) prices for exports;
PARAMETER countryImportPrices(import_crop) prices for imports; PARAMETER importPrices(import_crop) prices for imports;
PARAMETER maxNetImport(import_crop) maximum net import for each crop based on world market; PARAMETER maxNetImport(import_crop) maximum net import for each crop based on world market;
PARAMETER minNetImport(import_crop) minimum net import for each crop based on world market; PARAMETER minNetImport(import_crop) minimum net import for each crop based on world market;
PARAMETER irrigCost(location) irrigation cost in cost per 1000 Mlitre or Mha for each litre per m2; PARAMETER irrigCost(location) irrigation cost in cost per 1000 Mlitre or Mha for each litre per m2;
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
$gdxin %gdxincname% $gdxin %gdxincname%
$load location, suitableLandArea, previousArea, demand, landChangeCost $load location, suitableLandArea, previousArea, demand, landChangeCost
$load yieldNone, yieldFertOnly, yieldIrrigOnly, yieldBoth $load yieldNone, yieldFertOnly, yieldIrrigOnly, yieldBoth
$load fertParam, irrigParam, otherIParam, worldExportPrices, countryImportPrices, maxNetImport, minNetImport, unhandledCropArea $load fertParam, irrigParam, otherIParam, exportPrices, importPrices, maxNetImport, minNetImport, unhandledCropArea
$load meatEfficency, minFeedRate, otherICost, irrigCost, irrigMaxRate, irrigConstraint, fertiliserUnitCost, domesticPriceMarkup $load meatEfficency, minFeedRate, otherICost, irrigCost, irrigMaxRate, irrigConstraint, fertiliserUnitCost, domesticPriceMarkup
$gdxin $gdxin
...@@ -182,7 +182,7 @@ $gdxin ...@@ -182,7 +182,7 @@ $gdxin
) * landChangeCost ) * landChangeCost
) * domesticPriceMarkup + ) * domesticPriceMarkup +
SUM(import_crop, importAmount(import_crop) * countryImportPrices(import_crop) - exportAmount(import_crop) * worldExportPrices(import_crop)) SUM(import_crop, importAmount(import_crop) * importPrices(import_crop) - exportAmount(import_crop) * exportPrices(import_crop))
); );
MODEL LAND_USE /ALL/ ; MODEL LAND_USE /ALL/ ;
...@@ -217,7 +217,7 @@ $gdxin ...@@ -217,7 +217,7 @@ $gdxin
totalProdCost(crop) = sum(location, unitCost.l(crop, location) * area.l(crop, location)); totalProdCost(crop) = sum(location, unitCost.l(crop, location) * area.l(crop, location));
totalCropland(location) = sum(crop_less_pasture, area.l(crop_less_pasture, location)); totalCropland(location) = sum(crop_less_pasture, area.l(crop_less_pasture, location));
netImportCost(import_crop) = importAmount.l(import_crop) * countryImportPrices(import_crop) - exportAmount.l(import_crop) * worldExportPrices(import_crop); 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); 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) gt 0) = (totalProdCost(feed_crop) + netImportCost(feed_crop)) * feedAmount.l(feed_crop) / (totalProd(feed_crop) + netImportAmount(feed_crop));
......
...@@ -111,24 +111,5 @@ public class GamsCountryInput { ...@@ -111,24 +111,5 @@ public class GamsCountryInput {
} }
return netImport; return netImport;
} }
public Map<CropType, Double> getCountryImportPrices() {
Map<CropType, Double> prices = new HashMap<CropType, Double>();
for (Map.Entry<CropType, CountryPrice> entry : countryPrices.entrySet()) {
prices.put(entry.getKey(), entry.getValue().getImportPrice());
}
return prices;
}
public Map<CropType, Double> getCountryExportPrices() {
Map<CropType, Double> prices = new HashMap<CropType, Double>();
for (Map.Entry<CropType, CountryPrice> entry : countryPrices.entrySet()) {
prices.put(entry.getKey(), entry.getValue().getExportPrice());
}
return prices;
}
} }
...@@ -167,29 +167,27 @@ public class GamsLocationOptimiser { ...@@ -167,29 +167,27 @@ public class GamsLocationOptimiser {
} }
} }
if (DEBUG) { if (DEBUG) LogWriter.println("\nImport-export, min net imports, max net imports, global import price, global export price");
LogWriter.println("\nImport-export, min net imports, max net imports, global import price, global export price"); GAMSParameter minImportP = inDB.addParameter("minNetImport", 1);
for (CropType crop : CropType.getImportedTypes()) { GAMSParameter maxImportP = inDB.addParameter("maxNetImport", 1);
ImportExportConstraint iec = countryInput.getImportConstraints().get(crop); GAMSParameter importPriceP = inDB.addParameter("importPrices", 1);
double minNetImport = 0, maxNetImport = 0; GAMSParameter exportPriceP = inDB.addParameter("exportPrices", 1);
if (iec != null) {
minNetImport = iec.getMinNetImport(); for (CropType crop : CropType.getImportedTypes()) {
maxNetImport = iec.getMaxNetImport(); ImportExportConstraint iec = countryInput.getImportConstraints().get(crop);
} CountryPrice gp = countryInput.getCountryPrices().get(crop);
double minNetImport = iec.getMinNetImport();
CountryPrice gp = countryInput.getCountryPrices().get(crop); double maxNetImport = iec.getMaxNetImport();
double importPrice = gp.getImportPrice();
LogWriter.println(String.format(" %15s, \t %5.1f, \t %5.1f, \t %5.3f, \t %5.3f", double exportPrice = gp.getExportPrice();
crop.getGamsName(), minNetImport, maxNetImport, gp.getImportPrice(), gp.getExportPrice()));
} 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));
minImportP.addRecord(crop.getGamsName()).setValue(minNetImport);
maxImportP.addRecord(crop.getGamsName()).setValue(maxNetImport);
importPriceP.addRecord(crop.getGamsName()).setValue(importPrice);
exportPriceP.addRecord(crop.getGamsName()).setValue(exportPrice);
} }
addItemMapParm(inDB.addParameter("minNetImport", 1), countryInput.getMinNetImport(), false);
addItemMapParm(inDB.addParameter("maxNetImport", 1), countryInput.getMaxNetImport(), false);
addItemMapParm(inDB.addParameter("countryImportPrices", 1), countryInput.getCountryImportPrices(), false);
addItemMapParm(inDB.addParameter("worldExportPrices", 1), countryInput.getCountryExportPrices(), false);
//the above is not really world export price because it is scaled by country tradeBarriers, might want to change
//parameter name in GAMS i.e. countryExportPrices
LogWriter.print("\n"); LogWriter.print("\n");
addScalar(inDB, "meatEfficency", countryInput.getMeatEfficiency()); addScalar(inDB, "meatEfficency", countryInput.getMeatEfficiency());
addScalar(inDB, "fertiliserUnitCost", ModelConfig.FERTILISER_MAX_COST); addScalar(inDB, "fertiliserUnitCost", ModelConfig.FERTILISER_MAX_COST);
...@@ -321,15 +319,6 @@ public class GamsLocationOptimiser { ...@@ -321,15 +319,6 @@ public class GamsLocationOptimiser {
} }
} }
private void addItemMapParm(GAMSParameter parm, Map<CropType, Double> itemMap, boolean printOutput) {
for (Map.Entry<CropType, Double> entry : itemMap.entrySet()) {
double d = entry.getValue();
if (printOutput) LogWriter.println(String.format(" %15s,\t %.3f", entry.getKey().getGamsName(), d));
if (!Double.isNaN(d))
parm.addRecord(entry.getKey().getGamsName()).setValue(d);
}
}
private void addCommodityMapParm(GAMSParameter parm, Map<CommodityType, Double> itemMap) { private void addCommodityMapParm(GAMSParameter parm, Map<CommodityType, Double> itemMap) {
for (Map.Entry<CommodityType, Double> entry : itemMap.entrySet()) { for (Map.Entry<CommodityType, Double> entry : itemMap.entrySet()) {
double d = entry.getValue(); double d = entry.getValue();
......
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