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 {}
|
||||
impl Bee {
|
||||
pub fn worker_bee(
|
||||
pub fn employed_bee(
|
||||
food_sources: &mut [FoodSource],
|
||||
index: usize,
|
||||
decision_variable_count: usize,
|
||||
|
@ -31,7 +31,7 @@ impl Bee {
|
|||
}
|
||||
let mut candidate_coordinates = food_sources[index].coordinates.clone();
|
||||
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;
|
||||
if candidate.fitness > food_sources[index].fitness {
|
||||
food_sources[index] = candidate;
|
||||
|
@ -49,7 +49,7 @@ impl Bee {
|
|||
) {
|
||||
let fitness_for_index = food_sources[index].fitness;
|
||||
if fitness_for_index / total_fitness <= rand::thread_rng().gen_range(0.0..=1.0) {
|
||||
Self::worker_bee(
|
||||
Self::employed_bee(
|
||||
food_sources,
|
||||
index,
|
||||
decision_variable_count,
|
||||
|
@ -74,7 +74,7 @@ impl Bee {
|
|||
+ rand::thread_rng().gen_range(0.0..=1.0) * (upper_bound - lower_bound);
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,7 +11,7 @@ pub struct FoodSource {
|
|||
}
|
||||
|
||||
impl FoodSource {
|
||||
pub fn get(coordinates: Vec<f64>) -> Self {
|
||||
pub fn new(coordinates: Vec<f64>) -> Self {
|
||||
let mut food_source = FoodSource {
|
||||
fitness: 0.0,
|
||||
function_calculation: 0.0,
|
||||
|
@ -55,7 +55,7 @@ impl FoodSource {
|
|||
let random = rand::thread_rng().gen_range(lower_bound..=upper_bound);
|
||||
coordinates.push(random);
|
||||
}
|
||||
food_sources.push(FoodSource::get(coordinates));
|
||||
food_sources.push(FoodSource::new(coordinates));
|
||||
}
|
||||
food_sources
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ fn main() {
|
|||
);
|
||||
|
||||
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 {
|
||||
if best_food_source.fitness < food_source.fitness {
|
||||
best_food_source
|
||||
|
@ -24,7 +24,7 @@ fn main() {
|
|||
}
|
||||
for _ in 0..input.iteration {
|
||||
for index in 0..input.food_source_number as usize {
|
||||
Bee::worker_bee(
|
||||
Bee::employed_bee(
|
||||
&mut food_sources,
|
||||
index,
|
||||
input.decision_variable_count,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue