Skip to content
Snippets Groups Projects
Commit 0acbdfe6 authored by R0slyn's avatar R0slyn
Browse files

incorporating trade barriers. trade barriers only affect exports. rather than...

incorporating trade barriers. trade barriers only affect exports. rather than calculate global export calculate country export (global export * scaler for country). Parameter in GAMS still called worldExportPrice. Perhaps needs to be changed to country.
parent a29ea515
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,7 @@ import ac.ed.lurg.country.GlobalPrice;
import ac.ed.lurg.country.ImportExportConstraint;
import ac.ed.lurg.types.CommodityType;
import ac.ed.lurg.types.CropType;
import ac.ed.lurg.utils.LogWriter;
public class GamsCountryInput {
......@@ -18,15 +19,15 @@ public class GamsCountryInput {
private Map<CropType, ImportExportConstraint> importConstraints;
private Map<CropType, Double> cropAdjustments;
private boolean calibrateToObserved;
private Map<CropType, Double> tradeBarriers;
/* private double maxLandUseChange;
private double meatEfficiency;
private double minFeedRate;
private double tradeBarrier;
private double landChangeEnergy;*/
private GamsCountryInput(CompositeCountry country, Map<CommodityType, Double> projectedDemand, Map<CropType, GlobalPrice> worldPrices,
private GamsCountryInput(CompositeCountry country, Map<CommodityType, Double> projectedDemand, Map<CropType, Double> tradeBarriers, Map<CropType, GlobalPrice> worldPrices,
Map<CropType, ImportExportConstraint> importConstraints, Map<CropType, Double> cropAdjustments, boolean calibrateToObserved) {
super();
this.country = country;
......@@ -35,13 +36,14 @@ public class GamsCountryInput {
this.importConstraints = importConstraints;
this.cropAdjustments = cropAdjustments;
this.calibrateToObserved = calibrateToObserved;
this.tradeBarriers = tradeBarriers;
}
public GamsCountryInput(GamsCountryInput gamsInput, Map<CropType, Double> cropAdjs) {
this(gamsInput.country, gamsInput.projectedDemand, gamsInput.worldPrices, gamsInput.importConstraints, cropAdjs, false);
this(gamsInput.country, gamsInput.projectedDemand, gamsInput.tradeBarriers, gamsInput.worldPrices, gamsInput.importConstraints, cropAdjs, false);
}
public static GamsCountryInput createInput(CompositeCountry country, Map<CommodityType, Double> projectedDemand, Map<CropType, GlobalPrice> worldPrices,
public static GamsCountryInput createInput(CompositeCountry country, Map<CommodityType, Double> projectedDemand, Map<CropType, Double> tradeBarriers, Map<CropType, GlobalPrice> worldPrices,
Map<CropType, Double> baseNetImport, Map<CropType, Double> maxOfProdOrSupply, Map<CropType, Double> cropAdjustments, boolean calibrateToObserved) {
double allowedImportChange = calibrateToObserved ? 0.0 : ModelConfig.MAX_IMPORT_CHANGE;
......@@ -53,7 +55,7 @@ public class GamsCountryInput {
importConstraints.put(c, new ImportExportConstraint(entry.getValue() - change, entry.getValue() + change));
}
return new GamsCountryInput(country, projectedDemand, worldPrices, importConstraints, cropAdjustments, calibrateToObserved);
return new GamsCountryInput(country, projectedDemand, tradeBarriers, worldPrices, importConstraints, cropAdjustments, calibrateToObserved);
}
......@@ -116,16 +118,21 @@ public class GamsCountryInput {
public Map<CropType, Double> getWorldImportPrices() {
Map<CropType, Double> prices = new HashMap<CropType, Double>();
for (Map.Entry<CropType, GlobalPrice> entry : worldPrices.entrySet()) {
prices.put(entry.getKey(), entry.getValue().getImportPrice());
}
return prices;
}
public Map<CropType, Double> getWorldExportPrices() {
public Map<CropType, Double> getCountryExportPrices() {
Map<CropType, Double> prices = new HashMap<CropType, Double>();
for (Map.Entry<CropType, GlobalPrice> entry : worldPrices.entrySet()) {
prices.put(entry.getKey(), entry.getValue().getExportPrice());
double tradeBarrier = tradeBarriers.get(entry.getKey());
prices.put(entry.getKey(), entry.getValue().getExportPrice()*(1-tradeBarrier));
}
return prices;
}
}
......@@ -168,7 +168,7 @@ public class GamsLocationOptimiser {
}
if (DEBUG) {
LogWriter.println("\nImport-export, min net imports, max net imports, import price, export price");
LogWriter.println("\nImport-export, min net imports, max net imports, global import price, global export price");
for (CropType crop : CropType.getImportedTypes()) {
ImportExportConstraint iec = countryInput.getImportConstraints().get(crop);
double minNetImport = 0, maxNetImport = 0;
......@@ -187,8 +187,9 @@ public class GamsLocationOptimiser {
addItemMapParm(inDB.addParameter("minNetImport", 1), countryInput.getMinNetImport(), false);
addItemMapParm(inDB.addParameter("maxNetImport", 1), countryInput.getMaxNetImport(), false);
addItemMapParm(inDB.addParameter("worldImportPrices", 1), countryInput.getWorldImportPrices(), false);
addItemMapParm(inDB.addParameter("worldExportPrices", 1), countryInput.getWorldExportPrices(), 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");
addScalar(inDB, "meatEfficency", countryInput.getMeatEfficiency());
addScalar(inDB, "fertiliserUnitCost", ModelConfig.FERTILISER_MAX_COST);
......
......@@ -22,7 +22,7 @@ public class GamsLocationTest {
}
private void run() {
GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new CompositeCountry("Test"), getProjectedDemand(), null, null, null, null, true);
GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new CompositeCountry("Test"), getProjectedDemand(), getTradeBarriers(), null, null, null, null, true);
GamsLocationInput gamsInput = new GamsLocationInput(new Timestep(0), getYields(), getPreviousArea(), getIrrigationCosts(), countryLevelInputs);
GamsLocationOptimiser opti = new GamsLocationOptimiser(gamsInput);
......@@ -39,6 +39,19 @@ public class GamsLocationTest {
dummyMap.put(CommodityType.MEAT, 480.0);
return dummyMap;
}
Map<CropType, Double> getTradeBarriers() {
Map<CropType, Double> dummyTradeMap = new HashMap<CropType, Double>();
dummyTradeMap.put(CropType.WHEAT, 300.0);
dummyTradeMap.put(CropType.MAIZE, 50.0);
dummyTradeMap.put(CropType.RICE, 50.0);
dummyTradeMap.put(CropType.OILCROPS, 50.0);
dummyTradeMap.put(CropType.PULSES, 60.0);
dummyTradeMap.put(CropType.STARCHY_ROOTS, 150.0);
dummyTradeMap.put(CropType.MEAT, 480.0);
return dummyTradeMap;
}
Map<Integer, YieldResponsesItem> getYields() {
......
......@@ -283,7 +283,7 @@ public class GamsRasterOptimiser {
CropType crop = CropType.WHEAT;
if (yresp != null && (yresp.getYieldMax(crop) < yresp.getYieldFertOnly(crop) || yresp.getYieldMax(crop) < yresp.getYieldIrrigOnly(crop))) {
logErrorWithCoord(String.format("Inconsistency: F only: %.4f, I only %.4f, max %.4f at ", yresp.getYieldFertOnly(crop), yresp.getYieldIrrigOnly(crop), yresp.getYieldMax(crop)), key, yieldRaster);
logErrorWithCoord("Inconsistency F only:" + yresp.getYieldFertOnly(crop) + ", I only" + yresp.getYieldIrrigOnly(crop) + ", max " + yresp.getYieldMax(crop) + " at ", key, yieldRaster);
}
}
......
......@@ -18,7 +18,7 @@ public class GamsRasterTest extends GamsLocationTest {
}
private void run() {
GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new CompositeCountry("Test"), getProjectedDemand(), null, null, null, null, true);
GamsCountryInput countryLevelInputs = GamsCountryInput.createInput(new CompositeCountry("Test"), getProjectedDemand(), getTradeBarriers(), null, null, null, null, true);
GamsRasterInput input = new GamsRasterInput(new Timestep(0), getYieldRaster(), getPreviousAreaRaster(), getIrrigationCost(), countryLevelInputs);
GamsRasterOptimiser opti = new GamsRasterOptimiser(input);
......
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