Skip to content

Commit

Permalink
Added Guard against +Infinity Objective Values due to Termination
Browse files Browse the repository at this point in the history
If the search is terminated by a timer thread, it might terminate
between the last call to shouldTerminate() and the evaluate function.
This would cause objective values of positive infinity.
Then, FFA will break with an ArrayIndexOutOfBoundsException.

We now assign positive infinity as fitness to all non-finite objective
values.
  • Loading branch information
thomasWeise committed Oct 6, 2020
1 parent 5e7d74c commit 1eb4be1
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/java/aitoa/algorithms/IntFFA.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,16 @@ public void initialize() {
public void assignFitness(
final FitnessIndividual<? extends Object>[] pop) {
for (final FitnessIndividual<? extends Object> ind : pop) {
++this.mFrequencies[((int) (ind.quality))];
final double d = ind.quality;
if (Double.isFinite(d)) {
++this.mFrequencies[((int) (d))];
}
}
for (final FitnessIndividual<? extends Object> ind : pop) {
ind.fitness = this.mFrequencies[((int) (ind.quality))];
final double d = ind.quality;
ind.fitness =
Double.isFinite(d) ? this.mFrequencies[((int) (d))]
: Double.POSITIVE_INFINITY;
}
}

Expand Down

0 comments on commit 1eb4be1

Please sign in to comment.