Nicolas Fortin 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.

Assuming that you mean "...activated by *any* fact with...", (which, of course, need not exist as the maximum index1 could be in one fact and the minimum index2 in another),...

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))

...and assuming that Queue is supposed to be the same as My-Template,...

The rule would fire either with the first (id 1) or second (id 2) fact.
...and assuming that you mean "...would fire with the first (id 1) as well as with the 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?

...you could write:

(defrule minmax
 ?mt <- (My-Template (id ?id) (index1 ?ind1) (index2 ?ind2))
 (not (My-Template (index1 ?othind1 &:(> ?othind1 ?ind1))))
 (not (My-Template (index2 ?othind2 &:(< ?othind2 ?ind2))))
 =>
 (printout t "found " ?id crlf)
)

See the Jess manual's section 6.10., The 'not' conditional element.

Thanks in advance.

Nicolas

<http://www.emoticonesgratuites.ca/?icid=EMFRCA120>


--------------------------------------------------------------------
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