Genetic Algorithm Info

Crossover Operators

Mutation Operators

Scramble Mutation Operator

'Default Float 0 is "0.01" and represents Minimum Swath Size. Valid Values are [0, 0.75]
'Default Float 0 is "0.53" and represents Maximum Swath Size. Valid Values are [0, 0.75]

'If randswapsize is less than 2, we force it to be 2 so that a scramble happens each time
Public Sub Scramble_Mutation(ByRef Child As PChromo)

'X refers to the starting index of the first swap area
'Y refers to the starting index of the second swap area
'These areas are "randomwapsize" long
Dim counterscra As Integer = 0

Dim randswathsize As Integer = RAND.Next(Scramble_Master.Doubles(0) * AlleleCount, Scramble_Master.Doubles(1) * AlleleCount) 'Doubles(0) = Min Swath Size || Doubles(1) = Max Swath Size
If randswathsize < 2 Then randswathsize = 2

Dim X As Integer = RAND.Next(0, AlleleCount - randswathsize)

Dim K(randswathsize - 1) As Integer
Dim NewK(randswathsize - 1) As Integer

For counterscra = 0 To randswathsize - 1
K(counterscra) = Child.Alleles(X + counterscra)
Next
Dim TempK As Integer = 0
If (randswathsize <= 2) Then
TempK = K(0)
K(0) = K(1)
K(1) = TempK
End If
If (randswathsize > 2) Then
Dim done As Boolean = False

counterscra = 0
While (counterscra < randswathsize)
Dim swap1 = RAND.Next(0, randswathsize - 1)
Dim swap2 = RAND.Next(0, randswathsize - 1)
If (swap2 = swap1) Then
While (done = False)
swap2 = RAND.Next(0, randswathsize - 1)
If (swap2 <> swap1) Then
done = True
End If
End While
End If
TempK = K(swap1)
K(swap1) = K(swap2)
K(swap2) = TempK
counterscra += 1
End While
End If

For counterscra = 0 To randswathsize - 1
Child.Alleles(X + counterscra) = K(counterscra)
Next
End Sub