Hi Sid,
Your understanding is correct. If you reverse the order of ground1 and
ground2 in the input file, you'll make ground1 fire first. This will
cause (need-subgoal2 cat) to be asserted. This matches the
need-subgoal2 patterns of ground3 and ground4, and one of them fires
(ground4). Now you're stuck with (subgoal1 cat) and (subgoal2 bird)
and nothing else happens.
I guess the best way to look at this is to say that (from Jess'
perspective) the groundX rules are incomplete. They match all
need-subgoal facts, but they only provide specific ones; i.e., ground3
and 4 could be replaced by
(defrule ground3-4
(need-subgoal2 ?x&bird|dog)
=>
(assert (subgoal2 ?x)))
I was going to reccommend another rule like this
(defrule clear-bogus-goal1s
?x <- (subgoal1 ~bird&~dog)
=>
(retract ?x))
but this leads to an infinite loop, because then ground1 will then
fire again. I guess if you want this kind of sequencing (i.e., try X,
then Y, then Z) you have to code it yourself - i.e., ground1 must
either generate all possible subgoal1's in a single firing, or it must
generate a new one each time it is fired.
Regarding how rules are rewritten: in Jess versions prior to the 6.x
alphas, you can simply do a (ppdefrule) to see the rewritten
rule (This is temporarily disabled in 6.x as the LHS representation is
getting overhauled.) So, for instance, ground2 looks like
(defrule ground2
""
(declare (salience 0) (node-index-hash 0))
?__factidx4 <- (need-subgoal1 ?_blank_3)
(not (subgoal1 ?_blank_5))
=>
(assert (subgoal1 bird)))
Now, regarding whether the way Jess works in this regard is the best
way: I'm actually not sure. I know that there has to be some way to
block need-X rules from firing at some point. I've tried two different
approaches to this problem: one is the current 'not' solution. A
previous one was to insert code on the RHS of need-X rules to retract
the need-X trigger fact. This other approach had the same problem
we're discussing here. Another approach altogether might be to insert a
(not (fired-already-ground2)) pattern, custom for each need-X
rule. The problem here is deciding when to retract the
(fired-already-ground2) fact: if ground2 generated a new different
subgoal1 each time it fired, we might want the fired-already fact to
never be asserted in the first place, but as written, we need it to
hang around at least as long as the need-X fact does.
Anyhow, I'm open to suggestions on this from everyone, especially
well-thought-out ones informed by possible implementations.
I think Sidney Bailin wrote:
> Suppose I have the following:
>
> (do-backward-chaining the-goal)
> (do-backward-chaining subgoal1)
> (do-backward-chaining subgoal2)
>
> (defrule main-goal
> (the-goal ?a)
> =>
> (printout t "You won!" crlf)
> )
>
> (defrule support
> (need-the-goal ?)
> (subgoal1 ?s)
> (subgoal2 ?s)
> =>
> (assert (the-goal ?s))
> )
>
> (defrule ground1
> (need-subgoal1 ?)
> =>
> (assert (subgoal1 cat))
> )
>
> (defrule ground2
> (need-subgoal1 ?)
> =>
> (assert (subgoal1 bird))
> )
>
> (defrule ground3
> (need-subgoal2 ?)
> =>
> (assert (subgoal2 dog))
> )
>
> (defrule ground4
> (need-subgoal2 ?)
> =>
> (assert (subgoal2 bird))
> )
>
> Is the backchaining implementation such that, if it happens to fire
> "ground1" before firing "ground 2"
> (thereby associating subgoal1 with cat rather than bird), and therefore
> fails to fire "support" with
> this match, it will then fire "ground2" and "ground4" and thereby
> succeed?
>
> When I try this example, that does indeed happen, but watching the
> dribble doesn't give me
> a sense of what happens in general.
>
> Of course, ordinarily the "groundX" rules will fire with all possible
> matches. What makes me
> wonder is the statement in the user guide that Jess adds a "not"
> condition to the LHS of these rules.
> It seems to me that whether this "backtracking" will occur depends on
> how much is already
> bound in that added "not" condition.
>
> Thanks,
> Sidney Bailin
> Knowledge Evolution, Inc.
>
>
>
> ---------------------------------------------------------------------
> 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]
> ---------------------------------------------------------------------
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
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]
---------------------------------------------------------------------