Skip to content

Probabilistic Sudoku solver based on the Simulated Annealing algorithm and Monte Carlo Markov Chain (MCMC).

Notifications You must be signed in to change notification settings

giovanni-gatti/sudoku-solver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Sudoku Solver

Overview

This Python project shows how to implement a sudoku generator and solver using the Simulated Annealing algorithm. Simulated Annealing is a probabilistic optimization algorithm based on stochastic processes and Monte Carlo Markov Chain (MCMC) that is particularly effective in solving combinatorial optimization problems. The code can generate and solve sudoku problems of arbitrary size.

Getting Started

These instructions will help you set up the project on your local machine for development and testing purposes.

Prerequisites

Make sure you have the following installed on your system:

  • Python 3.x
  • Pip (Python package installer)

Installation

  1. Clone the repository:

    git clone https://github.com/giovanni-gatti/sudoku-solver.git
  2. Navigate to the project directory:

    cd sudoku-solver
  3. (Optional, recommended) Create and activate a virtual environment:

    python -m venv venv 
    source venv/bin/activate
  4. Install the required dependencies (using pip):

    pip install -r requirements.txt

Usage

Run the project code with the following command:

python3 solve.py

The src/SimAnn.py file contains the functions to run the Simulated Annealing algorithm to sample from the Boltzmann distribution using the Metropolis-Hastings rule. The constructor of the Sudoku class, defined in src/Sudoku.py, accepts either an integer number or another Sudoku object as an argument. If the constructor gets a number, it initializes a sudoku table of size equal to the number. If instead it receives a Sudoku object, it chooses at random a fraction of the entries to keep fixed (with probability defined by the argument r), and shuffles the rest. In the solve.py script, a valid sudoku table is first generated and filled up. Then, a sudoku problem to be solved is created from this valid sudoku table. Finally, the sudoku problem is solved.

References

About

Probabilistic Sudoku solver based on the Simulated Annealing algorithm and Monte Carlo Markov Chain (MCMC).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages