This project provides a comprehensive study of three fundamental NP-complete problems: SAT (Boolean Satisfiability), 3-SAT, and SUBSETSUM. The repository contains implementations for solving, verifying, and analyzing these problems, along with algorithmic reductions between them. The primary goal is to study their time and space complexity through both theoretical analysis and empirical benchmarking.
- Introduction
- Project Overview
- Repository Structure
- Installation
- Usage Guide
- Algorithmic Approach
- Results and Analysis
This project explores the complexity classes of NP-complete problems by implementing:
- Solvers: Exact algorithms (Brute Force) to find solutions for SAT, 3-SAT, and SUBSETSUM.
- Verifiers: Polynomial-time algorithms to verify the correctness of a given solution.
-
Reductions: Algorithms to transform instances of one problem into another:
- SAT
$\rightarrow$ 3-SAT - SAT
$\rightarrow$ SUBSETSUM
- SAT
- Benchmarks: Extensive performance testing on generated instances and standard libraries (SATLIB).
The project is organized as follows:
.
├── main.py # Main entry point for the project
├── structures.py # Data structures (Literal, Clause, Instances)
├── generation_instances.py # Script to generate random problem instances
├── Benchmarks/ # Benchmarking scripts and results
│ ├── Libs/ # Benchmarks on standard libraries (SATLIB)
│ └── Local/ # Benchmarks on locally generated instances
├── trouve_sol_SAT.py # Solver for SAT
├── trouve_sol_3SAT.py # Solver for 3-SAT
├── trouve_sol_subsetsum.py # Solver for SUBSETSUM
├── verification_sol_SAT.py # Verifier for SAT
├── verification_sol_3SAT.py # Verifier for 3-SAT
├── verification_sol_subsetsum.py # Verifier for SUBSETSUM
├── reduction_SAT_3SAT.py # Reduction algorithm: SAT to 3-SAT
├── reduction_sat_sabsetsum.py # Reduction algorithm: SAT to SUBSETSUM
└── analyse_*.ipynb # Jupyter Notebooks for complexity analysis
Ensure you have Python 3.8+ installed. The project requires the following dependencies:
pandasnumpymatplotlibseabornopenpyxl
You can install the required packages using pip:
pip install pandas numpy matplotlib seaborn openpyxlThe easiest way to run the entire project pipeline (generation, benchmarking, and reporting) is via the main.py script.
python main.py --autoThis command will:
- Verify the Python environment.
- Generate DIMACS instances for SAT, 3-SAT, and SUBSETSUM.
- Run benchmarks on the generated instances.
- Generate Excel reports in
Benchmarks/Local/machine_stats/. - Display a summary of the statistics.
You can also run individual components of the project.
Generating Instances:
python generation_instances.py --dimacsRunning Standard Benchmarks (SATLIB):
python Benchmarks/Libs/satlib_benchmarks.pyThe project includes two types of benchmarks:
- Local Benchmarks: Tests algorithms on randomly generated instances of increasing size to observe exponential growth.
- Library Benchmarks: Tests algorithms on standard problem sets (e.g., SATLIB
uf20-91) to validate correctness and performance against known standards.
Results are saved as Excel files in the Benchmarks/Local/machine_stats/ directory.
The project implements Brute Force solvers for all three problems. These algorithms systematically explore the solution space:
-
SAT / 3-SAT: Explores all
$2^n$ possible truth assignments. -
SUBSETSUM: Explores all
$2^n$ possible subsets.
While these algorithms guarantee finding a solution if one exists, they have an exponential time complexity of
The project demonstrates the NP-completeness of the problems by implementing polynomial-time reductions:
-
SAT
$\rightarrow$ 3-SAT: Transforms any SAT formula into an equivalent 3-CNF formula. It handles clauses of varying lengths by introducing auxiliary variables to split them into clauses of exactly 3 literals. -
SAT
$\rightarrow$ SUBSETSUM: Transforms a SAT formula into a set of integers and a target sum. It constructs numbers in base-10 (or higher) where digits represent the satisfaction of clauses and the selection of variables.
Detailed analysis of the algorithms' performance is available in the Jupyter Notebooks:
analyse_empirique_complete.ipynb: Comprehensive visualization of time and space complexity.analyse_complexite_SAT.ipynb: Specific analysis for SAT.analyse_complexite_3SAT.ipynb: Specific analysis for 3-SAT.analyse_complexite_SUBSETSUM.ipynb: Specific analysis for SUBSETSUM.
To view the analysis:
- Open the desired notebook in VS Code or Jupyter Lab.
- Run all cells to generate the graphs and statistics.