Created
February 23, 2020 07:35
-
-
Save optozorax/7e96e26b84e4a3535926af4559293c75 to your computer and use it in GitHub Desktop.
spiril.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use spiril::unit::Unit; | |
use spiril::population::Population; | |
struct Creature { | |
// Структура вашего существа | |
} | |
impl Unit for Creature { | |
fn fitness(&self) -> f64 { | |
// Вычисление пригодности | |
} | |
fn breed_with(&self, other: &Creature) -> Creature { | |
// Скрещивание | |
} | |
} | |
fn main() { | |
let units: Vec<Creature> = (0..1000) | |
.map(|_| { | |
// создание популяции | |
}) | |
.collect(); | |
// Вызов генетического алгоритма и его настройки | |
let result = Population::new(units) | |
.set_size(1000) | |
.set_breed_factor(0.3) | |
.set_survival_factor(0.5) | |
.epochs_parallel(5000, 4) // параллельно на 4 ядра | |
.finish() | |
.first() | |
.unwrap(); | |
// Вывод результата | |
println!("{:#?}", result); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment