在有条件的情况下退出 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 并退出进一步的规则执行。有没有办法做到这一点?

心血来潮

您可以使用 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)
)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在有条件的情况下减去熊猫中的两列

如何在有条件的情况下删除SQL Server中的重复行?

如何在有条件的情况下控制 YAML 中的作业流?

如何在有条件的情况下让表格单元执行两种不同的筛选?

抓取表中的所有行,并在有条件的情况下抓取一行

如何在有条件的情况下使用RemoveAll删除列表中的多个项目?

mysql-在有条件的情况下选择并插入查询到多个表中

Jess规则定义

在有条件的情况下在keras中实现自定义损失功能

如何在有条件的情况下执行“ mv”命令-将具有某些结尾的文件移动到其他文件夹

Jess 中的 if 子句

Codeigniter中如何在没有条件的情况下选择联接多个表?

在jess中命令激活模块

在有条件的情况下使用“输入”

js中是否有条件检查运算符在为真的情况下返回条件本身?

在没有条件格式的情况下突出显示LibreOffice(或OpenOffice)中的其他所有行?

有条件地在Inno Setup中刷新外壳关联(仅在选中功能的情况下)

熊猫数据框中的提前滚动平均值(有条件的情况下)

@Scripts 不在 cshtml head @if 分支中渲染,但在没有条件逻辑的情况下渲染

确保在有条件的承诺之后执行承诺

如果在有条件的情况下,“ set -e”不会导致代码块退出

在JESS中删除多槽变量

在R中没有if语句的情况下有条件地从向量中删除

从规则jess或drools返回值(专家系统)

如何在R中有多个新列是有条件的情况下使用R中的多个列来表示一列的值?

为什么在有注释的情况下忽略了此简单程序中的条件?

如何在没有条件的情况下将行从一列绑定到SQL Server中的另一列

确保代码在有条件的情况下运行两次

如何在有条件的情况下替换冲突(对于SQLite)?