A modular and extensible SAT solver implemented in Python, supporting multiple solving algorithms and advanced branching heuristics. Designed for educational purposes, experimentation, and research on SAT-solving techniques.
-
Multiple Solving Algorithms
- DPLL (Davis–Putnam–Logemann–Loveland)
- DP (Davis–Putnam)
- Resolution-based solving
-
Branching Heuristics for DPLL
firstrandomMAXO: Maximum OccurrencesMOMS: Maximum Occurrences in clauses of Minimum SizeMAMS: Combination of MAXO and MOMSJW: Jeroslow-WangUP: Unit PropagationGUP: Greedy Unit PropagationSUP: Selective Unit Propagation
-
Verbose Mode: Step-by-step tracing of the solving process.
-
Modular Architecture: Easy to extend with new algorithms and heuristics.
-
Testing Suite: Ensures correctness of parsing and solving logic.
-
Clone the Repository:
git clone https://github.com/Tudor230/SAT-Solver.git cd SAT-Solver -
(Optional) Create a Virtual Environment:
python -m venv venv source venv/bin/activate -
Install Dependencies:
This project uses only the Python standard library. No extra dependencies are required.
python -m solver.solver path_to_cnf_file.cnf --method METHOD_NAME [--verbose]| Argument | Description |
|---|---|
path_to_cnf_file.cnf |
Input CNF file in DIMACS format |
--method |
Solving method or branching heuristic (see below) |
--verbose |
(Optional) Print step-by-step solving process |
-
Solvers:
dp: Davis–Putnam procedureresolution: Resolution-based algorithm
-
DPLL Heuristics:
first,random,MAXO,MOMS,MAMS,JW,UP,GUP,SUP
The input file must follow the DIMACS CNF format:
c This is a comment
p cnf 3 2
1 -3 0
2 3 -1 0
p cnf <num_variables> <num_clauses>— declares the number of variables and clauses.- Each clause is a line of literals ending with
0.
The solver prints:
SATISFIABLE— If a satisfying assignment is found.UNSATISFIABLE— If the formula is unsatisfiable.
With --verbose, it will also print:
- Branching decisions
- Clause simplifications
- Unit propagations
SAT-Solver/
├── solver/
│ ├── parser.py # DIMACS parser
│ ├── solver.py # CLI + solving orchestration
│ ├── heuristics.py # Heuristic functions for DPLL
│ └── algorithms/
│ ├── dpll.py # DPLL implementation
│ └── resolution.py # DP and resolution algorithms
├── tests/ # Unit tests
└── README.md
The SAT-Solver project includes a test suite to verify the correctness of its components, such as the CNF parser, solving algorithms, and heuristics.
To execute the tests, use the following command:
python -m tests.test --folder FOLDER_PATH --methods METHODSReplace FOLDER_PATH with the path to the directory containing your CNF files, and METHODS with the solving methods or heuristics you wish to test. For example:
python -m tests.test --folder examples/ --methods dp dpllThis command will run the tests on all CNF files in the examples/ directory using the dp and dpll methods.
After running the tests, the results will be saved as a text file in the root directory of the project.
This file contains detailed information about each test case, including the input folder, the method used, and the average time and splits (for DPLL).
Contributions are welcome! To add a new heuristic or algorithm:
- Fork the repository.
- Add your logic under
solver/algorithms/orsolver/heuristics.py. - Write unit tests in the
tests/directory. - Submit a pull request with a clear description.
This project is licensed under the MIT License.
This project was built for educational and research purposes. It draws on foundational techniques from SAT solving literature and standard algorithm implementations.