Skip to content
Snippets Groups Projects
Commit 523e84ba authored by Bart Arendarczyk's avatar Bart Arendarczyk
Browse files

Slight changes to trade constraints.

parent 3f278de4
No related branches found
No related tags found
No related merge requests found
...@@ -178,7 +178,7 @@ public class CountryAgent extends AbstractCountryAgent { ...@@ -178,7 +178,7 @@ public class CountryAgent extends AbstractCountryAgent {
if (crop.isImportedCrop()) { if (crop.isImportedCrop()) {
changeUp = cropPrice.getTradeChangeUp(maxOfProdOrSupply); changeUp = cropPrice.getTradeChangeUp(maxOfProdOrSupply);
changeDown = cropPrice.getTradeChangeDown(maxOfProdOrSupply, crop.getStockToUseRatio()); //changeDown = cropPrice.getTradeChangeDown(maxOfProdOrSupply, crop.getStockToUseRatio());
if (changeUp < 0) { // need to reduce imports to avoid negative stocks if (changeUp < 0) { // need to reduce imports to avoid negative stocks
baseTrade += changeUp; baseTrade += changeUp;
...@@ -225,7 +225,7 @@ public class CountryAgent extends AbstractCountryAgent { ...@@ -225,7 +225,7 @@ public class CountryAgent extends AbstractCountryAgent {
} else { } else {
double maxOfProdOrSupply = carbonUsageData.getCarbonCredits() + Math.max(baseTrade, 0); double maxOfProdOrSupply = carbonUsageData.getCarbonCredits() + Math.max(baseTrade, 0);
changeUp = globalCarbonPrice.getTradeChangeUp(maxOfProdOrSupply); changeUp = globalCarbonPrice.getTradeChangeUp(maxOfProdOrSupply);
changeDown = globalCarbonPrice.getTradeChangeDown(maxOfProdOrSupply, ModelConfig.DEFAULT_STOCK_USE_RATIO); changeDown = maxOfProdOrSupply * ModelConfig.MAX_IMPORT_CHANGE;
if (changeUp < 0) { // need to reduce imports to avoid negative stocks if (changeUp < 0) { // need to reduce imports to avoid negative stocks
baseTrade += changeUp; baseTrade += changeUp;
...@@ -260,7 +260,7 @@ public class CountryAgent extends AbstractCountryAgent { ...@@ -260,7 +260,7 @@ public class CountryAgent extends AbstractCountryAgent {
changeUp = changeDown = 0.0; changeUp = changeDown = 0.0;
} else { } else {
changeUp = woodPrice.getTradeChangeUp(maxOfProdOrSupply); changeUp = woodPrice.getTradeChangeUp(maxOfProdOrSupply);
changeDown = woodPrice.getTradeChangeDown(maxOfProdOrSupply, ModelConfig.DEFAULT_STOCK_USE_RATIO); changeDown = maxOfProdOrSupply * ModelConfig.MAX_IMPORT_CHANGE;
if (changeUp < 0) { // need to reduce imports to avoid negative stocks if (changeUp < 0) { // need to reduce imports to avoid negative stocks
baseTrade += changeUp; baseTrade += changeUp;
...@@ -290,7 +290,7 @@ public class CountryAgent extends AbstractCountryAgent { ...@@ -290,7 +290,7 @@ public class CountryAgent extends AbstractCountryAgent {
double prodCost = cropUsageData.getProdCostRate(); double prodCost = cropUsageData.getProdCostRate();
Double tb = tradeBarriers.get(crop); Double tb = tradeBarriers.get(crop);
double tradeBarrier = tb==null ? 0 : tb; double tradeBarrier = tb==null ? 0 : tb;
double exportTaxRateForCrop = CommodityType.CEREALS.getCropTypes().contains(crop) ? exportTaxRate : 0.0; double exportTaxRateForCrop = CommodityType.CEREALS_STARCHY_ROOTS.getCropTypes().contains(crop) ? exportTaxRate : 0.0;
CountryPrice cp = new CountryPrice(crop, worldPrice, tradeBarrier, prodCost, weighting, exportTaxRateForCrop); CountryPrice cp = new CountryPrice(crop, worldPrice, tradeBarrier, prodCost, weighting, exportTaxRateForCrop);
return cp; return cp;
} }
......
...@@ -119,8 +119,9 @@ public class GlobalPrice implements Serializable { ...@@ -119,8 +119,9 @@ public class GlobalPrice implements Serializable {
// Adjust price based on stock change // Adjust price based on stock change
adjustment = 1 - lambda * stockChange / production; adjustment = 1 - lambda * stockChange / production;
// If below target stock and stocks not already increasing, nudge prices to increase stock. // If below target stock and stocks not already increasing, nudge prices up to increase stock.
if (updatedStock < targetStock & stockChange < 0) { // If above target stock and stocks not already decreasing, nudge prices down to decrease stock.
if ((updatedStock < targetStock & stockChange < 0 & stockChange < prevStockChange) | (updatedStock > targetStock & stockChange > 0 & stockChange > prevStockChange)) {
adjustment *= 1 - 0.5 * ModelConfig.MARKET_LAMBDA * (updatedStock - targetStock) / production; adjustment *= 1 - 0.5 * ModelConfig.MARKET_LAMBDA * (updatedStock - targetStock) / production;
} }
} }
...@@ -195,15 +196,7 @@ public class GlobalPrice implements Serializable { ...@@ -195,15 +196,7 @@ public class GlobalPrice implements Serializable {
maxOfProdOrSupply += 0.05 * production / CountryManager.getInstance().getCountryCount(); maxOfProdOrSupply += 0.05 * production / CountryManager.getInstance().getCountryCount();
double supplyFraction = maxOfProdOrSupply / (production * 1.05); double supplyFraction = maxOfProdOrSupply / (production * 1.05);
// ensures stocks don't go below zero even if no exports // ensures stocks don't go below zero even if no exports
return (0.95 * stockLevel - (importAmount - getExportsAfterTransportLosses())) * supplyFraction; return (0.9 * stockLevel - (importAmount - getExportsAfterTransportLosses())) * supplyFraction;
}
public double getTradeChangeDown(double maxOfProdOrSupply, double targetStockUseRatio) {
// plus 5% of global production divided by number of countries in case country has 0 supply
maxOfProdOrSupply += 0.05 * production / CountryManager.getInstance().getCountryCount();
double supplyFraction = maxOfProdOrSupply / (production * 1.05);
// Allow exports to increase until stocks 50% above target stock level
return Math.max(targetStockUseRatio * production * 1.5 - stockLevel, 0) * supplyFraction;
} }
} }
\ No newline at end of file
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