A simple 3-SAT solver written in Rust.
Create an istance of the Solver struct passing it the path to the DMACS file you wish to solve.
let solver = Solver::new("path/to/file.cnf");
Then call the solve method on the solver istance.
let solution = solver.solve();
The solve method returns an Option enum, which can be either Some or None. If the solve method returns Some, it means that the formula is satisfiable and the solution is contained in the Option. If the solve method returns None, it means that the formula is unsatisfiable.
match solution{
Some(solution) => println!("SAT: ({:?})", solution),
None => println!("UNSAT")
}
To compile the project you need to have Rust installed on your machine. You can download Rust from here.
Once you have Rust installed, you can run the following command to see if everything is working:
cargo test
If everything is working correctly you can now run the following command to compile and run the project:
cargo run --release
My euristics is a lookahead algorithm that tries to find implications between literals. First I need to address
the reason why I chose to solve 3-SAT instances instead of
As you'll see in the following sections, my algorithm takes advantage of the fact that in 3-SAT instances,
every clause contains exactly 3 literals. This allows me to find implications between literals in a very efficient way.
If I were to solve
You may be wondering now, why is it easier for you to find implications between 3 literals than between
First we need to define some terms:
let
In each
By enumerating all the possible 2-SAT satisfing assignments of
Same goes for the fact that while performing the lookahead algorithm on
These are just a handfull of glimpses about the implications that can be made while looking at
If the literal $x_i$ satisfies its $\phi'_i$ with only one assignment $A$ either $true\ or\ false$ , then that literal is implied to be $A$ in the current branch of $\phi$ .
While solving some $\phi'_i$ , if some other literal $x_j$ takes the same assignment in all satisfing assignments of $\phi'$ , then $x_j$ is also implied in the current branch of $\phi$ .
While solving some $\phi'_i$ , let $x_i$ the implication found , if some other literal $x_j$ takes the same assignment in all satisfing assignments of Phi', then $x_i\implies x_j$ in the current branch of $\phi$ .
In all satisfing assignments where