我是CLIPS的新手,我想过一开始就查看现有的已解决问题并尝试向后看。在Giarratano-Riley:Expert Systems and Programming 3rd edition中发现了以下问题,它说明了以下内容:
根据主要燃烧材料对火灾进行分类。 将以下信息翻译成确定火灾的规则 类。
A型火灾涉及普通易燃物,如纸张,木头和布料。
B类火灾涉及易燃和可燃液体(如 石油和天然气),油脂和类似材料。
C型火灾涉及带电的电气设备。
D型火灾涉及可燃金属,如镁,钠和钾。 应在火上使用的灭火器类型取决于防火等级。 将以下信息翻译成规则。
A类火灾应该用吸热或熄灭 燃烧延迟灭火器,如水或水 液体和干燥化学品。
- B类火灾应该是通过排除空气来抑制释放 可燃蒸汽,或中断燃烧链反应。灭火器 包括干化学品,二氧化碳,泡沫和溴三氟甲烷。
- C类火灾应使用非导电剂灭火以防止 短路。如果可能,应切断电源。灭火器 包括干化学品,二氧化碳和溴三氟甲烷。
- D级火灾应该用窒息和吸热化学物质熄灭>不会与燃烧的金属发生反应。这些化学物质包括三甲氧基环硼氧烷 和筛选的石墨化焦炭。
描述规则中使用的事实。程序的输入应该通过声明燃烧材料的类型作为事实来进行。输出应指示可以使用哪些灭火器以及应采取的其他措施,例如切断电源。显示您的程序适用于每个防火类的一种材料形式。
然后它由Berkely解决,代码如下。我的问题是,如何调用这些规则并使程序运行?我加载缓冲区,重置,运行,它只将规则加载到命令行。
; Define templates used in rules
(deftemplate fire (slot burning-material))
(deftemplate extinguisher-system (multislot function) (multislot extinguisher))
(deftemplate response (multislot actions))
(deftemplate fire-class (slot class))
; Define rules for determining fire classes
(defrule class-A-fire
(fire (burning-material paper | wood | cloth | other-ordinary-combustibles)) =>
(assert (fire-class (class A))))
(defrule class-B-fire
(fire (burning-material oil | gas | greases | other-flammable-combustible-liquids)) =>
(assert (fire-class (class B))))
(defrule class-C-fire
(fire (burning-material energized-electrical-equipment)) =>
(assert (fire-class (class C))))
(defrule class-D-fire
(fire (burning-material magnesium | sodium | potassium | other-combustible-metals)) =>
(assert (fire-class (class D))))
; Define rules for determining the type of extinguisher that should be used on a fire
(defrule class-A-emergency
(fire-class (class A))
=>
(assert (response (actions activate-extinguisher-A)))
(assert (extinguisher-system (function heat-absorbing combustion-retarding) (extinguisher water water-based-liquids dry-chemicals))))
(defrule class-B-emergency
(fire-class (class B))
=>
(assert (response (actions activate-extinguisher-B)))
(assert (extinguisher-system (function excluding-air inhibiting-release-of-combustible-vapors interrupting-combustion-chain-reaction) (extinguisher dry-chemicals carbon-dioxide foam bromotrifluoromethane))))
(defrule class-C-emergency
(fire-class (class C))
=>
(assert (response (actions activate-extinguisher-C power-cut)))
(assert (extinguisher-system (function nonconducting-agent) (extinguisher dry-chemicals carbon-dioxide bromotrifluoromethoane))))
(defrule class-D-emergency
(fire-class (class D))
=>
(assert (response (actions activate-extinguisher-D)))
(assert (extinguisher-system (function smothering-heatabsorbing-chemicals) (extinguisher trimethoxyboroxine screened-graphitized-coke))))
答案 0 :(得分:1)
我猜你直到这里才做到了:
CLIPS> Loading Selection...
Defining deftemplate: fire
Defining deftemplate: extinguisher-system
Defining deftemplate: response
Defining deftemplate: fire-class
Defining defrule: class-A-fire +j+j
Defining defrule: class-B-fire +j+j
Defining defrule: class-C-fire +j+j
Defining defrule: class-D-fire +j+j
Defining defrule: class-A-emergency +j+j
Defining defrule: class-B-emergency +j+j
Defining defrule: class-C-emergency +j+j
Defining defrule: class-D-emergency +j+j
CLIPS> (reset)
现在您需要加载问题数据。例如,对于柴火:
CLIPS> (assert (fire (burning-material wood)))
<Fact-1>
CLIPS> (facts)
f-0 (initial-fact)
f-1 (fire (burning-material wood))
然后运行规则引擎
CLIPS> (run)
CLIPS> (facts)
f-0 (initial-fact)
f-1 (fire (burning-material wood))
f-2 (fire-class (class A))
f-3 (response (actions activate-extinguisher-A))
f-4 (extinguisher-system (function heat-absorbing combustion-retarding) (extinguisher water water-based-liquids dry-chemicals))
并清理它以检查下一个问题
CLIPS> (reset)
CLIPS> (assert (fire (burning-material gas)))
<Fact-1>
CLIPS> (run)
...