On Feb 13, 2008, at 1:01 PM, Henrique Lopes Cardoso wrote:


(defrule r1
    ?b1 <- (some-fact)
    ?b2 <- (some-other-fact)
    (not (rule-fired-on $?b-list&:(equal-lists? ?b-list (list ?b1 ?
b2))))
   =>
    (assert (rule-fired-on ?b1 ?b2))
    (printout t "r1 fired on " ?b1 ?b2 crlf) )

Is this computationally expensive?


It certainly could be, yes, because you form all possible tuples of
matching facts, and then evaluate the function for each of the
tuples. If in the real rules those patterns are more specific, and
restrict the matches to a subset of the facts, then it would be
better, of course. The expense comes not so much from the function --
although this is a fairly complex test, with lots of object
allocation, so it's not ideal -- but really from the fact that it's a
test that will be executed very often. Cutting down on the number of
executions would be a good goal.

Something like this is a little bit better, because Jess can use
indexing to reduce the amount of computation:

(defrule r1
    ?b1 <- (some-fact)
    ?b2 <- (some-other-fact)
    (not (rule-fired-on ?b1 ?b2))
   =>


but the meaning is a little bit different, because it only enforces
one ordering. Still, you could write your rules to put the patterns
into a standard order.

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences          Phone: (925) 294-2154
Sandia National Labs                FAX:   (925) 294-2234
PO Box 969, MS 9012                 [EMAIL PROTECTED]
Livermore, CA 94550                 http://www.jessrules.com

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