ParCollection params = GlobalVariables.getPrematureParameters();
params.complete();
params.setLoggingLevel(-1);
String endungGZ = "gz";
String endung = "xml";
String[] gespGrGZ = path.list(new FileNamePostfixFilter(endungGZ));
String[] gespGr;
String[] gespGrFIT;
if (gespGrGZ == null) {
StaticMethods.log(
StaticMethods.LOG_ERROR,
"Ungueltiges Verzeichnis: " + path.getAbsolutePath(),
params);
throw new RuntimeException("Ungültiges Verzeichnis.\n" + path.getAbsolutePath());
}
// Entpacke Dateien.
for (String s : gespGrGZ) {
if (!new File(path.getAbsolutePath() + File.separator + StaticMethods.datNamOhneHintErw(s)).exists()) {
StaticMethods.logInfo("Entpacken " + s + ".", params);
StaticMethods.entpackeDatei(
path.getAbsolutePath() + File.separator + s,
path.getAbsolutePath() + File.separator + StaticMethods.datNamOhneHintErw(s),
false);
} else {
params.logInfo("Datei existiert bereits: " + StaticMethods.datNamOhneHintErw(s));
}
}
gespGr = path.list(new FileNamePostfixFilter(endung));
// Find all changing parameters.
HashSet<String> differingPars;
if (changingParams != null) {
differingPars = changingParams;
} else {
differingPars = new HashSet<String>();
ArrayList<SingleParameter> allPars0 = null;
for (String s : gespGr) {
if (new File(path + "\\" + s + "-fitness.txt").exists()) {
params.logInfo("Datei existiert bereits: " + s + "-fitness.txt");
} else {
XMLAufnLesen read = new XMLAufnLesen(new File(path + "\\" + s), params);
params.logInfo("Datei gelesen: " + s);
if (allPars0 == null) {
allPars0 = read.getParams().getAllPars();
}
ParCollection parColl = read.getParams();
ArrayList<SingleParameter> allParsI = parColl.getAllPars();
for (SingleParameter par0 : allPars0) {
for (SingleParameter parI : allParsI) {
if (par0.getParameterName().equals(parI.getParameterName())) {
if (!par0.getParValue().equals(parI.getParValue())) {
differingPars.add(par0.getParameterName());
}
}
}
}
}
}
}
params.logInfo("Folgende sich ändernde Parameter gefunden: " + differingPars);
int window = 50;
double[] formerValues = new double[window];
int count;
// Extrahiere Fitness in Einzeldateien.
for (String s : gespGr) {
if (new File(path + "\\" + s + "-fitness.txt").exists()) {
params.logInfo("Datei existiert bereits: " + s + "-fitness.txt");
} else {
XMLAufnLesen read = new XMLAufnLesen(new File(path + "\\" + s), params);
params.logInfo("Datei gelesen: " + s);
LinkedList<String> fitness = new LinkedList<String>();
String preAmble = "";
for (String par : differingPars) {
preAmble += par + "=" + read.getParams().getParValue(par) + ";";
}
count = 0;
double lastMovingAvgVal = 0;
int fitsumGes = 0;
for (Population pop : read.getAllPopulations()) {
String fit = "" + preAmble;
fit += pop.getCycle() + ";";
double fitSum = 0;
int min = Integer.MAX_VALUE;
int max = Integer.MIN_VALUE;
for (Roboter rob : pop.getRoboterArray()) {
if (rob.getFit() > max) {
max = rob.getFit();
}
if (rob.getFit() < min) {
min = rob.getFit();
}
fit += rob.getFit() +";";
fitSum += rob.getFit();
}
fitSum /= pop.getRoboterArray().length;
fit += fitSum;
formerValues[count % window] = fitSum;
if (count >= window) {
fit += ";" + average(formerValues) + ";" + (average(formerValues) - lastMovingAvgVal);
} else {
fit += ";" + 0 + ";0";
}
// Par;zyklus;rob0...robn;fitSum;movAvg;movAvgDelta;Integral;min;max
fitsumGes += fitSum;
fit += ";" + fitsumGes;
fit += ";" + min + ";" + max;
fitness.add(fit);
count++;
lastMovingAvgVal = average(formerValues);
}
StaticMethods.speichereTextAusArray(path.getAbsolutePath(), s + "-fitness.txt", fitness, params);
}
}
gespGrFIT = path.list(new FileNamePostfixFilter("-fitness.txt"));
LinkedList<String> liste = new LinkedList<String>();
for (String s : gespGrFIT) {
params.logInfo("Schreibe Daten in Gesamtdatei: " + s);
for (String line : StaticMethods.liesTextArray(new File(path + "\\"