On Jun 1, 2006, at 1:05 PM, Adair, John wrote:
I'm not sitting in front of Jess, so please excuse syntax errors.
I want to write rules whose conditions include inequalities, and am
wondering
about the most efficient way to do so. My first attempt looked
something
like
(deftemplate foo (slot d))
(defrule r-1
(foo (d ?d&:(>= ?d 123.45)))
=>
(printout t ?d crlf))
This is the expected way.
where I have many different rules of this form with different
values of
the
constant in the comparison, but performance degraded rapidly as the
number of
distinct constant values increased.
Even with this toy? Really?
I was able to get good performance by moving the inequality to the
right-hand-side
of the rule like
(defrule r-1
(foo (d ?d))
=>
(if (>= ?d 123.45) then (printout t ?d crlf)))
In general, this approach is not recommended. Corner cases may
exist, but this element of the pattern matching should be in the
antecedent, just as you expected and tried first.
but I would rather have the inequalities as part of the pattern
matching. Is there
something I'm missing here?
Perhaps, see next.
Incidentally, the examples above are of course toys. In my real case,
there are
other slots being matched directly, in addition to the slot with the
inequality.
Perhaps ordering of the conditional elements is relevant as well?
This is *very* relevant. If your non-toy example has several
patterns in the LHS, then the combinatorics can be drastically
different depending on the ordering. There are various rules of
thumb here, which may be in conflict. Two biggies for reducing the
matching effort include:
Put patterns that change infrequently first in the LHS.
Put the more constraining patterns first.
But its a balancing act. Try reordering the patterns and see if you
can improve performance. Most books that reference Rete-based
engines will address this to one degree or another. One way to see
it in action would be to experiment with some two-pattern toy rules,
a small fact base with different quantities of foo and bar facts, and
use the matches command to see the partial matches.
- Mike
--------------------------------------------------------------------
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]
--------------------------------------------------------------------