Class FitnessVector<T extends Comparable<T>>

java.lang.Object
net.bmahe.genetics4j.moo.FitnessVector<T>
Type Parameters:
T - the type of the fitness values, must be comparable
All Implemented Interfaces:
Comparable<FitnessVector<T>>

public class FitnessVector<T extends Comparable<T>> extends Object implements Comparable<FitnessVector<T>>
Represents a multi-objective fitness vector for multi-objective optimization (MOO).

A FitnessVector encapsulates multiple fitness values, each representing the quality of a solution in a different objective dimension. This is essential for multi-objective evolutionary algorithms like NSGA-II and SPEA-II where solutions are evaluated against multiple, often conflicting objectives.

The fitness vector provides:

  • Storage for multiple objective values
  • Custom comparators for each objective (minimization/maximization)
  • Pareto dominance comparison logic
  • Type-safe access to individual objective values

Pareto dominance comparison rules:

  • Vector A dominates B if A is better in all objectives
  • Vector A weakly dominates B if A is better or equal in all objectives and better in at least one
  • Vectors are non-dominated if neither dominates the other
See Also:
  • invalid reference
    net.bmahe.genetics4j.moo.nsga2
  • invalid reference
    net.bmahe.genetics4j.moo.spea2
  • ParetoUtils
  • Field Details

  • Constructor Details

    • FitnessVector

      public FitnessVector(Collection<T> _vector, Collection<Comparator<T>> _comparators)
      Creates a fitness vector with the specified values and comparators.
      Parameters:
      _vector - the fitness values for each objective
      _comparators - the comparators defining optimization direction for each objective
      Throws:
      IllegalArgumentException - if vectors are null, empty, or have different sizes
    • FitnessVector

      public FitnessVector(Collection<T> _vector)
      Creates a fitness vector with natural ordering for all objectives.

      All objectives will use natural ordering (ascending), which means smaller values are considered better (minimization).

      Parameters:
      _vector - the fitness values for each objective
      Throws:
      IllegalArgumentException - if vector is null or empty
    • FitnessVector

      public FitnessVector(T... _vector)
      Creates a fitness vector from variable arguments with natural ordering.
      Parameters:
      _vector - the fitness values for each objective
      Throws:
      IllegalArgumentException - if vector is empty
  • Method Details

    • dimensions

      public int dimensions()
      Returns the number of objectives in this fitness vector.
      Returns:
      the number of objectives
    • get

      public T get(int index)
      Returns the fitness value for the specified objective.
      Parameters:
      index - the index of the objective (0-based)
      Returns:
      the fitness value for the specified objective
      Throws:
      IllegalArgumentException - if index is out of bounds
    • getComparator

      public Comparator<T> getComparator(int index)
      Returns the comparator for the specified objective.
      Parameters:
      index - the index of the objective (0-based)
      Returns:
      the comparator defining optimization direction for the objective
      Throws:
      IllegalArgumentException - if index is out of bounds
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • compareTo

      public int compareTo(FitnessVector<T> o)
      Specified by:
      compareTo in interface Comparable<T extends Comparable<T>>
    • compare

      public static <U extends Comparable<U>> int compare(FitnessVector<U> fv1, FitnessVector<U> fv2)
      Compares two fitness vectors using Pareto dominance.

      This method implements Pareto dominance comparison:

      • Returns positive value if fv1 dominates fv2 (fv1 is better in all objectives)
      • Returns negative value if fv2 dominates fv1 (fv2 is better in all objectives)
      • Returns 0 if vectors are non-dominated (neither dominates the other)
      Type Parameters:
      U - the type of the fitness values
      Parameters:
      fv1 - the first fitness vector to compare
      fv2 - the second fitness vector to compare
      Returns:
      positive if fv1 dominates fv2, negative if fv2 dominates fv1, 0 if non-dominated
      Throws:
      IllegalArgumentException - if vectors are null or have different dimensions