CLIPS 打印输出规则触发次数
CLIPS Printout Number Of Times Rule Fired
我在下面有以下 CLIPS 构造,我有兴趣计算触发特定规则的次数,因此输出将是一系列触发的规则及其计数(参见图片示例)。
所以这将是所有这些规则后跟:
温度:(发射次数)秒
压力:(发射次数)秒
(deftemplate oil-measure
(slot utc-time (type STRING))
(slot temperature (type INTEGER))
(slot pressure (type INTEGER)))
(defrule oil-is-hot
(oil-measure (temperature ?temp) (utc-time ?time))
(test (> ?temp 32))
=>
(printout t ?time tab "temperature:" tab ?temp crlf))
(defrule pressure-is-high
(oil-measure (pressure ?press&:(> ?press 0)) (utc-time ?time))
=>
(printout t ?time tab "pressure:" tab ?press crlf))
您可以将计数器存储在全局变量中并相应地增加它们。
(defglobal ?*hot-oil-times* = 0)
(defrule oil-is-hot
(oil-measure (temperature ?temp) (utc-time ?time))
(test (> ?temp 32))
=>
(bind ?*hot-oil-times* (+ ?*hot-oil-times* 1))
(printout t ?time tab "temperature:" tab ?*hot-oil-times* tab ?temp crlf))
包含 noxdafox 解决方案的代码:
(defglobal ?*hot-oil-times* = 0)
(defglobal ?*high-pressure-times* = 0)
(deftemplate oil-measure
(slot utc-time (type STRING))
(slot temperature (type INTEGER))
(slot pressure (type INTEGER)))
(defrule oil-is-hot
(oil-measure (temperature ?temp) (utc-time ?time))
(test (> ?temp 32))
=>
(bind ?*hot-oil-times* (+ ?*hot-oil-times* 1))
(printout t ?time tab "temperature:" tab ?*hot-oil-times* tab ?temp crlf))
(defrule pressure-is-high
(oil-measure (pressure ?press&:(> ?press 0)) (utc-time ?time))
=>
(bind ?*high-pressure-times* (+ ?*high-pressure-times* 1))
(printout t ?time tab "pressure:" tab ?*high-pressure-times* tab ?press crlf))
我在下面有以下 CLIPS 构造,我有兴趣计算触发特定规则的次数,因此输出将是一系列触发的规则及其计数(参见图片示例)。
温度:(发射次数)秒
压力:(发射次数)秒
(deftemplate oil-measure
(slot utc-time (type STRING))
(slot temperature (type INTEGER))
(slot pressure (type INTEGER)))
(defrule oil-is-hot
(oil-measure (temperature ?temp) (utc-time ?time))
(test (> ?temp 32))
=>
(printout t ?time tab "temperature:" tab ?temp crlf))
(defrule pressure-is-high
(oil-measure (pressure ?press&:(> ?press 0)) (utc-time ?time))
=>
(printout t ?time tab "pressure:" tab ?press crlf))
您可以将计数器存储在全局变量中并相应地增加它们。
(defglobal ?*hot-oil-times* = 0)
(defrule oil-is-hot
(oil-measure (temperature ?temp) (utc-time ?time))
(test (> ?temp 32))
=>
(bind ?*hot-oil-times* (+ ?*hot-oil-times* 1))
(printout t ?time tab "temperature:" tab ?*hot-oil-times* tab ?temp crlf))
包含 noxdafox 解决方案的代码:
(defglobal ?*hot-oil-times* = 0)
(defglobal ?*high-pressure-times* = 0)
(deftemplate oil-measure
(slot utc-time (type STRING))
(slot temperature (type INTEGER))
(slot pressure (type INTEGER)))
(defrule oil-is-hot
(oil-measure (temperature ?temp) (utc-time ?time))
(test (> ?temp 32))
=>
(bind ?*hot-oil-times* (+ ?*hot-oil-times* 1))
(printout t ?time tab "temperature:" tab ?*hot-oil-times* tab ?temp crlf))
(defrule pressure-is-high
(oil-measure (pressure ?press&:(> ?press 0)) (utc-time ?time))
=>
(bind ?*high-pressure-times* (+ ?*high-pressure-times* 1))
(printout t ?time tab "pressure:" tab ?*high-pressure-times* tab ?press crlf))