Hi Greg,<div><br></div><div>Thanks for the response. Unfortunately your example doesn't appear to work, the SpeedIndicator doesn't get retracted, causing the consequence to only ever trigger once. However, I could add another rule to remove the SpeedingIndicator - meaning I no longer have to use the nasty global "state" object from my example.</div>
<div><br></div><div>Any other suggestions greatly appreciated.</div><div><br></div><div>Cheers,</div><div><br></div><div>Paul</div><div><br><div class="gmail_quote">On Thu, Dec 3, 2009 at 7:14 PM, Greg Barton <span dir="ltr"><<a href="mailto:greg_barton@yahoo.com">greg_barton@yahoo.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">Have you tried truth maintenance? (i.e. insertLogical)<br>
<div class="im"><br>
rule "OverSpeedLimit" no-loop true<br>
when<br>
</div> not SpeedingIndicator();<br>
$minSpeed : Double(doubleValue > 100) from accumulate(<br>
<div class="im"> $speedingEvent : SpeedingEvent ($speed : speed)<br>
over window:time( 30s )<br>
from entry-point SpeedingStream,<br>
min($speed)<br>
);<br>
</div>then<br>
insertLogical(new SpeedingIndicator());<br>
end<br>
<br>
Though I'm not sure this will work, because inserting the SpeedingIndicator negates the first condition, probably causing the SpeedingIndicator to be retracted automatically. :) But it's worth a try just to see if no-loop would override that somehow.<br>
<br>
Apart from that, note that you can test the results of an accumulate in the returned value. (The "Double(doubleValue > 100)" part.) YOu don't need the eval.<br>
<br>
Also, where is the "state" object coming from? If it's a global, it's not a good idea to use them in the conditions of your rules. Changes to them are not tracked by the rete.<br>
<br>
--- On Thu, 12/3/09, reverselogic <<a href="mailto:reverselogic@gmail.com">reverselogic@gmail.com</a>> wrote:<br>
<br>
> From: reverselogic <<a href="mailto:reverselogic@gmail.com">reverselogic@gmail.com</a>><br>
> Subject: [rules-users] CEP + prevent consequences from triggering multiple times?<br>
> To: <a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
> Date: Thursday, December 3, 2009, 12:41 PM<br>
<div><div></div><div class="h5">><br>
> Hi,<br>
><br>
> I'm trying to write a rule in drools, which triggers once<br>
> some condition is<br>
> active for a specified time interval. For example, if a<br>
> vehicle is over a<br>
> speed limit (100 mph) for 30 seconds, I want to trigger an<br>
> action. However,<br>
> once this rule has fired, I don't want it to fire again<br>
> until the vehicle<br>
> has dropped below the speed limit (and gone over the limit<br>
> again). The only<br>
> way I've managed to model this is by defining two rules;<br>
> one for determining<br>
> when the vehicle is speeding and one for determining when<br>
> it is not speeding<br>
> and using a global object to track the state of the vehicle<br>
> (see rules<br>
> below).<br>
><br>
> rule "OverSpeedLimit" no-loop true<br>
> when<br>
> $minSpeed : Double() from accumulate(<br>
> $speedingEvent :<br>
> SpeedingEvent ($speed : speed)<br>
> <br>
> over window:time( 30s )<br>
> <br>
> from entry-point SpeedingStream,<br>
> min($speed)<br>
> );<br>
> <br>
> eval ($minSpeed > 100.0 &&<br>
> !state.speeding)<br>
> then<br>
> state.speeding = true<br>
> end<br>
><br>
> rule "!OverSpeedLimit" no-loop true<br>
> when<br>
> $speedingEvent : SpeedingEvent()<br>
> from entry-point<br>
> SpeedingStream<br>
> eval ($speedingEvent.speed <= 100.0)<br>
> then<br>
> state.speeding = false<br>
> end<br>
><br>
> My questions is: Is there a better way to model the above<br>
> behaviour,<br>
> preferably as a single rule? The reason I ask is because I<br>
> believe it would<br>
> be too complicated for my users to define rules like this.<br>
> Ideally, I would<br>
> like to be able to create a DSL such as: "when Speed is<br>
> above X for Y<br>
> seconds then ..."<br>
><br>
> Any help greatly appreciated.<br>
><br>
> Thanks,<br>
><br>
> Paul<br>
><br>
><br>
><br>
><br>
> --<br>
> View this message in context: <a href="http://n3.nabble.com/CEP-prevent-consequences-from-triggering-multiple-times-tp67424p67424.html" target="_blank">http://n3.nabble.com/CEP-prevent-consequences-from-triggering-multiple-times-tp67424p67424.html</a><br>
> Sent from the Drools - User mailing list archive at<br>
> Nabble.com.<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>
_______________________________________________<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></div>