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) {
|
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) {
|
||||||
|
|
Loading…
Reference in New Issue