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

  • Log on to your account
  • Go the the handouts folder, then to the CLIPS folder, and copy the following files into your account:
    • clipsedt.exe
    • clipswin.exe
    • FZCLIPSwin.exe (only if you are interested in playing with Fuzzy Clips)
  •  Double-click on the editor (clipsedt) and type in the following code:
·                      (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)))
·                      )
;
  • Load this into clips
    • save the file
    • double click on the clips executable (clipswin.exe)
    • type (clear) or select clear from the execution menu
    • from the File menu, select "load constructs"
    • load the file you just typed in (it will have the extension ".clp"
    • (reset)
    • (run)
  • Play with it a bit (make it a rainy day, for example). Save this - we'll look at it again.
  • Then work the following problem to hand in.

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!