Compare candidate to all list points

This commit is contained in:
Alex Herbert 2022-10-22 23:24:24 +01:00
parent ab9b0b0c2d
commit a97523700a
1 changed files with 10 additions and 4 deletions

View File

@ -386,6 +386,10 @@ public class SimplexOptimizer extends MultivariateOptimizer {
* Stores the given {@code candidate} if its fitness is better than
* that of the last (assumed to be the worst) point in {@code list}.
*
* <p>If the list is below the maximum size then the {@code candidate}
* is added if it is not already in the list. The list is sorted
* when it reaches the maximum size.
*
* @param candidate Point to be stored.
* @param comp Fitness comparator.
* @param list Starting points (modified in-place).
@ -406,12 +410,14 @@ public class SimplexOptimizer extends MultivariateOptimizer {
if (Arrays.equals(pPoint, candidatePoint)) {
// Point was already stored.
return;
} else {
// Store candidate.
list.add(candidate);
return;
}
}
// Store candidate.
list.add(candidate);
// Sort the list when required
if (list.size() == max) {
Collections.sort(list, comp);
}
} else {
final int last = max - 1;
if (comp.compare(candidate, list.get(last)) < 0) {