<br> Aldian,<br> <br> Yes, this is the way to go:<br><br>rule "detect and set routers different from root for alarm 45"<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 "index != 0" and "probablecause == 45" 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"><<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;">
2009/7/10, Edson Tirelli <<a href="mailto:tirelli@post.com">tirelli@post.com</a>>:<br>
<div class="im">> Hi Aldian,<br>
><br>
> I think you misunderstood the semantics of forall(). Forall in Drools is<br>
> the same forall quantifier from the First Order Logic.<br>
><br>
> <a href="http://en.wikipedia.org/wiki/First-order_logic" target="_blank">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<br>
> 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<br>
> associated alarms, this rule will NOT fire, because the condition is not<br>
> matched. But, if an alarm is raised for the 10th router, then all of them<br>
> 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<br>
> "not" and "exists" are quantifiers. They operate on multiple facts at once,<br>
> and as so, you can not use the variables bound inside their scope outside of<br>
> it. In the above example, if you tried to use $e in the consequence, which<br>
> of the 10 routers would it be bound to? So, since it makes no sense, the<br>
> engine disallow the usage of variables bound inside quantifiers outside of<br>
> 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 "all routers but the root raise 45"<br>
When<br>
* All routers which index is different from 0 are raising the alarm 45<br>
then<br>
* write somewhere that rule "all routers but the root raise 45"<br>
has been validated<br>
end<br>
<br>
rule "set routers about the alarm 45"<br>
When<br>
* there is written somewhere that "all routers but the root raise<br>
45" 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 "detect and set routers different from root for alarm 45"<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>
><br>
> Just to be easier to remember I call quantifier CEs "scope delimiters".<br>
> The general rule is: variables bound inside a scope delimiter are never<br>
> available outside of them.<br>
><br>
> I don't understand what you are trying to do in your first rule in your<br>
> example. If you write your rule in plain English, the people from the list<br>
</div>> 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'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 "impossible to<br>
connect". 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>
><br>
> Finally, just for completeness, be careful with the semantics of time.<br>
> Your Alarm class is using the system clock to define timeout, and that will<br>
> 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't see how to improve that...<br>
<div class="im"><br>
<br>
> But this e-mail is already too long. I suggest you take a look at the Drools<br>
> 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>
><br>
> 2009/7/10 Gab Aldian <<a href="http://aldian.gp" target="_blank">aldian.gp</a>@<a href="http://gmail.com" target="_blank">gmail.com</a>><br>
><br>
>> 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>
>><br>
><br>
><br>
><br>
> --<br>
> Edson Tirelli<br>
> JBoss Drools Core Development<br>
> JBoss by Red Hat @ <a href="http://www.jboss.com" target="_blank">www.jboss.com</a><br>
><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>