Randomly mutates the bits in the object. The method steps through all of the bits of the object. For each bit, the Mutate method has a chance (based on the MutationProbability) to flip the bit, e.g., from True to False, or from False to True. If any bits are mutated, the method returns True.
Namespace: RSGeneticAlgorithm
Delphi
|
public
function Mutate( MutationProbability: TGAProbability ): Boolean;
|
Parameters
MutationProbability
Type: TGAProbability
Return Value
Type: Boolean
The following code modifies a child based on CrossOver, Mutation, and Inversion:
Delphi
|
procedure Reproduce(Parent1, Parent2, Child: TRSGAIndividual);
begin
Child.Assign(Parent1);
// crossover
if (goCrossover in Operations) and (Random < CrossoverProbability) then
Child.Crossover( Parent1, Parent2, Random(Child1.Bits.Size) );
// mutate
if goMutate in Operations then
Child.Bits.Mutate(MutationProbability);
// invert
if (goInvert in Operations) and (Random < InversionProbability) then
Child.Bits.Invert;
end;
|
|