2017-12-03 3 views
0

Ich lese mehrere Benutzereingaben in Jess. Die Regel lautet:Exit Regelausführung in Jess mit Bedingung

(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)))) 

Ich möchte in der Lage seinen Wert der Eingangsspannung zu überprüfen, und wenn es aus dem definierten Bereich ist, ist es auf 0 zu setzen und weitere Regelausführung verlassen. Gibt es einen Weg, das zu tun?

Antwort

1

Sie können eine if-Funktion verwenden (vgl. Jess-Handbuch Abschnitt 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) 
) 

Ähnliche Überprüfungen können auch für die anderen Werte vorgenommen werden.

Aber sollte der Benutzer nicht eine andere Chance gegeben? Vgl. Abschnitt 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) 
)