Programming Assignment 1

Assigned: Sept. 10
Due: Oct. 8

Overview

In this assignment, you are to implement the Davis-Putnam procedure and use it to solve the map-coloring problem.

Specifically: You will write three programs.

Specifications

Input / Output.

You have two choices as to how to organize your I/O:

1. All three programs take their input from standard input and produce their output in standard output.

2. The front end reads from a file called "MAP.DAT" and writes to a file "DP.DAT". The Davis-Putnam module reads from the file "DP.DAT" and writes to a file called "DPSOL.DAT". The back end reads from the file "DPSOL.DAT" and writes to a file called "COLORING.DAT".

Davis-Putnam

The input to the Davis-Putnam procedure has the following form: An atom is denoted by a natural number: 1,2,3 ... The literal P is the same number as atom P; the literal not P is the negative. A clause is a line of text containing the integes of the corresponding literals. After all the clauses have been given, the next line is the single value 0; anything further in the file is ignored in the execution of the procedure and reproduced at the end of the output file. (This is the mechanism we will use to allow the front end to communicate to the back end.)

The output from the Davis-Putnam procedure has the following form: First, a list of pairs of atom (a natural number) and truth value (either T or F). Second, a line containing the single value 0. Third, the back matter from the input file, reproduced.

Example: Given the input

1 2 3
-2 3
-3
0
This is a simple example with 3 clauses and 3 atoms.






Davis-Putnam will generate the output
1 T
2 F
3 F
0
This is a simple example with 3 clauses and 3 atoms.
This corresponds to the clauses
P or Q or R.
not Q or R.
not R.

If the clauses have no solution, then Davis-Putnam outputs a single line containing a 0, followed by the back-matter in the input file.

Note: Your implementation of Davis-Putnam must work on _any_ set of clauses, not just those that are generated by the map coloring program

You may assume that there are no more than 1000 atoms and no more than 10,000 clauses.

Front end

The front end takes as input a representation of a map and generates as output a set of clauses to be satisfied.

The format of the input contains the following elements:

Thus, the problem of coloring the map of New England + New York in three colors is expressed in the following input file.
RED BLUE YELLOW
MAINE VERMONT NEW-HAMPSHIRE MASSACHUSETTS
RHODE-ISLAND CONNECTICUT NEW-YORK *
MAINE NEW-HAMPSHIRE
NEW-HAMPSHIRE VERMONT
NEW-HAMPSHIRE MASSACHUSETTS
VERMONT MASSACHUSETTS
VERMONT NEW-YORK
MASSACHUSETTS NEW-YORK
MASSACHUSETTS RHODE-ISLAND
MASSACHUSETTS CONNECTICUT
RHODE-ISLAND CONNECTICUT
CONNECTICUT NEW-YORK
The output consists of Click below for the files illustrating the steps in one possible solution of the problem:

You may assume that there are no more than 10 colors and 100 countries.

Back-end

The back end takes as input the output that Davis-Putnam generates when run on the output of the front end. It generates as output a coloring of the map. The format is pairs of the form "country color", one pair per line. For example, one possible output for the above example would be
MAINE RED
VERMONT RED
NEW-HAMPSHIRE BLUE
MASSACHUSETTS YELLOW
RHODE-ISLAND BLUE
CONNECTICUT RED
NEW-YORK BLUE
If the input indicates that the clauses have no solution, the back end should output the message "NO COLORING POSSIBLE".

Another example for Davis-Putnam

The following is the input-output pair just for the Davis-Putnam module --- not the map-coloring modules --- corresponding to the example in the class notes.

Programming Language

My personal preference would be for Java or C; however, if you like something else that's also OK. Keep in mind that the onus is on you to demonstrate (a) that the program works (b) that it implements the Davis-Putnam algorithm correctly. As regards (a), if your program works fine on your machine and bombs when I try it, it's your responsibility, not mine, to fix the problem. So portability should be a priority, which is why I suggest Java. As regards (b), I will judge that by reading through your code, so you should try to write elegant, readable, well commented code.

Deliverable

You should email me (davise@cs.nyu.edu) (a) the source code; (b) instructions for running it, if there's anything at all non-obvious about it. Nothing else.

Grading

The Davis-Putnam program is worth 60% of the grade; the front end is worth 30%; the back end is worth 10%. In each of these, a program that does not compile will get a maximum of 10%; a correct program will get 90%; the remaining 10% is for being well-written and well commented.