Package io.jenetics

Enum Class Optimize

All Implemented Interfaces:
Serializable, Comparable<Optimize>, Constable

public enum Optimize extends Enum<Optimize>
This enum determines whether the GA should maximize or minimize the fitness function.
Since:
1.0
Version:
6.2
  • Enum Constant Details

  • Method Details

    • values

      public static Optimize[] 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

      public static Optimize valueOf(String name)
      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 name
      NullPointerException - 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 is null-hostile. If you need to make it null-friendly, you can wrap it with the Comparator.nullsFirst(Comparator) method.

      final 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);
      
      or
      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 is null.
    • 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.

      final Population<DoubleGene, Double> population = ...;
      population.sort(Optimize.MINIMUM.<Double>descending());
      
      The code example above will populationSort the population according its fitness values in ascending order, since lower values are better in this case.
      Type Parameters:
      T - the type of the objects to compare.
      Returns:
      a new Comparator for the type T.
    • 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.

      final Population<DoubleGene, Double> population = ...;
      population.sort(Optimize.MINIMUM.<Double>ascending());
      
      The code example above will populationSort the population according its fitness values in descending order, since lower values are better in this case.
      Type Parameters:
      T - the type of the objects to compare.
      Returns:
      a new Comparator for the type T.
    • 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 is null
      See Also:
    • best

      public <C extends Comparable<? super C>> BinaryOperator<C> best()
      Return a null-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

      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 is null
      See Also:
    • worst

      public <C extends Comparable<? super C>> BinaryOperator<C> worst()
      Return a null-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: