Thanks for the reply. This really helped me to think a bit more.
the "exists" statement is described which has almost the functionality
which
you want.
Unfortunately (but intuitively) you cannot access variable bindings
from
inside the "exists" body.
In my scenario, I need to know what are the data points that have violated
the rule condition. So, "exists" will not help here.
So for your purpose you have to think about, if you are really
interested
in which objects trigger the rule. If so, I can imagine, that you
don't want
to know only one portion of
information but information about each activation. Then the behaviour
of
your rule is correct.
Yes, you are right... the behavior of the rule is correct. What I missed
was, I need to include a condition more ...so that rule only considers those
data points which has been inserted after last successful rule execution
[i.e after those data points which caused the rule to get violated last
time].
One way to a solution would be to retract objects from the working
memory,
if you can safely assume that they "have done their work". I.e. if
you know,
that these objects should
not cause activations of this rule again AND you know that no other
rule
needs these objects, retract them in the rhs of your rule.
I can not do this as, there are couple of rules in same RuleBase who may
need those data points.
the only solution which I know is to mark the objects by yourself as
"processed" by the rule, e.g with your ruleID, and to test everytime in
the
lhs if the object of interest is not
rocessed... This is ugly, but it works.
Yes, this will solve the problem. Rule will only consider those objects
which have not participated in the rule violation.
In my scenario,
All data points inserted in Working Memory have timestamp associated with
those.
Rule need not consider all data points which have not participated in the
rule violation (i.e not marked as processed) each time I call
fireAllRules(). Only datapoints inserted after last rule violation need to
be considered.
I can think of another solution:
For every rule I can maintain a object which will contain the time stamp
value of last data points that have violated that rule. So in next
executions rule will only consider those objects which have greater
timestamp values then the last violated data point.
As sample,
rule "sample_rule"
when
$p4: DataObject(id == 4, stringValue == "230007014", $newTime4 :
timeStamp)
and ( not ProcessedObject(rule==
"sample_rule") or
( $po4: ProcessedObject(rule==
"sample_rule") and eval ( $newTime4.after( $po4.getLatestTimestamp(4) ) ) )
)
and
$p14: DataObject(id == 14, stringValue == "230007004", $newTime14
: timeStamp)
and (not ProcessedObject(rule==
"sample_rule") or
( $po14: ProcessedObject(rule==
"sample_rule") and eval ( $newTime14.after( $po14.getLatestTimestamp(14) )
) ) )
and
$p10: DataObject(id == 10, stringValue == "230007005", $newTime10
: timeStamp)
and (not ProcessedObject(rule==
"sample_rule") or
( $po10: ProcessedObject(rule==
"sample_rule") and eval ( $newTime10.after( $po14.getLatestTimestamp(10) )
) ) )
then
String ruleID = "sample_rule";
RuleOutput ruleOutput =
RuleEngineHelper.getRuleOutput(ruleSetOutput, ruleID);
ruleOutput.addDataObject($p4);
ruleOutput.addDataObject($p14);
ruleOutput.addDataObject($p10);
ProcessedObject po = ruleOutput.getProcessedObject();
insert(po);
end
[ Here ProcessedObject will have the timestamp of last data points that has
violated that rule. There will be another rule which will ensure per rule
only one ProcessedObject exists in Working Memory. Not sure if I can avoid
the 2nd Rule. Please provide your suggestions]
Do you see any problem with this solution ? Any opportunity to further tune
the rule mentioned above ? Feedback/Suggestions are welcome.
Regards
Siddhartha
Alexander Claus wrote:
> I need to write some rule which will *only* fire on newly inserted data
> points in Working Memory. Does Drools support any
> such feature which will help me to achieve this ? Any suggestion, how can
> I
> achieve this efficiently?
>
> I am inserting 6 matching DataObjects into Working Memory. Rule is
> getting fired once
>
> But in subsequent rule executions after I insert 6 more matching
> DataObjects
> into Working Memory, Rule is getting fired couple of times
> How can I avoid this ?
Hi,
here:
http://downloads.jboss.com/drools/docs/4.0.7.19894.GA/html/ch06s05.html#d...
the "exists" statement is described which has almost the functionality
which
you want.
Unfortunately (but intuitively) you cannot access variable bindings from
inside the "exists" body. This is intuitive, because "exists" models
the
logical existential quantifier which gives true, if there exist some facts
supporting the truth of the formula !no matter, which facts that are!.
So for your purpose you have to think about, if you are really interested
in
which objects trigger the rule. If so, I can imagine, that you don't want
to
know only one portion of information but information about each
activation.
Then the behaviour of your rule is correct.
But, I know about the problem. I faced it sometimes too. One way to a
solution would be to retract objects from the working memory, if you can
safely assume that they "have done their work". I.e. if you know, that
these
objects should not cause activations of this rule again AND you know that
no
other rule needs these objects, retract them in the rhs of your rule.
If other rules need the objects and you can't retract them therefore, the
only solution which I know is to mark the objects by yourself as
"processed"
by the rule, e.g with your ruleID, and to test everytime in the lhs if the
object of interest is not processed... This is ugly, but it works.
Hope I could help you, but, let me know, if you have found a better
solution.
Alexander Claus
_______________________________________________
rules-users mailing list
rules-users(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users
--
View this message in context:
http://www.nabble.com/Re%3A-Rule-is-firing-on-those-objects-for-which-tha...
Sent from the drools - user mailing list archive at
Nabble.com.