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) {