0

我是 CLIPS 的新手,我想从一开始就查看现有已解决的问题,然后尝试向后计算。Giarratano-Riley:专家系统和编程第 3 版中发现了以下问题,它指出以下内容:

火灾按主要燃烧材料分类。将以下信息转换为确定火灾等级的规则。

  • 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))))
4

1 回答 1

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)
...
于 2013-11-08T13:39:10.793 回答