[rules-users] Locating facts via slot values

Wolfgang Laun wolfgang.laun at gmail.com
Sat Apr 4 13:37:05 EDT 2009


Very good basic advice of how to write rules for a rete engine can be found
in this place <http://www.jessrules.com/jess/docs/71/rete.htm>. 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 at 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 at 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 at 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 at lists.jboss.org
>>> https://lists.jboss.org/mailman/listinfo/rules-users
>>>
>>>
>>
>> _______________________________________________
>> rules-users mailing list
>> rules-users at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/rules-users
>>
>>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090404/09c206cc/attachment.html 


More information about the rules-users mailing list