Class ParetoFront<T>

java.lang.Object
java.util.AbstractCollection<E>
java.util.AbstractSet<T>
io.jenetics.ext.moea.ParetoFront<T>
All Implemented Interfaces:
Iterable<T>, Collection<T>, Set<T>

public final class ParetoFront<T> extends AbstractSet<T>
This class only contains non-dominate (Pareto-optimal) elements according to a given dominance measure. Like a Set, it only contains no duplicate entries. Unlike the usual set implementation, the iteration order is deterministic.

You can create a new ParetoFront for Vec objects

final ParetoFront<Vec<double[]>> front = new ParetoFront<>(Vec::dominance); front.add(Vec.of(1.0, 2.0)); front.add(Vec.of(1.1, 2.5)); front.add(Vec.of(0.9, 2.1)); front.add(Vec.of(0.0, 2.9));
or directly for double[] array objects
final ParetoFront<double[]> front = new ParetoFront<>(Pareto::dominance); front.add(new double[]{1.0, 2.0}); front.add(new double[]{1.1, 2.5}); front.add(new double[]{0.9, 2.1}); front.add(new double[]{0.0, 2.9});
You only have to specify the Pareto dominance/efficiency measure.
Since:
4.1
Version:
5.1
See Also:
API Note:
Inserting a new element has a time complexity of O(n).
  • Constructor Details

    • ParetoFront

      public ParetoFront(Comparator<? super T> dominance, BiPredicate<? super T,? super T> equals)
      Create a new ParetoSet with the given dominance measure.
      Parameters:
      dominance - the Pareto dominance measure
      equals - the equals predicate used for keeping the set distinct
      Throws:
      NullPointerException - if the given dominance measure is null
      Since:
      5.1
    • ParetoFront

      public ParetoFront(Comparator<? super T> dominance)
      Create a new ParetoSet with the given dominance measure.
      Parameters:
      dominance - the Pareto dominance measure
      Throws:
      NullPointerException - if the given dominance measure is null
  • Method Details

    • add

      public boolean add(T element)
      Inserts an element to this pareto front.
      Specified by:
      add in interface Collection<T>
      Specified by:
      add in interface Set<T>
      Overrides:
      add in class AbstractCollection<T>
      Parameters:
      element - the element to add
      Returns:
      true if this set did not already contain the specified element
      Implementation Note:
      Inserting a new element has a time complexity of O(this.size()), where n is the number of elements of this pareto-front.
    • addAll

      public boolean addAll(Collection<? extends T> elements)
      Adds all elements of the given collection to this pareto front.
      Specified by:
      addAll in interface Collection<T>
      Specified by:
      addAll in interface Set<T>
      Overrides:
      addAll in class AbstractCollection<T>
      Parameters:
      elements - the elements to add to this pareto front
      Returns:
      true if this pareto front has been changed, false otherwise
      Implementation Note:
      The runtime complexity of this operation is O(elements.size()*this.size()).
    • merge

      public ParetoFront<T> merge(ParetoFront<? extends T> elements)
      Add the all elements to this pareto-set.
      Parameters:
      elements - the elements to add
      Returns:
      this pareto-set
      Throws:
      NullPointerException - if the given parameter is null
      Implementation Note:
      Merging two pareto fronts has a time complexity of O(elements.size()*this.size()).
    • trim

      public ParetoFront<T> trim(int size, ElementComparator<? super T> comparator, ElementDistance<? super T> distance, ToIntFunction<? super T> dimension)
      Trims this pareto front to the given size. The front elements are sorted according to its crowding distance, and the elements which have smaller distance to its neighbors are removed first.
      final ParetoFront<Vec<double[]>> front = new ParetoFront<>(Vec::dominance); front.trim(10, Vec::compare, Vec::distance, Vec::length);
      The example above reduces the given front to 10 elements.
      Parameters:
      size - the number of front elements after the trim. If size() <= size, nothing is trimmed.
      comparator - the element comparator used for calculating the crowded distance
      distance - the element distance measure
      dimension - the number of vector elements of T
      Returns:
      this trimmed pareto front
      Throws:
      NullPointerException - if one of the objects is null
    • iterator

      public Iterator<T> iterator()
      Specified by:
      iterator in interface Collection<T>
      Specified by:
      iterator in interface Iterable<T>
      Specified by:
      iterator in interface Set<T>
      Specified by:
      iterator in class AbstractCollection<T>
    • size

      public int size()
      Specified by:
      size in interface Collection<T>
      Specified by:
      size in interface Set<T>
      Specified by:
      size in class AbstractCollection<T>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<T>
      Specified by:
      isEmpty in interface Set<T>
      Overrides:
      isEmpty in class AbstractCollection<T>
    • toISeq

      public ISeq<T> toISeq()
      Return the elements of this pareto-front as ISeq.
      Returns:
      the elements of this pareto-front as ISeq
    • toParetoFront

      public static <C extends Comparable<? super C>> Collector<C,?,ParetoFront<C>> toParetoFront()
      Return a pareto-front collector. The natural order of the elements is used as pareto-dominance order.
      Type Parameters:
      C - the element type
      Returns:
      a new pareto-front collector
    • toParetoFront

      public static <T> Collector<T,?,ParetoFront<T>> toParetoFront(Comparator<? super T> dominance)
      Return a pareto-front collector with the given pareto dominance measure.
      Type Parameters:
      T - the element type
      Parameters:
      dominance - the pareto dominance comparator
      Returns:
      a new pareto-front collector
      Throws:
      NullPointerException - if the given dominance collector is null