⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 control.clp

📁 drools 一个开放源码的规则引擎
💻 CLP
字号:
;; Load our Userfunctions
(load-package control.HardwareFunctions)

;; Create a simulator
(defglobal ?*hw* = (init-simulator 33))

(defglobal ?*set-point* = 70)

;; Tell Jess about the Java Bean classes
(defclass Thermometer control.Thermometer)
(defclass Vent control.Vent)
(defclass HeatPump control.HeatPump)

;; Create the Vent and Thermometer Beans
(bind ?n (n-floors))
(while (> ?n 0) do
       (definstance Thermometer (new control.Thermometer ?*hw* ?n))
       (definstance Vent (new control.Vent ?*hw* ?n))
       (bind ?n (- ?n 1)))

;; Create the HeatPump Beans
(bind ?n (n-heatpumps))
(while (> ?n 0) do
       (definstance HeatPump (new control.HeatPump ?*hw* ?n))
       (bind ?n (- ?n 1)))

;; Deffunctions
(deffunction too-cold (?t)
  (return (< ?t (- ?*set-point* 2))))

(deffunction too-hot (?t)
  (return (> ?t (+ ?*set-point* 2))))

;; Heat pump rules
(defrule floor-too-cold-pump-off
  (HeatPump (state "off") (number ?p))
  (Thermometer (floor ?f&:(eq ?p (which-pump ?f)))
               (reading ?t&:(too-cold ?t)))
  =>
  (set-hp-state ?p heating))

(defrule floors-hot-enough
  (HeatPump (state "heating") (number ?p))
  (not (Thermometer (floor ?f&:(eq ?p (which-pump ?f)))
                    (reading ?t&:(< ?t ?*set-point*))))
  =>
  (set-hp-state ?p off))

(defrule floor-too-hot-pump-off
  (HeatPump (state "off") (number ?p))
  (Thermometer (floor ?f&:(eq ?p (which-pump ?f)))
               (reading ?t&:(too-hot ?t)))
  =>
  (set-hp-state ?p cooling))

(defrule floors-cool-enough
  (HeatPump (state "cooling") (number ?p))
  (not (Thermometer (floor ?f&:(eq ?p (which-pump ?f)))
                    (reading ?t&:(> ?t ?*set-point*))))
  =>
  (set-hp-state ?p off))

(defrule floor-too-cold-vent-closed
  (HeatPump (state "heating") (number ?p))
  (Vent (state "closed") (floor ?f&:(eq ?p (which-pump ?f))))
  (Thermometer (floor ?f)
               (reading ?t&:(< ?t ?*set-point*)))
  =>
  (set-vent-state ?f open))

(defrule floor-too-cold-vent-open
  (HeatPump (state "cooling") (number ?p))
  (Vent (state "open") (floor ?f&:(eq ?p (which-pump ?f))))
  (Thermometer (floor ?f)
               (reading ?t&:(< ?t ?*set-point*)))
  =>
  (set-vent-state ?f closed))

(defrule floor-too-hot-vent-closed
  (HeatPump (state "cooling") (number ?p))
  (Vent (state "closed") (floor ?f&:(eq ?p (which-pump ?f))))
  (Thermometer (floor ?f)
               (reading ?t&:(> ?t ?*set-point*)))
  =>
  (set-vent-state ?f open))

(defrule floor-too-hot-vent-open
  (HeatPump (state "heating") (number ?p))
  (Vent (state "open") (floor ?f&:(eq ?p (which-pump ?f))))
  (Thermometer (floor ?f)
               (reading ?t&:(> ?t ?*set-point*)))
  =>
  (set-vent-state ?f closed))

(watch rules)
(run-until-halt)


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -