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

Try to solve demand multiple times until finding a solution

parent 249644d5
No related branches found
No related tags found
No related merge requests found
......@@ -80,7 +80,7 @@ public abstract class AbstractCountryAgent {
else
priceMarkupFactor = priceMarkupFactors.get(commodity);
prices.put(commodity, commPrice);
prices.put(commodity, commPrice * priceMarkupFactor); // * priceMarkupFactor to rebase prices to those provide by G&G
LogWriter.println("Price for " + commodity.getGamsName() + " is " + commPrice * priceMarkupFactor + " after markup of " + priceMarkupFactor);
}
......
......@@ -41,4 +41,8 @@ public class GamsDemandOutput {
public String getStatus() {
return status;
}
public void resetForNewAttempt() {
utility = (Math.random()-0.5) * 40;
}
}
......@@ -41,7 +41,18 @@ public class ElasticDemandManager extends AbstractSSPDemandManager {
GamsDemandInput inputData = new GamsDemandInput(c, year, gdpPc, prices, usaGdpPc, previousGamsDemands.get(c));
// Do the projection
GamsDemandOutput gamsOutput = new GamsDemandOptimiser(inputData).getDemandPc();
GamsDemandOutput gamsOutput = null;
for (int i = 1; i < 50; ++i) {
gamsOutput = new GamsDemandOptimiser(inputData).getDemandPc();
if (gamsOutput.getStatus().equals("SOLVED"))
break;
else {
LogWriter.printlnError(i + ": Problem solving " + c + ", " + year + " got " + gamsOutput.getStatus());
gamsOutput.resetForNewAttempt();
inputData = new GamsDemandInput(c, year, gdpPc, prices, usaGdpPc, gamsOutput);
}
}
previousGamsDemands.put(c, gamsOutput);
Map<CommodityType, Double> foodPc = gamsOutput.getPlumDemands();
......
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