rewrite ratio to evaluate only once
This commit is contained in:
parent
ed4d53979b
commit
a05bdc4c03
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue