2017-12-03 97 views
0

我正在閱讀Jess中的幾個用戶輸入。規則是:退出Jess條件的執行條件

(defrule specify-input 
    ?act <- (Actuator (name 0) (inputVoltage ?v1&0)) 
    => 
    (printout t "Please specify input voltage of the actuator. [V] " crlf) 
    (modify ?act (inputVoltage (read))) 
    (printout t "Please specify desired force of the actuator. [N] " crlf) 
    (modify ?act (Force (read))) 
    (printout t "Please specify desired stroke lenght of the actuator. [mm] " crlf) 
    (modify ?act (StrokeLength (read)))) 

我想能夠檢查的輸入電壓的值,如果它超出了規定的範圍,將其設置爲0並退出進一步規則執行。有沒有辦法做到這一點?

回答

1

您可以使用if函數(參見Jess手冊第3.8.2節)。

(printout t "Please specify input voltage of the actuator. [V] " crlf) 
(bind ?v (read)) 
(if (and (> ?v 0) (<= ?v 1000)) then 
    (printout t "Please specify desired force of the actuator. [N] " crlf) 
    (bind ?f (read)) 
    (printout t "Please specify desired stroke lenght of the actuator. [mm] " crlf) 
    (bind ?sl (read)) 
    (modify ?act (inputVoltage ?iv)(Force ?f)(StrokeLength ?sl)) 
) else (
    (printout t "invalid voltage" crlf) 
) 

也可以對其他值進行類似的檢查。

但不應該給用戶另外的機會嗎?參看第3.8.1節。

(while true do 
    (printout t "Please specify input voltage of the actuator. [V] " crlf) 
    (bind ?v (read)) 
    (if (and (> ?v 0) (<= ?v 1000)) then (break)) 
    (printout t "invalid voltage, not in (0,1000]" crlf) 
)