Package io.jenetics
Enum Optimize
- java.lang.Object
-
- java.lang.Enum<Optimize>
-
- io.jenetics.Optimize
-
- All Implemented Interfaces:
Serializable
,Comparable<Optimize>
public enum Optimize extends Enum<Optimize>
Thisenum
determines whether the GA should maximize or minimize the fitness function.- Since:
- 1.0
- Version:
- 6.2
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description <T extends Comparable<? super T>>
Comparator<T>ascending()
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>descending()
Create an appropriate comparator of the given optimization strategy.static Optimize
valueOf(String name)
Returns the enum constant of this type with the specified name.static Optimize[]
values()
Returns an array containing the constants of this enum type, 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.
-
-
-
Method Detail
-
values
public static Optimize[] values()
Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:for (Optimize c : Optimize.values()) System.out.println(c);
- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
public static Optimize valueOf(String name)
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (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 type has no constant with the specified nameNullPointerException
- if the argument is null
-
compare
public abstract <T extends Comparable<? super T>> int compare(T a, T b)
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
public <T extends Comparable<? super T>> Comparator<T> 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 it's 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
public <T extends Comparable<? super T>> Comparator<T> 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 it's 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
public <C extends Comparable<? super C>> C best(C a, C b)
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()
-
best
public <C extends Comparable<? super C>> BinaryOperator<C> 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:
best(Comparable, Comparable)
-
worst
public <C extends Comparable<? super C>> C worst(C a, C b)
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()
-
worst
public <C extends Comparable<? super C>> BinaryOperator<C> 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:
worst(Comparable, Comparable)
-
-