From 1eb4be137de5c9250b3621474bc5f226c36f12d4 Mon Sep 17 00:00:00 2001 From: Thomas Weise Date: Wed, 7 Oct 2020 07:31:57 +0800 Subject: [PATCH] Added Guard against +Infinity Objective Values due to Termination 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. --- src/main/java/aitoa/algorithms/IntFFA.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/main/java/aitoa/algorithms/IntFFA.java b/src/main/java/aitoa/algorithms/IntFFA.java index 578bf91..f6d02f6 100644 --- a/src/main/java/aitoa/algorithms/IntFFA.java +++ b/src/main/java/aitoa/algorithms/IntFFA.java @@ -34,10 +34,16 @@ public void initialize() { public void assignFitness( final FitnessIndividual[] pop) { for (final FitnessIndividual ind : pop) { - ++this.mFrequencies[((int) (ind.quality))]; + final double d = ind.quality; + if (Double.isFinite(d)) { + ++this.mFrequencies[((int) (d))]; + } } for (final FitnessIndividual 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; } }