Giter Club home page Giter Club logo

sat-solver-using-dpll's Introduction

SAT Solver using DPLL

This code was originally written as an assignment for the course EE677: Foundations of VLSI CAD at IIT Bombay. The code solves a satisfiabilty problem in Conjuctive Normal Form (CNF) using the famous DPLL Algorithm. If the problem is satisfiable, one possible solution is returned.

Algorithm

The code is written in Python 3, it might not be compatible with previous versions. The problem is defined in CNF form. The DPLL algorithm can be explained by the following pseudocode.

solve_dpll(cnf):
    while(cnf has a unit clause {X}):
        delete clauses contatining {X}
        delete {!X} from all clauses
    if null clause exists:
        return False
    if CNF is null:
        return True
    select a literal {X}
    cnf1 = cnf + {X}
    cnf2 = cnf + {!X}
    return solve_dpll(cnf1)+solve_dpll(cnf2)

Usage

  • Please write the CNF form problem in a text file in the following way.
  • For Example: (!B+A+!C)(B+A+!C)(!B+!A+!C)(B)(C) will be written as
!B A !C
B A !C
!B !A !C
B
C
  • Save it in <filename> (example problem.txt).
  • Run the following command
$ python3 SATSolver.py --input problem.txt

Example

For CNF = (!B+A+!C)(B+A+!C)(!B+!A+!C)(B)(C), we get

CNF = (!B+A+!C)(B+A+!C)(!B+!A+!C)(B)(C)
Units = ['C', 'B']
CNF after unit propogation = (!A)(A)

CNF = (!A)(A)(A)
Units = ['!A', 'A']
CNF after unit propogation = ()
Null clause found, backtracking...

CNF = (!A)(A)(!A)
Units = ['!A', 'A']
CNF after unit propogation = ()
Null clause found, backtracking...

Reached starting node!
Number of Splits = 3
Unit Propogations = 6

Result: UNSATISFIABLE

TODO

  • Refactor into a pythonic module
  • Update README
  • Use argparse for command line inputs
  • Add a verbosity command line option

sat-solver-using-dpll's People

Contributors

safwankdb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.