CLIPS-规则、议程、结构处理、监视

一、

1、定义模板(deftemplate emergency(slot type ))

2、定义规则:

=>前的是前件,以后是后件。

defrule fire-emergency "fire-action"
(emergency(type fire))
=>
(assert (response(action "activate-sprinkler-system"))))
3、(run)运行CLIPS,运行后,议程中的规则被验证后放入事实,同时从议程中删除

4、事实可以在规则定义前或后增加

5、(list-defrules)列出当前规则

(list-deffacts)列出自动声明事实

(list-deftemplates)列出模板

6、

CLIPS> (watch facts )
CLIPS> (watch statistics)
CLIPS> (watch activations)
打开事实、统计、规则监控

打开监控后,run显示状态

(run)
==>f-2(response (action "activate-sprinkler-system"))
1 rulesfiredRun time is 0.0199999999999818 seconds.
50.0000000000455 rules per second.
3 mean number of facts (3 maximum).
1 mean number of instances (1 maximum).
1 mean number of activations (1 maximum).

(unwatch all)或(unwatch ...)撤销监控

7、(refresh fire-emergency)为撤销事实并重新声明它使规则再次触发。

8、以下为显示某个结构

(ppdefrule fire-emergency)
(defrule MAIN::fire-emergency "fire-action"
(emergency (type fire))
=>
(assert (response (action"activate-sprinkler-system"))))
CLIPS> (ppdeftemplate response)
(deftemplate MAIN::response
(slot action))
CLIPS> (ppdeffacts initial-fact)

9、

CLIPS> (undeffactsemergency)
[PRNTUTIL1] Unable to find deffacts emergency.

出错是因为没有把相应事实先删除 

10

deffacts test (test))

[PATTERN1] The symbol test has special meaning
and may not be used as a relation name.

出错因为用了关健字

11

CLIPS> (undeffacts mytest)

CLIPS> (undeftemplate mytest)
CLIPS> (undefrule fire-emergency)

删除自动生成事实,模板,规则

二、操作

CLIPS (Quicksilver Beta 09/24/07)
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (deftemplate emergency(slot type ))
CLIPS> (deftemplate response(slot action))
CLIPS> (defrule fire-emergency "fire-action"
(emergency(type fire))
=>
(assert (response(action "activate-sprinkler-system"))))
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (agenda)
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (run)
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (agenda)
CLIPS> (assert (emergency (type fire )))

CLIPS> (agenda)
0fire-emergency: f-1
For a total of 1 activation.
CLIPS> (agenda)
0fire-emergency: f-1
For a total of 1 activation.
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
For a total of 2 facts.
CLIPS> (run)
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
f-2(response (action "activate-sprinkler-system"))
For a total of 3 facts.
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
f-2(response (action "activate-sprinkler-system"))
For a total of 3 facts.
CLIPS> (agenda)
CLIPS> (watch facts )
CLIPS> (watch statistics)
CLIPS> (watch activations)
CLIPS> (reset)
<==f-0(initial-fact)
<==f-1(emergency (type fire))
<==f-2(response (action "activate-sprinkler-system"))
==>f-0(initial-fact)
CLIPS> (list-defrules)
fire-emergency
For a total of 1 defrule.
CLIPS> (list-deffacts)
initial-fact
For a total of 1 deffacts.
CLIPS> (list-deftemplates)
initial-fact
emergency
response
For a total of 3 deftemplates.
CLIPS> (assert (emergency (type fire)))
==>f-1(emergency (type fire))
==> Activation0fire-emergency: f-1

CLIPS> (agenda)
0fire-emergency: f-1
For a total of 1 activation.
CLIPS> (agenda)
0fire-emergency: f-1
For a total of 1 activation.
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
For a total of 2 facts.
CLIPS> (agenda)
0fire-emergency: f-1
For a total of 1 activation.
CLIPS> (reset)
<==f-0(initial-fact)
<==f-1(emergency (type fire))
<== Activation0fire-emergency: f-1
==>f-0(initial-fact)
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (agenda)
CLIPS> (assert (emergency (type fire)))
==>f-1(emergency (type fire))
==> Activation0fire-emergency: f-1

CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
For a total of 2 facts.
CLIPS> (agenda)
0fire-emergency: f-1
For a total of 1 activation.
CLIPS> (run)
==>f-2(response (action "activate-sprinkler-system"))
1 rulesfiredRun time is 0.0199999999999818 seconds.
50.0000000000455 rules per second.
3 mean number of facts (3 maximum).
1 mean number of instances (1 maximum).
1 mean number of activations (1 maximum).
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
f-2(response (action "activate-sprinkler-system"))
For a total of 3 facts.
CLIPS> (agenda)
CLIPS> (refresh fire-emergency)
==> Activation0fire-emergency: f-1
CLIPS> (agenda)
0fire-emergency: f-1
For a total of 1 activation.
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
f-2(response (action "activate-sprinkler-system"))
For a total of 3 facts.
CLIPS> (retract 1)
<==f-1(emergency (type fire))
<== Activation0fire-emergency: f-1
CLIPS> (facts)
f-0(initial-fact)
f-2(response (action "activate-sprinkler-system"))
For a total of 2 facts.
CLIPS> (agenda)
CLIPS> (run)
0 rulesfiredRun time is 0.00999999999999091 seconds.
0.0 rules per second.
2 mean number of facts (2 maximum).
1 mean number of instances (1 maximum).
0 mean number of activations (0 maximum).
CLIPS> (agenda)
CLIPS> (facts)
f-0(initial-fact)
f-2(response (action "activate-sprinkler-system"))
For a total of 2 facts.
CLIPS> (refresh fire-emergency)
CLIPS> (facts)
f-0(initial-fact)
f-2(response (action "activate-sprinkler-system"))
For a total of 2 facts.
CLIPS> (agenda)
CLIPS> (reset)
<==f-0(initial-fact)
<==f-2(response (action "activate-sprinkler-system"))
==>f-0(initial-fact)
CLIPS> (agenda)
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (assert (emergency(type fire)))
==>f-1(emergency (type fire))
==> Activation0fire-emergency: f-1

CLIPS> (unwatch all)
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
For a total of 2 facts.
CLIPS> (agenda)
0fire-emergency: f-1
For a total of 1 activation.
CLIPS> (ppdefrule fire-emergency)
(defrule MAIN::fire-emergency "fire-action"
(emergency (type fire))
=>
(assert (response (action"activate-sprinkler-system"))))
CLIPS> (ppdeftemplate response)
(deftemplate MAIN::response
(slot action))
CLIPS> (ppdeffacts initial-fact)
CLIPS> (undefrule fire-emergency)
CLIPS> (list-defrules)
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
For a total of 2 facts.
CLIPS> (undeffacts emergency)
[PRNTUTIL1] Unable to find deffacts emergency.
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
For a total of 2 facts.
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
For a total of 2 facts.
CLIPS> (list-rules)

[EXPRNPSR3] Missing function declaration for list-rules.
CLIPS> (list-defrules)
CLIPS> (undeffacts emergency)
[PRNTUTIL1] Unable to find deffacts emergency.
CLIPS> (deffacts test (test))

[PATTERN1] The symbol test has special meaning
and may not be used as a relation name.

ERROR:
(deffacts MAIN::test
(test
CLIPS> (deffacts mytest (mytest))
CLIPS> (list-deffacts)
initial-fact
mytest
For a total of 2 deffacts.
CLIPS> (undeffacts mytest)
CLIPS> (list-deffacts)
initial-fact
For a total of 1 deffacts.
CLIPS> (list-deffacts)
initial-fact
For a total of 1 deffacts.
CLIPS> (list-defrules)
CLIPS> (list-deftemplates)
initial-fact
emergency
response
mytest
For a total of 4 deftemplates.
CLIPS> (undeftemplate mytest)
CLIPS> (undeftemplate emergency)
[PRNTUTIL4] Unable to delete deftemplate emergency.
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
For a total of 2 facts.
CLIPS> (run)
CLIPS> (facts)
f-0(initial-fact)
f-1(emergency (type fire))
For a total of 2 facts.
CLIPS> (retract 1)
CLIPS> (facts)
f-0(initial-fact)
For a total of 1 fact.
CLIPS> (undeftemplate emergency)
CLIPS> (list-deftemplates)
initial-fact
response
For a total of 2 deftemplates.
CLIPS> (clear)
CLIPS> (list-deftemplates)
initial-fact
For a total of 1 deftemplate.
CLIPS> (list-defrules)
CLIPS> (list-deffacts)
initial-fact
For a total of 1 deffacts.
CLIPS>

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