From 46c53f17d3b5a4e02ce6905b1c176a62c4a9d0f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=9CM=C3=9C=C5=9E?= <96421894+Tahinli@users.noreply.github.com> Date: Wed, 20 Nov 2024 00:20:40 +0300 Subject: [PATCH] feat: :sparkles: oven --- simulated_annealing/src/main.rs | 36 +++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/simulated_annealing/src/main.rs b/simulated_annealing/src/main.rs index 43e89eb..7d255b9 100644 --- a/simulated_annealing/src/main.rs +++ b/simulated_annealing/src/main.rs @@ -12,10 +12,10 @@ fn main() { println!("Hello, world!"); println!("Temperature = "); - let temperature = get_float_input(); + let mut temperature = get_float_input(); - println!("Iteration = "); - let iteration: u64 = get_float_input() as u64; + println!("Max Iteration = "); + let max_iteration: u64 = get_float_input() as u64; println!("Upper Bound = "); let upper_bound = get_float_input(); @@ -27,7 +27,7 @@ fn main() { let mut x2: f64 = rand::thread_rng().gen_range(lower_bound..=upper_bound); let mut give_up_counter: u8 = 0; - for i in 0..iteration { + for i in 0..max_iteration { x1 = bound_detective(x1, upper_bound, lower_bound); x2 = bound_detective(x2, upper_bound, lower_bound); @@ -56,6 +56,8 @@ fn main() { } give_up_counter = give_up_return.1; + temperature = turbofan_oven(temperature, i, max_iteration); + let original_result = calculate(x1, x2); let new_result = calculate(new_x1, new_x2); let neighbour_dif = new_result - original_result; @@ -99,6 +101,32 @@ fn magic_trick(x: f64, what_happened: Bound) -> f64 { } } +fn turbofan_oven(mut temperature: f64, i: u64, max_iteration: u64) -> f64 { + let where_we_are = (i as f64 / max_iteration as f64) * 100.0; + if where_we_are < 5.0 { + } else if where_we_are < 10.0 { + temperature -= (1.0 / 100.0) * temperature; + } else if where_we_are < 15.0 { + temperature += (1.0 / 100.0) * temperature; + } else if where_we_are < 20.0 { + temperature -= (1.0 / 100.0) * temperature; + } else if where_we_are < 25.0 { + temperature += (1.0 / 100.0) * temperature; + } else if where_we_are < 30.0 { + temperature -= (1.0 / 100.0) * temperature; + } else if where_we_are < 35.0 { + temperature += (1.0 / 100.0) * temperature; + } else if where_we_are < 40.0 { + temperature -= (1.0 / 100.0) * temperature; + } else if where_we_are < 50.0 { + temperature += (2.0 / 100.0) * temperature; + } else if where_we_are < 60.0 { + } else if where_we_are < 70.0 { + temperature -= (5.0 / 100.0) * temperature; + } + temperature +} + fn give_up(x1: f64, x2: f64, new_x1: f64, new_x2: f64, mut give_up_counter: u8) -> (bool, u8) { if x1 == 0.0 && x2 == 0.0 { println!("Touched 0.0 for both variables");