Rubicite Genetic Algorith Framework Tutorial
General:
Basic Info
Selection Bias
Hard Problem
Downloads
Crossovers:
Cycle
Order X
Order 1
Edge Recombination
PMX Crossover
Order Multiple
Direct Insertion
Mutations:
Inversion
Random Slide
Insertion
Single Swap
Random Swap
Scramble
Crossover Technique:
Direct Insertion
VB.NET 2008 Source Code
Public Sub OrderSingleCrossover(ByRef Child As PChromo, ByRef Parent1 As PChromo, ByRef Parent2 As PChromo) Dim counter1, counter2 As Integer Dim CityTotal = AlleleCount - 1 Dim TempSeedPositionsMainC As New OrderMultipleCollection1 Dim AmountofSwaths As Integer = RAND.Next(0.3 * CityTotal, 0.7 * CityTotal) 'amount of swaths to create Dim Swaths(AmountofSwaths - 1) As Integer Dim Done As Boolean = False Dim TempSwathSize As Integer = 0 Dim MaxSwathSize As Integer = AmountofSwaths * 2.5 'max swath size Dim SwathHashTable1 As New Hashtable 'stack 'Dim P2Stack As New Stack Dim P2Queue As New Queue 'Determines where all the seeds start For counter1 = 0 To AmountofSwaths - 1 Swaths(counter1) = RAND.Next(0, CityTotal) 'If hashtable does not contain parent1.value then its ok to start another seed at this location If (SwathHashTable1.ContainsKey(Parent1.Alleles(Swaths(counter1))) = False) Then TempSwathSize = RAND.Next(1, MaxSwathSize) SwathHashTable1.Add(Parent1.Alleles(Swaths(counter1)), Nothing) Else 'Else, randomizer chose an already chosen location... so try for another While (Done = False) Swaths(counter1) = RAND.Next(0, CityTotal) If (SwathHashTable1.ContainsKey(Parent1.Alleles(Swaths(counter1))) = False) Then TempSwathSize = RAND.Next(1, MaxSwathSize) SwathHashTable1.Add(Parent1.Alleles(Swaths(counter1)), Nothing) Done = True End If End While End If Next 'move down parent 1 values For counter1 = 0 To CityTotal 'this moves down parent 1 values to child If (SwathHashTable1.Contains(Parent1.Alleles(counter1))) Then Child.Alleles(counter1) = Parent1.Alleles(counter1) Else Child.Alleles(counter1) = -1 End If 'this sets which values of parent 2 to use If (SwathHashTable1.ContainsKey(Parent2.Alleles(counter1)) = False) Then P2Queue.Enqueue(Parent2.Alleles(counter1)) End If Next 'move down parent2 values to child For counter1 = 0 To CityTotal If (Child.Alleles(counter1) = -1) Then Child.Alleles(counter1) = P2Queue.Dequeue() End If Next 'Check for errors here... disable if no checking (comment out) 'OrderMultipleAndSingleChecker(Child, Parent1, Parent2, CityTotal, SwathHashTable1) End Sub
© 2008/2009 Rubicite Interactive Inc.