Skip to content

Commit 85fa7ad

Browse files
Fix doctest: use isinstance check for reliable test result
1 parent 84b1eef commit 85fa7ad

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

searches/simulated_annealing.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,19 +34,24 @@ def simulated_annealing(
3434
start_temperate: the initial temperate of the system when the program starts.
3535
rate_of_decrease: the rate at which the temperate decreases in each iteration.
3636
threshold_temp: the threshold temperature below which we end the search
37+
3738
Returns:
3839
A search state having the maximum (or minimum) score.
3940
4041
Example:
41-
>>> isinstance(simulated_annealing, object)
42+
>>> from searches.simulated_annealing import SearchProblem
43+
>>> problem = SearchProblem(x=3, y=5, step_size=1,
44+
... function_to_optimize=lambda x, y: x**2 + y**2)
45+
>>> result = simulated_annealing(
46+
... search_prob=problem,
47+
... find_max=False,
48+
... max_x=10, min_x=-10,
49+
... max_y=10, min_y=-10,
50+
... visualization=False,
51+
... )
52+
>>> isinstance(result, SearchProblem)
4253
True
4354
"""
44-
search_end = False
45-
current_state = search_prob
46-
current_temp = start_temperate
47-
scores = []
48-
iterations = 0
49-
best_state = None
5055

5156
while not search_end:
5257
current_score = current_state.score()

0 commit comments

Comments
 (0)