Package org.moeaframework.core.fitness
Class FitnessBasedArchive
java.lang.Object
org.moeaframework.core.population.Population
org.moeaframework.core.population.NondominatedPopulation
org.moeaframework.core.fitness.FitnessBasedArchive
- All Implemented Interfaces:
Iterable<Solution>,Copyable<Population>,Stateful,Displayable,Formattable<Solution>
Maintains a non-dominated archive of solutions with a maximum capacity. If the size exceeds the capacity, one or
more solutions are pruned based on the fitness calculation. The fitness calculation only occurs when the
addition of a solution exceeds the capacity. The fitness can be manually calculated by calling
update().-
Nested Class Summary
Nested classes/interfaces inherited from class org.moeaframework.core.population.NondominatedPopulation
NondominatedPopulation.DuplicateMode -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final intThe maximum capacity of this archive.protected final FitnessComparatorThe fitness comparator for comparing fitness values.protected final FitnessEvaluatorThe fitness evaluator for computing the fitness of solutions.Fields inherited from class org.moeaframework.core.population.NondominatedPopulation
comparator, duplicateMode -
Constructor Summary
ConstructorsConstructorDescriptionFitnessBasedArchive(FitnessEvaluator evaluator, int capacity) Constructs an empty fitness-based archive.FitnessBasedArchive(FitnessEvaluator evaluator, int capacity, Iterable<? extends Solution> iterable) Constructs a fitness-based archive initialized with the specified solutions.FitnessBasedArchive(FitnessEvaluator evaluator, int capacity, DominanceComparator comparator) Constructs an empty fitness-based archive.FitnessBasedArchive(FitnessEvaluator evaluator, int capacity, DominanceComparator comparator, Iterable<? extends Solution> iterable) Constructs a fitness-based archive initialized with the specified solutions. -
Method Summary
Modifier and TypeMethodDescriptionbooleanIfnewSolutionis dominates any solution or is non-dominated with all solutions in this population, the dominated solutions are removed andnewSolutionis added to this population.copy()Returns a copy of this population.intReturns the maximum number of solutions stored in this archive.voidupdate()Updates the fitness of all solutions in this population.Methods inherited from class org.moeaframework.core.population.NondominatedPopulation
forceAddWithoutCheck, getComparator, getDuplicateMode, isDuplicate, load, load, load, replaceMethods inherited from class org.moeaframework.core.population.Population
addAll, addAll, asList, asTabularData, clear, contains, containsAll, containsAll, filter, get, getLowerBounds, getUpperBounds, indexOf, isEmpty, iterator, loadState, remove, remove, removeAll, removeAll, removeAll, save, save, saveState, size, sort, truncateMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.moeaframework.util.format.Displayable
displayMethods inherited from interface org.moeaframework.util.format.Formattable
display, display, display, save, save, saveMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Field Details
-
capacity
protected final int capacityThe maximum capacity of this archive. -
fitnessEvaluator
The fitness evaluator for computing the fitness of solutions. -
fitnessComparator
The fitness comparator for comparing fitness values.
-
-
Constructor Details
-
FitnessBasedArchive
Constructs an empty fitness-based archive.- Parameters:
evaluator- the fitness evaluator for computing the fitness of solutionscapacity- the maximum capacity of this archive
-
FitnessBasedArchive
public FitnessBasedArchive(FitnessEvaluator evaluator, int capacity, DominanceComparator comparator) Constructs an empty fitness-based archive.- Parameters:
evaluator- the fitness evaluator for computing the fitness of solutionscapacity- the maximum capacity of this archivecomparator- the dominance comparator
-
FitnessBasedArchive
public FitnessBasedArchive(FitnessEvaluator evaluator, int capacity, DominanceComparator comparator, Iterable<? extends Solution> iterable) Constructs a fitness-based archive initialized with the specified solutions.- Parameters:
evaluator- the fitness evaluator for computing the fitness of solutionscapacity- the maximum capacity of this archivecomparator- the dominance comparatoriterable- the solutions used to initialize this population
-
FitnessBasedArchive
public FitnessBasedArchive(FitnessEvaluator evaluator, int capacity, Iterable<? extends Solution> iterable) Constructs a fitness-based archive initialized with the specified solutions.- Parameters:
evaluator- the fitness evaluator for computing the fitness of solutionscapacity- the maximum capacity of this archiveiterable- the solutions used to initialize this population
-
-
Method Details
-
getCapacity
public int getCapacity()Returns the maximum number of solutions stored in this archive.- Returns:
- the maximum number of solutions stored in this archive
-
add
Description copied from class:NondominatedPopulationIfnewSolutionis dominates any solution or is non-dominated with all solutions in this population, the dominated solutions are removed andnewSolutionis added to this population. Otherwise,newSolutionis dominated and is not added to this population.- Overrides:
addin classNondominatedPopulation- Parameters:
solution- the solution to be added- Returns:
trueif the population was modified as a result of this method;falseotherwise.
-
update
public void update()Updates the fitness of all solutions in this population. -
copy
Description copied from class:PopulationReturns a copy of this population. This can be thought of as a "deep copy", which creates a copy of both the population itself and copies of the individual solutions in the population. Consequently, the returned copy is completely independent, such that any modifications to the contents or order will not impact the original.Since creating such a "deep copy" can be expensive, prefer using the constructor
Population(Iterable)orPopulation.addAll(Iterable)whenever possible. These alternatives are useful when filtering or reordering the solutions, but the solutions themselves are left unchanged.- Specified by:
copyin interfaceCopyable<Population>- Overrides:
copyin classNondominatedPopulation- Returns:
- the copy of this population
-