Title: <Newbie>defining a rules that gets max value joining a list of facts and a multifield

Hi, l looked around the mailing list and couldn't find a comparable problem to mine.

I'm trying to fire a rule when:
   1) I have indication facts for all the links of a system
   2) The indications should have the same timestamp
   3) the returned ?dvalue should be the maximum for all the indication facts with the same timestamp


With the following facts:

(assert (indication (link "LINK001") (timestamp 20) (value 22)))
(assert (indication (link "LINK002") (timestamp 20) (value 20)))
(assert (indication (link "LINK003") (timestamp 20) (value 18)))
(assert (system (name "retail")  (links (create$ "LINK001" "LINK002" "LINK003"))))


I got this far and now I'm stuck:

(defrule max
    "Calculate the maximum value"
    (system (name ?pname) (links $?links))
    (indication (link ?dlink) (value ?dvalue) (timestamp ?dtimestamp))
    (test (member$ ?dlink ?links))
     =>
    (printout t "Found pair " ?pname " for link " ?dlink " with datalag " ?dvalue crlf)
)

This only makes sure that the indications have matching system, but not the same one.
I know this will match the indication 3 times.  I'm not sure how to write the pattern to make sure we have an indication for all the links for a system with the same timestamp.

I want this to fire off and give me a value of 22.

Any help is appreciated.

+ - + - + - + - + - + - + - + - + - + - + - + - + - + - +
hitesh lad


Reply via email to