A rule only gets re-evaluated when something it depends on in it’s ‘when’ part is updated (or added).
Because the one shot rule doesn’t depend on anything it never gets re-evaluated so will only fire at the start.
Whether you retract them at the end depends on whether your are planning to reuse your working memory, if you aren’t planning to reuse it just dispose of
the working memory as retracting facts causes the rete graph to be re-evaluated and rules triggered as necessary.
If you are using the standard mode then no, the working memory is just a specialised form of database. If you are using event processing then Events will
be removed when they are no longer relevant.
Asking whether rules are applied sequentially or parallel is actually pretty meaningless, with declarative programming such as drools you are declaring what
you want to happen not how it is achieved (as opposed to imperative programming such as java where you define the steps to achieve something). Whether the rules are evaluated in parallel or sequentially is just a implementation, although the actions (“then
part) of the rules will be performed serially. If you want more details I’d recommend reading up about Rete and how drools implements it.
Thomas
From: rules-users-bounces@lists.jboss.org [mailto:rules-users-bounces@lists.jboss.org]
On Behalf Of Manav
Sent: 14 August 2010 03:38
To: Wolfgang Laun
Cc: rules-users@lists.jboss.org
Subject: Re: [rules-users] Caching results in temperory variables
Great stuff. Things are very clear now . It raised some more questions though :-
-- Say we use the one shot insert at the very start of the rule. And i am using this rule to validate some
100,000 User facts . Will these inserts be done only once or as many times as new facts are inserted
in WM. Is there something that we can use to determine this as per the need.
-- As done in the example below there will be as many UserResult objects inserted in the memory as there are User facts. We insert them in the WM at the start and update them as the rule executes . At the very end should we retract them
as well from the WM . Is that a suggested practice or doesn't really matter .
-- Does WM automatically remove objects if they have not been used for long time or it's the responsibility of the application developer to keep track of what's goes in and out.
-- Instead of inserting one fact at a time if we insert a collection at one go in the WM how does this rule get applied . Sequentially to all the objects or in parallel ?
Regards,
Manav
From: Wolfgang Laun <wolfgang.laun@gmail.com>
To: Manav <manav7574@yahoo.com>
Cc: rules-users@lists.jboss.org
Sent: Fri, August 13, 2010 11:41:53 PM
Subject: Re: [rules-users] Caching results in temperory variables
On 13 August 2010 18:36, Manav <manav7574@yahoo.com> wrote:
Your explanation is absolutely superb. I modified my drl as per your suggestions and it's just been completely transformed. Just one question regarding one suggestion below :
-- is this something like a for each loop in java . This is the first example i have seen in drl
In a way, yes. Since
Foo( ... ) # match any Foo according to constraints, if any
Bar( ... ) # match any Bar according to constraints, if any
these two patterns produce the Cartesian product, such as a nested loop does. BUT, the order of the pairings is indeterministic, and changes in WM might influence this loop, even make it infinitive. Therefore, "in a way".
-- will this automatically iterate over as many languages as have been inserted ?
That's the whole idea :-)
-- the inserts .. don't they have to be within a rule block ? or did you just omit other things to keep it simple
You can do it in the Java application framework. You can also write a high-salience one-shot rule such as
rule "1st shot"
when
then
insert( new Language( "Japanese" ) );
insert( new Language( "French" ) );
// more of the same
end
Cheers
Wolfgang