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

I는 입력 전압의 값을 체크 할 수 있도록하고자하며이 정의 된 범위를 벗어나면, 0으로 설정하고 상기 규칙 실행을 종료. 그렇게 할 수있는 방법이 있습니까?

답변

1

if 함수를 사용할 수 있습니다 (cf. 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) 
) 

다른 값들에 대해서도 유사한 체크가 이루어질 수 있습니다.

하지만 사용자에게 다른 기회가 주어져서는 안됩니까? Cf. 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) 
)