feat: Add Simulated Annealing algorithm with GUI visualization#13704
feat: Add Simulated Annealing algorithm with GUI visualization#1370429di wants to merge 2 commits intoTheAlgorithms:masterfrom 29di:feature/simulated-annealing-gui
Conversation
- Implement SimulatedAnnealingOptimizer for general optimization - Add interactive GUI with real-time visualization - Implement TSP solver with route visualization - Add comprehensive test suite - Include detailed documentation and guides - Support multiple benchmark functions (Sphere, Rastrigin, Rosenbrock, Ackley) - Add parameter tuning controls and pause/resume functionality
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper reviewto trigger the checks for only added pull request files@algorithms-keeper review-allto trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
| class City: | ||
| """Represents a city with x, y coordinates.""" | ||
|
|
||
| def __init__(self, x: float, y: float, name: str = ""): |
There was a problem hiding this comment.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide descriptive name for the parameter: x
Please provide descriptive name for the parameter: y
| class TSPRoute: | ||
| """Represents a route through all cities.""" | ||
|
|
||
| def __init__(self, cities: list[City], order: list[int] | None = None): |
There was a problem hiding this comment.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
| self._distance = distance | ||
| return self._distance | ||
|
|
||
| def swap_cities(self, i: int, j: int) -> "TSPRoute": |
There was a problem hiding this comment.
Please provide descriptive name for the parameter: i
Please provide descriptive name for the parameter: j
| new_order[i], new_order[j] = new_order[j], new_order[i] | ||
| return TSPRoute(self.cities, new_order) | ||
|
|
||
| def reverse_segment(self, i: int, j: int) -> "TSPRoute": |
There was a problem hiding this comment.
Please provide descriptive name for the parameter: i
Please provide descriptive name for the parameter: j
| class TSPSimulatedAnnealing: | ||
| """Simulated Annealing solver for TSP.""" | ||
|
|
||
| def __init__( |
There was a problem hiding this comment.
Please provide return type hint for the function: __init__. If the function does not return a value, please provide the type hint as: def function() -> None:
|
|
||
| self.status_var.set("Ready") | ||
|
|
||
| def _animate(self): |
There was a problem hiding this comment.
Please provide return type hint for the function: _animate. If the function does not return a value, please provide the type hint as: def function() -> None:
| # Schedule next frame | ||
| self.animation_id = self.root.after(50, self._animate) | ||
|
|
||
| def _update_plots(self): |
There was a problem hiding this comment.
Please provide return type hint for the function: _update_plots. If the function does not return a value, please provide the type hint as: def function() -> None:
| self.fig.tight_layout() | ||
| self.canvas.draw() | ||
|
|
||
| def _optimization_complete(self): |
There was a problem hiding this comment.
Please provide return type hint for the function: _optimization_complete. If the function does not return a value, please provide the type hint as: def function() -> None:
| ) | ||
|
|
||
|
|
||
| def main(): |
There was a problem hiding this comment.
Please provide return type hint for the function: main. If the function does not return a value, please provide the type hint as: def function() -> None:
| print("=" * 50) | ||
|
|
||
| # Test with Sphere function | ||
| sphere = lambda x: sum(xi**2 for xi in x) |
There was a problem hiding this comment.
Please provide descriptive name for the parameter: x
Describe your change:
Checklist: