diff --git a/artificial_bee_colony/src/lib.rs b/artificial_bee_colony/src/lib.rs index a0b3656..b71c77b 100644 --- a/artificial_bee_colony/src/lib.rs +++ b/artificial_bee_colony/src/lib.rs @@ -3,6 +3,7 @@ use std::{ env::args, fs::{File, OpenOptions}, io::{self, BufRead, BufReader, Write}, + process::exit, }; use food::FoodSource; @@ -24,10 +25,15 @@ impl Input { let mut read_file = false; for arg in args().collect::>() { match arg.as_str() { - "-r" | "--read-file" => read_file = true, + "-r" | "--read_file" => read_file = true, + "-h" | "--help" => { + show_help(); + exit(0); + } _ => {} } } + if read_file { Input::read_config_file_input() } else { @@ -128,7 +134,7 @@ pub fn give_output( let mut write_file = false; for arg in args().collect::>() { match arg.as_str() { - "-w" | "--write-file" => write_file = true, + "-w" | "--write_file" => write_file = true, _ => {} } } @@ -144,7 +150,7 @@ pub fn give_output( standard_deviation(fitness_results, fitness_results_arithmetic_mean); write!( print_buffer, - "[function_calculation_results]\narithmetic_mean = {:e}\nstandard_deviation = {:e}\n\n[fitness_calculation_results]\narithmetic_mean = {:e}\nstandard_deviation = {:e}", + "[function_calculations_results]\narithmetic_mean = {:e}\nstandard_deviation = {:e}\n\n[fitness_calculations_results]\narithmetic_mean = {:e}\nstandard_deviation = {:e}", function_results_arithmetic_mean, function_results_standard_deviation, fitness_results_arithmetic_mean, fitness_results_standard_deviation ) .unwrap(); @@ -205,3 +211,13 @@ fn standard_deviation(results: &[f64], arithmetic_mean: f64) -> f64 { } f64::sqrt(total_difference_square / (results.len() - 1) as f64) } + +fn show_help() { + println!("\n\n\n"); + println!(" Arguments | Details "); + println!("----------------------------------------------------------------------"); + println!(" -r -> --read_file | Reads Config from abc_config.toml File"); + println!(" -w -> --write_file | Writes Results to abc_result.toml File"); + println!(" -h -> --help | Shows Help "); + println!("\n\n\n"); +} diff --git a/artificial_bee_colony/src/main.rs b/artificial_bee_colony/src/main.rs index c6dd2a2..6a67130 100644 --- a/artificial_bee_colony/src/main.rs +++ b/artificial_bee_colony/src/main.rs @@ -14,7 +14,11 @@ fn main() { ); for run_counter in 0..input.run { - let mut best_food_source = food_sources.iter().max_by(|x,y|x.fitness_calculation.total_cmp(&y.fitness_calculation)).unwrap().clone(); + let mut best_food_source = food_sources + .iter() + .max_by(|x, y| x.fitness_calculation.total_cmp(&y.fitness_calculation)) + .unwrap() + .clone(); for food_source in &food_sources { if best_food_source.fitness_calculation < food_source.fitness_calculation { best_food_source = food_source.clone(); @@ -47,7 +51,7 @@ fn main() { most_tried_index = i; } } - + for food_source in &food_sources { if best_food_source.fitness_calculation < food_source.fitness_calculation { best_food_source = food_source.clone(); @@ -68,7 +72,7 @@ fn main() { } function_results.push(best_food_source.function_calculation); fitness_results.push(best_food_source.fitness_calculation); - + give_output( &best_food_source, &function_results[..],