refactor: ♻️ better naming for creating food source function
refactor: ♻️ name correction for employed bee
This commit is contained in:
parent
cca9a7a253
commit
8eda015039
3 changed files with 8 additions and 8 deletions
|
@ -4,7 +4,7 @@ use crate::food::FoodSource;
|
||||||
|
|
||||||
pub enum Bee {}
|
pub enum Bee {}
|
||||||
impl Bee {
|
impl Bee {
|
||||||
pub fn worker_bee(
|
pub fn employed_bee(
|
||||||
food_sources: &mut [FoodSource],
|
food_sources: &mut [FoodSource],
|
||||||
index: usize,
|
index: usize,
|
||||||
decision_variable_count: usize,
|
decision_variable_count: usize,
|
||||||
|
@ -31,7 +31,7 @@ impl Bee {
|
||||||
}
|
}
|
||||||
let mut candidate_coordinates = food_sources[index].coordinates.clone();
|
let mut candidate_coordinates = food_sources[index].coordinates.clone();
|
||||||
candidate_coordinates[selected_coordinate_index] = candidate_one_index;
|
candidate_coordinates[selected_coordinate_index] = candidate_one_index;
|
||||||
let candidate = FoodSource::get(candidate_coordinates);
|
let candidate = FoodSource::new(candidate_coordinates);
|
||||||
food_sources[index].try_counter += 1;
|
food_sources[index].try_counter += 1;
|
||||||
if candidate.fitness > food_sources[index].fitness {
|
if candidate.fitness > food_sources[index].fitness {
|
||||||
food_sources[index] = candidate;
|
food_sources[index] = candidate;
|
||||||
|
@ -49,7 +49,7 @@ impl Bee {
|
||||||
) {
|
) {
|
||||||
let fitness_for_index = food_sources[index].fitness;
|
let fitness_for_index = food_sources[index].fitness;
|
||||||
if fitness_for_index / total_fitness <= rand::thread_rng().gen_range(0.0..=1.0) {
|
if fitness_for_index / total_fitness <= rand::thread_rng().gen_range(0.0..=1.0) {
|
||||||
Self::worker_bee(
|
Self::employed_bee(
|
||||||
food_sources,
|
food_sources,
|
||||||
index,
|
index,
|
||||||
decision_variable_count,
|
decision_variable_count,
|
||||||
|
@ -74,7 +74,7 @@ impl Bee {
|
||||||
+ rand::thread_rng().gen_range(0.0..=1.0) * (upper_bound - lower_bound);
|
+ rand::thread_rng().gen_range(0.0..=1.0) * (upper_bound - lower_bound);
|
||||||
coordinates_for_new.push(random);
|
coordinates_for_new.push(random);
|
||||||
}
|
}
|
||||||
let new_food_source = FoodSource::get(coordinates_for_new);
|
let new_food_source = FoodSource::new(coordinates_for_new);
|
||||||
food_sources[most_tried_index] = new_food_source;
|
food_sources[most_tried_index] = new_food_source;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ pub struct FoodSource {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FoodSource {
|
impl FoodSource {
|
||||||
pub fn get(coordinates: Vec<f64>) -> Self {
|
pub fn new(coordinates: Vec<f64>) -> Self {
|
||||||
let mut food_source = FoodSource {
|
let mut food_source = FoodSource {
|
||||||
fitness: 0.0,
|
fitness: 0.0,
|
||||||
function_calculation: 0.0,
|
function_calculation: 0.0,
|
||||||
|
@ -55,7 +55,7 @@ impl FoodSource {
|
||||||
let random = rand::thread_rng().gen_range(lower_bound..=upper_bound);
|
let random = rand::thread_rng().gen_range(lower_bound..=upper_bound);
|
||||||
coordinates.push(random);
|
coordinates.push(random);
|
||||||
}
|
}
|
||||||
food_sources.push(FoodSource::get(coordinates));
|
food_sources.push(FoodSource::new(coordinates));
|
||||||
}
|
}
|
||||||
food_sources
|
food_sources
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ fn main() {
|
||||||
);
|
);
|
||||||
|
|
||||||
for run_counter in 0..input.run {
|
for run_counter in 0..input.run {
|
||||||
let mut best_food_source = FoodSource::get(vec![]);
|
let mut best_food_source = FoodSource::new(vec![]);
|
||||||
for food_source in &food_sources {
|
for food_source in &food_sources {
|
||||||
if best_food_source.fitness < food_source.fitness {
|
if best_food_source.fitness < food_source.fitness {
|
||||||
best_food_source
|
best_food_source
|
||||||
|
@ -24,7 +24,7 @@ fn main() {
|
||||||
}
|
}
|
||||||
for _ in 0..input.iteration {
|
for _ in 0..input.iteration {
|
||||||
for index in 0..input.food_source_number as usize {
|
for index in 0..input.food_source_number as usize {
|
||||||
Bee::worker_bee(
|
Bee::employed_bee(
|
||||||
&mut food_sources,
|
&mut food_sources,
|
||||||
index,
|
index,
|
||||||
input.decision_variable_count,
|
input.decision_variable_count,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue