Programming Mini-Project 2
Max possible score:
- 4308: 100 Points (+50 Points EC)
- 5360: 100 Points (+50 Points EC)
Complete Task 1 and either Task 2-A or 2-B (Complete both for 50 Points
Extra Credit)
Task 1:
Max: [4308: 50 Points,
5360: 50 Points]
The
task in this programming assignment is to design appropriate
descriptions of facts, actions, and goals, using the PDDL language, for
two planning problems: the Tower
of Hanoi problem,
and the 7-puzzle problem (a variation of the 8-puzzle problem where two
squares are clear instead of one). You will use your descriptions as
inputs to a Graphplan implementation. If your descriptions are correct,
Graphplan will produce appropriate plans.
Compiling
and Running the Software
The
Graphplan software can be downloaded from graphplan.zip.
See the README file in that package for additional information. To
compile the software on omega,
unzip the directory, and, from that directory, type
make graphplan
Once
the program compiles, it can be invoked from the commandline as follows:
graphplan -o [operators_file] -f [facts_file]
For
example:
graphplan -o block_ops.txt -f block_facts3.txt
- Argument operators_file specifies
the location of a text file containing definitions of actions. For
example, see block_ops.txt for definitions of
actions appropriate for the blocks world.
- Argument facts_file specifies
the location of a text file containing definitions of facts about the
environment, including objects (and types for those objects), general
predicates that are always true, initial state description, and goal
description. For example, see block_facts2.txt, block_facts3.txt,
and block_facts4.txt for example
fact descriptions for the blocks world.
Once
you start running the software, it will ask you three questions. Just
hit enter for each question,
so as to use the default settings. If your descriptions of actions and
facts are correct, the program will print out a plan achieving the
stated goal.
Note
that the preconds in each fact file will contain both statements that
are always true in that domain (i.e., in the Tower of Hanoi domain or
the 7-puzzle domain), and statements that simply describe the initial
state for that specific planning problem. In addition to the facts
files for the specific planning problems you are given, you will have
to create a separate text file that includes all the statements that
must be present in ANY facts file for that domain.
Tower
of Hanoi Description
A
description of the Tower of Hanoi domain can be found at Wikipedia.
In all problems that your program will be tested with there will be
five discs (called disk1, disk2, disk3, disk4, disk5) and three pegs
(called A, B, C). In all your facts files you will have to include both
a common part (defining objects and relations among objects) and a
plan-specific part (describing the initial state and goal for each
plan). Note that some of the five disks may not appear in some of the
planning problems.
The
two planning problems you have to solve are:
Problem
1
initial state:
(on disk1 disk2)
(on disk2 A)
(clear disk1)
(clear B)
(clear C)
goal:
(on disk1 B)
(on disk2 C)
Problem
2
initial state:
(on disk1 disk2)
(on disk2 disk3)
(on disk3 disk4)
(on disk4 disk5)
(on disk5 C)
(clear disk1)
(clear A)
(clear B)
goal:
(on disk1 disk2)
(on disk2 disk3)
(on disk3 disk4)
(on disk4 disk5)
(on disk5 A)
7-puzzle
Description
7-puzzle
is like 8-puzzle, except that there are only pieces numbered from 1 to
7 (not from 1 to 8), and there are two clear squares on the board. At
any move, we can move a numbered piece to an adjacent clear square.
The
two planning problems you have to solve are (X indicates a clear
square):
Problem
1
initial state:
123
456
7XX
goal:
123
X56
4X7
Problem
2
initial state:
XX7
654
321
goal:
123
456
7XX
Grading
This
task will be graded for 50 points. Half the points will correspond to
your solutions for the Tower of Hanoi world, and the rest will
correspond to your solutions for the 7-puzzle problem. Specifically,
the point allocation is:
- 20 points: defining facts and actions correctly. The language
that you define (i.e., the actions, objects, and general statements
that are always true) should be sufficient not only for the specific
plans that you are required to construct, but also for any other
planning problems that we can define in the Tower of Hanoi domain or
the 7-puzzle domain. As part of grading, we will also test your
solutions on planning problems that we will make up.
- 30 points: solving the planning problems you are given (two for
the Tower of Hanoi domain, two for the 7-puzzle domain) + 1 additional
problem per domain. You get 5 points for each problem. If you solve all
6 correctly, you get 30 points.
Task 2-A:
Max: [4308: 50 Points,
5360: 50 Points]
The
task
in this part is to implement a system that:
- Can determine the posterior probability of different
hypotheses, given priors for these hypotheses, and given a sequence of
observations.
- Can determine the probability that the next observation
will be of a specific type, priors for different hypotheses, and given
a sequence of observations.
As
in the slides that we saw in class, there are five types of bags of
candies. Each bag has an infinite amount of candies. We have one of
those bags, and we are picking candies out of it. We don't know what
type of bag we have, so we want to figure out the probability of each
type based on the candies that we have picked.
The
five possible hypotheses for our bag are:
- h1 (prior:
10%): This type of bag contains 100% cherry candies.
- h2 (prior:
20%): This type of bag contains 75% cherry candies and 25% lime candies.
- h3 (prior:
40%): This type of bag contains 50% cherry candies and 50% lime candies.
- h4 (prior:
20%): This type of bag contains 25% cherry candies and 75% lime candies.
- h5 (prior:
10%): This type of bag contains 100% lime candies.
Command
Line arguments:
The
program takes a single command line argument, which is a string, for
example CLLCCCLLL. This string represents a sequence of observations,
i.e., a sequence of candies that we have already picked. Each character
is C if we picked a cherry candy, and L if we picked a lime candy.
Assuming that characters in the string are numbered starting with 1,
the i-th character of the string corresponds to the i-th observation.
The program should be invoked from the commandline as follows:
compute_a_posteriori observations
For
example:
compute_a_posteriori CLLCCLLLCCL
We
also allow the case of not having a command line argument at all, this
represents the case where we have made no observations yet.
Output:
Your
program should create a text file called "result.txt", that is
formatted exactly as shown below. ??? is used where your program should
print values that depend on its command line argument. Atleast five
decimal
points should appear for any floating point number.
Observation sequence Q: ???
Length of Q: ???
After Observation ??? = ???: (This and all remaining lines are repeated for every observation)
P(h1 | Q) = ???
P(h2 | Q) = ???
P(h3 | Q) = ???
P(h4 | Q) = ???
P(h5 | Q) = ???
Probability that the next candy we pick will be C, given Q: ???
Probability that the next candy we pick will be L, given Q: ???
Task 2-B:
Max: [4308: 50 Points,
5360: 50 Points]
Figure 1: A Bayesian network
establishing
relations between events on the burglary-earthquake-alarm domain,
together with complete specifications of all probability distributions.
For the Bayesian network of Figure 1, implement a program that
computes and prints out the probability of any combination of events
given any other combination of events. If the executable is called
bnet, here are some example invocations of the program
- To print out the probability P(Burglary=true and
Alarm=false | MaryCalls=false).
bnet Bt Af given Mf
- To print out the probability P(Alarm=false and
Earthquake=true).
bnet Af Et
- To print out the probability P(JohnCalls=true and
Alarm=false | Burglary=true and Earthquake=false).
bnet Jt Af given Bt Ef
- To print out the probability P(Burglary=true and
Alarm=false and MaryCalls=false and JohnCalls=true and
Earthquake=true).
bnet Bt Af Mf Jt Et
In general, bnet takes 1 to 6(no more, no fewer) command line
arguments, as follows:
- First, there are one to five arguments, each argument
specifying a variable among Burglary, Earthquake, Alarm, JohnCalls, and
MaryCalls and a value equal to true or false. Each of these arguments
is a string with two letters. The first letter is B (for Burglary), E
(for Earthquake), A (for Alarm), J (for JohnCalls) or M (for
MaryCalls). The second letter is t (for true) or f (for false). These
arguments specify a combination C1 of events whose probability we want
to compute. For example, in the first example above, C1 =
(Burglary=true and Alarm=false), and in the second example above C1 =
(Alarm=false and Earthquake=true).
- Then, optionally, the word "given" follows, followed by one
to four arguments. Each of these one to four arguments is again a
string with two letters, where, as before the first letter is B (for
Burglary), E (for Earthquake), A (for Alarm), J (for JohnCalls) or M
(for MaryCalls). The second letter is t (for true) or f (for false).
These last arguments specify a combination of events C2 such that we
need to compute the probability of C1 given C2. For example, in the
first example above C2 = (MaryCalls=false), and in the second example
there is no C2, so we simply compute the probability of C1, i.e.,
P(Alarm=false and Earthquake=true).
The implementation should not contain hardcoded values for all
combinations of arguments. Instead, your code should use the tables
shown on Figure 1 and the appropriate formulas to evaluate the
probability of the specified event. It is OK to hardcode values from
the tables on Figure 1 in your code, but it is not OK to hard code
values for all possible command arguments, or probability values for
all possible atomic events. More specifically, for full credit, the
code should include and use a Bayesian network class. The class should
include a member function called computeProbability(b, e, a, j, m),
where each argument is a boolean, specifying if the corresponding event
(burglary, earthquake, alarm, john-calls, mary-calls) is true or false.
This function should return the joint probability of the five events.
Sample output for both Task 2-A and 2-B are given here.
How to submit
For each part: Implementations in C, C++, Java, and Python will
be accepted. Points will be taken off
for failure to comply
with this requirement.
Create a ZIPPED
directory called <net-id>_proj2.zip (no other
forms
of compression
accepted, contact the instructor or TA if you do not know how to
produce .zip files). The zip file should contain:
- A folder for each Task (Task1, Task2A and/or Task2B)
- For Task 1, Make sure the folder contains
- Predicates used for each task and what they mean.
- Constants used for each task and what they mean.
- hanoi_ops.txt: Operations for Tower of Hanoi problem
- hanoi_facts1.txt: Description for Problem 1
- hanoi_facts2.txt: Description for Problem 2
- hanoi_facts_common.txt: The part of each facts file that is
common to any problem in this domain
- 7puzzle_ops.txt: Operations for 7-puzzle problem
- 7puzzle_facts1.txt: Description for Problem 1
- 7puzzle_facts2.txt: Description for Problem 2
- 7puzzle_facts_common.txt: The part of each facts file that is
common to any problem in this domain
- For each Task 2 folder, Make sure the folder contains
- A README file with:
- Name and UTA ID of the student.
- What programming language is used.
- How the code is structured.
- Instructions for Compiling and Executing
- The code for the task.