Week 9 - Oct 20 - CLIPS


Review this document.

Read Chapters 9 (Advanced Pattern Matching) and 12 (Expert System Design Examples) in the text "Expert Systems: Principles and Programming" and pages 158-194, 221-243, and 256-262.

Complete the following problems and submit results for problems 1-3 electronically to me (email engelb) by the end (Friday) of week 10.

  1. Problem 8-1 in your text "Expert Systems: Principles and Programming".
  2. Problem 8-2 in your text "Expert Systems: Principles and Programming".
  3. Problem 8-6 in your text "Expert Systems: Principles and Programming".
  4. Irrigation Scheduling

    Problem description:

    You are a consultant working for a firm that provides an irrigation scheduling service. You have a number of clients and would like to automate the irrigation scheduling procedure. Develop a prototype system using CLIPS given the following information.

    The following is known about each field:

    name of farm field
    crop name
    irrigation status (on off)
    soil moisture depletion (smd) level

    An example fact for a field might be (note you'll need to define a template):

    (field (field-name Field1) (crop corn) (irrigation-status off) 
      (smd 1.5) (flag 0))

    Field data will be stored in a separate file. Updated field information should be stored in this file before the knowledge-based system quits. Your CLIPS program should request the name of this file. The user should also supply the corn and soybean ET (evaportranspiration) for the previous day, the rainfall for the previous day, and the chance of rainfall for the current day. A very simple interface is sufficient. (Note corn ET and soybean ET are usually different and thus both should be requested). Each field's soil moisture depletion (smd) should be updated to reflect the current value once the previous day's corn ET, soybean ET, and rainfall amount are known. The value of smd should always be positive. Rainfall decreases soil moisture depletion (smd) and ET increases soil moisture depletion. (Note: a flag for each field fact might be required to prevent looping once the soil moisture depletion is updated for ET and rainfall.)

    Irrigation should be started when smd is greater than 1.5 inches (irrigation status set to "on" and a message printed to the screen indicating irrigation in a particular field should be started). Irrigation in a field should be stopped (irrigation status set of "off" and a message printed) when rainfall causes soil moisture depletion to fall below 0.50 inches. Irrigation should also be stopped when the chance of rain is greater than or equal to 50 percent.

    Turn in (electronically) your CLIPS rules for your program.


    A rule something like the following might be used to keep track of the file name in which the facts about farm fields that are being irrigated are being stored and load the facts.

    (defrule load
      (file $?x)
      (test (= 1 (length $?x)))
      (load-facts (str-implode $?x)))

    The soil moisture depletion update rule for corn might be written as:

    (defrule update-smd-corn
      (rainfall ?r)
      (corn-et ?c)
      ?f <-(field (crop corn) (smd ?s) (flag 0))
      (modify ?f (smd =(+ (- ?s ?r) ?c) (flag 1))) 

    A similar rule to update soybean soil moisture depletion should be written.

    The following rules might be used to place the updated field information back into the file from which it was obtained:

    (defrule open
      (declare (salience -10))
      (file $?x)
      (test (= (length $?x) 1))
      (open (str-implode $?x) out "w"))
    (defrule print-to-file
      (declare (salience -20))
      (field (field-name ?x) (crop ?c) (irrigation-status ?i)
               (smd ?s) (flag 1))
      (printout out "(field (field-name " ?x ") (crop " ?c ") (irrigation-status "
           ?i ") (smd " ?s ") (flag 0))" crlf))
    The following example facts might be used to test your program:
    (field (field-name field1) (crop corn) (irrigation-status on) 
      (smd 1.8) (flag 0))
    (field (field-name engel-2) (crop soybeans) (irrigation-status off) 
      (smd .5) (flag 0))
    (field (field-name jones-7) (crop corn) (irrigation-status on) 
      (smd 1.4) (flag 0))
    (field (field-name smith-3) (crop soybeans) (irrigation-status on) 
      (smd 1.55) (flag 0))