feat: ✨ now able to run abc multiple times
This commit is contained in:
parent
5a2100fd30
commit
7d54ed4795
2 changed files with 53 additions and 46 deletions
|
@ -10,6 +10,7 @@ pub struct Input {
|
||||||
pub upper_bound: f64,
|
pub upper_bound: f64,
|
||||||
pub lower_bound: f64,
|
pub lower_bound: f64,
|
||||||
pub iteration: usize,
|
pub iteration: usize,
|
||||||
|
pub run: usize,
|
||||||
}
|
}
|
||||||
impl Input {
|
impl Input {
|
||||||
pub fn get() -> Self {
|
pub fn get() -> Self {
|
||||||
|
@ -31,6 +32,8 @@ impl Input {
|
||||||
println!("Iteration");
|
println!("Iteration");
|
||||||
let iteration = Self::get_input().parse().unwrap();
|
let iteration = Self::get_input().parse().unwrap();
|
||||||
|
|
||||||
|
println!("Run");
|
||||||
|
let run = Self::get_input().parse().unwrap();
|
||||||
Input {
|
Input {
|
||||||
decision_variable_count,
|
decision_variable_count,
|
||||||
food_source_number,
|
food_source_number,
|
||||||
|
@ -38,6 +41,7 @@ impl Input {
|
||||||
upper_bound,
|
upper_bound,
|
||||||
lower_bound,
|
lower_bound,
|
||||||
iteration,
|
iteration,
|
||||||
|
run,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn get_input() -> String {
|
fn get_input() -> String {
|
||||||
|
|
|
@ -10,51 +10,54 @@ fn main() {
|
||||||
input.upper_bound,
|
input.upper_bound,
|
||||||
input.lower_bound,
|
input.lower_bound,
|
||||||
);
|
);
|
||||||
let mut best = FoodSource::get(vec![]);
|
|
||||||
for food_source in &food_sources {
|
|
||||||
if best.fitness < food_source.fitness {
|
|
||||||
best.coordinates = food_source.coordinates.clone();
|
|
||||||
best.fitness = food_source.fitness;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for _ in 0..input.iteration {
|
|
||||||
for index in 0..input.food_source_number as usize {
|
|
||||||
Bee::worker_bee(
|
|
||||||
&mut food_sources,
|
|
||||||
index,
|
|
||||||
input.decision_variable_count,
|
|
||||||
input.upper_bound,
|
|
||||||
input.lower_bound,
|
|
||||||
);
|
|
||||||
let mut total_fitness = 0.0;
|
|
||||||
for food_source in &food_sources {
|
|
||||||
total_fitness += food_source.fitness;
|
|
||||||
}
|
|
||||||
Bee::onlooker_bee(
|
|
||||||
&mut food_sources,
|
|
||||||
index,
|
|
||||||
total_fitness,
|
|
||||||
input.decision_variable_count,
|
|
||||||
input.upper_bound,
|
|
||||||
input.lower_bound,
|
|
||||||
);
|
|
||||||
let mut most_tried_index = 0;
|
|
||||||
for i in 0..food_sources.len() {
|
|
||||||
if food_sources[most_tried_index].try_counter < food_sources[i].try_counter {
|
|
||||||
most_tried_index = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
best = food_sources[most_tried_index].clone();
|
|
||||||
Bee::scout_bee(
|
|
||||||
&mut food_sources,
|
|
||||||
most_tried_index,
|
|
||||||
input.food_source_try_limit,
|
|
||||||
input.lower_bound,
|
|
||||||
input.upper_bound,
|
|
||||||
input.decision_variable_count,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
println!("{:#?}", best);
|
for _ in 0..input.run {
|
||||||
|
let mut best = FoodSource::get(vec![]);
|
||||||
|
for food_source in &food_sources {
|
||||||
|
if best.fitness < food_source.fitness {
|
||||||
|
best.coordinates = food_source.coordinates.clone();
|
||||||
|
best.fitness = food_source.fitness;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _ in 0..input.iteration {
|
||||||
|
for index in 0..input.food_source_number as usize {
|
||||||
|
Bee::worker_bee(
|
||||||
|
&mut food_sources,
|
||||||
|
index,
|
||||||
|
input.decision_variable_count,
|
||||||
|
input.upper_bound,
|
||||||
|
input.lower_bound,
|
||||||
|
);
|
||||||
|
let mut total_fitness = 0.0;
|
||||||
|
for food_source in &food_sources {
|
||||||
|
total_fitness += food_source.fitness;
|
||||||
|
}
|
||||||
|
Bee::onlooker_bee(
|
||||||
|
&mut food_sources,
|
||||||
|
index,
|
||||||
|
total_fitness,
|
||||||
|
input.decision_variable_count,
|
||||||
|
input.upper_bound,
|
||||||
|
input.lower_bound,
|
||||||
|
);
|
||||||
|
let mut most_tried_index = 0;
|
||||||
|
for i in 0..food_sources.len() {
|
||||||
|
if food_sources[most_tried_index].try_counter < food_sources[i].try_counter {
|
||||||
|
most_tried_index = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
best = food_sources[most_tried_index].clone();
|
||||||
|
Bee::scout_bee(
|
||||||
|
&mut food_sources,
|
||||||
|
most_tried_index,
|
||||||
|
input.food_source_try_limit,
|
||||||
|
input.lower_bound,
|
||||||
|
input.upper_bound,
|
||||||
|
input.decision_variable_count,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
println!("{:#?}", best);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue