feat: ✨ scientific notation
This commit is contained in:
parent
e9d8b8dbde
commit
e8706182b4
3 changed files with 14 additions and 11 deletions
|
@ -18,9 +18,7 @@ impl FoodSource {
|
|||
coordinates,
|
||||
try_counter: 0,
|
||||
};
|
||||
if !food_source.coordinates.is_empty() {
|
||||
food_source.fitness_function();
|
||||
}
|
||||
food_source.fitness_function();
|
||||
food_source
|
||||
}
|
||||
fn fitness_function(&mut self) {
|
||||
|
@ -63,10 +61,14 @@ impl FoodSource {
|
|||
|
||||
impl fmt::Display for FoodSource {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(
|
||||
writeln!(
|
||||
f,
|
||||
"function_calculation = {}\nfitness_calculation = {}\ncoordinates = {:#?}\ntry_counter = {}\n",
|
||||
self.function_calculation, self.fitness_calculation, self.coordinates, self.try_counter
|
||||
)
|
||||
"function_calculation = {:e}\nfitness_calculation = {:e}\ncoordinates = [",
|
||||
self.function_calculation, self.fitness_calculation
|
||||
)?;
|
||||
for coordinate in &self.coordinates {
|
||||
writeln!(f, " {:e},", coordinate)?;
|
||||
}
|
||||
write!(f, "]\ntry_counter = {}\n", self.try_counter)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -119,7 +119,7 @@ impl Input {
|
|||
}
|
||||
|
||||
pub fn give_output(
|
||||
best_food_source: FoodSource,
|
||||
best_food_source: &FoodSource,
|
||||
function_results: &[f64],
|
||||
fitness_results: &[f64],
|
||||
input_run: usize,
|
||||
|
@ -144,7 +144,7 @@ pub fn give_output(
|
|||
standard_deviation(fitness_results, fitness_results_arithmetic_mean);
|
||||
write!(
|
||||
print_buffer,
|
||||
"[evaluation_function_results]\nfunction_results_arithmetic_mean = {}\nfunction_results_standard_deviation = {}\n\n[evaluation_fitness_results]\nfitness_results_arithmetic_mean = {}\nfitness_results_standard_deviation = {}",
|
||||
"[function_calculation_results]\narithmetic_mean = {:e}\nstandard_deviation = {:e}\n\n[fitness_calculation_results]\narithmetic_mean = {:e}\nstandard_deviation = {:e}",
|
||||
function_results_arithmetic_mean, function_results_standard_deviation, fitness_results_arithmetic_mean, fitness_results_standard_deviation
|
||||
)
|
||||
.unwrap();
|
||||
|
|
|
@ -14,7 +14,7 @@ fn main() {
|
|||
);
|
||||
|
||||
for run_counter in 0..input.run {
|
||||
let mut best_food_source = FoodSource::new(vec![]);
|
||||
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();
|
||||
|
@ -68,8 +68,9 @@ fn main() {
|
|||
}
|
||||
function_results.push(best_food_source.function_calculation);
|
||||
fitness_results.push(best_food_source.fitness_calculation);
|
||||
|
||||
give_output(
|
||||
best_food_source,
|
||||
&best_food_source,
|
||||
&function_results[..],
|
||||
&fitness_results[..],
|
||||
input.run,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue