Class DoubleTournament<T extends Comparable<T>>
java.lang.Object
net.bmahe.genetics4j.gp.spec.selection.DoubleTournament<T>
- Type Parameters:
T
- the fitness type, must be Comparable
- All Implemented Interfaces:
SelectionPolicy
- Direct Known Subclasses:
ImmutableDoubleTournament
@Immutable
public abstract class DoubleTournament<T extends Comparable<T>>
extends Object
implements SelectionPolicy
Double tournament selection strategy that combines fitness-based and parsimony-based selection to control bloat in
genetic programming and other evolutionary algorithms.
Double tournament selection operates in two modes:
- Fitness First Mode (default): Performs two independent fitness tournaments, then applies parsimony selection between the winners to select the less complex individual
- Parsimony First Mode: For each tournament candidate, performs parsimony selection on random pairs first, then selects the fittest among the parsimony winners
The parsimony tournament uses a probabilistic approach where the parsimony tournament size parameter controls the selection pressure toward less complex individuals:
- Size 0.0: Always selects randomly (no parsimony pressure)
- Size 1.0: Balanced selection between complexity preferences
- Size 2.0: Always selects the less complex individual
This selection method is particularly effective in genetic programming where it helps prevent code bloat while maintaining competitive fitness levels.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
check()
Validates that the parsimony tournament size is within the allowed range [0.0, 2.0].boolean
Determines the order of selection operations.abstract Tournament
<T> The fitness tournament configuration used for selecting individuals based on fitness.static <U extends Comparable<U>>
DoubleTournament<U> of
(Tournament<U> fitnessTournament, Comparator<Individual<U>> parsimonyComparator, double parsimonyTournamentSize) Creates a new DoubleTournament selection policy with fitness-first mode enabled.abstract Comparator
<Individual<T>> Comparator used to evaluate parsimony (complexity) between individuals.abstract double
Controls the selection pressure toward less complex individuals in parsimony tournaments.
-
Constructor Details
-
DoubleTournament
public DoubleTournament()
-
-
Method Details
-
fitnessTournament
The fitness tournament configuration used for selecting individuals based on fitness. This tournament determines how many candidates compete in each fitness-based selection round.- Returns:
- the tournament configuration for fitness-based selection
-
parsimonyComparator
Comparator used to evaluate parsimony (complexity) between individuals. Typically compares individuals based on size, depth, or other complexity metrics. The comparator should return:- Negative value if first individual is less complex than second
- Zero if both individuals have equal complexity
- Positive value if first individual is more complex than second
- Returns:
- the comparator for evaluating individual complexity
-
parsimonyTournamentSize
@Parameter public abstract double parsimonyTournamentSize()Controls the selection pressure toward less complex individuals in parsimony tournaments. Must be between 0.0 and 2.0 inclusive.- 0.0: No parsimony pressure, selection is random
- 1.0: Balanced parsimony pressure
- 2.0: Maximum parsimony pressure, always selects less complex individual
- Returns:
- the parsimony tournament size parameter
-
doFitnessFirst
@Default public boolean doFitnessFirst()Determines the order of selection operations.true
(default): Fitness first mode - perform fitness tournaments first, then apply parsimony selection between winnersfalse
: Parsimony first mode - apply parsimony selection to random pairs first, then perform fitness tournament among parsimony winners
- Returns:
- true for fitness-first mode, false for parsimony-first mode
-
check
@Check public void check()Validates that the parsimony tournament size is within the allowed range [0.0, 2.0].- Throws:
IllegalArgumentException
- if parsimony tournament size is outside valid range
-
of
public static <U extends Comparable<U>> DoubleTournament<U> of(Tournament<U> fitnessTournament, Comparator<Individual<U>> parsimonyComparator, double parsimonyTournamentSize) Creates a new DoubleTournament selection policy with fitness-first mode enabled.- Type Parameters:
U
- the fitness type, must be Comparable- Parameters:
fitnessTournament
- the tournament configuration for fitness-based selectionparsimonyComparator
- comparator for evaluating individual complexityparsimonyTournamentSize
- selection pressure parameter, must be between 0.0 and 2.0- Returns:
- a new DoubleTournament instance with the specified parameters
- Throws:
IllegalArgumentException
- if parsimony tournament size is outside valid range
-