Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions searches/simulated_annealing.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,29 @@

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
Expand Down Expand Up @@ -135,3 +151,8 @@
"The maximum score for f(x, y) = 3*x^2 - 6*y found via hill climbing: "
f"{local_min.score()}"
)
```

Check failure on line 154 in searches/simulated_annealing.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

searches/simulated_annealing.py:154:3: invalid-syntax: Got unexpected token `

Check failure on line 154 in searches/simulated_annealing.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

searches/simulated_annealing.py:154:2: invalid-syntax: Got unexpected token `

Check failure on line 154 in searches/simulated_annealing.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

searches/simulated_annealing.py:154:1: invalid-syntax: Got unexpected token `

Check failure on line 155 in searches/simulated_annealing.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

searches/simulated_annealing.py:154:4: invalid-syntax: Expected a statement
Depois commit com a mensagem:

Check failure on line 156 in searches/simulated_annealing.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

searches/simulated_annealing.py:156:21: invalid-syntax: Simple statements must be separated by newlines or semicolons

Check failure on line 156 in searches/simulated_annealing.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

searches/simulated_annealing.py:156:19: invalid-syntax: Simple statements must be separated by newlines or semicolons

Check failure on line 156 in searches/simulated_annealing.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

searches/simulated_annealing.py:156:15: invalid-syntax: Simple statements must be separated by newlines or semicolons

Check failure on line 156 in searches/simulated_annealing.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

searches/simulated_annealing.py:156:8: invalid-syntax: Simple statements must be separated by newlines or semicolons
```

Check failure on line 157 in searches/simulated_annealing.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

searches/simulated_annealing.py:157:1: invalid-syntax: Got unexpected token `

Check failure on line 157 in searches/simulated_annealing.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (invalid-syntax)

searches/simulated_annealing.py:156:30: invalid-syntax: Expected an expression
Fix: restore function body indentation and fix docstring
Loading