dizys / nyu-ai-lab-2

NYU Artificial Intelligence Course Lab 2: A BNF to CNF converter and generic DPLL solver

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

nyu-ai-lab-2

NYU Artificial Intelligence Course Lab 2: A BNF to CNF converter and generic DPLL solver. BNF parser is built with ANTLR4.

This implementation properly handles grouping (()) and symbol _ in atom's names.

Prerequisite

  • Python 3.8+

Getting-started

Switch to Python 3.8 on CIMS machines

The Python version has to at least have full type hint support, thus requiring Python 3.8+.

module load python-3.8

If successful, the command python3 --version should give you:

$ python3 --version
Python 3.8.6

Install dependencies/packages

Install Python packages used in this lab by running the following command:

pip3 install -r requirements.txt

or if you want to specify ANTLR4 runtime manually:

pip3 install antlr4-python3-runtime==4.9.3

Script usages

The main entrance is a python script, not a binary. It is in Shebang style, thus can be executed directly.

Use ./solver -h command to see the usage:

usage: solver [-h] [-v] -m MODE inputfile

A BNF to CNF converter and DPLL solver.

positional arguments:
  inputfile             input file path

optional arguments:
  -h, --help            show this help message and exit
  -v, --verbose         verbose output
  -m MODE, --mode MODE  solver mode, should be one of "cnf", "dpll" or
                        "solver"

Examples:

$ ./solver -m cnf input.txt
$ ./solver -m dpll -v input.txt
$ ./solver -m solver -v input.txt

Project structure

project
├─solving                       solving python module
│  ├─bnf_parser                     BNF parser python module
│  │  ├─__init__.py                     Module initialization
│  │  ├─bnf_listener.py                 BNF parser tree walk listener
│  │  ├─bnf_node.py                     BNF parser output custom tree node
│  │  ├─bnf_tree.py                     Function to call parser and generate tree
│  │  ├─BNFLexer.py                     BNF lexer generated by ANTLR4
│  │  └─BNFParser.py                    BNF parser generated by ANTLR4
│  │
│  ├─__init__.py                    Module initialization
│  ├─bnf.py                         Text/CNF converter and BNF to CNF converter
│  └─dpll.py                        DPLL solver
│
├─solver                        Main entrance python script (shebang style)
├─requirements.txt              Python packages used in this project
└─README.md                     The file you're reading

About

NYU Artificial Intelligence Course Lab 2: A BNF to CNF converter and generic DPLL solver

License:MIT License


Languages

Language:Python 97.8%Language:Makefile 1.0%Language:ANTLR 0.9%Language:Shell 0.3%