Very good basic advice of how to write rules for a rete engine can be found
in this place <
;. You'll also
find a discussion of the technical details in the Drools Expert part of the
manual.
-W
2009/4/3 Michal Bali <michalbali(a)gmail.com>
Hi Wolfgang,
Is it the number of instances or how often they are modified that makes the
difference? I am just wondering why it is better.
Best Regards,
Michal
2009/4/3 David Sinclair <dsinclair(a)chariotsolutions.com>
Here you go WolfGang
>
> rule shoot-3
> when
> $h : Hunter( $target : target)
> Animal(this == $target)
> then
> $h.shoot( $a );
> retract( $a );
> end
>
> 2009/4/3 Wolfgang Laun <wolfgang.laun(a)gmail.com>
>
>> Given a working memory containing a large number of rather static facts
>> which are from several subclasses (Ape, Bear, Crocodile,...) of some base
>> class (Animal) and a single fact of class Hunter with a field target of type
>> Animal, the shooting of an animal might be written with a rule like this:
>>
>> rule shoot-1
>> when
>> ?h : Hunter( ?target : target )
>> ?a : Animal()
>> eval(?target == ?a)
>> then
>> ?h.shoot( ?a );
>> retract( ?a );
>> end
>>
>> Avoiding eval (which is said to be inefficient), it could also be written
>> as
>>
>> rule shoot-2
>> when
>> ?a: Animal()
>> ?h : Hunter( target == ?a )
>> then
>> ?h.shoot( ?a );
>> retract( ?a );
>> end
>>
>> This, however, places the pattern with many instances up front, which is
>> (AFAIK) not so good in a Rete implementation.
>>
>> Which one is to be preferred in Drools?
>>
>> Ideally, one might want to write
>>
>> rule shoot-3
>> when
>> ?h : Hunter( ?target : target )
>> ?a == ?target : Animal() ### not valid DRL
>> then
>> ?h.shoot( ?a );
>> retract( ?a );
>> end
>>
>> This avoids eval, has the single instance fact up front, but it isn't
>> available.
>>
>> -W
>>
>>
>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users(a)lists.jboss.org
>>
https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/rules-users
>
>
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users