[rules-users] Locating facts via slot values

Michal Bali michalbali at gmail.com
Fri Apr 3 15:37:27 EDT 2009


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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20090403/6c1f5171/attachment.html 


More information about the rules-users mailing list