Skip to content
Snippets Groups Projects
Commit 05bfae9a authored by alexanpe's avatar alexanpe
Browse files

Some improvements in demand related to nonfood

parent 0602d142
No related branches found
No related tags found
No related merge requests found
...@@ -72,7 +72,6 @@ public abstract class AbstractCountryAgent { ...@@ -72,7 +72,6 @@ public abstract class AbstractCountryAgent {
LogWriter.println(commodity.getGamsName() + ": " + commPrice); LogWriter.println(commodity.getGamsName() + ": " + commPrice);
} }
prices.put(CommodityType.NONFOOD, Double.NaN);
return prices; return prices;
} }
......
...@@ -33,4 +33,9 @@ public class GamsCommodityDemand { ...@@ -33,4 +33,9 @@ public class GamsCommodityDemand {
public CommodityType getCommodity() { public CommodityType getCommodity() {
return commodity; return commodity;
} }
@Override
public String toString() {
return String.format("%14s: subs=%.3f,\tdisc=%.3f,\tdemand(kcal)=%.1f,\tdemand(plum)= %.3f", commodity, subsistence, discretionary, getKcalTotal(), getPlumDemand());
}
} }
\ No newline at end of file
...@@ -70,33 +70,31 @@ public class GamsDemandOptimiser { ...@@ -70,33 +70,31 @@ public class GamsDemandOptimiser {
for (Map.Entry<CommodityType, Double> entry : inputData.getPrices().entrySet()) { for (Map.Entry<CommodityType, Double> entry : inputData.getPrices().entrySet()) {
CommodityType comm = entry.getKey(); CommodityType comm = entry.getKey();
Vector<String> v = new Vector<String>(); double priceComm = entry.getValue() * 1000 / comm.getkcalPerT()*2000*365; //price per calorie of commodity x per year assuming 2000 kcal a day for whole year
v.add(comm.getGamsName()); doCommodity(inDB, priceP, prevSubsP, prevDiscP, gdpPc, previousGamsDemands, comm, priceComm, 0.1, 0.1);
double priceComm, prevSubs = 0.1, prevDisc = 0.1;
if (comm == CommodityType.NONFOOD) {
prevSubs = 5;
prevDisc = 1;
priceComm = 45.376+53.036*gdpPc/inputData.getUsaGdpPc();
}
else
priceComm = entry.getValue() * 1000 / comm.getkcalPerT()*2000*365; //price per calorie of commodity x per year assuming 2000 kcal a day for whole year
if (previousGamsDemands != null) {
GamsCommodityDemand demand = previousGamsDemands.getGamsDemands(comm);
if (demand == null)
LogWriter.printlnError("Null GamsCommodityDemand for " + comm);
else {
prevSubs = demand.getSubsistence();
prevDisc = demand.getDiscretionary();
}
}
LogWriter.println(String.format("%14s: price=%.4f, previousSubs=%.4f, previousDisc=%.4f", comm.getGamsName(), priceComm, prevSubs, prevDisc));
setGamsParamValue(priceP.addRecord(v), priceComm, 4);
setGamsParamValue(prevSubsP.addRecord(v), prevSubs, 4);
setGamsParamValue(prevDiscP.addRecord(v), prevDisc, 4);
} }
double nonfoodPrice = 45.376+53.036*gdpPc/inputData.getUsaGdpPc();
doCommodity(inDB, priceP, prevSubsP, prevDiscP, gdpPc, previousGamsDemands, CommodityType.NONFOOD, nonfoodPrice, 5, 1);
}
private void doCommodity(GAMSDatabase inDB, GAMSParameter priceP, GAMSParameter prevSubsP, GAMSParameter prevDiscP, double gdpPc,
GamsDemandOutput previousGamsDemands, CommodityType comm, double price, double defaultSubs, double defaultDisc) {
Vector<String> v = new Vector<String>();
v.add(comm.getGamsName());
double prevSubs = defaultSubs, prevDisc = defaultDisc;
if (previousGamsDemands != null) {
GamsCommodityDemand demand = previousGamsDemands.getGamsDemands(comm);
prevSubs = demand.getSubsistence();
prevDisc = demand.getDiscretionary();
}
LogWriter.println(String.format("%14s: price=%.4f, previousSubs=%.4f, previousDisc=%.4f", comm.getGamsName(), price, prevSubs, prevDisc));
setGamsParamValue(priceP.addRecord(v), price, 4);
setGamsParamValue(prevSubsP.addRecord(v), prevSubs, 4);
setGamsParamValue(prevDiscP.addRecord(v), prevDisc, 4);
} }
private double setGamsParamValue(GAMSParameterRecord param, double val, int places) { private double setGamsParamValue(GAMSParameterRecord param, double val, int places) {
...@@ -129,16 +127,9 @@ public class GamsDemandOptimiser { ...@@ -129,16 +127,9 @@ public class GamsDemandOptimiser {
else { else {
double subsGams = rec.getLevel(); double subsGams = rec.getLevel();
double discGams = varDisc.findRecord(commodityName).getLevel(); double discGams = varDisc.findRecord(commodityName).getLevel();
GamsCommodityDemand demand = new GamsCommodityDemand(commodity, subsGams, discGams);
if (commodity == CommodityType.NONFOOD) { // we don't want to consider non-food, so not added to demandMap LogWriter.println(demand.toString());
LogWriter.println(String.format("%14s: subs=%.3f, disc=%.3f", commodityName, subsGams, discGams)); demandMap.add(demand);
}
else { //gams is calculating demand in number of 2000 kcal servings per day so * by 2000 and * 365 to get kcal per year
GamsCommodityDemand demand = new GamsCommodityDemand(commodity, subsGams, discGams);
LogWriter.println(String.format("%14s: subs=%.3f, disc=%.3f, demand(kcal)=%.1f, demand(plum)= %.3f", commodityName, subsGams, discGams, demand.getKcalTotal(), demand.getPlumDemand()));
demandMap.add(demand);
}
} }
} }
......
...@@ -79,7 +79,8 @@ public class BaseConsumpManager { ...@@ -79,7 +79,8 @@ public class BaseConsumpManager {
Map<CommodityType, Double> commodityMap = baseConsumpMap.get(country); Map<CommodityType, Double> commodityMap = baseConsumpMap.get(country);
if (commodityMap == null || !commodityMap.containsKey(commodity)) { if (commodityMap == null || !commodityMap.containsKey(commodity)) {
LogWriter.printlnError("BaseConsumpManager: can't get value for " + commodity + ", " + country); if (commodity != CommodityType.NONFOOD) // don't report this, as expected for nonfood
LogWriter.printlnError("BaseConsumpManager: can't get value for " + commodity + ", " + country);
return 0.0; return 0.0;
} }
......
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