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

no message

parent bb5aabdf
No related branches found
No related tags found
No related merge requests found
...@@ -87,12 +87,13 @@ public class ModelConfig { ...@@ -87,12 +87,13 @@ public class ModelConfig {
public static final String DEMAND_CURVES_FILE = DATA_DIR + File.separator + "com_curves.csv"; public static final String DEMAND_CURVES_FILE = DATA_DIR + File.separator + "com_curves.csv";
public static final String SSP_FILE = DATA_DIR + File.separator + "ssp.csv"; public static final String SSP_FILE = DATA_DIR + File.separator + "ssp.csv";
public static final String COUNTRY_DATA_FILE = DATA_DIR + File.separator + "country_data.csv"; public static final String COUNTRY_DATA_FILE = DATA_DIR + File.separator + "country_data.csv";
public static final String REF_YIELD_FILE = DATA_DIR + File.separator + "ref_yields.csv";
public static final int START_TIMESTEP = getIntProperty("START_TIMESTEP", 0); public static final int START_TIMESTEP = getIntProperty("START_TIMESTEP", 0);
public static final int END_TIMESTEP = getIntProperty("END_TIMESTEP", 1); public static final int END_TIMESTEP = getIntProperty("END_TIMESTEP", 0);
public static final int BASE_YEAR = getIntProperty("BASE_YEAR", 2010); public static final int BASE_YEAR = getIntProperty("BASE_YEAR", 2010);
} }
\ No newline at end of file
...@@ -7,7 +7,6 @@ import ac.ed.lurg.country.CountryAgentCreator; ...@@ -7,7 +7,6 @@ import ac.ed.lurg.country.CountryAgentCreator;
import ac.ed.lurg.demand.DemandManager; import ac.ed.lurg.demand.DemandManager;
import ac.ed.lurg.types.ModelFitType; import ac.ed.lurg.types.ModelFitType;
import ac.ed.lurg.yield.YieldManager; import ac.ed.lurg.yield.YieldManager;
import ac.ed.lurg.yield.YieldManager;
public class ModelMain { public class ModelMain {
......
...@@ -38,11 +38,14 @@ public class CountryAgent { ...@@ -38,11 +38,14 @@ public class CountryAgent {
} }
public void determineProduction(int timestep) { public void determineProduction(int timestep) {
int year = ModelConfig.BASE_YEAR + timestep;
// get projected demand // get projected demand
Map<Item, Double> projectedDemand = modelContext.getDemandManager().getDemand(country, ModelConfig.BASE_YEAR + timestep); Map<Item, Double> projectedDemand = modelContext.getDemandManager().getDemand(country, year);
// get ref yields // get ref yields
Map<Item, Double> refYield = modelContext.getYieldManager().getRefYield(country, year);
// optimise areas and intensity // optimise areas and intensity
......
...@@ -21,7 +21,7 @@ public class CountryAgentCreator { ...@@ -21,7 +21,7 @@ public class CountryAgentCreator {
private static final int FOREST_COL = 7; private static final int FOREST_COL = 7;
private static final int PERM_CROP_COL = 8; private static final int PERM_CROP_COL = 8;
private static final int PASTURE_COL = 9; private static final int PASTURE_COL = 9;
private static final int FERT_N_COL = 12; // private static final int FERT_N_COL = 12;
public Collection<CountryAgent> getAgents(ModelContext modelContext) { public Collection<CountryAgent> getAgents(ModelContext modelContext) {
Collection<CountryAgent> countryAgents = new HashSet<CountryAgent>(); Collection<CountryAgent> countryAgents = new HashSet<CountryAgent>();
......
package ac.ed.lurg.yield;
import ac.ed.lurg.country.Country;
import ac.ed.lurg.types.Item;
class YieldKey {
private Country country;
private Item item;
YieldKey (Country country, Item item) {
this.item = item;
this.country = country;
}
public Country getCountry() {
return country;
}
public Item getItem() {
return item;
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((country == null) ? 0 : country.hashCode());
result = prime * result + ((item == null) ? 0 : item.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
YieldKey other = (YieldKey) obj;
if (country == null) {
if (other.country != null)
return false;
} else if (!country.equals(other.country))
return false;
if (item == null) {
if (other.item != null)
return false;
} else if (!item.equals(other.item))
return false;
return true;
}
}
package ac.ed.lurg.yield; package ac.ed.lurg.yield;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashMap;
import java.util.Map;
import ac.ed.lurg.ModelConfig;
import ac.ed.lurg.country.Country; import ac.ed.lurg.country.Country;
import ac.ed.lurg.demand.DemandCurve;
import ac.ed.lurg.demand.SspData;
import ac.ed.lurg.types.Item; import ac.ed.lurg.types.Item;
import ac.ed.lurg.utils.LogWriter;
public class YieldManager { public class YieldManager {
public double getRefYield(Country country, int year, Item commodity) { private Map<Country, Map<Item, Double>> cache = new HashMap<Country, Map<Item, Double>>();
// TODO Auto-generated method stub
return 0; private static final int COUNTRY_COL = 0;
private static final int ITEM_COL = 1;
private static final int REF_YIELD_COL = 2;
public YieldManager () {
super();
readRefYields();
}
private void readRefYields() {
String filename = ModelConfig.REF_YIELD_FILE;
try {
BufferedReader reader = new BufferedReader(new FileReader(filename));
String line, itemName, countryName;
double refYield;
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];
refYield = Double.parseDouble(tokens[REF_YIELD_COL]);
Map<Item, Double> countryMap = cache.get(Country.get(countryName));
if (countryMap == null) {
countryMap = new HashMap<Item, Double>();
cache.put(Country.get(countryName), countryMap);
}
countryMap.put(Item.get(itemName), refYield);
} catch (Exception e) {
LogWriter.printlnError("Failed in processing ssp line " + line);
e.printStackTrace();
}
}
reader.close();
} catch (Exception e) {
LogWriter.printlnError("Failed in reading ssp data file");
e.printStackTrace();
}
LogWriter.println("Processed " + filename + ", create " + cache.size() + " ref yield entries");
}
public Map<Item, Double> getRefYield(Country country, int year) {
return cache.get(country);
} }
public String getModelAndScenarioDescription() { public String getModelAndScenarioDescription() {
return "Dummy yield model"; return "Estimated ref yields";
} }
} }
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