retract

17 views
Skip to first unread message

gowabash

unread,
Oct 20, 2008, 11:38:32 AM10/20/08
to Rools Users
I have a set of initial facts similar to the security council example
from this thread (http://groups.google.com/group/rools-users/
browse_thread/thread/3348e19ca1885a55). I assert an additional fact
to evaluate the rules against. I want to reassert a different fact
with out recreating all the rules again (I've been conditioned that
rule creation is expensive, fact manipulation is cheap). What is the
best practice?

I hacked the rule_set class and added a method retract to remove the
fact. This allowed me to reassert country over and over without adding
to the string fact. Is this the right practice.

def retract(fact)
@facts.delete(fact.class.to_s.downcase)
end

Pat G Cappelaere

unread,
Oct 20, 2008, 11:50:19 AM10/20/08
to rools...@googlegroups.com
And what happened to the facts that were created by some rules based
on that fact that you have now removed?
Pat.

gowabash

unread,
Oct 20, 2008, 1:51:55 PM10/20/08
to Rools Users
Those facts are still valid.

Pat G Cappelaere

unread,
Oct 20, 2008, 2:10:37 PM10/20/08
to rools...@googlegroups.com
How can they still be valid if they were based on a fact that has been
retracted?
I am not sure I understand the use-case, then.
This must be a special case for your project?

Pat.

gowabash

unread,
Oct 20, 2008, 2:19:39 PM10/20/08
to Rools Users
Most likely, I have done a bad job describing my issue. There are
initial facts that are asserted with my rules. These are parameters
that help determine the conditions of my rules. So I assert 10 facts
with my initial rules creation in order to get the engine to a default
state where I am ready to ask a question with a paramter. Then I want
to ask the same question again with a different parameter, but the
same default state. Is it better to recreate the state, or retract
the parameter.

Ultimately, my question is around setup cost versus execution cost.
Is rule creation more expensive than fact manipulation (asserting and
retracting) or vice versa.

Pat G Cappelaere

unread,
Oct 20, 2008, 2:25:31 PM10/20/08
to rools...@googlegroups.com
So you are not retracting a fact as much as changing the value of an
existing one?

Fact manipulation is certainly cheap when no rule firing is involved.
Problem is when do you know for sure that no rule evaluation is
required when you add or retract facts!!!

Pat.

gowabash

unread,
Oct 20, 2008, 2:38:32 PM10/20/08
to Rools Users
My thought is that the paradigm would be add fact, evaluate, retract
fact. The consequences of my rules are actions that do not manipulate
facts (at least not yet). So at the end of my transaction, the engine
should be at the same state as before the start of the transaction.
Reply all
Reply to author
Forward
0 new messages