【问题标题】:Exit rule execution in Jess with condition在 Jess 中有条件的退出规则执行
【发布时间】:2018-05-16 19:58:19
【问题描述】:
我正在阅读 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 并退出进一步的规则执行。有没有办法做到这一点?
【问题讨论】:
标签:
clips
expert-system
jess
【解决方案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)
)