CLIPS打印输出规则被触发的次数

时间:2019-01-13 20:52:13

标签: clips

我在下面有以下CLIPS构造,我有兴趣计算特定规则的触发次数,因此输出将是一系列触发的规则及其计数(例如,参见图片)。 CLIPS Output 因此,将遵循以下所有规则:

温度:(触发时间)秒
压力:(发射时间)秒

(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))

2 个答案:

答案 0 :(得分:1)

您可以将计数器存储在全局变量中,并相应地增加它们。

(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))

答案 1 :(得分:0)

包含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))