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

Changed getSuitable function.

Change trade barriers to affect imports rather than exports.
Created 'TradeManager' to allow for switching on and off of barriers from file.
parent ff5c60f7
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="/Applications/GAMS24.7/sysdir/apifiles/Java/api/GAMSJavaAPI.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="lib" path="C:/GAMS/win64/24.7/apifiles/Java/api/GAMSJavaAPI.jar"/>
<classpathentry kind="lib" path="C:/GAMS/win64/24.7/apifiles/Java/api/gams.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
......@@ -20,7 +20,7 @@
PARAMETER irrigParam(crop, location) yield response to irrigation parameter;
PARAMETER demand(all_types) in t;
PARAMETER worldExportPrices(import_crop) prices for exports;
PARAMETER worldImportPrices(import_crop) prices for imports;
PARAMETER countryImportPrices(import_crop) prices for imports;
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 irrigCost(location) irrigation cost in cost per 1000 Mlitre or Mha for each litre per m2;
......@@ -40,7 +40,7 @@
$gdxin %gdxincname%
$load location, suitableLandArea, previousArea, demand, landChangeCost
$load yieldNone, yieldFertOnly, yieldIrrigOnly, yieldBoth
$load fertParam, irrigParam, otherIParam, worldExportPrices, worldImportPrices, maxNetImport, minNetImport, unhandledCropArea
$load fertParam, irrigParam, otherIParam, worldExportPrices, countryImportPrices, maxNetImport, minNetImport, unhandledCropArea
$load meatEfficency, minFeedRate, otherICost, irrigCost, irrigMaxRate, irrigConstraint, fertiliserUnitCost, domesticPriceMarkup
$gdxin
......@@ -182,7 +182,7 @@ $gdxin
) * landChangeCost
) * domesticPriceMarkup +
SUM(import_crop, importAmount(import_crop) * worldImportPrices(import_crop) - exportAmount(import_crop) * worldExportPrices(import_crop))
SUM(import_crop, importAmount(import_crop) * countryImportPrices(import_crop) - exportAmount(import_crop) * worldExportPrices(import_crop))
) / 1000000;
MODEL LAND_USE /ALL/ ;
......@@ -218,7 +218,7 @@ $gdxin
totalProdCost(crop) = sum(location, unitCost.l(crop, location) * area.l(crop, location));
totalCropland(location) = sum(crop_less_pasture, area.l(crop_less_pasture, location));
netImportCost(import_crop) = importAmount.l(import_crop) * worldImportPrices(import_crop) - exportAmount.l(import_crop) * worldExportPrices(import_crop);
netImportCost(import_crop) = importAmount.l(import_crop) * countryImportPrices(import_crop) - exportAmount.l(import_crop) * worldExportPrices(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));
......
......@@ -96,7 +96,7 @@ public class ModelConfig {
public static final String COUNTRY_DATA_FILE = DATA_DIR + File.separator + "country_data.csv";
public static final String COMMODITY_DATA_FILE = DATA_DIR + File.separator + "con_prod_c_and_m.csv";
public static final String BIOENERGY_DEMAND_FILE = DATA_DIR + File.separator + "bio_demand.csv";
public static final String TRADE_BARRIERS_FILE = DATA_DIR + File.separator + "trade_barriers.csv";
public static final String TRADE_BARRIERS_FILE = DATA_DIR + File.separator + "trade_barriers_dummy.csv";
// yield data
......@@ -171,8 +171,10 @@ public class ModelConfig {
public static final double DOMESTIC_PRICE_MARKUP = getDoubleProperty("DOMESTIC_PRICE_MARKUP", 1.0);
public static final double TRANSPORT_LOSSES = getDoubleProperty("TRANSPORT_LOSSES", 0.1); // in international trade
//public static final double TRADE_BARRIER_FACTOR = getDoubleProperty("TRADE_BARRIER_FACTOR", 1.5); // price factor in international trade, transport cost and real trade barriers
public static final double TRADE_BARRIER_FACTOR_DEFAULT = getDoubleProperty("TRADE_BARRIER_FACTOR", 0.2); // price factor in international trade, transport cost and real trade barriers
public static final boolean ACTIVE_TRADE_BARRIERS = getBooleanProperty("ACTIVE_TRADE_BARRIERS", false); // if set to true read in barrier information from file, otherwise use default as above
public static final int NUM_CEREAL_CATEGORIES = getIntProperty("NUM_CEREAL_CATEGORIES", 5);
public static final int NUM_PASTURE_CATEGORIES = getIntProperty("NUM_PASTURE_CATEGORIES", 1);
......
......@@ -17,7 +17,7 @@ import ac.ed.lurg.country.CountryAgent;
import ac.ed.lurg.country.CountryBoundaryRaster;
import ac.ed.lurg.country.CountryBoundaryReader;
import ac.ed.lurg.country.GlobalPrice;
import ac.ed.lurg.country.TradeBarriersReader;
import ac.ed.lurg.country.TradeManager;
import ac.ed.lurg.country.gams.GamsRasterOutput;
import ac.ed.lurg.demand.BaseConsumpManager;
import ac.ed.lurg.demand.DemandManager;
......@@ -37,6 +37,7 @@ import ac.ed.lurg.types.CropToDoubleMap;
import ac.ed.lurg.types.CropType;
import ac.ed.lurg.types.LandCoverType;
import ac.ed.lurg.types.ModelFitType;
import ac.ed.lurg.utils.LazyHashMap;
import ac.ed.lurg.utils.LogWriter;
import ac.ed.lurg.yield.LPJYieldResponseMapReader;
import ac.ed.lurg.yield.YieldRaster;
......@@ -53,6 +54,7 @@ public class ModelMain {
private Collection<CountryAgent> countryAgents;
private CountryBoundaryRaster countryBoundaryRaster;
private DemandManager demandManager;
private TradeManager tradeManager;
private CompositeCountryManager compositeCountryManager;
private RasterHeaderDetails desiredProjection;
......@@ -73,6 +75,7 @@ public class ModelMain {
BaseConsumpManager baseConsumpManager = new BaseConsumpManager();
compositeCountryManager = new CompositeCountryManager(baseConsumpManager);
demandManager = new DemandManager(ModelFitType.LOGISTIC, ModelConfig.SSP_SCENARIO, baseConsumpManager, compositeCountryManager);
tradeManager = new TradeManager(compositeCountryManager);
currentIrrigationData = getFixedIrrigationData();
countryBoundaryRaster = getCountryBoundaryRaster();
......@@ -338,10 +341,8 @@ public class ModelMain {
RasterSet<LandCoverItem> initLC = getInitialLandCover();
Map<CompositeCountry, Map<CropType, CropUsageData>> cropUsageDataMap = new CropUsageReader(compositeCountryManager).getCommodityData();
Map<CompositeCountry, CropToDoubleMap> tradeBarriersMap = new TradeBarriersReader(compositeCountryManager).getTradeBarriers();
for (CompositeCountry cc : countryGrouping) {
// DEBUG code
......@@ -354,9 +355,10 @@ public class ModelMain {
List<RasterKey> keys = countryBoundaryRaster.getKeysFor(cc);
RasterSet<LandCoverItem> initCountryLC = initLC.createSubsetForKeys(keys);
Map<CropType, CropUsageData> countryCommodityData = cropUsageDataMap.get(cc);
Map<CropType, Double> countryTradeBarriers = tradeBarriersMap.get(cc);
Map<CropType, Double> countryTradeBarriers = tradeManager.getTradeBarriers(cc);
//Map<CropType, Double> countryTradeBarriers = (ModelConfig.ACTIVE_TRADE_BARRIERS) ? tradeBarriersMap.get(cc): getDefaultTradeBarriers();
if (countryCommodityData == null) {
LogWriter.printlnError("No commodities data for " + cc + ", so skipping");
}
......
package ac.ed.lurg.country;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.Map;
import java.util.Map.Entry;
import ac.ed.lurg.ModelConfig;
import ac.ed.lurg.types.CropType;
import ac.ed.lurg.utils.LazyHashMap;
import ac.ed.lurg.utils.LogWriter;
import ac.ed.lurg.types.CropToDoubleMap;
public class TradeBarriersReader {
private static final int COUNTRY_COL = 0;
private static final int ITEM_COL = 1;
private static final int TRADE_BARRIER_COL = 2;
private CompositeCountryManager compositeCountryManager;
public TradeBarriersReader(CompositeCountryManager compositeCountryManager) {
// super();
this.compositeCountryManager = compositeCountryManager;
}
public Map<CompositeCountry, CropToDoubleMap> getTradeBarriers() {
String filename = ModelConfig.TRADE_BARRIERS_FILE;
@SuppressWarnings("serial")
LazyHashMap<CompositeCountry, CropToDoubleMap> tradeMap = new LazyHashMap<CompositeCountry, CropToDoubleMap>() {
protected CropToDoubleMap createValue() { return new CropToDoubleMap(); }
};
//
try {
BufferedReader reader = new BufferedReader(new FileReader(filename));
String line, countryName, itemName;
double barrierValue;
reader.readLine(); // read header
while ((line=reader.readLine()) != null) {
String[] tokens = line.split(",");
if (tokens.length < 3)
LogWriter.printlnError("Too few columns in " + filename + ", " + line);
try {
countryName = tokens[COUNTRY_COL];
itemName = tokens[ITEM_COL];
barrierValue = Double.parseDouble(tokens[TRADE_BARRIER_COL]);
SingleCountry country = CountryManager.getForName(countryName);
CropType crop = CropType.getForFaoName(itemName);
CompositeCountry cc = compositeCountryManager.getForSingleCountry(country);
CropToDoubleMap countryData = tradeMap.lazyGet(cc);
countryData.incrementValue(crop, barrierValue);
} catch (Exception e) {
LogWriter.printlnError("Failed in processing trade barriers line " + line);
LogWriter.print(e);
}
}
reader.close();
} catch (Exception e) {
LogWriter.printlnError("Failed in reading trade barriers data file");
LogWriter.print(e);
}
LogWriter.println("Processed " + filename + ", create " + tradeMap.size() + " barriers entries");
for (Entry<CompositeCountry, CropToDoubleMap> entry : tradeMap.entrySet()) {
// LogWriter.println("country name " + entry.getKey());
// LogWriter.println("crops " + entry.getValue());
entry.getValue().divideBy(compositeCountryManager.getAllForCompositeCountry(entry.getKey()).size());
// LogWriter.println("number of countries " + compositeCountryManager.getAllForCompositeCountry(entry.getKey()).size());
// LogWriter.println("crops " + entry.getValue());
}
return tradeMap;
}
}
......@@ -115,21 +115,25 @@ public class GamsCountryInput {
return netImport;
}
public Map<CropType, Double> getWorldImportPrices() {
public Map<CropType, Double> getCountryImportPrices() {
double tradeBarrier;
double baseImportPrice;
Map<CropType, Double> prices = new HashMap<CropType, Double>();
for (Map.Entry<CropType, GlobalPrice> entry : worldPrices.entrySet()) {
prices.put(entry.getKey(), entry.getValue().getImportPrice());
tradeBarrier = tradeBarriers.get(entry.getKey());
baseImportPrice = entry.getValue().getImportPrice();
prices.put(entry.getKey(), baseImportPrice+baseImportPrice*tradeBarrier);
}
return prices;
}
public Map<CropType, Double> getCountryExportPrices() {
public Map<CropType, Double> getWorldExportPrices() {
Map<CropType, Double> prices = new HashMap<CropType, Double>();
for (Map.Entry<CropType, GlobalPrice> entry : worldPrices.entrySet()) {
double tradeBarrier = tradeBarriers.get(entry.getKey());
prices.put(entry.getKey(), entry.getValue().getExportPrice()*(1-tradeBarrier));
prices.put(entry.getKey(), entry.getValue().getExportPrice());
}
return prices;
......
......@@ -186,8 +186,8 @@ 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.getCountryExportPrices(), false);
addItemMapParm(inDB.addParameter("countryImportPrices", 1), countryInput.getCountryImportPrices(), false);
addItemMapParm(inDB.addParameter("worldExportPrices", 1), countryInput.getWorldExportPrices(), 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");
......
......@@ -202,25 +202,13 @@ public class LandUseItem implements InterpolatingRasterItem<LandUseItem> {
double d = 0;
double protectedTotal = protectedArea;
double forestArea = getLandCoverArea(LandCoverType.FOREST);
double naturalArea = getLandCoverArea(LandCoverType.OTHER_NATURAL);
double totalNatural = forestArea+naturalArea;
double totalNatural = getLandCoverArea(LandCoverType.OTHER_NATURAL) + getLandCoverArea(LandCoverType.FOREST);
if (totalNatural >= protectedTotal){
double unavailableNatural = naturalArea/totalNatural*protectedTotal;
unavailableNatural = (Double.isNaN(unavailableNatural) || Double.isInfinite(unavailableNatural)) ? 0.0 : unavailableNatural;
double unavailableForest = forestArea/totalNatural*protectedTotal;
unavailableForest = (Double.isNaN(unavailableForest) || Double.isInfinite(unavailableForest)) ? 0.0 : unavailableForest;
d += naturalArea - unavailableNatural + forestArea - unavailableForest;
if (totalNatural >= protectedTotal)
d += totalNatural - protectedTotal;
}
for (LandCoverType l : LandCoverType.values()) {
if (LandCoverType.PASTURE.equals(l)|| LandCoverType.CROPLAND.equals(l) ) // barren land is not suitable
d += getLandCoverArea(l);
}
d += getLandCoverArea(LandCoverType.PASTURE);
d += getLandCoverArea(LandCoverType.CROPLAND);
return d;
}
......
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