java.lang.Object
java.util.AbstractCollection<T>
java.util.AbstractSet<T>
io.jenetics.ext.moea.ParetoFront<T>
- All Implemented Interfaces:
Iterable<T>,Collection<T>,Set<T>
This class only contains non-dominate (Pareto-optimal) elements according to
a given dominance measure. Like a
or directly for
You only have to specify the
Pareto dominance/efficiency measure.
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));
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});
- Since:
- 4.1
- Version:
- 5.1
- See Also:
- API Note:
- Inserting a new element has a time complexity of
O(n).
-
Constructor Summary
ConstructorsConstructorDescriptionParetoFront(Comparator<? super T> dominance) Create a newParetoSetwith the givendominancemeasure.ParetoFront(Comparator<? super T> dominance, BiPredicate<? super T, ? super T> equals) Create a newParetoSetwith the givendominancemeasure. -
Method Summary
Modifier and TypeMethodDescriptionbooleanInserts anelementto this pareto front.booleanaddAll(Collection<? extends T> elements) Adds all elements of the given collection tothispareto front.booleanisEmpty()iterator()merge(ParetoFront<? extends T> elements) Add the allelementstothispareto-set.intsize()toISeq()Return the elements ofthispareto-front asISeq.static <C extends Comparable<? super C>>
Collector<C, ?, ParetoFront<C>> Return a pareto-front collector.static <T> Collector<T, ?, ParetoFront<T>> toParetoFront(Comparator<? super T> dominance) Return a pareto-front collector with the given paretodominancemeasure.trim(int size, ElementComparator<? super T> comparator, ElementDistance<? super T> distance, ToIntFunction<? super T> dimension) Trimsthispareto front to the given size.Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAllMethods inherited from class java.util.AbstractCollection
clear, contains, containsAll, remove, retainAll, toArray, toArray, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.Set
clear, contains, containsAll, remove, retainAll, spliterator, toArray, toArray
-
Constructor Details
-
ParetoFront
Create a newParetoSetwith the givendominancemeasure.- Parameters:
dominance- the Pareto dominance measureequals- the equals predicate used for keeping the set distinct- Throws:
NullPointerException- if the givendominancemeasure isnull- Since:
- 5.1
-
ParetoFront
Create a newParetoSetwith the givendominancemeasure.- Parameters:
dominance- the Pareto dominance measure- Throws:
NullPointerException- if the givendominancemeasure isnull
-
-
Method Details
-
add
Inserts anelementto this pareto front.- Specified by:
addin interfaceCollection<T>- Specified by:
addin interfaceSet<T>- Overrides:
addin classAbstractCollection<T>- Parameters:
element- the element to add- Returns:
trueif 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 ofthispareto-front.
-
addAll
Adds all elements of the given collection tothispareto front.- Specified by:
addAllin interfaceCollection<T>- Specified by:
addAllin interfaceSet<T>- Overrides:
addAllin classAbstractCollection<T>- Parameters:
elements- the elements to add tothispareto front- Returns:
trueifthispareto front has been changed,falseotherwise- Implementation Note:
- The runtime complexity of this operation is
O(elements.size()*this.size()).
-
merge
Add the allelementstothispareto-set.- Parameters:
elements- the elements to add- Returns:
thispareto-set- Throws:
NullPointerException- if the given parameter isnull- 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) Trimsthispareto 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.The example above reduces the given front to 10 elements.final ParetoFront<Vec<double[]>> front = new ParetoFront<>(Vec::dominance); front.trim(10, Vec::compare, Vec::distance, Vec::length);- Parameters:
size- the number of front elements after the trim. Ifsize() <= size, nothing is trimmed.comparator- the element comparator used for calculating the crowded distancedistance- the element distance measuredimension- the number of vector elements ofT- Returns:
thistrimmed pareto front- Throws:
NullPointerException- if one of the objects isnull
-
iterator
-
size
- Specified by:
sizein interfaceCollection<T>- Specified by:
sizein interfaceSet<T>- Specified by:
sizein classAbstractCollection<T>
-
isEmpty
- Specified by:
isEmptyin interfaceCollection<T>- Specified by:
isEmptyin interfaceSet<T>- Overrides:
isEmptyin classAbstractCollection<T>
-
toISeq
Return the elements ofthispareto-front asISeq.- Returns:
- the elements of
thispareto-front asISeq
-
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
Return a pareto-front collector with the given paretodominancemeasure.- Type Parameters:
T- the element type- Parameters:
dominance- the pareto dominance comparator- Returns:
- a new pareto-front collector
- Throws:
NullPointerException- if the givendominancecollector isnull
-