Class NondominatedSortingPopulation

java.lang.Object
org.moeaframework.core.Population
org.moeaframework.core.NondominatedSortingPopulation
All Implemented Interfaces:
Iterable<Solution>, Stateful, Displayable, Formattable<Solution>
Direct Known Subclasses:
ReferencePointNondominatedSortingPopulation

public class NondominatedSortingPopulation extends Population
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 Details

    • NondominatedSortingPopulation

      public NondominatedSortingPopulation()
      Constructs an empty population that maintains the rank and crowdingDistance attributes for its solutions.
    • NondominatedSortingPopulation

      public NondominatedSortingPopulation(DominanceComparator comparator)
      Constructs an empty population that maintains the rank and crowdingDistance attributes 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 the rank and crowdingDistance attributes for its solutions.
      Parameters:
      comparator - the dominance comparator
      iterable - the solutions used to initialize this population
    • NondominatedSortingPopulation

      public NondominatedSortingPopulation(Iterable<? extends Solution> iterable)
      Constructs a population initialized with the specified solutions that maintains the rank and crowdingDistance attributes for its solutions.
      Parameters:
      iterable - the solutions used to initialize this population
  • Method Details

    • getComparator

      public DominanceComparator getComparator()
      Returns the dominance comparator used by this non-dominated population.
      Returns:
      the dominance comparator
    • add

      public boolean add(Solution solution)
      Description copied from class: Population
      Adds the specified solution to this population.
      Overrides:
      add in class Population
      Parameters:
      solution - the solution to be added
      Returns:
      true if the population was modified as a result of this method; false otherwise.
    • replace

      public void replace(int index, Solution solution)
      Description copied from class: Population
      Replaces the solution at the given index.
      Overrides:
      replace in class Population
      Parameters:
      index - the index to replace
      solution - the new solution
    • get

      public Solution get(int index)
      Description copied from class: Population
      Returns the solution at the specified index in this population.
      Overrides:
      get in class Population
      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: Population
      Removes the solution at the specified index from this population.
      Overrides:
      remove in class Population
      Parameters:
      index - the index of the solution to be removed
    • remove

      public boolean remove(Solution solution)
      Description copied from class: Population
      Removes the specified solution from this population, if present.
      Overrides:
      remove in class Population
      Parameters:
      solution - the solution to be removed
      Returns:
      true if this population was modified as a result of this method; false otherwise
    • clear

      public void clear()
      Description copied from class: Population
      Removes all solutions from this population.
      Overrides:
      clear in class Population
    • iterator

      public Iterator<Solution> iterator()
      Description copied from class: Population
      Returns an iterator for accessing the solutions in this population.
      Specified by:
      iterator in interface Iterable<Solution>
      Overrides:
      iterator in class Population
    • sort

      public void sort(Comparator<? super Solution> comparator)
      Description copied from class: Population
      Sorts the solutions in this population using the specified comparator. Invocations of certain methods on this population may alter the ordering of solutions, so the get, remove and iteration methods should be called immediately after invoking this method.
      Overrides:
      sort in class Population
      Parameters:
      comparator - the comparator to be used for sorting
    • truncate

      public void truncate(int size, Comparator<? super Solution> comparator)
      Description copied from class: Population
      Sorts this population using the specified comparator and removes the last (maximum) solutions until this population's size is within the specified size.
      Overrides:
      truncate in class Population
      Parameters:
      size - the target population size after truncation
      comparator - the comparator to be used for truncation
    • truncate

      public void truncate(int size)
      Equivalent to calling truncate(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 to truncate(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 invoke update() manually.
    • saveState

      public void saveState(ObjectOutputStream stream) throws IOException
      Description copied from interface: Stateful
      Writes the state of this object to the stream. The order that objects are written to the stream is important. We recommend first calling super.saveState(stream) followed by writing each field.
      Specified by:
      saveState in interface Stateful
      Overrides:
      saveState in class Population
      Parameters:
      stream - the stream
      Throws:
      IOException - if an I/O error occurred
    • loadState

      public void loadState(ObjectInputStream stream) throws IOException, ClassNotFoundException
      Description copied from interface: Stateful
      Loads 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 in Stateful.saveState(ObjectOutputStream).
      Specified by:
      loadState in interface Stateful
      Overrides:
      loadState in class Population
      Parameters:
      stream - the stream
      Throws:
      IOException - if an I/O error occurred
      ClassNotFoundException - if the stream referenced a class that is not defined