Class IntChromosomeSpec
java.lang.Object
net.bmahe.genetics4j.core.spec.chromosome.IntChromosomeSpec
- All Implemented Interfaces:
ChromosomeSpec
- Direct Known Subclasses:
ImmutableIntChromosomeSpec
Specification for integer array chromosomes in evolutionary algorithms.
IntChromosomeSpec defines the blueprint for creating chromosomes that represent solutions as arrays of integer values. This is one of the most commonly used chromosome types, suitable for discrete optimization problems, permutation problems, and integer programming.
The specification includes:
- Size: The number of integer genes in the chromosome
- Value range: Minimum and maximum bounds for each integer value
- Validation: Automatic constraint checking for valid parameters
Common use cases for integer chromosomes:
- Combinatorial optimization: Knapsack, bin packing, scheduling problems
- Parameter optimization: Integer hyperparameters, configuration values
- Permutation problems: Traveling salesman, job scheduling (with appropriate operators)
- Graph problems: Node selection, path optimization, network design
- Resource allocation: Assignment problems, load balancing
The integer values in the chromosome are constrained to the specified range [minValue, maxValue], inclusive on both ends. The genetic operators (crossover and mutation) respect these constraints and ensure that offspring remain within valid bounds.
Example usage:
// Create specification for 10 integers in range [0, 100]
IntChromosomeSpec spec = IntChromosomeSpec.of(10, 0, 100);
// Create specification for permutation of 20 items (values 0-19)
IntChromosomeSpec permutationSpec = IntChromosomeSpec.of(20, 0, 19);
// Use in EA configuration
EAConfiguration<Double> config = EAConfigurationBuilder.<Double>builder()
.chromosomeSpecs(spec)
.parentSelectionPolicy(Tournament.of(3))
.build();
- See Also:
-
Nested Class Summary
Nested Classes -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected void
check()
abstract int
maxValue()
Returns the maximum value (inclusive) for integer alleles in the chromosome.abstract int
minValue()
Returns the minimum value (inclusive) for integer alleles in the chromosome.static IntChromosomeSpec
of
(int size, int minValue, int maxValue) Creates a new integer chromosome specification with the given parameters.abstract int
size()
Returns the number of integer values in chromosomes created from this specification.
-
Constructor Details
-
IntChromosomeSpec
public IntChromosomeSpec()
-
-
Method Details
-
size
@Parameter public abstract int size()Returns the number of integer values in chromosomes created from this specification.- Returns:
- the chromosome size, always positive
-
minValue
@Parameter public abstract int minValue()Returns the minimum value (inclusive) for integer alleles in the chromosome.- Returns:
- the minimum allowed integer value
-
maxValue
@Parameter public abstract int maxValue()Returns the maximum value (inclusive) for integer alleles in the chromosome.- Returns:
- the maximum allowed integer value
-
check
@Check protected void check() -
of
Creates a new integer chromosome specification with the given parameters.- Parameters:
size
- the number of integer values in the chromosome, must be positiveminValue
- the minimum value (inclusive) for each integer in the chromosomemaxValue
- the maximum value (inclusive) for each integer in the chromosome- Returns:
- a new IntChromosomeSpec instance with the specified parameters
- Throws:
IllegalArgumentException
- if size is not positive or if minValue > maxValue
-