GithubHelp home page GithubHelp logo

hw2's Introduction

CDCL SAT solver.

This repository contains the framework you must extend to solve homework 2. In the following sections, we describe how you can build and extend the framework. We present commands for UNIX-based systems. However, these commands are simple enough, and it shouldn't be hard to port them to other platforms.

Building and Running the Project.

Prerequisite.

This project is built with maven. If your system does not have maven installed, follow system-specific instructions on how to install it here.

Building the JAR file.

In order to build the project simply type the following command:

$ mvn package

This will create a JAR named hw2-1.0-SNAPSHOT-jar-with-dependencies.jar under directory target.

Running the Project.

To run the project simply run the following command:

$ java -cp target/hw2-1.0-SNAPSHOT-jar-with-dependencies.jar <fully qualified name of Main class>

The program accepts the formula through the standard input. If you are typing the expression manually on the terminal, you must also explicitly type EOF (Ctrl+d in UNIX systems). The easiest way would be to redirect the input from a file to the application, like the following:

$ java -cp target/hw2-1.0-SNAPSHOT-jar-with-dependencies.jar <fully qualified name of Main class> < <path to input file>

The JAR contains the following three main classes:

  1. edu.utexas.cs.alr.CNFDriver: This is the main class for part a. It invokes method ExprUtils.toCNF and prints the result in dimacs format.
  2. edu.utexas.cs.alr.TseitinDriver: This is the main class for part b. It invokes method ExprUtils.toTseitin and prints the result in dimacs format.
  3. edu.utexas.cs.alr.SATDriver: This is the main class for part c. It invokes method ExprUtils.checkSAT and it prints either SAT or UNSAT depending on the return value of the checkSAT.

By default, invoking the tool with any of the above classes is going to throw an UnsupportedOperationException with the message "implement this". To solve this problem set, you must implement the body of all methods that throw this type of exceptions.

Input Format.

The program accepts propositional formulas in prefix format. For instance, the input (impl x1 (not x2)) represents the propositional formula x1 -> not x2. Propositional variables are of the form xN, where N is a positive integer (i.e., N > 0). The BNF grammar for the input format can be found in src/main/antlr4/edu/utexas/cs/alr/parser/Expr.g4. You can find some sample input formulas under directory resources/sample-inputs. Furthermore, directory resources/test-cases contains several test cases you can use to test your implementation. Directory sat contains statisfiable formulas, whereas directory unsat contains unsatisfiable formulas.

Framework Outline.

The framework provides some basic functionality for creating and manipulating ASTs for propositional formulas. You must use the provided components in order to implement the missing parts of the framework (as also mentioned above). You can generally create any additional classes you need for implementing the required functionality. But you cannot modify the main classes (mentioned above) and use any libraries except for Java's standard library.

Creating and manipulating expressions.

Package edu.utexas.cs.alr.ast contains classes that describe ASTs for propositional formulas. Every class is a subtype of edu.utexas.cs.alr.ast.Expr. The base class contains a single abstract method called getKind, which returns the type of the expression (e.g., OR, AND, IMPL, etc.).

To create an AST node you must use class edu.utexas.cs.alr.ast.ExprFactory. This class provides one static method for each type of node. For example, the following code snippet creates an AST for expression (and x1 (not x2)).

import edu.utexas.cs.alr.ast.*;

...

VarExpr x1 = ExprFactory.mkVAR(1),
        x2 = ExprFactory.mkVAR(2);
NegExpr notX2 = ExprFactory.mkNEG(x2);
AndExpr and = ExprFactory.mkAND(x1, notX2);

This factory class memorizes all the expressions it creates and always returns the same expression for syntactically equivalent propositional formulas. That is, if you invoke a static method with the same arguments multiple types, the return value is always going to be the first expression the factory returned. For example, consider the following code snippet:

import edu.utexas.cs.alr.ast.*;

...

VarExpr x1 = ExprFactory.mkVAR(1),
        x2 = ExprFactory.mkVAR(2);

AndExpr and1 = ExprFactory.mkAND(x1, x2),
        and2 = ExprFactory.mkAND(x1, x2);

assert and1 == and2; // This assertion holds

The assertion above is guaranteed to hold. That means, in case you want whether two Expr objects are syntactically equivalent, you just need to compare them with Java's == operator.

hw2's People

Contributors

kferles 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.