CLIPS-多模式规则、调入和保存结构、注释

来源:互联网 发布:阿里云学生认证包过 编辑:程序博客网 时间:2024/06/09 20:27

一、

1、设火灾有A类和B类,A类用水喷water sprinkler,B类用汽喷carbon dioxideextinguisher,STATUS表示相应的喷洒装置是否开启。

2、调入和保存结构使用save和load命令

3、注释使用;标注

二、操作

  CLIPS (Quicksilver Beta 09/24/07)
CLIPS> (deftemplate emergency (slot type ))
CLIPS> (deftemplate extiguisher-system
(slot type)
(slot status))
CLIPS>  (defrule B-emergency
(emergency (type B-FIRE))
(extiguisher-system
(type carbon-dioxide)
(status off))
=>
(printout t "Activate carbon dioxide extinguisher" crlf))

CLIPS> (defrule A-emergency
(emergency (type A-FIRE))
(extiguisher-system
(type water-sprinkler)
(status off))
=>
(printout t "Activate water sprinkler" crlf))
CLIPS> (list-defrules)
B-emergency
A-emergency
For a total of 2 defrules.
CLIPS> (assert (extiguisher-system (typecarbon-dioxide)(status off)))

CLIPS> (agenda)
CLIPS> (assert (emergency (type A-FIRE)))

CLIPS> (agenda)
CLIPS> (facts)
f-0    (initial-fact)
f-1    (extiguisher-system (type carbon-dioxide) (status off))
f-2    (emergency (type A-FIRE))
For a total of 3 facts.
CLIPS> (assert (emergency (type B-FIRE)))

CLIPS> (facts)
f-0    (initial-fact)
f-1    (extiguisher-system (type carbon-dioxide) (status off))
f-2    (emergency (type A-FIRE))
f-3    (emergency (type B-FIRE))
For a total of 4 facts.
CLIPS> (agenda)
0     B-emergency: f-3,f-1
For a total of 1 activation.
CLIPS> (run)
Activate carbon dioxide extinguisher
CLIPS> (save"d:/aa.clp")
TRUE
CLIPS> (clear)
CLIPS> (list-defrules)
CLIPS> (load "d:/aa.clp")
Defining deftemplate: emergency
Defining deftemplate: extiguisher-system
Defining defrule: B-emergency +j+j+j
Defining defrule: A-emergency +j+j+j
TRUE
CLIPS> (list-defrules)
B-emergency
A-emergency
For a total of 2 defrules.

原创粉丝点击