;;; must load templates first ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Initializing rule ;; (defrule start => (initShower) ) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;; Rules that control the shower with fuzzy inferencing ;; (defrule Shower_OFF ?off <- (Shower is OFF) => (assert (change_vh Z)) (assert (change_vc NB)) (retract ?off) ) (defrule cold_low ?f1 <- (outTemp cold) ?f2 <- (outFlow low) => ;; MAR 06/09/05 - added debugging (bind ?howcold (moment-defuzzify ?f1)) (bind ?howlow (moment-defuzzify ?f2)) (bind ?coldclipped (get-fs-value (create-fuzzy-value outTemp cold) ?howcold)) (bind ?lowclipped (get-fs-value (create-fuzzy-value outFlow low) ?howlow )) (printout t "> debug in cold_low how cold is it? membership: " ?coldclipped " how low is it? membership: " ?lowclipped t) (assert (change_vh PB)) (assert (change_vc Z)) ) (defrule cold_OK ?f1 <- (outTemp cold) ?f2 <- (outFlow OK) => ;; MAR 06/09/05 - added debugging (bind ?howcold (moment-defuzzify ?f1)) (bind ?howOK (moment-defuzzify ?f2)) (bind ?coldclipped (get-fs-value (create-fuzzy-value outTemp cold) ?howcold)) (bind ?OKclipped (get-fs-value (create-fuzzy-value outFlow OK) ?howOK)) (printout t "> debug in cold_OK how cold is it? membership: " ?coldclipped " how OK is flow? membership: " ?OKclipped t) (assert (change_vh PM)) (assert (change_vc Z)) ) (defrule cold_strong ?f1 <- (outTemp cold) ?f2 <- (outFlow strong) => ;; MAR 06/09/05 - added debugging (bind ?howcold (moment-defuzzify ?f1)) (bind ?howstrong (moment-defuzzify ?f2)) (bind ?coldclipped (get-fs-value (create-fuzzy-value outTemp cold) ?howcold)) (bind ?strongclipped (get-fs-value (create-fuzzy-value outFlow strong) ?howstrong)) (printout t "> debug in cold_strong how cold is it? membership: " ?coldclipped " how strong is it? membership: " ?strongclipped t) (assert (change_vh Z)) (assert (change_vc NB)) ) (defrule OK_low ?f1 <- (outTemp OK) ?f2 <- (outFlow low) => ;; MAR 06/09/05 - added debugging (bind ?howOK (moment-defuzzify ?f1)) (bind ?howlow (moment-defuzzify ?f2)) (bind ?OKclipped (get-fs-value (create-fuzzy-value outTemp OK) ?howOK)) (bind ?lowclipped (get-fs-value (create-fuzzy-value outFlow low) ?howlow)) (printout t "> debug in OK_low how OK is temp? membership: " ?OKclipped " how low is it? membership: " ?lowclipped t) (assert (change_vh PS)) (assert (change_vc PS)) ) (defrule OK_strong ?f1 <- (outTemp OK) ?f2 <- (outFlow strong) => ;; MAR 06/09/05 - added debugging (bind ?howOK (moment-defuzzify ?f1)) (bind ?howstrong (moment-defuzzify ?f2)) (bind ?OKclipped (get-fs-value (create-fuzzy-value outTemp OK) ?howOK)) (bind ?strongclipped (get-fs-value (create-fuzzy-value outFlow strong) ?howstrong)) (printout t "> debug in OK_strong how OK is temp? membership: " ?OKclipped " how strong is it? membership: " ?strongclipped t) (assert (change_vh NS)) (assert (change_vc NS)) ) (defrule hot_low ?f1 <- (outTemp hot) ?f2 <- (outFlow low) => ;; MAR 06/09/05 - added debugging (bind ?howhot (moment-defuzzify ?f1)) (bind ?howlow (moment-defuzzify ?f2)) (bind ?hotclipped (get-fs-value (create-fuzzy-value outTemp hot) ?howhot)) (bind ?lowclipped (get-fs-value (create-fuzzy-value outFlow low) ?howlow)) (printout t "> debug in hot_low how hot is it? membership: " ?hotclipped " how low is it? membership: " ?lowclipped t) (assert (change_vh Z)) (assert (change_vc PB)) ) (defrule hot_OK ?f1 <- (outTemp hot) ?f2 <- (outFlow OK) => ;; MAR 06/09/05 - added debugging (bind ?howhot (moment-defuzzify ?f1)) (bind ?howOK (moment-defuzzify ?f2)) (bind ?hotclipped (get-fs-value (create-fuzzy-value outTemp hot) ?howhot)) (bind ?OKclipped (get-fs-value (create-fuzzy-value outFlow OK) ?howOK)) (printout t "> debug in hot_OK how hot is it? membership: " ?hotclipped " how OK is flow? membership: " ?OKclipped t) (assert (change_vh NM)) (assert (change_vc Z)) ) (defrule hot_strong ?f1 <- (outTemp hot) ?f2 <- (outFlow strong) => ;; MAR 06/09/05 - added debugging (bind ?howhot (moment-defuzzify ?f1)) (bind ?howstrong (moment-defuzzify ?f2)) (bind ?hotclipped (get-fs-value (create-fuzzy-value outTemp hot) ?howhot)) (bind ?strongclipped (get-fs-value (create-fuzzy-value outFlow strong) ?howstrong)) (printout t "> debug in hot_strong how hot is it? membership: " ?hotclipped " how strong is it? membership: " ?strongclipped t) (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) )