<br>   Aldian,<br> <br>   Yes, this is the way to go:<br><br>rule &quot;detect and set routers different from root for alarm 45&quot;<br>
When<br>
    * All routers which index is different from 0 are raising the alarm 45<br>
    * There is an alarm $a of numero 45 raised by an equipement $e<br>
different from the root<br>
Then<br>
    * execute some specific code on ($a,$e)<br>
end<br><br>   It would be like this:<br><br>when<br>    forall( $e1 : Equipment( index != 0 )<br>             Alarm( origin == $<a href="http://e1.name">e1.name</a>, probablecause == 45 )  )<br>    $e2 : Equipment( index != 0 )<br>
    $a2 : Alarm( origin == $<a href="http://e.name">e.name</a>, probablecause == 45 )<br>then<br>    // do something with $e2 and $a2<br>end<br><br>   The beauty of Rete is that although you are writing constraints like &quot;index != 0&quot; and &quot;probablecause == 45&quot; twice in the rule, the engine will optimize and share them, effectively executing them only once for each fact. Performance will be very good. <br>
   Just be careful with what you do in the consequence, because if for instance you remove $a2, the forall in the rule will immediately become false, and all subsequent activations will be canceled.<br><br>   The above is the preferred way of dealing with multiple facts of the same type, with the rule firing once for each pair ($e2, $a2), but If you want to gather a set of them all at once, you can use accumulate and collect CEs. Check the manual.<br>
<br>    Regarding the system clock, the problem is that the clock is not a fact inside the engine, but you are using it to do your reasoning. Meaning it is changing, but the engine does not know that. <br><br>    In Drools 5 we implement temporal reasoning and the concept of session clock. This makes your reasoning process safe, correct and also allows reproducibility and auditability. <br>
<br>    []s<br>    Edson<br><br><div class="gmail_quote">2009/7/15 Gab Aldian <span dir="ltr">&lt;<a href="http://aldian.gp">aldian.gp</a>@<a href="http://gmail.com">gmail.com</a>&gt;</span><br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
2009/7/10, Edson Tirelli &lt;<a href="mailto:tirelli@post.com">tirelli@post.com</a>&gt;:<br>
<div class="im">&gt;    Hi Aldian,<br>
&gt;<br>
&gt;    I think you misunderstood the semantics of forall(). Forall in Drools is<br>
&gt; the same forall quantifier from the First Order Logic.<br>
&gt;<br>
&gt; <a href="http://en.wikipedia.org/wiki/First-order_logic" target="_blank">http://en.wikipedia.org/wiki/First-order_logic</a><br>
&gt;<br>
&gt;    So, if you want to write a rule that says: &quot;When for all equipments of<br>
&gt; type &#39;router&#39; there is an alarm, then raise a general failure alarm&quot;.<br>
&gt;<br>
&gt; when<br>
&gt;     forall( $e : Equipment( type == &quot;router&quot; )<br>
&gt;              Alarm( source == $e ) )<br>
&gt; then<br>
&gt;     // raise a general failure alarm<br>
&gt; end<br>
&gt;<br>
&gt;     So, if you have 10 routers in the working memory and only 9 of them have<br>
&gt; associated alarms, this rule will NOT fire, because the condition is not<br>
&gt; matched. But, if an alarm is raised for the 10th router, then all of them<br>
&gt; have an associated alarm and the rule will fire.<br>
&gt;<br>
&gt;     So, as you can see, &quot;forall&quot; is a quantifier CE, in the same way that<br>
&gt; &quot;not&quot; and &quot;exists&quot; are quantifiers. They operate on multiple facts at once,<br>
&gt; and as so, you can not use the variables bound inside their scope outside of<br>
&gt; it. In the above example, if you tried to use $e in the consequence, which<br>
&gt; of the 10 routers would it be bound to? So, since it makes no sense, the<br>
&gt; engine disallow the usage of variables bound inside quantifiers outside of<br>
&gt; them.<br>
<br>
</div>Hello, and Thank you very much for the answer. But your explanation<br>
shows that my understanding of this keyword was correct. And what if I<br>
want to ewecute this condition/consequence:<br>
<br>
When<br>
     * All routers which index is different from 0 are raising the alarm 45<br>
then<br>
     * Execute some specific code on all these routers<br>
end<br>
<br>
As you can see If I attribute a $e to the routers from the condition,<br>
it makes sense hoping to retrieve a reference on these routers to<br>
execute code on them. I think I will escape this problem doing it with<br>
two rules:<br>
<br>
rule &quot;all routers but the root raise 45&quot;<br>
When<br>
     * All routers which index is different from 0 are raising the alarm 45<br>
then<br>
     * write somewhere that rule &quot;all routers but the root raise 45&quot;<br>
has been validated<br>
end<br>
<br>
rule &quot;set routers about the alarm 45&quot;<br>
When<br>
    * there is written somewhere that &quot;all routers but the root raise<br>
45&quot; has been validated<br>
    * $a : Alarm is raising 45 from an equipement $e different from root<br>
then<br>
    * execute some specific code on $a and $e<br>
end<br>
<br>
There is also the possibility to do it in only one rule, but I have<br>
some doubts about time optimization:<br>
<br>
rule &quot;detect and set routers different from root for alarm 45&quot;<br>
When<br>
    * All routers which index is different from 0 are raising the alarm 45<br>
    * There is an alarm $a of numero 45 raised by an equipement $e<br>
