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
ConstructorDescriptionParetoFront
(Comparator<? super T> dominance) Create a newParetoSet
with the givendominance
measure.ParetoFront
(Comparator<? super T> dominance, BiPredicate<? super T, ? super T> equals) Create a newParetoSet
with the givendominance
measure. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Inserts anelement
to this pareto front.boolean
addAll
(Collection<? extends T> elements) Adds all elements of the given collection tothis
pareto front.boolean
isEmpty()
iterator()
merge
(ParetoFront<? extends T> elements) Add the allelements
tothis
pareto-set.int
size()
toISeq()
Return the elements ofthis
pareto-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 paretodominance
measure.trim
(int size, ElementComparator<? super T> comparator, ElementDistance<? super T> distance, ToIntFunction<? super T> dimension) Trimsthis
pareto front to the given size.Methods inherited from class java.util.AbstractSet
equals, hashCode, removeAll
Methods inherited from class java.util.AbstractCollection
clear, contains, containsAll, remove, retainAll, toArray, toArray, toString
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.Set
clear, contains, containsAll, remove, retainAll, spliterator, toArray, toArray
-
Constructor Details
-
ParetoFront
Create a newParetoSet
with the givendominance
measure.- Parameters:
dominance
- the Pareto dominance measureequals
- the equals predicate used for keeping the set distinct- Throws:
NullPointerException
- if the givendominance
measure isnull
- Since:
- 5.1
-
ParetoFront
Create a newParetoSet
with the givendominance
measure.- Parameters:
dominance
- the Pareto dominance measure- Throws:
NullPointerException
- if the givendominance
measure isnull
-
-
Method Details
-
add
Inserts anelement
to this pareto front.- Specified by:
add
in interfaceCollection<T>
- Specified by:
add
in interfaceSet<T>
- Overrides:
add
in classAbstractCollection<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 ofthis
pareto-front.
-
addAll
Adds all elements of the given collection tothis
pareto front.- Specified by:
addAll
in interfaceCollection<T>
- Specified by:
addAll
in interfaceSet<T>
- Overrides:
addAll
in classAbstractCollection<T>
- Parameters:
elements
- the elements to add tothis
pareto front- Returns:
true
ifthis
pareto front has been changed,false
otherwise- Implementation Note:
- The runtime complexity of this operation is
O(elements.size()*this.size())
.
-
merge
Add the allelements
tothis
pareto-set.- Parameters:
elements
- the elements to add- Returns:
this
pareto-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) Trimsthis
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);
- 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:
this
trimmed pareto front- Throws:
NullPointerException
- if one of the objects isnull
-
iterator
-
size
- Specified by:
size
in interfaceCollection<T>
- Specified by:
size
in interfaceSet<T>
- Specified by:
size
in classAbstractCollection<T>
-
isEmpty
- Specified by:
isEmpty
in interfaceCollection<T>
- Specified by:
isEmpty
in interfaceSet<T>
- Overrides:
isEmpty
in classAbstractCollection<T>
-
toISeq
Return the elements ofthis
pareto-front asISeq
.- Returns:
- the elements of
this
pareto-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 paretodominance
measure.- Type Parameters:
T
- the element type- Parameters:
dominance
- the pareto dominance comparator- Returns:
- a new pareto-front collector
- Throws:
NullPointerException
- if the givendominance
collector isnull
-