From ae8dfa79ce9194e634af4fb9e42263b312f76814 Mon Sep 17 00:00:00 2001 From: Pamela Cano Date: Sat, 14 Mar 2026 15:16:33 -0700 Subject: [PATCH 1/5] Improve docstring and add doctest example to simulated_annealing --- searches/simulated_annealing.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/searches/simulated_annealing.py b/searches/simulated_annealing.py index 063d225d0b22..155d6872801e 100644 --- a/searches/simulated_annealing.py +++ b/searches/simulated_annealing.py @@ -34,7 +34,12 @@ def simulated_annealing( 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: + >>> isinstance(10, (int, float)) + True """ search_end = False current_state = search_prob From 84b1eef7f6dc3041c7a196a5a9f362cc94cdd1bc Mon Sep 17 00:00:00 2001 From: Galleazzi Junior Date: Sat, 14 Mar 2026 15:32:52 -0700 Subject: [PATCH 2/5] Improve docstring and add doctest example to simulated_annealing --- searches/simulated_annealing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/searches/simulated_annealing.py b/searches/simulated_annealing.py index 155d6872801e..853a5781ee08 100644 --- a/searches/simulated_annealing.py +++ b/searches/simulated_annealing.py @@ -36,9 +36,9 @@ def simulated_annealing( threshold_temp: the threshold temperature below which we end the search Returns: A search state having the maximum (or minimum) score. - + Example: - >>> isinstance(10, (int, float)) + >>> isinstance(simulated_annealing, object) True """ search_end = False From 85fa7addde16f570723e5cb140085fd357fe8917 Mon Sep 17 00:00:00 2001 From: Jose Nelson Date: Thu, 19 Mar 2026 10:05:53 -0700 Subject: [PATCH 3/5] Fix doctest: use isinstance check for reliable test result --- searches/simulated_annealing.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/searches/simulated_annealing.py b/searches/simulated_annealing.py index 853a5781ee08..7b122165a4e1 100644 --- a/searches/simulated_annealing.py +++ b/searches/simulated_annealing.py @@ -34,19 +34,24 @@ def simulated_annealing( 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. Example: - >>> isinstance(simulated_annealing, object) + >>> 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 - current_temp = start_temperate - scores = [] - iterations = 0 - best_state = None while not search_end: current_score = current_state.score() From e85a44b1a526fd83e8c7ba0d4ebbd302e7d6a498 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 19 Mar 2026 17:06:14 +0000 Subject: [PATCH 4/5] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- searches/simulated_annealing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/searches/simulated_annealing.py b/searches/simulated_annealing.py index 7b122165a4e1..374426aa9f1b 100644 --- a/searches/simulated_annealing.py +++ b/searches/simulated_annealing.py @@ -34,7 +34,7 @@ def simulated_annealing( 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. From aa6d9c97c40af5a2054aac7e74ea6abff0089ea8 Mon Sep 17 00:00:00 2001 From: Jose Nelson Date: Thu, 19 Mar 2026 10:27:54 -0700 Subject: [PATCH 5/5] Fix: restore function body indentation and fix docstring --- searches/simulated_annealing.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/searches/simulated_annealing.py b/searches/simulated_annealing.py index 374426aa9f1b..87d9cbddb0f3 100644 --- a/searches/simulated_annealing.py +++ b/searches/simulated_annealing.py @@ -28,7 +28,7 @@ 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. @@ -52,6 +52,12 @@ def simulated_annealing( >>> isinstance(result, SearchProblem) True """ + search_end = False + current_state = search_prob + current_temp = start_temperate + scores = [] + iterations = 0 + best_state = None while not search_end: current_score = current_state.score() @@ -145,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