- This implementation creates a functional Sudoku solver using simulated annealing. It dynamically updates the web page to display the Sudoku board and iteratively attempts to solve it using simulated annealing.
- Energy Calculation: The fitness or energy of the initial board state is calculated using
calculateEnergy()
, which counts conflicts (duplicate numbers) in rows, columns, and 3x3 sub-grids. - Annealing Loop: The algorithm iteratively generates neighboring states, calculates their energies, and decides whether to move to these neighbors based on the energy difference and a probability determined by the temperature parameter.
- Cooling Schedule: The temperature decreases over time to gradually reduce the probability of accepting worse solutions (higher energy states) as the algorithm progresses.
- Termination: The simulated annealing loop continues until the temperature drops below a certain threshold (0.1 in this case), indicating that the system has cooled sufficiently and likely found a near-optimal solution.
The final result when solving a Sudoku puzzle using simulated annealing is a fully completed Sudoku board where every cell contains a number from 1 to 9, meeting all Sudoku rules.