From a05bdc4c03cb5c25c788a9af11b52993ba929a00 Mon Sep 17 00:00:00 2001 From: mos Date: Wed, 13 Nov 2024 14:39:38 +0100 Subject: [PATCH] rewrite ratio to evaluate only once --- src/lib.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 6dc7bc7..32f5807 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -380,10 +380,9 @@ impl Agent { } fn cross(&mut self, seed: &Self, cr: usize) { - let ratio = rnd!(cr) + 1; - let len = self.dna.len(); + let ratio = self.dna.len() / (rnd!(cr) + 1); - self.dna[..len / ratio].copy_from_slice(&seed.dna[..len / ratio]); + self.dna[..ratio].copy_from_slice(&seed.dna[..ratio]); } fn mutate(&mut self, max: usize) {