https://github.com/bergio13/simulated-annealing-sudoku
Solving sudoku using simulated annealing optimization
https://github.com/bergio13/simulated-annealing-sudoku
heuristics metaheuristics optimization simulated-annealing sudoku
Last synced: 7 months ago
JSON representation
Solving sudoku using simulated annealing optimization
- Host: GitHub
- URL: https://github.com/bergio13/simulated-annealing-sudoku
- Owner: bergio13
- Created: 2024-10-23T18:08:18.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-10-25T10:19:19.000Z (12 months ago)
- Last Synced: 2024-10-25T10:31:10.284Z (12 months ago)
- Topics: heuristics, metaheuristics, optimization, simulated-annealing, sudoku
- Language: Jupyter Notebook
- Homepage:
- Size: 1.03 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Simulated Annealing Applied to Sudoku Puzzles
![]()
This project implements a **Simulated Annealing** (SA) algorithm to solve Sudoku puzzles, inspired by the paper **"Metaheuristics can solve Sudoku puzzles"** by Lewis (2007). The algorithm demonstrates a reliable approach to consistently find solutions to Sudoku puzzles using a metaheuristic optimization technique.
## Project Overview
The SA algorithm works by iteratively exploring the solution space and probabilistically allowing worse solutions to escape local minima. As the process progresses, the "temperature" parameter gradually decreases, refining the search. If a better solution isn't found within a set number of steps, a reheating mechanism is applied to help the search escape potential plateaus.
![]()
### File Descriptions
- `notebook.ipynb` - A Jupyter Notebook demonstrating and visualizing the SA approach for solving Sudoku puzzles, with step-by-step explanations.
- `simulated_annealing.py` - Core implementation of the Simulated Annealing algorithm.
- `sudoku_solver.py` - Contains helper functions, the objective funciton, the nieghborhood operator, the delta evaluation function and the necessary Sudoku-specific logic required by the SA algorithm.### Key Functions
- [`find_square`](sudoku_solver.py): Determines the 3x3 grid for a given cell.
- [`initial_candidate_sudoku`](sudoku_solver.py): Generates an initial candidate Sudoku solution.
- [`objective_function`](sudoku_solver.py): Computes the objective function value for a given Sudoku solution.
- [`neighborhood_operator`](sudoku_solver.py): Swaps two random cells in the same 3x3 grid of the Sudoku.
- [`delta_evaluation`](sudoku_solver.py): Evaluates the change in the objective function value after a swap operation.
- [`simulated_annealing`](simulated_annealing.py): Executes the Simulated Annealing algorithm.
- [`simulated_annealing_e`](simulated_annealing.py): Executes an enhanced version of the Simulated Annealing algorithm with delta evaluation.### Visualization and Results
The results and visualizations can be found in the `notebook.ipynb` file. Open it with Jupyter Notebook to see step-by-step explanations and plots.
### Webpage
Webpage where you can specify sudoku problem and parameters:
- [Webpage](https://bergione.pythonanywhere.com/)---
#### Reference
- Lewis, R. Metaheuristics can solve sudoku puzzles. J Heuristics 13, 387–401 (2007). DOI: https://doi.org/10.1007/s10732-007-9012-8