2017-12-03 59 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) 
)