- All Implemented Interfaces:
Serializable
,Comparable<Optimize>
,Constable
This
enum
determines whether the GA should maximize or minimize the
fitness function.- Since:
- 1.0
- Version:
- 6.2
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
-
Method Summary
Modifier and TypeMethodDescription<T extends Comparable<? super T>>
Comparator<T>Create an appropriate comparator of the given optimization strategy.<C extends Comparable<? super C>>
BinaryOperator<C>best()
Return anull
-friendly function which returns the best element of two values.<C extends Comparable<? super C>>
Cbest
(C a, C b) Return the best value, according to this optimization direction.abstract <T extends Comparable<? super T>>
intcompare
(T a, T b) Compares two comparable objects.<T extends Comparable<? super T>>
Comparator<T>Create an appropriate comparator of the given optimization strategy.static Optimize
Returns the enum constant of this class with the specified name.static Optimize[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.<C extends Comparable<? super C>>
BinaryOperator<C>worst()
Return anull
-friendly function which returns the worst element of two values.<C extends Comparable<? super C>>
Cworst
(C a, C b) Return the worst value, according to this optimization direction.
-
Enum Constant Details
-
MINIMUM
GA minimization -
MAXIMUM
GA maximization
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
compare
Compares two comparable objects. Returns a negative integer, zero, or a positive integer as the first argument is better than, equal to, or worse than the second. This compare method isnull
-hostile. If you need to make itnull
-friendly, you can wrap it with theComparator.nullsFirst(Comparator)
method.orfinal Comparator<Integer> comparator = nullsFirst(Optimize.MAXIMUM::compare); assertEquals(comparator.compare(null, null), 0); assertEquals(comparator.compare(null, 4), -1); assertEquals(comparator.compare(4, null), 1);
final Comparator<Integer> comparator = nullsFirst(Optimize.MINIMUM::compare); assertEquals(comparator.compare(null, null), 0); assertEquals(comparator.compare(null, 4), -1); assertEquals(comparator.compare(4, null), 1);
- Type Parameters:
T
- the comparable type- Parameters:
a
- the first object to be compared.b
- the second object to be compared.- Returns:
- a negative integer, zero, or a positive integer as the first argument is better than, equal to, or worse than the second.
- Throws:
NullPointerException
- if one of the arguments isnull
.
-
descending
Create an appropriate comparator of the given optimization strategy. A collection of comparable objects with the returned comparator will be sorted in descending order, according to the given definition of better and worse.The code example above will populationSort the population according its fitness values in ascending order, since lower values are better in this case.final Population<DoubleGene, Double> population = ... population.sort(Optimize.MINIMUM.<Double>descending());
- Type Parameters:
T
- the type of the objects to compare.- Returns:
- a new
Comparator
for the typeT
.
-
ascending
Create an appropriate comparator of the given optimization strategy. A collection of comparable objects with the returned comparator will be sorted in ascending order, according to the given definition of better and worse.The code example above will populationSort the population according its fitness values in descending order, since lower values are better in this case.final Population<DoubleGene, Double> population = ... population.sort(Optimize.MINIMUM.<Double>ascending());
- Type Parameters:
T
- the type of the objects to compare.- Returns:
- a new
Comparator
for the typeT
.
-
best
Return the best value, according to this optimization direction.- Type Parameters:
C
- the fitness value type.- Parameters:
a
- the first value.b
- the second value.- Returns:
- the best value. If both values are equal, the first one is returned.
- Throws:
NullPointerException
- if one of the given arguments isnull
- See Also:
-
best
Return anull
-friendly function which returns the best element of two values. E.g.assertNull(Optimize.MAXIMUM.<Integer>best().apply(null, null)); assertEquals(Optimize.MAXIMUM.<Integer>best().apply(null, 4), (Integer)4); assertEquals(Optimize.MAXIMUM.<Integer>best().apply(6, null), (Integer)6);
- Type Parameters:
C
- the comparable argument type- Returns:
- a
null
-friendly method which returns the best element of two values - Since:
- 6.2
- See Also:
-
worst
Return the worst value, according to this optimization direction.- Type Parameters:
C
- the fitness value type.- Parameters:
a
- the first value.b
- the second value.- Returns:
- the worst value. If both values are equal, the first one is returned.
- Throws:
NullPointerException
- if one of the given arguments isnull
- See Also:
-
worst
Return anull
-friendly function which returns the worst element of two values. E.g.assertNull(Optimize.MAXIMUM.<Integer>worst().apply(null, null)); assertEquals(Optimize.MAXIMUM.<Integer>worst().apply(null, 4), (Integer)4); assertEquals(Optimize.MAXIMUM.<Integer>worst().apply(6, null), (Integer)6);
- Type Parameters:
C
- the comparable argument type- Returns:
- a
null
-friendly method which returns the worst element of two values - Since:
- 6.2
- See Also:
-