Fmt.
This commit is contained in:
2018-02-16 12:04:33 +01:00
parent 849c0aacb0
commit 95f67eedf7
4 changed files with 42 additions and 57 deletions

View File

@@ -1,8 +1,8 @@
#[macro_use]
extern crate criterion;
extern crate genetisk;
extern crate rand;
extern crate rayon;
extern crate genetisk;
use std::cmp::Ordering;
@@ -10,7 +10,7 @@ use criterion::Criterion;
use rand::distributions::{IndependentSample, Range};
use rayon::prelude::*;
use genetisk::{Individual, Wrapper, Simulation};
use genetisk::{Individual, Simulation, Wrapper};
#[derive(Clone, Copy, Debug)]
struct Fitness(f64);
@@ -35,7 +35,6 @@ impl Ord for Fitness {
}
}
#[derive(Clone, Debug)]
struct Parabole {
x: f64,
@@ -45,7 +44,9 @@ impl Individual for Parabole {
type Fitness = Fitness;
fn mate(&self, other: &Parabole) -> Parabole {
Parabole { x: (self.x + other.x) / 2.0 }
Parabole {
x: (self.x + other.x) / 2.0,
}
}
fn mutate(&mut self) {
@@ -102,13 +103,13 @@ fn criterion_benchmark(c: &mut Criterion) {
.take(5),
)
.map(|(a, b)| a.individual.mate(&b.individual))
.map(|individual| {
Wrapper {
individual: individual,
fitness: None,
}
.map(|individual| Wrapper {
individual: individual,
fitness: None,
})
.for_each(|wrapper| { population.push(wrapper); });
.for_each(|wrapper| {
population.push(wrapper);
});
// Mutate all to get new children.
parents