CPSC 420 - AI Homework #4 due: Monday, April 23, 2007 The goal of this project is to get some experience using JESS, as a real-world knowledge-based programming environment (expert system shell). Students will have to download and install their own demo copies of JESS, available from: http://herzberg.ca.sandia.gov/jess/ Java is required to run JESS, so students will have to install it on a system where java is available. However, no Java programming will be required for the project. (You might need to set your CLASSPATH environment variable to point to /lib/jess.jar - see the TA for help on this.) Part A (easy - just a warm-up exercise to get familiar with JESS) ------ Encode the mini wumpus-world decision making problem from Homework #2. Recall that this involved a knowledge-base of rules for deciding when the agent can leave the cave. Write these rules in a Jess knowledge base ("CLIPS" file). Then use (deffacts) to define the 3 different cases shown below. Load each and run run them (separately), and show that "can leave" is entailed by the first two but not the third. Note that the original knowledge base has been converted from propositional logic to first-order logic. For example, instead of using the proposition "found_gold", we now use the predicate "found(gold)". In JESS, this fact would be written as "(found gold)". You should see that "(can leave)" gets generated as a fact by typing (facts) after (reset) and (run). You may also print out a message if and when (can leave) gets generated. KB: have(treasure) ^ wumpus(dead) -> can(leave) found(gold) -> have(treasure) found(silver) -> have(treasure) heard(scream) -> wumpus(dead) killed(wumpus) -> wumpus(dead) had(weapon) ^ was_near(wumpus) -> killed(wumpus) had(bow) -> had(weapon) had(gun) -> had(weapon) case 1: facts = { found(silver), heard(scream), carrying(pack), was_near(wumpus) } case 2: facts = { found(gold), had(gun), was_near(wumpus) } case 3: facts = { found(gold), had(arrows), carrying(water) } Here is a transcript of the output for my implmentation (for case #2), which you should try to mimic: 6 sun> Jess70p1/bin/jess Jess, the Rule Engine for the Java Platform Copyright (C) 2006 Sandia Corporation Jess Version 7.0p1 12/21/2006 This copy of Jess will expire in 19 day(s). Jess> (batch "treasure.clp") TRUE Jess> (reset) TRUE Jess> (facts) f-0 (MAIN::initial-fact) f-1 (MAIN::found gold) f-2 (MAIN::had gun) f-3 (MAIN::was-near wumpus) For a total of 4 facts in module MAIN. Jess> (run) Mission done. Can leave! // does not print out for case #3 6 Jess> (facts) f-0 (MAIN::initial-fact) f-1 (MAIN::found gold) f-2 (MAIN::had gun) f-3 (MAIN::was-near wumpus) f-4 (MAIN::had weapon) f-5 (MAIN::killed wumpus) f-6 (MAIN::wumpus dead) f-7 (MAIN::have treasure) f-8 (MAIN::can leave) For a total of 9 facts in module MAIN. Jess> (exit) Part B ------ Encode the tennis-ball problem from Homework #1 (Sammy's Sport Shop), with rules in first-order logic that express constraints of the problem (e.g. what does it mean if a box is labeled with a given color? what does it mean if a ball of a given color is drawn/observed? if one box is a given color, none of the other boxes can be that color, by mutual exclusion...). Use (deffacts) to describe the observations and labels. Then, by doing (reset) and (run), JESS should infer the correct contents of all 3 boxes, including the fact the box 2 contains white tennis balls. Again, we will be switching from a propostional representation to a first-order representation, so instead of propositions like C2W, use predicates like "contains(2,white)", which is written as "(contains 2 white)" in JESS. Here is a transcript of my implementation. Note that I print out the contents as they are determined, as a side-effect. Also, I include a few extra initial facts, such as the 3 colors and the 3 box numbers, which were used in my rules. Here is a hint. I found it useful to infer a predicate called "wrong(A,B)" whenever I was sure box A could *not* contain balls of color B. 7 sun> Jess70p1/bin/jess Jess, the Rule Engine for the Java Platform Copyright (C) 2006 Sandia Corporation Jess Version 7.0p1 12/21/2006 This copy of Jess will expire in 19 day(s). Jess> (batch "tennis.clp") TRUE Jess> (reset) TRUE Jess> (facts) f-0 (MAIN::initial-fact) f-1 (MAIN::observe 1 yellow) f-2 (MAIN::observe 2 white) f-3 (MAIN::observe 3 yellow) f-4 (MAIN::label 1 white) f-5 (MAIN::label 2 yellow) f-6 (MAIN::label 3 both) f-7 (MAIN::color white) f-8 (MAIN::color yellow) f-9 (MAIN::color both) f-10 (MAIN::box 1) f-11 (MAIN::box 2) f-12 (MAIN::box 3) For a total of 13 facts in module MAIN. Jess> (run) box 2 contains tennis balls colored white box 1 contains tennis balls colored both box 3 contains tennis balls colored yellow 21 Jess> (facts) f-0 (MAIN::initial-fact) f-1 (MAIN::observe 1 yellow) f-2 (MAIN::observe 2 white) f-3 (MAIN::observe 3 yellow) f-4 (MAIN::label 1 white) f-5 (MAIN::label 2 yellow) f-6 (MAIN::label 3 both) f-7 (MAIN::color white) f-8 (MAIN::color yellow) f-9 (MAIN::color both) f-10 (MAIN::box 1) f-11 (MAIN::box 2) f-12 (MAIN::box 3) f-13 (MAIN::wrong 3 both) f-14 (MAIN::wrong 2 yellow) f-15 (MAIN::wrong 1 white) f-16 (MAIN::wrong 3 white) f-17 (MAIN::contains 3 yellow) f-18 (MAIN::wrong 1 yellow) f-19 (MAIN::contains 1 both) f-20 (MAIN::wrong 2 both) f-21 (MAIN::contains 2 white) For a total of 22 facts in module MAIN. Jess> (exit) What you have to turn in ------------------------ No report is needed. You just have to turn in a hard-copy (print out) of your source code (JESS rules), along with a transcript of some illustrative examples that shows that it works. You will also have to schedule time with the TA to demo your program.