Record Class ChosenOtherChromosome
java.lang.Object
java.lang.Record
net.bmahe.genetics4j.neat.combination.parentcompare.ChosenOtherChromosome
- Record Components:
chosen
- the chromosome designated as "chosen" (typically fitter) for preferred inheritanceother
- the chromosome designated as "other" (typically less fit) for secondary inheritance
Represents the result of parent comparison during NEAT genetic crossover.
ChosenOtherChromosome is a simple record that encapsulates the result of comparing two parent chromosomes for NEAT crossover operations. It designates which parent should be considered "chosen" (typically the fitter parent) and which should be "other" for the purposes of biased gene inheritance.
Usage in NEAT crossover:
- Inheritance bias: Chosen parent typically contributes disjoint and excess genes
- Gene selection: Inheritance threshold applied relative to chosen parent
- Topology guidance: Chosen parent's structure often forms the offspring base
- Equal fitness handling: Both parents may be treated equally when fitness is identical
Parent role significance:
- Chosen parent: Usually the fitter parent, contributes more genes to offspring
- Other parent: Usually the less fit parent, contributes fewer genes
- Matching genes: Both parents can contribute genes with equal probability (biased)
- Gene re-enabling: Both parents considered for connection state decisions
Common usage patterns:
// Result of parent comparison
ChosenOtherChromosome comparison = parentHandler.compare(
policy, parent1, parent2, fitnessComparison
);
// Extract parents for crossover
NeatChromosome chosenParent = comparison.chosen();
NeatChromosome otherParent = comparison.other();
// Use in gene inheritance decisions
if (fitnessComparison != 0 || random.nextDouble() < inheritanceThreshold) {
// Inherit from chosen parent
inheritGene(chosenParent.getConnections().get(index));
} else {
// Inherit from other parent
inheritGene(otherParent.getConnections().get(index));
}
// Access parent properties
int numInputs = chosenParent.getNumInputs();
float minWeight = chosenParent.getMinWeightValue();
List<Connection> chosenConnections = chosenParent.getConnections();
List<Connection> otherConnections = otherParent.getConnections();
Immutability and value semantics:
- Immutable: Record provides immutability for safe passing between methods
- Value equality: Two instances are equal if both chosen and other chromosomes match
- Compact representation: Minimal memory overhead with clear semantic meaning
- Null safety: Both chromosomes are expected to be non-null in valid comparisons
Integration with comparison handlers:
- Return type: Standard return type for ParentComparisonHandler.compare()
- Type safety: Ensures correct parent roles in crossover operations
- Clear semantics: Eliminates confusion about which parent is which
- Consistent interface: All comparison handlers return same type
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final NeatChromosome
The field for thechosen
record component.private final NeatChromosome
The field for theother
record component. -
Constructor Summary
ConstructorsConstructorDescriptionChosenOtherChromosome
(NeatChromosome chosen, NeatChromosome other) Creates an instance of aChosenOtherChromosome
record class. -
Method Summary
Modifier and TypeMethodDescriptionchosen()
Returns the value of thechosen
record component.final boolean
Indicates whether some other object is "equal to" this one.final int
hashCode()
Returns a hash code value for this object.other()
Returns the value of theother
record component.final String
toString()
Returns a string representation of this record class.
-
Field Details
-
Constructor Details
-
Method Details
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
chosen
Returns the value of thechosen
record component.- Returns:
- the value of the
chosen
record component
-
other
Returns the value of theother
record component.- Returns:
- the value of the
other
record component
-