Part of a rule-based system I am developing compares
data values to thresholds and outputs a warning if any
data value in a data set exceeds its threshold.
This is encapsulated in the notify-only rule below.

The requirements were then changed to include which
data values in a data set exceeded their thresholds.
This resulted in the notify-with-reason rule below.

Is this an appropriate use of the 'if' function?
I read in Giarratano & Riley that 'if' and 'while'
should be used judiciously.
One problem I see with notify-with-reason is data
values are compared to their thresholds twice.
Any suggestions on reworking this rule?
I should note that the deftemplate and defrule
commands are generated at runtime based on what
options a user selects, so data sets can vary
between runs of the system.

I am using Jess 6.0.

Thanks,
John


(deftemplate thresholds
    (slot RPM)
    (slot Temperature)
    (slot Pressure))

(deftemplate data-set
    (slot RPM)
    (slot Temperature)
    (slot Pressure))

(defrule notify-only
    (thresholds (RPM ?RPM-threshold)
                (Temperature ?Temperature-threshold)
                (Pressure ?Pressure-threshold))
    (data-set (RPM ?RPM-value)
              (Temperature ?Temperature-value)
              (Pressure ?Pressure-value))
    (test (or (> ?RPM-value ?RPM-threshold)
              (> ?Temperature-value ?Temperature-threshold)
              (> ?Pressure-value ?Pressure-threshold)))
=>
    (printout t "THRESHOLD EXCEEDED" crlf))

(defrule notify-with-reason
    (thresholds (RPM ?RPM-threshold)
                (Temperature ?Temperature-threshold)
                (Pressure ?Pressure-threshold))
    (data-set (RPM ?RPM-value)
              (Temperature ?Temperature-value)
              (Pressure ?Pressure-value))
    (test (or (> ?RPM-value ?RPM-threshold)
              (> ?Temperature-value ?Temperature-threshold)
              (> ?Pressure-value ?Pressure-threshold)))
=>
    (bind ?reason-code 0)
    (if (> ?RPM-value ?RPM-threshold)
        then (bind ?reason-code (bit-or ?reason-code 1)))
    (if (> ?Temperature-value ?Temperature-threshold)
        then (bind ?reason-code (bit-or ?reason-code 2)))
    (if (> ?Pressure-value ?Pressure-threshold)
        then (bind ?reason-code (bit-or ?reason-code 4)))
    (printout t "THRESHOLD EXCEEDED, REASON CODE IS " ?reason-code crlf))

(reset)


_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx


--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------

Reply via email to