Package net.bmahe.genetics4j.moo
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:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionFitnessVector(Collection<T> _vector) Creates a fitness vector with natural ordering for all objectives.FitnessVector(Collection<T> _vector, Collection<Comparator<T>> _comparators) Creates a fitness vector with the specified values and comparators.FitnessVector(T... _vector) Creates a fitness vector from variable arguments with natural ordering. -
Method Summary
Modifier and TypeMethodDescriptionstatic <U extends Comparable<U>>
intcompare(FitnessVector<U> fv1, FitnessVector<U> fv2) Compares two fitness vectors using Pareto dominance.intcompareTo(FitnessVector<T> o) intReturns the number of objectives in this fitness vector.booleanget(int index) Returns the fitness value for the specified objective.getComparator(int index) Returns the comparator for the specified objective.inthashCode()toString()
-
Field Details
-
fitnesses
-
comparators
-
-
Constructor Details
-
FitnessVector
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
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
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
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
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() -
equals
-
toString
-
compareTo
- Specified by:
compareToin interfaceComparable<T extends Comparable<T>>
-
compare
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 comparefv2- 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
-