Hello everybody and specially to Jason and Wolfgang. Thank you for your help 
guys.
 
First, concerning what you said Jason, I don't want to hunt fact with the 
highest index1 and lowest index2 among all instances of an arbitrary number of 
fact template (e.g. My-Template, Queue, etc.). I did a typo (damn copy and 
paste), you should have seen only My-Template. So forget the Queue template.
 
Second, I have already done an example as you said guys, but what puzzled me is 
that the result is not really what I expected. So let's say I have:
 
(deftemplate MAIN::My-Template
(slot id (type INTEGER))
(slot index1 (type INTEGER))
(slot index2 (type INTEGER)))

(reset)

 
(assert (MAIN::My-Template 
(id 1) (index1 1) (index2 0)))
(assert (MAIN::My-Template 
(id 2) (index1 1) (index2 0)))
(assert (MAIN::My-Template 
(id 3) (index1 0) (index2 0)))

 
(defrule MAIN::greatest-one-smallest-two
"Find the My-Template with greatest index1 and smallest index2"
(MAIN::My-Template 
(id ?id1)
(index1 ?index1_1)
(index2 ?index2_1)) 
(not (MAIN::My-Template 
(id ~?id1)
(index1 ?index1_2&:(>= ?index1_2 ?index1_1))
(index2 ?index2_2&:(< ?index2_2 ?index2_1 ))))
=>
(printout t 
"No My-Template fact has both a larger index1 and a smallest index2 than fact # 
" ?id1 crlf)
(printout t 
" index1: " ?index1_1 " index2: " ?index2_1 crlf))

(run)
 
The output is not what I want, since the third fact (id 3) activates the rule. 
As far as I can understand it should not, because its index1 slot is not the 
greatest. In this example, I would be expected that only the first and the 
second facts activate this rule, since they both have the greatest index1 and 
the smallest index2. Maybe I am wrong, but it seems for me that Jess is 
performing a *or* rather than an *and* in this example. What is wrong?
 
Thanks again.
 
Nicolas



Date: Thu, 18 Oct 2007 02:56:18 -0400From: [EMAIL PROTECTED]: [EMAIL 
PROTECTED]: Re: JESS: How can I write this rule?
Hi NIcolas,
A rule like this seems to work for me:(defrule greatest-one-smallest-two    
"Find the My-Template with greatest index1 and smallest index2"    
(MAIN::My-Template (id ?id1)(index1 ?i1_1)(index2 ?i1_2))     (not 
(MAIN::My-Template 
         (id ~?id1)
         (index1 ?i2_1&:(>= ?i2_1 ?i1_1))
         (index2 ?i2_2&:(< ?i2_2 ?i1_2 ))))    =>    (printout t 
       "No My-Template fact has both a larger index1 and a smallest index2 than 
fact # " ?id1 crlf)    (printout t 
       "    index1: " ?i1_1 "  index2: " ?i1_2 crlf))It seems a bit more 
complicated if you want to hunt for a particular fact with the highest index1 
and lowest index2 among all instances of an arbitrary number of fact templates 
( i.e., my-template, queue, etc.) that share these two slots in common

Reply via email to