https://github.com/rorypoulter/sat-solver
Python SAT Solver
https://github.com/rorypoulter/sat-solver
dimacs-cnf python sat-solver
Last synced: 21 days ago
JSON representation
Python SAT Solver
- Host: GitHub
- URL: https://github.com/rorypoulter/sat-solver
- Owner: RoryPoulter
- License: mit
- Created: 2025-02-27T14:49:10.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-03-20T11:53:38.000Z (about 1 year ago)
- Last Synced: 2025-03-20T12:48:22.817Z (about 1 year ago)
- Topics: dimacs-cnf, python, sat-solver
- Language: Python
- Homepage:
- Size: 129 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# SAT-Solver





SAT Solver for Computational Thinking Coursework.
## Usage
### Using the `rlnf55.py` File
* Write a .txt file in DIMACs format for the clause-set
* Set the `PATH` constant to the path to the file relative to `rlnf55.py`, e.g.
```python
PATH = "Examples\Examples-for-SAT\LNP-6.txt"
```
* Run `rlnf55.py`
### Importing `rlnf55.py`
Functions to import:
* `load_dimacs(PATH)` - Loads a .txt file in DIMACs format and generates the corresponding clause-set
* `simple_sat_solve(clause_set)` - SAT solver that uses brute force to check every assignment until either a satisfying assignment is found or all have been checked
* `branching_sat_solve(clause_set, partial_assignment)` - SAT solver that uses recursion to branch on each literal
* `dpll_sat_solve(clause_set, partial_assignment)` - SAT solver that uses the DPLL algorithm
```py
import rlnf55 as ss
if __name__ == "__main__":
PATH = "relative/path/to/file"
# Load the DIMACs file
clause_set = ss.load_dimacs(PATH)
# Use SAT solver to find satisfying assignment of if clause-set is unsatisfiable
assignment = ss.dpll_sat_solve(clause_set, [])
if assignment:
print(f"Clause-set from {PATH} is satisfiable under the assignment: {assignment}.")
else:
print(f"Clause-set from {PATH} is unsatisfiable.")
```