Improve factory generation
This commit is contained in:
parent
0f8bf5000c
commit
ec869d4c18
7 changed files with 107 additions and 46 deletions
|
|
@ -31,10 +31,11 @@ impl Layouter for GeneticAlgorithm {
|
|||
}
|
||||
}
|
||||
}
|
||||
population.sort_by_key(|(_, s)| *s);
|
||||
|
||||
let mut best_result = population[0].clone();
|
||||
|
||||
for g in 0..self.generations {
|
||||
population.sort_by_key(|(_, s)| *s);
|
||||
|
||||
for i in 0..(self.population_size - self.population_keep - self.population_new) {
|
||||
loop {
|
||||
let parent = &population[i % self.population_keep].0;
|
||||
|
|
@ -71,11 +72,13 @@ impl Layouter for GeneticAlgorithm {
|
|||
}
|
||||
}
|
||||
|
||||
population.sort_by_key(|(_, s)| *s);
|
||||
if population[0].1 < best_result.1 {
|
||||
best_result = population[0].clone();
|
||||
}
|
||||
println!("completed generation {g}\nscore: {}", population[0].1);
|
||||
}
|
||||
|
||||
population.sort_by_key(|(_, s)| *s);
|
||||
|
||||
population.into_iter().next().map(|(l, _)| l)
|
||||
Some(best_result.0)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ pub struct LayoutInput {
|
|||
pub connections: Vec<Connection>,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct LayoutResult {
|
||||
pub size: Position,
|
||||
pub positions: Vec<Block>,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue