<br> Hi Aldian,<br><br> I think you misunderstood the semantics of forall(). Forall in Drools is the same forall quantifier from the First Order Logic. <br><br><a href="http://en.wikipedia.org/wiki/First-order_logic">http://en.wikipedia.org/wiki/First-order_logic</a><br>
<br> So, if you want to write a rule that says: "When for all equipments of type 'router' there is an alarm, then raise a general failure alarm".<br><br>when<br> forall( $e : Equipment( type == "router" )<br>
Alarm( source == $e ) )<br>then<br> // raise a general failure alarm<br>end<br><br> So, if you have 10 routers in the working memory and only 9 of them have associated alarms, this rule will NOT fire, because the condition is not matched. But, if an alarm is raised for the 10th router, then all of them have an associated alarm and the rule will fire.<br>
<br> So, as you can see, "forall" is a quantifier CE, in the same way that "not" and "exists" are quantifiers. They operate on multiple facts at once, and as so, you can not use the variables bound inside their scope outside of it. In the above example, if you tried to use $e in the consequence, which of the 10 routers would it be bound to? So, since it makes no sense, the engine disallow the usage of variables bound inside quantifiers outside of them.<br>
<br> Just to be easier to remember I call quantifier CEs "scope delimiters". The general rule is: variables bound inside a scope delimiter are never available outside of them.<br><br> I don't understand what you are trying to do in your first rule in your example. If you write your rule in plain English, the people from the list can help you write it correctly.<br>
<br> Finally, just for completeness, be careful with the semantics of time. Your Alarm class is using the system clock to define timeout, and that will give you all kinds of headaches, not to mention wrong/unexpected results. But this e-mail is already too long. I suggest you take a look at the Drools Fusion docs on temporal reasoning.<br>
<br> []s<br> Edson<br><br><br><div class="gmail_quote">2009/7/10 Gab Aldian <span dir="ltr"><<a href="http://aldian.gp">aldian.gp</a>@<a href="http://gmail.com">gmail.com</a>></span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi everybody<br>
<br>
I have read with attention the drools expert documentation, which was<br>
very interesting, but a little 'too simple". For example, most<br>
examples don't present rules with the keyword "forall". I also met big<br>
difficulties mixing the references on the objects to my javacode. This<br>
is why I would need some more documentation with examples that go<br>
deeper into drools capacities.<br>
<br>
<br>
To give you clues about my plan, here is an example (which works<br>
perfectly in drools 5) that I have developed:<br>
java code - <a href="http://drools.pastebin.com/m1a705614" target="_blank">http://drools.pastebin.com/m1a705614</a><br>
rule code - <a href="http://drools.pastebin.com/m3f30cbdc" target="_blank">http://drools.pastebin.com/m3f30cbdc</a><br>
<br>
As you can see I am studying the case where drools is used for the<br>
monitoring of a network of equipments that send alarms about their<br>
problems. But I have big difficulties, because I would like to get<br>
references on the objects of the "forall", and to execute javacode<br>
such as $toto.method($titi, $tata), but such things seems impossible<br>
(systematic failed of compilation)<br>
<br>
Could you please help me?<br>
<br>
Thank you very much!<br>
<br>
Aldian<br>
_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
</blockquote></div><br><br clear="all"><br>-- <br> Edson Tirelli<br> JBoss Drools Core Development<br> JBoss by Red Hat @ <a href="http://www.jboss.com">www.jboss.com</a><br>