From b5efeb06422db5c7d4f6dfceb921b8abf204c0fd Mon Sep 17 00:00:00 2001 From: Fredrik Robertsen Date: Sat, 31 Jan 2026 12:03:35 +0100 Subject: [PATCH] implement swap_mutation --- src/main.odin | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.odin b/src/main.odin index 0d551a1..cfb579d 100644 --- a/src/main.odin +++ b/src/main.odin @@ -181,6 +181,17 @@ bit_flip_mutation :: proc(chrom: ^Chromosome, mutation_rate: f32 = 0.01) { } } +swap_mutation :: proc(chrom: ^Chromosome) { + idx1 := rand.int_max(NUMBER_OF_ITEMS) + idx2 := rand.int_max(NUMBER_OF_ITEMS) + + 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 {