Computer Science 431
Second Exercise Set
Due: Friday, November 8
A short exercises in expert systems.
When you arrive in the lab Wednesday, please do the following
· (deftemplate weather
· (slot kind))
· (deftemplate clouds
· (slot status))
· (deftemplate activity
· (slot where))
· ;
· (deffacts some-facts
· (clouds (status none)))
· ;
· (defrule rule-1
· (clouds (status visible))
· =>
· (assert (weather (kind rainy)))
· )
· ;
· (defrule rule-2
· (clouds (status none))
· =>
· (assert (weather (kind sunny)))
· )
· ;
· (defrule rule-3
· (weather (kind rainy))
· =>
· (printout t "Stay inside today")
· (assert (activity (where indoors)))
· )
· ;
· (defrule rule-4
· (weather (kind sunny))
· =>
· (printout t "Let's go outside!" crlf)
· (assert (activity (where outdoors)))
· )
;
The following problem is from Grarratano and Riley, Expert Systems, PWS, 1994. It appears there as problem 8-13 on page 440.
Write a program that accepts the blood types of a patient in need of a blood transfusion and a donor. The program should then determine if the transfusion should proceed based upon the blood types. Type O blood can only be transfused with type O blood. Type A blood can be transfused with either type A or type O blood. (i.e., if the patient has type A blood, then the donor can be either type A or type O). Type B blood can be transfused with either type B or type O blood. Type AB blood can be transfused with type AB, type A, type B, or type O blood.
Write deftemplates for the donor and the patient with a patient or donor name and patient or donor blood type. Use deffacts to insert some initial facts (such as "(patient (name George) (type O))" to test out your system. Results can be printed out (for example "Patient George with type O blood can receive a transfusion from donor Pam with type O blood"). Be sure to include enough facts so that each rule you write (there should be several) is tested at least once.
Should you have any questions on any of these please let me know. Many thanks!