| Crates.io | sat-solver |
| lib.rs | sat-solver |
| version | 0.2.1 |
| created_at | 2020-05-09 14:10:32.282558+00 |
| updated_at | 2025-06-12 14:45:08.098186+00 |
| description | A SAT solver implemented in Rust, focusing on performance, efficiency and experimentation. |
| homepage | https://github.com/jacobjedwards/rust_sat_solver |
| repository | https://github.com/jacobjedwards/rust_sat_solver |
| max_upload_size | |
| id | 239264 |
| size | 519,165 |
sat_solver is a command-line application written in Rust that implements a SAT (Boolean Satisfiability) solver based on the CDCL (Conflict-Driven Clause Learning) algorithm. It's designed to be configurable and includes modules for solving standard CNF (Conjunctive Normal Form) problems as well as specific applications like Sudoku puzzles by reducing them to SAT.
SolverConfig) allowing different implementations for:
Literal)Assignment)VariableSelector, e.g. VSIDS)Propagator, e.g. Watched Literals)Restarter, e.g. Luby sequence)ClauseManager, e.g. LBD-based)tikv-jemallocator for potentially better memory allocation performance and reporting accurate memory statistics.clap.Clone the repository:
git clone https://github.com/jacobjedwards/rust_sat_solver.git
cd rust_sat_solver
Build the project: For a release build (recommended for performance):
cargo build --release
The executable will be located at target/release/sat_solver.
For a debug build:
cargo build
The executable will be located at target/debug/sat_solver.
For installation, you can also use:
cargo install --path .
This will install the sat_solver binary globally, making it accessible from anywhere in your terminal.
The solver can be invoked in several ways depending on the input type.
# General structure
sat_solver [GLOBAL OPTIONS] [COMMAND]
# Implicitly solve a DIMACS file
sat_solver <path/to/problem.cnf> [OPTIONS]
# Explicitly solve a DIMACS file
sat_solver file --path <path/to/problem.cnf> [OPTIONS]
# Solve CNF provided as text
sat_solver text --input "1 -2 0\n-1 3 0\n2 -3 0" [OPTIONS]
# Solve a Sudoku puzzle
sat_solver sudoku --path <path/to/sudoku.txt> [OPTIONS]
These options can be used with most commands:
-d, --debug: Enable detailed debug output during solving.-v, --verify: Verify the solution after solving (default: true). Use --no-verify to disable.-s, --stats: Print performance statistics (default: true). Use --no-stats to disable.-p, --print-solution: Print the satisfying assignment if found (default: false).--help: Show help information.--version: Show version information.Solve a DIMACS file (example.cnf) and print stats:
sat_solver example.cnf
# or
sat_solver file --path example.cnf
Solve inline CNF text and print the solution:
./target/release/sat_solver text --input "1 2 0\n-1 0\n-2 0" -p
(Note: Input string uses \n for newlines if necessary in your shell)
Solve a Sudoku puzzle (puzzle.sudoku) and print the solution:
sat_solver sudoku --path puzzle.sudoku -p
Solve a Sudoku puzzle and export its CNF representation:
sat_solver sudoku --path puzzle.sudoku --export-dimacs
# This will create puzzle.sudoku.cnf
The solver's behavior is determined by the components defined in a SolverConfig implementation. The DefaultConfig uses:
Literal: PackedLiteral (an efficient representation for literals)LiteralStorage: SmallVec<[PackedLiteral; 8]> (optimises storage for small clauses)Assignment: VecAssignment (standard vector-based assignment tracking)VariableSelector: Vsids (Variable State Independent Decaying Sum heuristic)Propagator: WatchedLiterals (efficient unit propagation)Restarter: Luby<2> (Luby sequence based restarts)ClauseManager: LbdClauseManagement (Literal Block Distance based clause deletion)While the current command-line interface uses DefaultConfig, the underlying structure allows for creating different configurations by implementing the SolverConfig trait and associated component traits.
.cnf)The standard format for SAT problems:
c are comments.p cnf <num_vars> <num_clauses>0.Example:
c Example DIMACS file
p cnf 3 3
1 -2 0
-1 3 0
2 -3 0
.txt, .sudoku, etc.)A text file representing the 9x9 grid:
1 through 9 for pre-filled cells.0 for empty cells.Example:
5 3 0 0 7 0 0 0 0
6 0 0 1 9 5 0 0 0
0 9 8 0 0 0 0 6 0
0 0 0 0 4 0 8 0 3
0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 2 8
0 0 0 0 6 0 0 0 0
0 0 0 0 0 0 0 0 0
Upon completion, the solver will output:
-d is enabled.--verify is enabled.--stats is enabled (see below).-p is enabled and the problem is SAT.SATISFIABLE or UNSATISFIABLE.--stats)The statistics block includes:
conflicts: Number of conflicts encountered.decisions: Number of decisions made.propagations: Number of propagations performed.restarts: Number of restarts performed.time: Total time taken for solving (in seconds).memory: Memory usage (in bytes).solution: The satisfying assignment (if found).verification: Verification result (if enabled).exported_cnf: Path to the exported CNF file (if applicable).src/main.rs: CLI parsing and main application logic.src/sat/: Core SAT solver implementation (CDCL, CNF, components).src/sudoku/: Sudoku parsing, CNF encoding, and solution decoding.cargo test.cargo bench.clap, itertools, tikv-jemallocator, tikv-jemalloc-ctl, rustc_hash, smallvec.