rewrite ratio to evaluate only once

This commit is contained in:
mos 2024-11-13 14:39:38 +01:00
parent ed4d53979b
commit a05bdc4c03
1 changed files with 2 additions and 3 deletions

View File

@ -380,10 +380,9 @@ impl Agent {
} }
fn cross(&mut self, seed: &Self, cr: usize) { fn cross(&mut self, seed: &Self, cr: usize) {
let ratio = rnd!(cr) + 1; let ratio = self.dna.len() / (rnd!(cr) + 1);
let len = self.dna.len();
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) { fn mutate(&mut self, max: usize) {