Skip to content
Snippets Groups Projects
Commit 74048431 authored by Lennart Eichhorn's avatar Lennart Eichhorn
Browse files

Changed Evaluator interface.

parent 75cd94d9
Branches
Tags
No related merge requests found
......@@ -16,7 +16,7 @@ public class EvaluatorNESW implements Evaluator {
}
@Override
public double evaluateFitness(Candidate candidate) {
public Candidate evaluateFitness(Candidate candidate) {
//TODO Is it a good idea to "cache" fitness this way? Maybe
//If fitness was not calculated yet, calculate it
if (candidate.getFitness() <= -1) { // Not calculated before
......@@ -30,7 +30,7 @@ public class EvaluatorNESW implements Evaluator {
candidate.setFitness(fitness);
}
return candidate.getFitness();
return candidate;
}
public int evaluateBonds(Candidate candidate) {
......
......@@ -4,5 +4,5 @@ import MainClasses.Candidate;
public interface Evaluator {
double evaluateFitness(Candidate candidate);
Candidate evaluateFitness(Candidate candidate);
}
......@@ -153,7 +153,8 @@ public class GeneticAlgorithm {
int bestIndex = 0;
this.totalFitness = 0;
for (int i = 0; i < config.getPopulationSize(); i++) {
this.fitness[i] = this.evaluator.evaluateFitness(this.population[i]);
this.population[i] = this.evaluator.evaluateFitness(this.population[i]);
this.fitness[i] = this.population[i].getFitness();
this.totalFitness += this.fitness[i];
if (this.fitness[i] > bestFitness) {
......@@ -182,7 +183,7 @@ public class GeneticAlgorithm {
double averageFitness = this.totalFitness / config.getPopulationSize();
String log = String.format("%d\t%.4f\t%.4f\t%.4f\t %d\t%d\n",
gen, averageFitness, bestFitness,
this.evaluator.evaluateFitness(overallBest),
this.overallBest.getFitness(),
-1,
-1);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment