implement inversion_mutation
This commit is contained in:
@@ -192,6 +192,26 @@ swap_mutation :: proc(chrom: ^Chromosome) {
|
||||
bit_array.set(chrom, idx2, bit1)
|
||||
}
|
||||
|
||||
inversion_mutation :: proc(chrom: ^Chromosome) {
|
||||
point1 := rand.int_max(NUMBER_OF_ITEMS)
|
||||
point2 := rand.int_max(NUMBER_OF_ITEMS)
|
||||
|
||||
if point1 > point2 {
|
||||
point1, point2 = point2, point1
|
||||
}
|
||||
|
||||
for i in 0 ..< (point2 - point1) / 2 {
|
||||
idx1 := point1 + i
|
||||
idx2 := point2 - i - 1
|
||||
|
||||
bit1 := bit_array.get(chrom, idx1)
|
||||
bit2 := bit_array.get(chrom, idx2)
|
||||
|
||||
bit_array.set(chrom, idx1, bit2)
|
||||
bit_array.set(chrom, idx2, bit1)
|
||||
}
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
items, ok := read_data(DATA_FILE)
|
||||
if !ok {
|
||||
|
||||
Reference in New Issue
Block a user