Programming Assignment 3
Due dates:
Interim report: Sunday 10/14/2012, 11:59pm
Full assignment: Monday 10/22/2012 Friday 10/26/2012, 11:59pm.
Task
The task in this programming assignment is to implement, a knowledge
base and an inference engine for the wumpus world. First of all, you
have to create a knowledge base (stored as a text file) storing the
rules of the wumpus world, i.e., what we know about pits, monsters,
breeze, and stench. Second, you have to create an inference engine,
that given a knowledge base and a statement determines if, based on the
knowledge base, the statement is definitely true, definitely false, or
of unknown truth value.
Command-line Arguments
The program should be invoked from the commandline as follows:
check_true_false
wumpus_rules.txt [additional_knowledge_file]
[statement_file]
For example:
check_true_false
wumpus_rules.txt kb1.txt statement1.txt
- Argument wumpus_rules.txt specifies the location of a text
file
containing the wumpus rules, i.e., the rules that are true in any
possible wumpus world, as specified above (once again, note that the
specifications above are not identical to the ones in the book).
- Argument [additional_knowledge_file] specifies an input
file that
contains additional information, presumably collected by the agent as
it moves from square to square. For example, see kb3.txt.
- Argument [statement_file] specifies an input file that
contains a
single logical statement. The program should check if, given the
information in wumpus_rules.txt and [additional_knowledge_file], the
statement in [statement_file] is definitely true, definitely false, or
none of the above.
Output
Your program should create a text file called "result.txt". Depending
on what your inference algorithm determined about the statement being
true or false, the output file should contain one of the following four
outputs:
- definitely true
- definitely false
- possibly true, possibly false
- both true and false
Notice that the sample code provided below stores the words "result
unknown" to the result.txt file. Also, the "both true and false" output
should be given when the knowledge base (i.e., the info stored in
wumpus_rules.txt AND in the additional knowledge file) entails both the
statement from statement_file AND the negation of that statement.
Syntax
The wumpus rules file and the additional knowledge file contain
multiple lines. Each line contains a logical statement. The knowledge
base constructed by the program should be a conjunction of all the
statements contained in the two files. The sample code (as described
later) already does that. The statement file contains a single line,
with a single logical statement.
Statements are given in prefix notation. Some examples of prefix
notation are:
(or
M_1_1 B_1_2)
(and
M_1_2 S_1_1 (not (or M_1_3 M_1_4)))
(if
M_1_1 (and S_1_2 S_1_3))
(iff
M_1_2 (and S_1_1 S_1_3 S_2_2))
(xor
B_2_2 P_1_2)
P_1_1
B_3_4
(not
P_1_1)
Statements can be nested, as shown in the above examples.
Note that:
- Any open parenthesis that is not the first character of a
text line
must be preceded by white space.
- Any open parenthesis must be immediately followed by a
connective
(without any white space in between).
- Any close parenthesis that is not the last character of a
text line
must be followed by white space.
- If the logical expression contains just a symbol (and no
connectives),
the symbol should NOT be enclosed in parentheses. For example, (P_1_1)
is not legal, whereas (not P_1_1) is legal. See also the example
statements given above.
- Each logical expression should be contained in a single
line.
- The wumpus rules file and the additional knowledge file
contain a set
of logical expressions. The statement file should contain a single
logical expression. If it contains more than one logical expression,
only the first one is read.
- Lines starting with # are treated as comment lines, and
ignored.
- You can have empty lines, but they must be totally empty.
If a line has
a single space on it (and nothing more) the program will complain and
not read the file successfully.
There are six connectives: and, or, xor, not, if, iff. No other
connectives are allowed to be used in the input files. Here is some
additional information:
- A statement can consist of either a single symbol, or a
connective
connecting multiple (sub)statements. Notice that this is a recursive
definition. In other words, statements are symbols or more complicated
statements that we can make by connecting simpler statements with one
of the six connectives.
- Connectives "and", "or", and "xor" can connect any number
of
statements, including 0 statements. It is legal for a statement
consisting of an "and", "or", or "xor" connective to have no
substatements, e.g., (and). An "and" statement with zero substatements
is true. An "or" or "xor" statement with zero substatements is false.
An "xor" statement is true if exactly 1 substatement is true (no more,
no fewer).
- Connectives "if" and "iff" require exactly two
substatements.
- Connective "not" requires exactly one substatement.
The only symbols that are allowed to be used are:
- M_i_j (standing for "there is a monster at square (i, j)).
- S_i_j (standing for "there is a stench at square (i, j)).
- P_i_j (standing for "there is a pit at square (i, j)).
- B_i_j (standing for "there is a breeze at square (i, j)).
NO OTHER SYMBOLS ARE
ALLOWED. Also, note that i and j can take values
1, 2, 3, and 4. In other words, there will be 16 unique symbols of the
form M_i_j, 16 unique symbols of the form S_i_j, 16 unique symbols of
the form P_i_j, and 16 unique symbols of the form B_i_j, for a total of
64 unique symbols.
The Wumpus Rules
Here is what we know to be true in any wumpus world, for the purposes
of this assignment (NOTE
THAT THESE RULES ARE NOT IDENTICAL TO THE ONES
IN THE TEXTBOOK):
- If there is a monster at square (i,j), there is stench at
all adjacent
squares.
- If there is stench at square (i,j), there is a monster at
one of the
adjacent squares.
- If there is a pit at square (i,j), there is breeze at all
adjacent
squares.
- If there is breeze at square (i,j), there is a pit at one
or more of
the adjacent squares.
- There is one and only one monster (no more, no fewer).
- Squares (1,1), (1,2), (2,1), (2,2) have no monsters and no
pits.
- The number of pits can be between 1 and 11.
- We don't care about gold, glitter, and arrows, there will
be no
information about them in the knowledge base, and no reference to them
in the statement.
Sample code
The following code implements, in Java and C++, a system that reads
text files containing information for the knowledge base and the
statement whose truth we want to check. Feel free to use that code and
build on top of it. Also feel free to ignore that code and start from
scratch.
You can test this code, by compiling on omega, and running on input
files a.txt, b.txt, and c.txt. For example, for the
Java code you can
run it as:
javac
*.java
java
CheckTrueFalse a.txt b.txt c.txt
and for C++, you can do:
g++
-o check_true_false check_true_false.cpp
./check_true_false
a.txt b.txt c.txt
Extracting symbols and evaluating sets of assignments
Note that, as stated below in the grading specifications, you need to
include, in your code, specific functions that perform the following:
a function that extracts, and stores in a list, the set of all symbols
used in the wumpus rule, the knowledge base, and the statement. The
list should contain no repetitions.
a function that, given as arguments the knowledge base (including the
wumpus rules), the statement to be shown true or false, and a a set of
boolean assigments (i.e., either true or false) for each symbol,
determines whether, under that set of assignments, the knowledge base
entails the statement.
Choices for Inference
You can implement any inference algorithm you want. Efficiency will not
be considered for grading (except for the extra credit competition).
You are also free to use first-order logic instead of propositional
logic. However, you should note that the sample code uses propositional
logic, and that in general it will probably be easier if you stick to
propositional logic. Also, EVEN
IF YOU DECIDE TO USE FIRST-ORDER LOGIC,
YOUR PROGRAM STILL HAS TO WORK WITH INPUT FILES THAT USE PROPOSITIONAL
LOGIC AS EXPLAINED ABOVE.
Efficiency
Brute-force enumeration of all possible assignments to the Boolean
variables will be too inefficient to produce answers in a reasonable
amount of time. You should look closely at question 3 of the third
written assignment, and integrate the answer to that question
into your
implementation. If you do that correctly, your program should produce
answers in a reasonable amount of time (like a few seconds) when the
agent has already visited 10 or more squares (and has added the
information collected from those squares to the knowledge base that you
will use as input).
Efficiency Contest
This contest is not
part of the CSE 4308 assessment, and is for extra
credit only. People who wish to participate should explicitly state
that in their submitted readme.txt file. We will test participating
submissions by timing them on several different inputs. The five
submissions with the fastest average time will be awarded 5-15 extra
credit points. Submissions will be automatically excluded if any of the
answers they provide is wrong.
Interim report
For this assignment only, the interim report is optional (though still
highly recommended) and will receive 0 points. The
interim report
should be submitted via e-mail to the instructor and the TA, and should
contain the following:
- On subject line: "CSE 4308/5360 - -
Programming Assignment 3 - Interim
report".
- On body of message: Your name and UTA ID (all
10 digits, no spaces).
- On body of message, or as an attachment (in
text, Word, PDF, or
OpenOffice format): a description (as brief or long as you want) of
what you have done so far for the assignment, and any
difficulties/bottlenecks you may have reached (in case you encounter
such difficulties, it is highly recommended to contact the instructor
and/or TA for help).
For purposes of grading, it is absolutely fine if your
interim report
simply states that you have done nothing so far. At the same time,
starting early and identifying potential bottlenecks by the deadline
for the interim report is probably a good strategy for doing well in
this assignment
Grading
The assignment will be graded out of 100 points. There is also extra
credit. Extra credit points are used at the end of the semester, after
grade thresholds have been determined, to adjust cumulative course
scores and possibly give higher grades when the adjusted cumulative
scores reach the threshold for a higher grade. The upper limit on extra
credit points for this assignment is 30. However, the extra credit
points cannot be counted towards the requirement of achieving a score
of at least 60% on the CSE4308 assessment.
- 40 points: submitting an appropriate wumpus_rules.txt file
that can be
used as the first command-line input to the program, according to the
propositional logic syntax and symbols defined above. The file should
contain logical statements corresponding to the wumpus rules stated
above. For each of the 8 rules, you need to determine if you need to
add any statements to wumpus_rules.txt because of that rule, and if so,
what statements to add. Correct handling of any of the eight rules is
worth 5 points.
- 10 points: designing a function that extracts, and stores
in a list,
the set of all symbols used in the wumpus rule, the knowledge base, and
the statement. The list should contain no repetitions.
- 10 points: designing a function that, given as arguments
the knowledge
base (including the wumpus rules), the statement to be shown true or
false, and a a set of boolean assigments (i.e., either true or false)
for each symbol, determines whether, under that set of assignments, the
knowledge base entails the statement.
- 6 points: integrating, in your implementation, the correct
answer to
question 3 of the third written assignment, so that your program is
reasonably efficient when the knowledge base contains information
obtained by the agent visiting 10 or more squares.
- 24 points: correctness of results. In particular, 4 points
will be
allocated for each of the following requirements that the program
satisfies:
- In all cases where a statement is definitely true (and
its negation is
not definitely true) given the wumpus rules and knowledge base, the
program outputs "definitely true".
- In all cases where the program outputs "definitely true",
the statement
is definitely true (and its negation is not definitely true) given the
wumpus rules and knowledge base.
- In all cases where a statement is definitely false given
the wumpus
rules and knowledge base, the program outputs "definitely false".
- In all cases where the program outputs "definitely
false", the
statement is definitely false given the wumpus rules and knowledge base.
- In all cases where a statement is possibly true and
possibly false
given the wumpus rules and knowledge base, the program outputs
"possibly true, possibly false".
- In all cases where the program outputs "possibly true,
possibly false",
the statement is possibly true and possibly false given the wumpus
rules and knowledge base.
- 10 points: Elegance of the software implementation: modular
design,
good code organization, code that is easy to read and understand,
proper comments.
- 15 points extra credit: efficiency contest first-place
winner.
- 10 points extra credit: efficiency contest second-place
winner.
- 5 points extra credit: efficiency contest third, fourth,
and
fifth-place winner.
Also, please note that, for CSE 4308
students, written assignment 3 and programming assignment 3 together
will be used as the CSE 4308
assessment, worth 6.7% of the grade.
How to submit
Submissions should be made using Blackboard. Implementations in Python,
C, C++, and Java will be accepted. If you would like to use another
language, please first check with the instructor via e-mail. Points
will be taken off for failure to comply with this requirement.
Submit a ZIPPED directory called <name>-programming3.zip
(no other forms of
compression accepted, contact the instructor or TA if you do not know
how to produce .zip files). The directory should contain source code.
Including binaries is optional. The submission should also contain a
file called readme.txt, which should specify precisely:
- Name and UTA ID of the student.
- What programming language is used.
- How the code is structured.
- How to run the code, including very specific compilation
instructions.
Instructions such as "compile using g++" are NOT considered specific.
Providing all the command lines that are needed to complete the
compilation on omega is specific.
Insufficient or unclear instructions will be penalized by up to 20
points. Code that does not run on omega machines gets AT MOST half
credit (50 points).
Submission checklist
- DID YOU
INCLUDE THE wumpus_rules.txt file?
- Is the code running on omega?
- Is the submitted zipped file called <name>-programming3.zip?
- Does the attachment include a readme.txt file, as
specified?