Title: Message
There are obviously many ways to satisfy a given set of requirements.  My experience has shown that often times when I run into trouble, I'm trying to do too much with a single rule.  I can usually find a solution by interjecting some intermediate facts and/or splitting the logic across multiple rules.
 
Taking some liberty with your fact/rule definitions, I believe that the attached .clp file demonstrates *a* viable solution to your basic requirements. ;)
 
I hope this helps.
 
-Mitch 
 
 -----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Hitesh Lad
Sent: Tuesday, December 28, 2004 4:23 PM
To: [email protected]
Subject: JESS: <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


Attachment: links.clp
Description: Binary data

Reply via email to