Hi Greg,
Have you tried truth maintenance? (i.e. insertLogical)
not SpeedingIndicator();
rule "OverSpeedLimit" no-loop true
when
$minSpeed : Double(doubleValue > 100) from accumulate(
$speedingEvent : SpeedingEvent ($speed : speed)then
over window:time( 30s )
from entry-point SpeedingStream,
min($speed)
);
insertLogical(new SpeedingIndicator());
end
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.
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.
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.
--- On Thu, 12/3/09, reverselogic <reverselogic@gmail.com> wrote:
> From: reverselogic <reverselogic@gmail.com>
> Subject: [rules-users] CEP + prevent consequences from triggering multiple times?
> To: rules-users@lists.jboss.org
> Date: Thursday, December 3, 2009, 12:41 PM
>
> Hi,
>
> I'm trying to write a rule in drools, which triggers once
> some condition is
> active for a specified time interval. For example, if a
> vehicle is over a
> speed limit (100 mph) for 30 seconds, I want to trigger an
> action. However,
> once this rule has fired, I don't want it to fire again
> until the vehicle
> has dropped below the speed limit (and gone over the limit
> again). The only
> way I've managed to model this is by defining two rules;
> one for determining
> when the vehicle is speeding and one for determining when
> it is not speeding
> and using a global object to track the state of the vehicle
> (see rules
> below).
>
> rule "OverSpeedLimit" no-loop true
> when
> $minSpeed : Double() from accumulate(
> $speedingEvent :
> SpeedingEvent ($speed : speed)
>
> over window:time( 30s )
>
> from entry-point SpeedingStream,
> min($speed)
> );
>
> eval ($minSpeed > 100.0 &&
> !state.speeding)
> then
> state.speeding = true
> end
>
> rule "!OverSpeedLimit" no-loop true
> when
> $speedingEvent : SpeedingEvent()
> from entry-point
> SpeedingStream
> eval ($speedingEvent.speed <= 100.0)
> then
> state.speeding = false
> end
>
> My questions is: Is there a better way to model the above
> behaviour,
> preferably as a single rule? The reason I ask is because I
> believe it would
> be too complicated for my users to define rules like this.
> Ideally, I would
> like to be able to create a DSL such as: "when Speed is
> above X for Y
> seconds then ..."
>
> Any help greatly appreciated.
>
> Thanks,
>
> Paul
>
>
>
>
> --
> View this message in context: http://n3.nabble.com/CEP-prevent-consequences-from-triggering-multiple-times-tp67424p67424.html
> Sent from the Drools - User mailing list archive at
> Nabble.com.
> _______________________________________________
> rules-users mailing list
> rules-users@lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users