diff --git a/searches/simulated_annealing.py b/searches/simulated_annealing.py index 063d225d0b22..87d9cbddb0f3 100644 --- a/searches/simulated_annealing.py +++ b/searches/simulated_annealing.py @@ -28,13 +28,29 @@ def simulated_annealing( Args: search_prob: The search state at the start. - find_max: If True, the algorithm should find the minimum else the minimum. + find_max: If True, the algorithm should find the maximum else the minimum. max_x, min_x, max_y, min_y: the maximum and minimum bounds of x and y. visualization: If True, a matplotlib graph is displayed. start_temperate: the initial temperate of the system when the program starts. rate_of_decrease: the rate at which the temperate decreases in each iteration. threshold_temp: the threshold temperature below which we end the search - Returns a search state having the maximum (or minimum) score. + + Returns: + A search state having the maximum (or minimum) score. + + Example: + >>> from searches.simulated_annealing import SearchProblem + >>> problem = SearchProblem(x=3, y=5, step_size=1, + ... function_to_optimize=lambda x, y: x**2 + y**2) + >>> result = simulated_annealing( + ... search_prob=problem, + ... find_max=False, + ... max_x=10, min_x=-10, + ... max_y=10, min_y=-10, + ... visualization=False, + ... ) + >>> isinstance(result, SearchProblem) + True """ search_end = False current_state = search_prob @@ -135,3 +151,8 @@ def test_f2(x, y): "The maximum score for f(x, y) = 3*x^2 - 6*y found via hill climbing: " f"{local_min.score()}" ) +``` + +Depois commit com a mensagem: +``` +Fix: restore function body indentation and fix docstring