I think Rudolph George-P27574 wrote:
>
> > -----Original Message-----
> > From: Ernest Friedman-Hill [mailto:[EMAIL PROTECTED]]
> >
> >
> > Join nodes with function call tests are not shared. Although
> > simple ones like this could be, deciding to share more
> > complex ones could
> > be very hard, so Jess simply punts. Expect to see improvement here as
> > an optimization in the future.
As it turns out, getting this to work was very easy. The last time I
looked into it, it would have been hard, but some recent internal
modifications have changed this situation. The next Jess release
(5.0b3) will indeed share join nodes containing function-call tests,
possibly leading to performance improvements or memory-use reductions
for some users.
> >
> > Note that these particular tests would be more efficient if written in
> > the pattern itself, rather than in test CEs, anyway.
>
> Oh. I thought the two forms were equivalent. Maybe that means functionally
> equivalent.
They are functionally equivalent, but they are implemented
differently. Tests done in-line
(foo (bar ?X&:(eq ?X baz)))
are done in the Rete pattern network, while (test) CEs,
(foo (bar ?X))
(test (eq ?X baz))
being separate CE's, are done in the join network. The important
difference is that the test CE test, being in the join network, may be
executed more times than the equivalent in-line test. For example,
the eq function in rule-1 function will be called 3 times -- each time
a token is processed by the (test) CE -- while that in rule-2 will be
called only once, each time a (B) fact is asserted:
(defrule rule-1
(A ?X)
(B ?Y)
(test (eq ?Y 3))
=>)
(defrule rule-2
(A ?X)
(B ?Y&:(eq ?Y 3))
=>)
(assert (B 1) (A 1) (A 2) (A 3))
This rule is even better, incidentally:
(defrule rule-3
(A ?X)
(B 3)
=>)
The identity test is quite a bit more efficient than dispatching to an
(eq) function call.
OTOH, you have to weigh runtime performance vs. the capabilities of your
automatic rule generator. If using "test" CEs makes the generator
simpler, that might be enough to justify the added computational
expense, in some circumstances, anyway.
>
> The reason we chose to use CE's instead of patterns is that in many cases we
> want to do more than
> just a pattern match (with EQUALS). We could replace the call to equals
> with some other (boolean)
> arbitrary boolean function. But we wanted a uniform algorithm for
> generating rules in all cases.
> (Rules are being entered via a gui that doesn't know about Jess rules, but
> uses an intermediate format.
> Jess rules are then generated from that format.)
>
> It looks like it's worth checking to see if the desired function is EQUAL,
> and if so, generating the rule
> using pattern matching syntax. Only in cases where it's not EQUAL would we
> then be forced to use a CE.
>
> I know quite a number of people on the list have dealt with the same
> issues--any suggestions would be welcome.
>
>
> >
> > -----------------------------
> >
> > I have a bunch of rules of the following type, where
> > clauses look identical,
> > but when I use the (watch compilations) command or the
> > (view), it clearly
> > shows that 2-input nodes are not being reused. Why?
> > And what can I do to solve the problem?
> >
> > (BTW, the thing object is defined by a defclass, if that makes a
> > difference).
> >
> >
> > (defrule rule1
> > ""
> > (declare (salience 0))
> > (thing (color ?f1) (shape ?f0))
> > (test (EQUALS ?f0 "02907"))
> > (test (EQUALS ?f1 "64772"))
> > =>
> > )
> >
> > (defrule rule2
> > ""
> > (declare (salience 0))
> > (thing (color ?f1) (shape ?f0))
> > (test (EQUALS ?f0 "02907"))
> > (test (EQUALS ?f1 "64772"))
> > =>
> > )
> > --
> >
> > Ernest Friedman-Hill
> > Distributed Systems Research Phone: (925) 294-2154
> > Sandia National Labs FAX: (925) 294-2234
> > Org. 8920, MS 9214 [EMAIL PROTECTED]
> > PO Box 969 http://herzberg.ca.sandia.gov
> > Livermore, CA 94550
> >
> ---------------------------------------------------------------------
> 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]
> ---------------------------------------------------------------------
>
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
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]
---------------------------------------------------------------------