Hi qfhe.
A simple approach that allows you to trace the flow of execution is to
store the rules that produced a given fact in a multislot in the facts
themselves.
Note: This approach has some disadvantages: (a) it requires that facts
be re-designed to carry an additional multislot for tracing; and (b) it
requires rules to be re-written to append their names to the trace list
of new or modified facts.
A tracing script that follows your simple example:
;; trace.clp
;;
;; Jess script that demonstrates tracing flow of execution;
;; Facts contain a trace list
(deftemplate self-tracing-fact
(slot variable)
(slot value)
(multislot trace))
(deffacts a-b-c-facts
(self-tracing-fact (variable a) (value 0))
(self-tracing-fact (variable b) (value 0)))
(defrule first-rule
?stf <- (self-tracing-fact (variable a) (value 0))
=>
(modify ?stf (value 1) (trace (fact-slot-value ?stf trace) first-rule)))
(defrule second-rule
?stf <- (self-tracing-fact (variable b) (value 0))
=>
(modify ?stf (value 1) (trace (fact-slot-value ?stf trace) second-rule)))
(defrule third-rule
?stf-1 <- (self-tracing-fact (variable a) (value 1))
?stf-2 <- (self-tracing-fact (variable b) (value 1))
=>
(assert (self-tracing-fact (variable c) (value 1)
(trace (fact-slot-value ?stf-1
trace) (fact-slot-value ?stf-2 trace) third-rule))))
(reset)
(run)
qfhe wrote:
Hi,
I am trying to provide some explanation capability for
why a rule is fired or why a conclusion is made. I
understand a backward-chaining engine is more
appropriate to achieve that. I am thinking of
alternative ways to do that in a foward-chaining
engine, as most commercial rule engines are
implemented using forward-chaining.
An alternative way is to trace the rule execution
sequence using the engine's eventing mechanism and
build a tree to visually present the execution
sequence that leads to the activation of a rule.
However, I'm having two problems with this approach.
(1) The eventing mechanism only allows me to find the
last rule that immediately triggers the next rule. If
there are several rules that lead to the activation of
a rule, I am unable to capture that. For example,
consider the following three rules:
a)if a=0 then a=1
b)if b=0 then b=1
c)if a=1 and b=1 then c=1
Initially, the working memory contains the facts that
a=0, b=0 and c=0. Suppose the execution sequence is a)
b) c). (Note the order of a) and b) does not matter,
let's assume it in that order for the sake of
discussion.) Using the above method, only rule b) will
be marked as the one that triggers c). Actually rule
a) also contributes to the activation of c). How can
we solve this problem by capturing both rules a) and
b)?
(2)The second problem is with regard to redundant
information when presenting the execution sequence.
Suppose the main purpose of my system is to perform
compliance check. I am only interested in those
execution sequences that cause some violation rules to
be activated. Is there a good way to capture only
those information instead of the entire execution
sequence? Note the tricky part of this problem is that
we don't know which rule/instance will be violated
before the execution. When the rule that we're
interested in is violated, it is hard to
backward-trace its causes at that time.
Are both my questions the fundamental limitation of a
forward-chaining engine?
Any insights are appreciated.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------
begin:vcard
fn:Win Carus
n:Carus;Win
org:Information Extraction Systems, Inc.
adr:;;20 East Quinobequin Road;Waban;MA;02468;USA
email;internet:[EMAIL PROTECTED]
title:President
tel;work:(617) 244-5068
tel;fax:(617) 244-5068
x-mozilla-html:FALSE
url:http://www.InfoExtract.com
version:2.1
end:vcard