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

📄 wxshower.clp

📁 模糊clips专家系统
💻 CLP
📖 第 1 页 / 共 2 页
字号:
    (assert (change_vh  PM))
    (assert (change_vc Z))
)

(defrule cold_strong
    (outTemp cold)
    (outFlow strong)
   =>
    (assert (change_vh Z))
    (assert (change_vc NB))
)

(defrule OK_low
   (outTemp OK)
   (outFlow low)
  =>
   (assert (change_vh  PS))
   (assert (change_vc  PS))
)

(defrule OK_strong
   (outTemp OK)
   (outFlow strong)
  =>
   (assert (change_vh  NS))
   (assert (change_vc NS))
)


(defrule hot_low
  (outTemp hot)
   (outFlow low)
  =>
   (assert (change_vh Z))
   (assert (change_vc  PB))
)

(defrule hot_OK
   (outTemp hot)
   (outFlow OK)
  =>
   (assert (change_vh NM))
   (assert (change_vc Z))
)

(defrule hot_strong
   (outTemp hot)
   (outFlow strong)
  =>
   (assert (change_vh NB))
   (assert (change_vc Z))
)

;; when all rules have fired and contributed to determination of the
;; control changes to be made then defuzzify the change values and
;; pass these new values to the simulate function

(defrule defuzzification-and-control
   (declare (salience -1))
   ?f1 <- (change_vc ?)
   ?f2 <- (change_vh ?)
   ?f3 <- (outTemp ?)
   ?f4 <- (outFlow ?)
 =>
   (bind ?coldChange (moment-defuzzify ?f1))
   (bind ?hotChange  (moment-defuzzify ?f2))
   (retract ?f1 ?f2 ?f3 ?f4)
   (Simulate ?coldChange ?hotChange)
)




;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Functions that define the user interface to the Shower
;; Example
;;
;;
;; app-on-init   - start the application by executing this fcn
;;
;;


;;; Callback for Main Frame -- ?*main-frame*
;;; Sizing callback
(deffunction on-size (?id ?w ?h)
 (if (and (> ?id 0) (> ?*panel* 0) (> ?*canvas* 0)) then
;  (window-fit ?*panel*)
 )
)

;;; close callback
(deffunction on-close (?frame)
 (format t "Closing frame.%n")
 1
)

