Skip to content

matthewchao/HW2

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 98.6%
  • ANTLR 1.4%