我有以下程序(使用 CLIPS)
事实:
(deffacts family
(father tom nicholas)
(mother clair nicholas)
(father tom john)
(father brad tom)
(father mark clair))
然后我使用(重置)
规则1:
(defrule parent
(or (father ?x ?y) (mother ?x ?y))
=> (assert (parent ?x ?y)))
规则2:
(defrule gp
(and (parent ?x ?y) (parent ?y ?z))
=> (assert (gp ?x ?z)))
如果我写了(议程),我只会得到
0 parent: f-5
0 parent: f-4
0 parent: f-3
0 parent: f-2
0 parent: f-1
对于匹配(匹配父级):
Matches for Pattern 1
f-1
f-3
f-4
f-5
Matches for Pattern 1
f-2
Activations
f-5
f-4
f-3
f-2
f-1
但是对于 gp:(匹配 gp)
Matches for Pattern 1
None
Matches for Pattern 2
None
Partial matches for CEs 1 - 2
None
Activations
None
(0 0 0)
为什么基于另一个规则的规则 id 既没有出现在议程中,也没有出现在比赛中?或者有什么问题吗?
更新:是因为当我们执行(议程)时,CLIPS 会评估规则库中的所有规则,以确定哪些规则具有与工作记忆当前状态(由断言事实组成)相匹配的条件(模式)。如果规则的条件与事实相符,则该规则的激活将被列入议程。所以这只是为了事实?
事实必须存在才能匹配规则中的模式。当发出(重置)命令时,默认事实系列中的事实将被断言,并且这些事实将与父规则中的模式相匹配。当发出(运行)命令时,父规则将能够执行,这将导致父事实被断言,可以匹配并激活 gp 规则。
CLIPS (6.4.1 4/8/23)
CLIPS>
(deffacts family
(father tom nicholas)
(mother clair nicholas)
(father tom john)
(father brad tom)
(father mark clair))
CLIPS>
(defrule parent
(or (father ?x ?y) (mother ?x ?y))
=>
(assert (parent ?x ?y)))
CLIPS>
(defrule gp
(and (parent ?x ?y) (parent ?y ?z))
=>
(assert (gp ?x ?z)))
CLIPS> (agenda)
CLIPS> (matches parent)
Matches for Pattern 1
None
Matches for Pattern 1
None
Activations
None
(0 0 0)
CLIPS> (matches gp)
Matches for Pattern 1
None
Matches for Pattern 2
None
Partial matches for CEs 1 - 2
None
Activations
None
(0 0 0)
CLIPS> (reset)
CLIPS> (agenda)
0 parent: f-5
0 parent: f-4
0 parent: f-3
0 parent: f-2
0 parent: f-1
For a total of 5 activations.
CLIPS> (matches gp)
Matches for Pattern 1
None
Matches for Pattern 2
None
Partial matches for CEs 1 - 2
None
Activations
None
(0 0 0)
CLIPS> (matches parent)
Matches for Pattern 1
f-1
f-3
f-4
f-5
Matches for Pattern 1
f-2
Activations
f-5
f-4
f-3
f-2
f-1
(5 0 5)
CLIPS> (run 1)
CLIPS> (facts)
f-1 (father tom nicholas)
f-2 (mother clair nicholas)
f-3 (father tom john)
f-4 (father brad tom)
f-5 (father mark clair)
f-6 (parent mark clair)
For a total of 6 facts.
CLIPS> (matches gp)
Matches for Pattern 1
f-6
Matches for Pattern 2
f-6
Partial matches for CEs 1 - 2
None
Activations
None
(2 0 0)
CLIPS> (agenda)
0 parent: f-4
0 parent: f-3
0 parent: f-2
0 parent: f-1
For a total of 4 activations.
CLIPS> (run 4)
CLIPS> (facts)
f-1 (father tom nicholas)
f-2 (mother clair nicholas)
f-3 (father tom john)
f-4 (father brad tom)
f-5 (father mark clair)
f-6 (parent mark clair)
f-7 (parent brad tom)
f-8 (parent tom john)
f-9 (gp brad john)
f-10 (parent clair nicholas)
For a total of 10 facts.
CLIPS> (agenda)
0 gp: f-6,f-10
0 parent: f-1
For a total of 2 activations.
CLIPS>