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.

Would you describe what your goal is and perhaps we can suggest a better
approach?

Cheers,
Jason

----

Morris Technical Solutions LLC
[EMAIL PROTECTED]


On 10/17/07, Nicolas Fortin <[EMAIL PROTECTED]> wrote:
>
>
>
> Hello everybody,
>
>
>
> Suppose that I have the following template:
>
>
>
> (deftemplate MAIN::My-Template
>
>   (slot id (type INTEGER))
>
>   (slot index1 (type INTEGER))
>
>   (slot index2 (type INTEGER)))
>
>
>
>
>
> I want a rule that would be activated by the fact with the greatest index1
*and* the smallest index2. Note that index1 and index2 *are not* unique.
>
>
>
>
>
> So let's say that these facts are in the working memory:
>
> (assert (MAIN::My-Template
>
>   (id 1) (index1 1) (index2 0))
>
> (assert (MAIN::Queue
>
>   (id 2) (index1 1) (index2 0))
>
> (assert (MAIN::Queue
>
>   (id 3) (index1 0) (index2 0))
>
>
>
>
>
> The rule would fire either with the first (id 1) or second (id 2) fact.
>
>
>
> And now let's say that these facts are in the working memory:
>
> (assert (MAIN::My-Template
>
>   (id 1) (index1 1) (index2 -1))
>
> (assert (MAIN::Queue
>
>   (id 2) (index1 1) (index2 0))
>
> (assert (MAIN::Queue
>
>   (id 3) (index1 0) (index2 0))
>
>
>
>
>
> The rule would fire only with the first fact (id 1).
>
>
>
>
>
> How can I write this kind of rule?
>
>
>
>
>
> Thanks in advance.
>
>
> Nicolas
>
> ________________________________
Envoie un sourire, fais rire, amuse-toi! Employez-le maintenant!



-- 
-----------------------------------------------------------
Jason Morris
Morris Technical Solutions LLC
http://www.morris-technical-solutions.com

Reply via email to