different from the root<br>
Then<br>
    * execute some specific code on ($a,$e)<br>
end<br>
<br>
this way, drools will proceed to two verifications:<br>
* if forall routers which index is different from 0, they have raised<br>
an alarm of numero 45<br>
* if any alarm $a originated from a routers $e different from the<br>
root, is of numero 45 and then execute some code on it.<br>
<div class="im"><br>
<br>
&gt;<br>
&gt;     Just to be easier to remember I call quantifier CEs &quot;scope delimiters&quot;.<br>
&gt; The general rule is: variables bound inside a scope delimiter are never<br>
&gt; available outside of them.<br>
&gt;<br>
&gt;     I don&#39;t understand what you are trying to do in your first rule in your<br>
&gt; example. If you write your rule in plain English, the people from the list<br>
</div>&gt; can help you write it correctly.*<br>
<br>
I am sorry, English is not my mother language, but I hope you will<br>
understand a lot. I will know give further explanations on my example:<br>
<br>
I am supervising a network of equipements. They are not all routers,<br>
and actually, they are very different from each others, but you can<br>
consider them as routers, it doesn&#39;t matter. There is a central<br>
equipement, the root, which centralized all the alarms sent by the<br>
other equipements. And there is a software that supervise that root<br>
equipment and that folow me the alarms. I am trying to make<br>
correlation on some basic cases as this one:<br>
<br>
* for all equipements but the root I have the alarm &quot;impossible to<br>
connect&quot;. It is a very common alarm, because we often work with<br>
virtual equipements, so we know that when we have that alarm on every<br>
equipement but the root, there is no worry to have. But we would like<br>
to suppress all that alarms that are all the same to only one that<br>
agregate all the others. So what we wish to do is the folowing:<br>
<br>
when<br>
     * For all equipement different from the root an alarm of type 45<br>
as been raised,<br>
then<br>
     * Suppress all these alarms and create an alarm that agregate all<br>
these alarms in only one<br>
end<br>
<br>
As you can see the ideal would be that the forall allow to attribute<br>
to a $tabarray variable an Array of type Alarm [] containing all the<br>
alarms meeting the requirement.<br>
<div class="im"><br>
<br>
<br>
<br>
<br>
&gt;<br>
&gt;     Finally, just for completeness, be careful with the semantics of time.<br>
&gt; Your Alarm class is using the system clock to define timeout, and that will<br>
&gt; give you all kinds of headaches, not to mention wrong/unexpected results.<br>
<br>
</div>I suppose you say this because of the risk of unsynchronized clocks on<br>
the network? But for now I don&#39;t see how to improve that...<br>
<div class="im"><br>
<br>
&gt; But this e-mail is already too long. I suggest you take a look at the Drools<br>
&gt; Fusion docs on temporal reasoning.<br>
<br>
<br>
</div>Thank you very much, I will take a look about this<br>
<br>
Regards<br>
<font color="#888888"><br>
Aldian<br>
</font><div><div></div><div class="h5"><br>
<br>
<br>
<br>
<br>
<br>
<br>
&gt;<br>
&gt; 2009/7/10 Gab Aldian &lt;<a href="http://aldian.gp" target="_blank">aldian.gp</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>&gt;<br>
&gt;<br>
&gt;&gt; Hi everybody<br>
&gt;&gt;<br>
&gt;&gt; I have read with attention the drools expert documentation, which was<br>
&gt;&gt; very interesting, but a little &#39;too simple&quot;. For example, most<br>
&gt;&gt; examples don&#39;t present rules with the keyword &quot;forall&quot;. I also met big<br>
&gt;&gt; difficulties mixing the references on the objects to my javacode. This<br>
&gt;&gt; is why I would need some more documentation with examples that go<br>
&gt;&gt; deeper into drools capacities.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; To give you clues about my plan, here is an example (which works<br>
&gt;&gt; perfectly in drools 5) that I have developed:<br>
&gt;&gt; java code - <a href="http://drools.pastebin.com/m1a705614" target="_blank">http://drools.pastebin.com/m1a705614</a><br>
&gt;&gt; rule code - <a href="http://drools.pastebin.com/m3f30cbdc" target="_blank">http://drools.pastebin.com/m3f30cbdc</a><br>
&gt;&gt;<br>
&gt;&gt; As you can see I am studying the case where drools is used for the<br>
&gt;&gt; monitoring of a network of equipments that send alarms about their<br>
&gt;&gt; problems. But I have big difficulties, because I would like to get<br>
&gt;&gt; references on the objects of the &quot;forall&quot;, and to execute javacode<br>
&gt;&gt; such as $toto.method($titi, $tata), but such things seems impossible<br>
&gt;&gt; (systematic failed of compilation)<br>
&gt;&gt;<br>
&gt;&gt; Could you please help me?<br>
&gt;&gt;<br>
&gt;&gt; Thank you very much!<br>
&gt;&gt;<br>
&gt;&gt; Aldian<br>
&gt;&gt; _______________________________________________<br>
&gt;&gt; rules-users mailing list<br>
&gt;&gt; <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
&gt;&gt; <a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt;  Edson Tirelli<br>
&gt;  JBoss Drools Core Development<br>
&gt;  JBoss by Red Hat @ <a href="http://www.jboss.com" target="_blank">www.jboss.com</a><br>
&gt;<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>
</div></div></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>