I've got a problem that I've been going 'round 'n' 'round with, and was
hoping someone could help:
I'm trying to build a rule that compares two instances of a bean. For
instance, if I (assume properly) define a bean in java like this:
public class Foo implements Runnable
{
public int value = 0;
public int uniqueId = <time-based>;
public Foo previousFoo;
... (gets & sets & firePropertyChanges, etc.)
}
Note that when a new Foo is created, it will contain a reference to another
'previous' Foo, i.e. in a LinkedList.
Now in Jess, after a proper defclass foo Foo statement, and after using
Funcall to 'definstance' several instances of Foo, I want to make a rule
that compares one instance of Foo's value to another's. My initial try was:
(defrule value-rule
(foo (value ?val1) (OBJECT ?foo1))
(foo (value ?val2) (previousFoo ?foo1) (uniqueId ?id) (OBJECT ?foo2))
(test (> ?val1 ?val2))
=>
(assert (warning foo-values ?id)))
In this case, the rule is looking for two instances of foo, one of which has
the same previousFoo reference as the other's OBJECT reference.
Though that didn't work for me, I did have a bit of success with the
following:
(defrule value-rule
(foo (value ?val2) (previousFoo ?foo1) (uniqueId ?id) (OBJECT ?foo2))
(test (< ?val2 (?foo1 getValue)))
=>
(assert (warning foo-values ?id)))
This works...but only half the time. If foo1's value is already
established, and foo2's value is later set to a value below that of foo1,
the warning is asserted. If, however, foo1 and foo2 are set such that foo2
> foo1 (rule won't fire) and then foo1's value is changed such that foo1 >
foo2, the rule won't fire. This is obviously because the rule is based on
the single instance of foo2, which leads me to believe that I was on the
right track with my first try.
If anyone has any ideas about this problem, I would be eternally grateful.
//Darryl Leon//
---------------------------------------------------------------------
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]
---------------------------------------------------------------------