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,15 +1,13 @@
extern crate genetisk;
extern crate rand;
extern crate rayon;
extern crate genetisk;
use std::cmp::Ordering;
use rand::distributions::{IndependentSample, Range};
use rayon::prelude::*;
use genetisk::{Individual, Wrapper, MaximizeSelector, MinimizeSelector, Select, Simulation};
use genetisk::{Individual, MaximizeSelector, MinimizeSelector, Select, Simulation, Wrapper};
#[derive(Clone, Copy, Debug)]
struct Fitness(f64);
@@ -34,7 +32,6 @@ impl Ord for Fitness {
}
}
#[derive(Clone, Debug)]
struct Parabole {
x: f64,
@@ -44,7 +41,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) {
@@ -61,7 +60,6 @@ impl Individual for Parabole {
}
}
fn main() {
let initial = (0..300)
.map(|i| Parabole { x: i as f64 })
@@ -91,13 +89,13 @@ fn main() {
.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