;;; menu callback
(deffunction on-menu-command (?frame ?id)
(printout t ?id "******" crlf)
 (if (eq ?id 201) ;; About selection
  then 
    (message-box "FuzzyCLIPS Shower Demo
by National Research Council of Canada" "About Shower Demo")
  else
    (if (eq ?id 1) ;; Quit selection
     then
       (on-close ?frame)
       (window-delete ?frame)
    )
 )
)

;;; Callbacks for sliders
(deffunction on-outtemp (?id) ;; cannot change this manually
  (slider-set-value ?*outtemp-slider* (integer (+ 0.5 ?*outTemp*)))
)

(deffunction on-outflow (?id) ;; cannot change this manually
  (slider-set-value ?*outflow-slider* (integer (+ 0.5 ?*outFlow*)))
)

(deffunction on-hot-temp (?id)
  (bind ?*hotTemp* (slider-get-value ?id))
  (if (< ?*hotTemp* 5) then 
      (bind ?*hotTemp* 5.0)
      (slider-set-value ?id 5)
  )
  (if (> ?*hotTemp* 100) then
      (bind ?*hotTemp* 100.0)
      (slider-set-value ?id 100)
  )
  (if (eq ?*manual-auto* "manual")
     then
       (calc-outFlow-and-outTemp)
     else
       (Simulate 0.0 0.0)
       (run)
  )
)

(deffunction on-cold-temp (?id)
  (bind ?*coldTemp* (slider-get-value ?id))
  (if (< ?*coldTemp* 5) then 
      (bind ?*coldTemp* 5.0)
      (slider-set-value ?id 5)
  )
  (if (> ?*coldTemp* 100) then
      (bind ?*coldTemp* 100.0)
      (slider-set-value ?id 100)
  )
  (if (eq ?*manual-auto* "manual")
     then
       (calc-outFlow-and-outTemp)
     else
       (Simulate 0.0 0.0)
       (run)
  )
)

(deffunction on-hot-press (?id)
  (bind ?*hotPress* (slider-get-value ?id))
  (if (< ?*hotPress* 30) then 
      (bind ?*hotPress* 30.0)
      (slider-set-value ?id 30)
  )
  (if (eq ?*manual-auto* "manual")
     then
       (calc-outFlow-and-outTemp)
     else
       (Simulate 0.0 0.0)
       (run)
  )
)

(deffunction on-cold-press (?id)
  (bind ?*coldPress* (slider-get-value ?id))
  (if (< ?*coldPress* 30) then 
      (bind ?*coldPress* 30.0)
      (slider-set-value ?id 30)
  )
  (if (eq ?*manual-auto* "manual")
     then
       (calc-outFlow-and-outTemp)
     else
       (Simulate 0.0 0.0)
       (run)
  )
)

(deffunction on-hot-valve (?id)
  (if (eq ?*manual-auto* "manual")
     then
       (bind ?*hotValvePos* (/ (float (slider-get-value ?id)) 100.0))
       (calc-outFlow-and-outTemp)
     else
       (slider-set-value ?id (integer (+ 0.5 (* ?*hotValvePos* 100))))
  )
)

(deffunction on-cold-valve (?id)
  (if (eq ?*manual-auto* "manual")
     then
       (bind ?*coldValvePos* (/ (float (slider-get-value ?id)) 100.0))
       (calc-outFlow-and-outTemp)
     else
       (slider-set-value ?id (integer (+ 0.5 (* ?*coldValvePos* 100))))
  )
)


;;; Callback for manual/auto check-box
(deffunction on-manual-auto (?id)
  (bind ?value (check-box-get-value ?id))
  (if (eq ?value 0)  ;; manual
     then
       (frame-set-status-text ?*main-frame* "Manual Mode: Select 'auto' check box for Fuzzy Control")
       (bind ?*manual-auto* "manual")
     else
       (frame-set-status-text ?*main-frame* "Auto Mode: Fuzzy Control in effect")
       (bind ?*manual-auto* "auto")
       (Simulate 0.0 0.0)
       (run)
  )
  
)

;;; painting the canvas -- shower graphic
;;; Painting callback
(deffunction on-paint (?id)
 (if (> ?id 0) then
  (bind ?dc (canvas-get-dc ?id))
  (bind ?red-pen (pen-create RED 8 wxSOLID))
  (dc-set-pen ?dc ?red-pen)
  (dc-draw-line ?dc 30.0 300.0 30.0 100.0)
  (dc-draw-line ?dc 30.0 100.0 110.0 100.0)
  (bind ?blue-pen (pen-create BLUE 8 wxSOLID))
  (dc-set-pen ?dc ?blue-pen)
  (dc-draw-line ?dc 190.0 300.0 190.0 100.0)
  (dc-draw-line ?dc 190.0 100.0 110.0 100.0)
  (bind ?green-pen (pen-create GREEN 8 wxSOLID))
  (dc-set-pen ?dc ?green-pen)
  (dc-draw-line ?dc 110.0 100.0 110.0 35.0)
  (dc-draw-line ?dc 110.0 35.0 160.0 35.0)
  (bind ?green-brush (brush-create GREEN wxSOLID))
  (dc-set-brush ?dc ?green-brush)
  (dc-set-pen ?dc ?green-pen)
  (dc-draw-polygon ?dc (create$ 145.0 35.0 165.0 15.0 165.0 55.0))
  (dc-draw-ellipse ?dc 105 95 10 10)
  (bind ?green-dashed-pen (pen-create GREEN 2 wxSHORT_DASH))
  (dc-set-pen ?dc ?green-dashed-pen) 
  (dc-draw-spline ?dc 
     (create$ 170.0 20.0 180.0 25.0 200.0 35.0 210.0 50.0)) 
  (dc-draw-spline ?dc 
     (create$ 170.0 30.0 180.0 35.0 200.0 45.0 210.0 60.0)) 
  (dc-draw-spline ?dc 
     (create$ 170.0 40.0 180.0 45.0 200.0 55.0 210.0 70.0)) 
  (dc-draw-spline ?dc 
     (create$ 170.0 50.0 180.0 55.0 200.0 65.0 210.0 80.0)) 
  (bind ?black-pen (pen-create BLACK 2 wxSOLID))
  (bind ?cyan-brush (brush-create CYAN wxSOLID))
  (dc-set-brush ?dc ?cyan-brush)
  (dc-set-pen ?dc ?black-pen)
  (dc-draw-polygon ?dc (create$ 5.0 160.0 55.0 190.0 55.0 160.0 5.0 190.0))
  (dc-draw-polygon ?dc (create$ 165.0 160.0 215.0 190.0 215.0 160.0 165.0 190.0))
 )
)


(deffunction app-on-init ()

  (bind ?*main-frame* (frame-create 0 "Fuzzy Shower Example" -1 -1 640 480))
  (frame-create-status-line ?*main-frame*)
  (frame-set-status-text ?*main-frame* "Initializing Fuzzy Shower Problem")
  (window-centre ?*main-frame* wxBOTH)

  (window-add-callback ?*main-frame* OnSize on-size)
  (window-add-callback ?*main-frame* OnClose on-close)
  (window-add-callback ?*main-frame* OnMenuCommand on-menu-command)

  ;;; Make a menu bar
  (bind ?file-menu (menu-create))
  (menu-append ?file-menu 1 "&Quit")

  (bind ?help-menu (menu-create))
  (menu-append ?help-menu 201 "&About")

  (bind ?menu-bar (menu-bar-create))
  (menu-bar-append ?menu-bar ?file-menu "&File")
  (menu-bar-append ?menu-bar ?help-menu "&Help")
  
  (frame-set-menu-bar ?*main-frame* ?menu-bar)

  ;;; Make a panel and panel items
  (bind ?*panel* (panel-create ?*main-frame* 0 0 640 460))
  (panel-set-label-position ?*panel* wxVERTICAL)

  ;; Make some sliders for temp, press, valves, and outputs
  (message-create ?*panel* "Hot Valve" 20 200)
  (bind ?*hot-valve-slider*
       (slider-create ?*panel* "on-hot-valve" ""
                      0 0 100 85 20 230)
  )
  (message-create ?*panel* "Cold Valve" 440 200)
  (bind ?*cold-valve-slider* 
       (slider-create ?*panel* "on-cold-valve" "" 
                      0 0 100 85 440 230)
  )
  (message-create ?*panel* "Hot Temp" 20 310)
  (bind ?*hot-temp-slider*
       (slider-create ?*panel* "on-hot-temp" ""
                      0 0 100 85 20 340)
  )
  (message-create ?*panel* "Cold Temp" 440 310)
  (bind ?*cold-temp-slider* 
       (slider-create ?*panel* "on-cold-temp" "" 
                      0 0 100 85 440 340)
  )
  (message-create ?*panel* "Hot Pressure" 20 90)
  (bind ?*hot-press-slider*
       (slider-create ?*panel* "on-hot-press" ""
                      55 30 90 85 20 120)
  )
  (message-create ?*panel* "Cold Pressure" 440 90)
  (bind ?*cold-press-slider* 
       (slider-create ?*panel* "on-cold-press" "" 
                      55 30 90 85 440 120)
  )
  (message-create ?*panel* "Shower Temp" 140 5)
  (bind ?*outtemp-slider*
       (slider-create ?*panel* "on-outtemp" ""
                      0 0 72 85 140 30)
  )
  (message-create ?*panel* "Shower Flow" 350 5)
  (bind ?*outflow-slider* 
       (slider-create ?*panel* "on-outflow" "" 
                      0 0 25 85 350 30)
  )

  ;; check-box for manual/auto mode
  (bind ?*manual-auto-check-box* 
       (check-box-create ?*panel* "on-manual-auto" "Auto" 20 30)
  )
  (check-box-set-value ?*manual-auto-check-box* 0)
  (bind ?*manual-auto* "manual")
  (frame-set-status-text ?*main-frame* "Manual Mode: Select 'auto' for Fuzzy Control")

  ;;; Make a canvas for displaying the graphic
  (bind ?*canvas* (canvas-create ?*main-frame* 210 80 220 270))
  (window-add-callback ?*canvas* OnPaint on-paint)

  (initShower)

  (window-show ?*main-frame* 1)

  ?*main-frame*
)

⌨️ 快捷键说明

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