[rules-users] New to rules engine - help in defining rules

Jeevan Tambuluri jeevan_tambuluri at symantec.com
Sun Feb 4 18:35:44 EST 2007


Hi Edson,
My procedural mind is unable to see how a helper class gets the job 
done. Could you elaborate?
Let's say I want to write a rule: The sum of lengths of all branches in 
a tree must be more than 100.

Also, another question.  I defined a rule to identify all trees that 
have same length branches as follows:

rule "same length"
when
   $t : Tree( $bl : branchLength != -1 )
   exists not Branch( mytree == $t, branch_length != $bl )
then
   // Print Tree object, because the branches have same length
end

When I call fireAllRules() on workingmemory object, I see this rule 
triggering for tree objects with same length branches.

Now, let's say I have an assreted  tree object with two branches with 
different lengths. Rule "check length" would fire for it. Then I go and 
modify working memory by setting the branch length of Branch object to 
same value as the other Branch object. I expected the "same length" rule 
to fire and print the Tree object, but that didnot happen. I simply 
called workingMemory.modifyOject() by passing the fact handle of the 
Branch object and the same old Branch object with modified branch length.

Thanks

Jeevan

Edson Tirelli wrote:

>
>   Jeevan,
>
>   Same idea. You need a helper class that will accumulate your value.
>
>   []s
>   Edson
>
> Jeevan Tambuluri wrote:
>
>> Thanks Edson! The rule pattern you suggested works for me. Any such 
>> pattern to simulate "accumulate" in 3.0.x?
>>
>> Jeevan
>>
>> Edson Tirelli wrote:
>>
>>>
>>>    Jeevan,
>>>
>>>    You are right: the simplest way would be use "forall". 
>>> Unfortunatelly it is only available in trunk.
>>>    To do it in 3.0.x you will need either a helper attribute or a 
>>> helper class. For instance, you may add a "branchLength" attribute 
>>> to the tree and define 2 rules:
>>>
>>> rule "define length"
>>> when
>>>     $t : Tree( branchLength == -1 )
>>>     Branch( mytree == $t, $bl : branch_length )
>>> then
>>>     $t.setBranchLength( $bl.intValue() );
>>>     modify( $t );
>>> end
>>>
>>> rule "check length"
>>> when
>>>    $t : Tree( $bl : branchLength != -1 )
>>>    exists Branch( mytree == $t, branch_length != $bl )
>>> then
>>>    // do something because the branch has a different length
>>> end
>>>
>>>   There are several variations but you will need 2 rules to emulate 
>>> this.
>>>   Hopefully the new version will be out soon solving this kind of 
>>> problem.
>>>
>>>   []s
>>>   Edson
>>>
>>> Jeevan Tambuluri wrote:
>>>
>>>> Hello all,
>>>>
>>>> I am looking for a way to define rules for the following problem:
>>>>
>>>> class Tree {
>>>> ...
>>>> }
>>>>
>>>> class Branch {
>>>>    Tree  mytree;
>>>>     int     branch_length;
>>>> ...
>>>> }
>>>>
>>>> Let's say I have a fact called Tree and another fact called Branch. 
>>>> Brach identifies which tree it belongs to.
>>>> Now, I want to write a rule to say that all branches in a tree must 
>>>> be of same length.
>>>> How do I do this with/without using accumulate or forall?
>>>>
>>>> Thanks a lot for any help,
>>>>
>>>> J
>>>>
>>>> _______________________________________________
>>>> 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
>>
>
>





More information about the rules-users mailing list