|
i = makePropertyList?(args, vars, i); |
i = makeVariableList?(args, vars, i); |
String fileBase = file.substring(0, file.length() - 4); for (int season = 1; season > 0 && season <= numSeasons; ++season) { season = run(vars, 0, fileBase, file, season); |
System.out.println("RUNNING SINGLE VARIABLES"); for (int season = 1; season <= numSeasons; ++season) { int minRun = Integer.MAX_VALUE; for (i = 0; i < vars.size(); ++i) { int finished = runSingle(vars, i, file, season); vars.get(i).initialize(); if (finished == -1) { System.out.println("INTURRUPTED!"); return; } if (finished < minRun) { minRun = finished; } } season = minRun; System.out.println("FINISHED SEASON " + season); } System.out.println("RUNNING COMBINED VARIABLES"); for (int season = 1; season <= numSeasons; ++season) { season = runCombined(vars, 0, file, season); if (season == -1) { System.out.println("INTURRUPTED!"); return; } |
gracefullExit(); |
private boolean load(File file) { CompetitionDataModel? before = loadedDataModel?; bg_openDataModel?(file); if (loadedDataModel? == null || loadedDataModel? == before) { System.out.println("Load failed"); return false; |
private int runSingle(List<Variable> vars, int i, String originalFile, int season) { Variable var = vars.get(i); int minCount = Integer.MAX_VALUE; for (String val : var.values) { System.setProperty(var.name, val); int count = run(vars, originalFile, season); if (count == -1) { return -1; } if (count < minCount) { minCount = count; } |
return true; |
return minCount; |
private int run(List<Variable> vars, int i, String baseFilename, String originalFile, int curSeason) { |
private int runCombined(List<Variable> vars, int i, String originalFile, int curSeason) { |
File file = new File(baseFilename + ".xml"); if (exists(file, originalFile) && load(file)) { int seasonCount = getCompletedSeasonCount?(); if (seasonCount < curSeason) { runSeasons(1); try { runSeasonJob?.join(); } catch (InterruptedException? e) { // no prob, we'll abort when inturrupted // possible race condition if inturrupted right away, // but the job is still running, we get the old season // count, then the new non-terminated state (it depends // on the order in which the state & season count are // updated) } int newSeasonCount? = getCompletedSeasonCount?(); if (newSeasonCount? == seasonCount) { return -1; } assert newSeasonCount? == seasonCount + 1; return newSeasonCount?; } System.out.println(baseFilename + " already ran season " + curSeason); return seasonCount; } System.out.println("Couldn't find, create, or run " + file); return Integer.MAX_VALUE; |
return run(vars, originalFile, curSeason); |
baseFilename += "_" + var.name + "-"; |
System.out.println(System.getProperty("patternDepth")); int count = run(vars, i + 1, baseFilename + val, originalFile, curSeason); |
int count = runCombined(vars, i + 1, originalFile, curSeason); |
private int run(List<Variable> vars, String originalFile, int curSeason) { File file = new File(getFilename(vars, originalFile)); if (exists(file, originalFile) && load(file)) { int seasonCount = getCompletedSeasonCount?(); if (seasonCount < curSeason) { runSeasons(1); try { runSeasonJob?.join(); } catch (InterruptedException? e) { // no prob, we'll abort when inturrupted // possible race condition if inturrupted right away, // but the job is still running, we get the old season // count, then the new non-terminated state (it depends // on the order in which the state & season count are // updated) } int newSeasonCount? = getCompletedSeasonCount?(); if (newSeasonCount? == seasonCount) { return -1; } return newSeasonCount?; } System.out.println(file + " already ran season " + curSeason); return seasonCount; } System.out.println("Couldn't find, create, or run " + file); return Integer.MAX_VALUE; } private String getFilename(List<Variable> vars, String originalFile) { String filename = originalFile.substring(0, originalFile.length() - 4); Set<Variable> varSet = new TreeSet?<Variable>(vars); for (Variable var : varSet) { filename += "-" + var; } return filename + ".xml"; } private boolean load(File file) { CompetitionDataModel? before = loadedDataModel?; bg_openDataModel?(file); if (loadedDataModel? == null || loadedDataModel? == before) { System.out.println("Load failed"); return false; } return true; } |
private int makePropertyList?(String[] args, List<Variable> vars, int i) { |
private int makeVariableList?(String[] args, List<Variable> vars, int i) { |
class Variable { |
class Variable implements Comparable<Variable> { |
initialize(); } public void initialize() { System.setProperty(name, values.get(0)); } public String toString() { return name + "=" + System.getProperty(name); } public int compareTo(Variable o) { return name.compareTo(o.name); |
Now in version 1.1! It has been updated to vary all variables while keeping the others fixed at their first values, THEN start in on all the rest of the combinations. It also now sorts the variable names when naming files, so that you can change the order of them at will without losing saved data (changing the order lets you dictate which variables are varied first). I think it should also allow you to define a variable twice (e.g. wallMargin number 110 120 2 wallMargin number 130 200 10), but I did not test that. I think there's a bug in the order in which it does "first vary each variable while keeping the others fixed", but I'm not sure. |