CLIPS-logical条件元素-事实依赖

1、logical表示某事实的存在依赖于另一事实或另一组事实的存在,下例查出优秀学生的学号,优秀的标准是成绩>90或技能为good。

2、有时,某事实的存在依赖于2个或多个事实的存在,如下例中的3号学生,在其中一个事实不存在时,某事实仍然存在,只有这2个或多个事实都不存在了,某事实才不存在

3、一旦所依赖的事实不存在,则某事实也相应从事实库中删除。

4、dependents和dependencies 观察事实联系的依赖关系

5、操作

CLIPS (Quicksilver Beta 09/24/07)
CLIPS> (deftemplate student-skill
(slot no)
(slot skill)
)
CLIPS> (deftemplate student-mark
(slot no)
(slot mark)
)
CLIPS> (defrule goodstudentskill
(logical (student-skill (no ?no)(skill?skill))
(test (eq ?skill good)))
=>
(assert (good-student-no ?no))
)
CLIPS> (defrule goodstudentmark
(logical (student-mark (no ?no)(mark ?mark))
(test(> ?mark 90)))
=>
(assert (good-student-no ?no)))

CLIPS> (watch all)
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (assert (student-mark (no1)(mark 90))
(student-skill (no 1)(skill good)))
==>f-1(student-mark (no 1) (mark 90))
==>f-2(student-skill (no 1) (skill good))
==> Activation0goodstudentskill: f-2

CLIPS> (assert (student-mark (no2)(mark 95))
(student-skill (no 2)(skill poor)))
==>f-3(student-mark (no 2) (mark 95))
==> Activation0goodstudentmark: f-3
==>f-4(student-skill (no 2) (skill poor))

CLIPS>(assert (student-mark (no 3)(mark 95))
(student-skill (no 3)(skill good)))
==>f-5(student-mark (no 3) (mark 95))
==> Activation0goodstudentmark: f-5
==>f-6(student-skill (no 3) (skill good))
==> Activation0goodstudentskill: f-6

CLIPS> (facts)
f-0(initial-fact)
f-1(student-mark (no 1) (mark 90))
f-2(student-skill (no 1) (skill good))
f-3(student-mark (no 2) (mark 95))
f-4(student-skill (no 2) (skill poor))
f-5(student-mark (no 3) (mark 95))
f-6(student-skill (no 3) (skill good))
For a total of 7 facts.
CLIPS> (run)
FIRE 1goodstudentskill: f-6
==>f-7(good-student-no 3)
FIRE 2goodstudentmark: f-5
FIRE 3goodstudentmark: f-3
==>f-8(good-student-no 2)
FIRE 4goodstudentskill: f-2
==>f-9(good-student-no 1)
<== Focus MAIN
4 rulesfiredRun time is 0.0300000000000296 seconds.
133.333333333202 rules per second.
8 mean number of facts (10 maximum).
1 mean number of instances (1 maximum).
2 mean number of activations (4 maximum).
CLIPS> (facts)
f-0(initial-fact)
f-1(student-mark (no 1) (mark 90))
f-2(student-skill (no 1) (skill good))
f-3(student-mark (no 2) (mark 95))
f-4(student-skill (no 2) (skill poor))
f-5(student-mark (no 3) (mark 95))
f-6(student-skill (no 3) (skill good))
f-7(good-student-no 3)
f-8(good-student-no 2)
f-9(good-student-no 1)
For a total of 10 facts.
CLIPS> (modify 1 (skill poor))

[TMPLTDEF1] Invalid slot skill not defined in correspondingdeftemplate student-mark.
FALSE
CLIPS> (modify 2 (skill poor))
<==f-2(student-skill (no 1) (skill good))
<==f-9(good-student-no 1)
==>f-10(student-skill (no 1) (skill poor))

CLIPS> (refresh goodstudentskill)
==> Activation0goodstudentskill: f-6
CLIPS> (refresh goodstudentmark)
==> Activation0goodstudentmark: f-5
==> Activation0goodstudentmark: f-3
CLIPS> (facts)
f-0(initial-fact)
f-1(student-mark (no 1) (mark 90))
f-3(student-mark (no 2) (mark 95))
f-4(student-skill (no 2) (skill poor))
f-5(student-mark (no 3) (mark 95))
f-6(student-skill (no 3) (skill good))
f-7(good-student-no 3)
f-8(good-student-no 2)
f-10(student-skill (no 1) (skill poor))
For a total of 9 facts.
CLIPS> (modify 6 (skill poor))
<==f-6(student-skill (no 3) (skill good))
<== Activation0goodstudentskill: f-6
==>f-11(student-skill (no 3) (skill poor))

CLIPS> (refresh goodstudentmark)
CLIPS> (refresh goodstudentskill)
CLIPS> (facts)
f-0(initial-fact)
f-1(student-mark (no 1) (mark 90))
f-3(student-mark (no 2) (mark 95))
f-4(student-skill (no 2) (skill poor))
f-5(student-mark (no 3) (mark 95))
f-7(good-student-no 3)
f-8(good-student-no 2)
f-10(student-skill (no 1) (skill poor))
f-11(student-skill (no 3) (skill poor))
For a total of 9 facts.
CLIPS> (modify 5 (mark 80))
<==f-5(student-mark (no 3) (mark 95))
<== Activation0goodstudentmark: f-5
<==f-7(good-student-no 3)
==>f-12(student-mark (no 3) (mark 80))

CLIPS> (refresh goodstudentskill)
CLIPS> (refresh goodstudentmark)
CLIPS> (facts)
f-0(initial-fact)
f-1(student-mark (no 1) (mark 90))
f-3(student-mark (no 2) (mark 95))
f-4(student-skill (no 2) (skill poor))
f-8(good-student-no 2)
f-10(student-skill (no 1) (skill poor))
f-11(student-skill (no 3) (skill poor))
f-12(student-mark (no 3) (mark 80))
For a total of 8 facts.
CLIPS> (dependents 1)
None
CLIPS> (dependents 3)
f-8
CLIPS> (dependencies 3)
None
CLIPS> (dependencies 11)
None
CLIPS> (dependents 12)
None
CLIPS> (dependents 10)
None
CLIPS>

你可能感兴趣的:(F#)