Skip to content

Instantly share code, notes, and snippets.

@optozorax
Created February 23, 2020 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save optozorax/7e96e26b84e4a3535926af4559293c75 to your computer and use it in GitHub Desktop.
Save optozorax/7e96e26b84e4a3535926af4559293c75 to your computer and use it in GitHub Desktop.
spiril.rs
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