Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

CLIPS Expert System 1 Formulate the following problem as a set of facts and rule

ID: 3738538 • Letter: C

Question

CLIPS Expert System 1 Formulate the following problem as a set of facts and rules, and use CLIPS to implement your formulation: A monkey, a stick, two boxes (box A and box B) and a banana are in a room. The banana is suspended from the center of the ceiling. Monkey wants to get the banana, but the banana cannot be reached because the ceiling in too high. The monkey tries to hit the banana with the stick, but it is not long enough. Initially, monkey, boxes, and the stick are all on the floor and boxes are at the corners of the room. Monkey can push the boxes to the center of the room, one box at a time. When both boxes are at the center, monkey can stack them and then climb each box at a time. Monkey can also pick up, put down and swing the stick. Monkey cannot push or stack boxes while holding the stick and can only swing the stick when holding it. The monkey can hit and get the banana by swinging the stick when boxes are stacked at the center of the room and the monkey is on top of the boxes 2- Your code should print a detailed sequence of instructions in correct order for the monkey on how to get the banana. Make necessary assumptions if needed 3- Please submit your code and a page of documentation including the assumptions that you have made. 4- You may download CLIPS from: http://clipsrules.sourceforge.net

Explanation / Answer

...************************* / / ;;* chest unlocking rules *

(defmodule unlock (?chest) "To unlock ?chest."

(defrule hold-chest-to-put-on-floor "" (object ?chest ? light ~floor ? ?)

(monkey ? ? ~?chest> => (goal holds ?chest))

(defrule put-chegt-on-floor ""

?fl <- (monkey ?place ?on ?chest)

?f2 <- (object ?chest held light held ?contains ?key)

=>

(printout "Monkey throws " ?chest " off " ?on " onto floor." crlf)

(retract ?fl ?f2)

(assert (monkey ?place ?on blank))

(assert (object ?chest ?place light floor ?contains ?key)))

(defrule get-key-to-unlock ""

(object ?chest ?place ? floor ? ?key)

(monkey ? ? ~?key) => (goal holds ?key))

(defrule move-to-chest-with-key ""

(monkey ?mplace ? ?key)

(object ?chest ?cplaceS~?mplace ? floor ? ?key)

-> (goal walk-to ?cplace)) (defrule unlock-chest-with-key ""

?fl <- (object ?chest ?place ?weight ?on ?obj-in ?key)

(monkey ?place ?on ?key)

=>

(printout "Monkey opens chest with " ?key " revealing " ?obj-in crlf)

(retract ?fl)

(assert (object ?chest ?place ?weight ?on nil ?key))

(assert (object ?obj-in ?place light ?chest nil nil))

(return))

)

The example above, taken from the monkey-and-bananas problem, shows a module called "unlock", whose purpose is to accomplish the goal of unlocking a chest; the particular chest to unlock is indicated by the formal parameter ?chest. This module represents the rules that accomplish this subgoal of the overall goal of the monkey to eat the bananas. There are five rules in this module, three of which invoke further subgoals as part of solving this one, and two which are able to take immediate action. Only one rule has an explicit return statement. This is an example of a well-coded module, with rules which cooperate in solving a single, well-defined task.

Compare these rules with the corresponding normal CLIPS counterparts: (defrule hold-chest-to-put-on-floor "" (object ?chest ? light -floor ? ?) (monkey ? ? ~?chest) => (goal holds ?chest)) versus (defrule hold-chest-to-put-on-floor "" (goal-is-to active unlock ?chest) (object ?chest ? light -floor ? ?) (monkey ? ? ~?chest) (not (goal-is-to active holds ?chest)) => (assert (goal-is-to active holds ?chest») The ECLIPS code for the "unlock" module is shorter by 5 lines, over 12%, and the lines are shorter and less complex. In particular, note the CLIPS need for special code to prevent goal duplication. This section is typical of the entire monkey-and-bananas example.