Skip to content

Commit

Permalink
Better implementation of niches when m is 0.
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin1887 committed Jan 13, 2021
1 parent c5eefa2 commit f3e2ce5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 26 deletions.
2 changes: 1 addition & 1 deletion oxigen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "oxigen"
version = "2.1.1"
version = "2.1.2"
authors = ["Martin1887 <marcos.martin.pozo.delgado@gmail.com>"]
description = "Fast, parallel, extensible and adaptable genetic algorithm library."
repository = "https://github.com/Martin1887/oxigen"
Expand Down
41 changes: 16 additions & 25 deletions oxigen/src/population_refitness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,35 +77,26 @@ impl<T: PartialEq + Send + Sync, G: Genotype<T>> PopulationRefitness<T, G>
let current_ind = &population[individual_index].ind;
let current_fitness = &population[individual_index].fitness;
let mut current_fitness = current_fitness.unwrap().original_fitness;
/*
let avg_sim: f64 = population
.par_iter()
.enumerate()
.filter(|(i, _ind)| *i != individual_index)
.map(|(_i, ind)| current_ind.similarity(&ind.0))
.sum::<f64>()
/ (population.len() as f64 - 1.0);
*/
let m = population
.par_iter()
.enumerate()
.filter(|(i, _ind)| *i != individual_index)
.map(|(_i, ind)| current_ind.distance(&ind.ind))
.map(|d| {
if d >= sigma.0 {
0.0
} else {
1.0 - (d / sigma.0).powf(alfa.0)
}
})
.sum::<f64>();
if current_fitness > 0.0 {
let mut m = population
.par_iter()
.enumerate()
.filter(|(i, _ind)| *i != individual_index)
.map(|(_i, ind)| current_ind.distance(&ind.ind))
.map(|d| {
if d >= sigma.0 {
0.0
} else {
1.0 - (d / sigma.0).powf(alfa.0)
}
})
.sum::<f64>();
current_fitness =
current_fitness.powf(beta.rate(generation, progress, n_solutions));
if m > 0.0 {
current_fitness /= m;
if m == 0.0 {
m = f64::EPSILON;
}
current_fitness
current_fitness / m
} else {
current_fitness
}
Expand Down

0 comments on commit f3e2ce5

Please sign in to comment.