From 8ca904fc0a2014d1b7b22d50cd1b53af985d7bb2 Mon Sep 17 00:00:00 2001 From: Fredrik Robertsen Date: Sat, 31 Jan 2026 15:55:51 +0100 Subject: [PATCH] fix penalty bug --- src/main.odin | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/src/main.odin b/src/main.odin index 6545ac7..dc7e8e8 100644 --- a/src/main.odin +++ b/src/main.odin @@ -38,14 +38,6 @@ read_data :: proc(file: string) -> (res: [NUMBER_OF_ITEMS]Item, ok := true) { Chromosome :: bit_array.Bit_Array -distance :: proc(x, y: int) -> int { - return math.abs(x - y) -} - -penalize :: proc(d: int) -> int { - return math.min(d, 0) -} - // side-effect: reads global `items` fitness :: proc(chrom: ^Chromosome) -> int { tot_profit, tot_weight := 0, 0 @@ -54,7 +46,7 @@ fitness :: proc(chrom: ^Chromosome) -> int { tot_profit += items[idx].profit tot_weight += items[idx].weight } - return tot_profit + penalize(distance(tot_weight, CAPACITY)) + return tot_profit - 3 * math.max(tot_weight - CAPACITY, 0) } Population :: [POPULATION_SIZE]Chromosome