[rules-users] New to rules engine - help in defining rules
Edson Tirelli
tirelli at post.com
Sun Feb 4 08:54:39 EST 2007
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
>
--
Edson Tirelli
Software Engineer - JBoss Rules Core Developer
Office: +55 11 3124-6000
Mobile: +55 11 9218-4151
JBoss, a division of Red Hat @ www.jboss.com
More information about the rules-users
mailing list