Class NondominatedSortingPopulation
java.lang.Object
org.moeaframework.core.population.Population
org.moeaframework.core.population.NondominatedSortingPopulation
- All Implemented Interfaces:
 Iterable<Solution>,Copyable<Population>,Stateful,Displayable,Formattable<Solution>
- Direct Known Subclasses:
 ReferencePointNondominatedSortingPopulation
Population that maintains the 
rank and crowdingDistance attributes for its solutions by invoking
 NondominatedSorting.evaluate(Population).  This population tracks modifications and performs fast
 non-dominated sorting only when required.  Only changes made to this population can be tracked; changes made
 directly to the contained solutions will not be detected.  Therefore, it may be necessary to invoke
 update() manually.
 
 The iterator() method returned by Population must use the size(), get(int) and
 remove(int) methods to ensure proper functionality.
- 
Constructor Summary
ConstructorsConstructorDescriptionConstructs an empty population that maintains therankandcrowdingDistanceattributes for its solutions.NondominatedSortingPopulation(Iterable<? extends Solution> iterable) Constructs a population initialized with the specified solutions that maintains therankandcrowdingDistanceattributes for its solutions.NondominatedSortingPopulation(DominanceComparator comparator) Constructs an empty population that maintains therankandcrowdingDistanceattributes for its solutions.NondominatedSortingPopulation(DominanceComparator comparator, Iterable<? extends Solution> iterable) Constructs a population initialized with the specified solutions that maintains therankandcrowdingDistanceattributes for its solutions. - 
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds the specified solution to this population.voidclear()Removes all solutions from this population.copy()Returns a copy of this population.get(int index) Returns the solution at the specified index in this population.Returns the dominance comparator used by this non-dominated population.iterator()Returns an iterator for accessing the solutions in this population.voidloadState(ObjectInputStream stream) Loads the state of this object from the stream.voidprune(int size) Prunes the population to the specified size.voidremove(int index) Removes the solution at the specified index from this population.booleanRemoves the specified solution from this population, if present.voidReplaces the solution at the given index.voidsaveState(ObjectOutputStream stream) Writes the state of this object to the stream.voidsort(Comparator<? super Solution> comparator) Sorts the solutions in this population using the specified comparator.voidtruncate(int size) Equivalent to callingtruncate(size, new NondominatedSortingComparator()).voidtruncate(int size, Comparator<? super Solution> comparator) Sorts this population using the specified comparator and removes the last (maximum) solutions until this population's size is within the specified size.voidupdate()Updates the rank and crowding distance of all solutions in this population.Methods inherited from class org.moeaframework.core.population.Population
addAll, addAll, asList, asTabularData, contains, containsAll, containsAll, filter, getLowerBounds, getUpperBounds, indexOf, isEmpty, load, load, removeAll, removeAll, removeAll, save, save, sizeMethods 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 
- 
Constructor Details
- 
NondominatedSortingPopulation
public NondominatedSortingPopulation()Constructs an empty population that maintains therankandcrowdingDistanceattributes for its solutions. - 
NondominatedSortingPopulation
Constructs an empty population that maintains therankandcrowdingDistanceattributes for its solutions.- Parameters:
 comparator- the dominance comparator
 - 
NondominatedSortingPopulation
public NondominatedSortingPopulation(DominanceComparator comparator, Iterable<? extends Solution> iterable) Constructs a population initialized with the specified solutions that maintains therankandcrowdingDistanceattributes for its solutions.- Parameters:
 comparator- the dominance comparatoriterable- the solutions used to initialize this population
 - 
NondominatedSortingPopulation
Constructs a population initialized with the specified solutions that maintains therankandcrowdingDistanceattributes for its solutions.- Parameters:
 iterable- the solutions used to initialize this population
 
 - 
 - 
Method Details
- 
getComparator
Returns the dominance comparator used by this non-dominated population.- Returns:
 - the dominance comparator
 
 - 
add
Description copied from class:PopulationAdds the specified solution to this population.- Overrides:
 addin classPopulation- Parameters:
 solution- the solution to be added- Returns:
 trueif the population was modified as a result of this method;falseotherwise.
 - 
replace
Description copied from class:PopulationReplaces the solution at the given index.- Overrides:
 replacein classPopulation- Parameters:
 index- the index to replacesolution- the new solution
 - 
get
Description copied from class:PopulationReturns the solution at the specified index in this population.- Overrides:
 getin classPopulation- Parameters:
 index- the index of the solution to be returned- Returns:
 - the solution at the specified index
 
 - 
remove
public void remove(int index) Description copied from class:PopulationRemoves the solution at the specified index from this population.- Overrides:
 removein classPopulation- Parameters:
 index- the index of the solution to be removed
 - 
remove
Description copied from class:PopulationRemoves the specified solution from this population, if present.- Overrides:
 removein classPopulation- Parameters:
 solution- the solution to be removed- Returns:
 trueif this population was modified as a result of this method;falseotherwise
 - 
clear
public void clear()Description copied from class:PopulationRemoves all solutions from this population.- Overrides:
 clearin classPopulation
 - 
iterator
Description copied from class:PopulationReturns an iterator for accessing the solutions in this population.- Specified by:
 iteratorin interfaceIterable<Solution>- Overrides:
 iteratorin classPopulation
 - 
sort
Description copied from class:PopulationSorts the solutions in this population using the specified comparator. Invocations of certain methods on this population may alter the ordering of solutions, so theget,removeand iteration methods should be called immediately after invoking this method.- Overrides:
 sortin classPopulation- Parameters:
 comparator- the comparator to be used for sorting
 - 
truncate
Description copied from class:PopulationSorts this population using the specified comparator and removes the last (maximum) solutions until this population's size is within the specified size.- Overrides:
 truncatein classPopulation- Parameters:
 size- the target population size after truncationcomparator- the comparator to be used for truncation
 - 
truncate
public void truncate(int size) Equivalent to callingtruncate(size, new NondominatedSortingComparator()).- Parameters:
 size- the target population size after truncation
 - 
prune
public void prune(int size) Prunes the population to the specified size. This is similar totruncate(int), except the crowding distance is recalculated each time a solution is removed.- Parameters:
 size- the target population size after pruning
 - 
update
public void update()Updates the rank and crowding distance of all solutions in this population. This method will in general be called automatically when the population is modified. However, only changes made to this population can be tracked; changes made directly to the contained solutions will not be detected. Therefore, it may be necessary to invokeupdate()manually. - 
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 classPopulation- Returns:
 - the copy of this population
 
 - 
saveState
Description copied from interface:StatefulWrites the state of this object to the stream. The order that objects are written to the stream is important. We recommend first callingsuper.saveState(stream)followed by writing each field.- Specified by:
 saveStatein interfaceStateful- Overrides:
 saveStatein classPopulation- Parameters:
 stream- the stream- Throws:
 IOException- if an I/O error occurred
 - 
loadState
Description copied from interface:StatefulLoads the state of this object from the stream. The order for reading objects from the stream must match the order they are written to the stream inStateful.saveState(ObjectOutputStream).- Specified by:
 loadStatein interfaceStateful- Overrides:
 loadStatein classPopulation- Parameters:
 stream- the stream- Throws:
 IOException- if an I/O error occurredClassNotFoundException- if the stream referenced a class that is not defined
 
 -