Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/main/java/simpaths/data/Parameters.java
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ else if(numberOfChildren <= 5) {
//public static int MAX_AGE_IN_EDUCATION;// = MAX_AGE;//30; // Max age a person can stay in education //Cannot set here, as MAX_AGE is not known yet. Now set to MAX_AGE in buildObjects in Model class.
//public static int MAX_AGE_MARRIAGE;// = MAX_AGE;//75; // Max age a person can marry //Cannot set here, as MAX_AGE is not known yet. Now set to MAX_AGE in buildObjects in Model class.
private static int MIN_START_YEAR = 2011; //Minimum allowed starting point. Should correspond to the oldest initial population.
private static int MAX_START_YEAR = 2023; //Maximum allowed starting point. Should correspond to the most recent initial population.
private static int MAX_START_YEAR = 2024; //Maximum allowed starting point. Should correspond to the most recent initial population.
public static int startYear;
public static int endYear;
private static final int MIN_START_YEAR_TESTING = 2019;
Expand Down Expand Up @@ -2154,6 +2154,20 @@ public static int getMinStartYear() {
return (trainingFlag) ? MIN_START_YEAR_TRAINING : MIN_START_YEAR;
}

public static void validateStartYear(int year) {
int min = getMinStartYear();
int max = getMaxStartYear();
if (year < min || year > max) {
String mode;
if (TESTING_FLAG) mode = "testing data";
else if (trainingFlag) mode = "training data";
else mode = "real data";
throw new IllegalArgumentException(
"Start year " + year + " is outside the allowed range [" + min + ", " + max + "] for " + mode + ". " +
"Choose a value within the supported initial-population years.");
}
}

public static String getEuromodOutputDirectory() {
if (TESTING_FLAG)
return EUROMOD_OUTPUT_DIRECTORY;
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/simpaths/experiment/SimPathsMultiRun.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public static void main(String[] args) {
}
country = Country.getCountryFromNameString(countryString);

Parameters.validateStartYear(startYear);

//Save the last selected country and year to Excel to use in the model
String[] columnNames = {"Country", "Year"};
Object[][] data = new Object[1][columnNames.length];
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/simpaths/experiment/SimPathsStart.java
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,8 @@ private static void printHelpMessage(HelpFormatter formatter, Options options) {
@Override
public void buildExperiment(SimulationEngine engine) {

Parameters.validateStartYear(startYear);

// instantiate simulation processes
SimPathsModel model = new SimPathsModel(country, startYear);
SimPathsCollector collector = new SimPathsCollector(model);
Expand All @@ -233,11 +235,13 @@ public void buildExperiment(SimulationEngine engine) {

private static void runGUIlessSetup(int option) throws FileNotFoundException {

// Detect if data available; set to testing data if not
// Detect if data available; set to training data if not.
Collection<File> testList = FileUtils.listFiles(new File(Parameters.getInputDirectoryInitialPopulations()), new String[]{"csv"}, false);
if (testList.size()==0)
Parameters.setTrainingFlag(true);

Parameters.validateStartYear(startYear);

// Create EUROMODPolicySchedule input from files
if (!rewritePolicySchedule &&
!new File(Parameters.getInputDirectory() + Parameters.EUROMODpolicyScheduleFilename + ".xlsx").exists()) {
Expand Down
Loading