public class BitString extends Object implements Chromosome
Crossover rate determines how often will be crossover performed. If there is no crossover, offspring is exact copy of parents. If there is a crossover, offspring is made from parts of parents' chromosome. If crossover rate is 100%, then all offspring is made by crossover. If it is 0%, whole new generation is made from exact copies of chromosomes from old population. However, it this does not mean that the new generation is the same because of mutation. Crossover is made in hope that new chromosomes will have good parts of old chromosomes and maybe the new chromosomes will be better. However it is good to leave some part of population survive to next generation. Crossover rate generally should be high, about 80% - 95%. However some results show that for some problems crossover rate about 60% is the best.
Mutation rate determines how often will be parts of chromosome mutated. If there is no mutation, offspring is taken after crossover (or copy) without any change. If mutation is performed, part of chromosome is changed. Mutation is made to prevent falling GA into local extreme, but it should not occur very often, because then GA will in fact change to random search. Best rates reported are about 0.5% - 1%.
Modifier and Type | Class and Description |
---|---|
static class |
BitString.Crossover
The types of crossover operation.
|
Modifier and Type | Field and Description |
---|---|
int |
length
The length of chromosome.
|
Constructor and Description |
---|
BitString(int[] bits,
FitnessMeasure<BitString> measure)
Constructor.
|
BitString(int[] bits,
FitnessMeasure<BitString> measure,
BitString.Crossover crossover,
double crossoverRate,
double mutationRate)
Constructor.
|
BitString(int length,
FitnessMeasure<BitString> measure)
Constructor.
|
BitString(int length,
FitnessMeasure<BitString> measure,
BitString.Crossover crossover,
double crossoverRate,
double mutationRate)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
int[] |
bits()
Returns the bit string of chromosome.
|
int |
compareTo(Chromosome o) |
BitString[] |
crossover(Chromosome another)
Returns a pair of offsprings by crossovering this one with another one
according to the crossover rate, which determines how often will be
crossover performed.
|
double |
fitness()
Returns the fitness of chromosome.
|
void |
mutate()
For genetic algorithms, this method mutates the chromosome randomly.
|
BitString |
newInstance()
Returns a new random instance.
|
public BitString(int length, FitnessMeasure<BitString> measure)
length
- the length of bit string.measure
- the fitness measure.public BitString(int length, FitnessMeasure<BitString> measure, BitString.Crossover crossover, double crossoverRate, double mutationRate)
length
- the length of bit string.measure
- the fitness measure.crossover
- the strategy of crossover operation.crossoverRate
- the crossover rate.mutationRate
- the mutation rate.public BitString(int[] bits, FitnessMeasure<BitString> measure)
bits
- the bit string of chromosome.measure
- the fitness measure.public BitString(int[] bits, FitnessMeasure<BitString> measure, BitString.Crossover crossover, double crossoverRate, double mutationRate)
bits
- the bit string of chromosome.measure
- the fitness measure.crossover
- the strategy of crossover operation.crossoverRate
- the crossover rate.mutationRate
- the mutation rate.public int[] bits()
public int compareTo(Chromosome o)
compareTo
in interface Comparable<Chromosome>
public double fitness()
Chromosome
fitness
in interface Chromosome
public BitString newInstance()
Chromosome
newInstance
in interface Chromosome
public BitString[] crossover(Chromosome another)
Chromosome
crossover
in interface Chromosome
public void mutate()
Chromosome
mutate
in interface Chromosome
Copyright © 2015. All rights reserved.