The inbreeding is pretty simple. Each accessible byte from the first element is looped and the obtained byte is calculated as follows. If the same byte from the second element is mutation-resistant, we call on the mutation routine with a probability of 1/20. Otherwise, we use a 1/2 probability rate.
- Private Function Mutation(bt As Byte, rate As Byte) As Byte
- Randomize()
- Dim prob As Integer = Int(Rnd() * rate)
- If prob Mod rate = 0 Then
- Return _GACode(Int(Rnd() * (_GACode.Count - 1)))
- Else
- Return bt
- End If
- End Function
Mutation() takes place with a probability, if the mutation rate catches up, the specific byte is randomly extracted from the standard pool. Otherwise, the second element byte will be reproduced in the offspring. The loop through each generation/population for a single generation will eventually evolve towards the final (and expected) result.
This is only one of the methods that can be used to implement evolutive algorithms: each coder is the judge in defining what are the parameters to be called into question and what are the general rules to solve a specific problem.
In our case, as long as it can bring valid results, other kinds of approaches are possible.
Sample video
A sample running session could be seen here: g6JebAjtWQ
Download source code
Bibliography