【问题标题】:CLIPS conditional ruleCLIPS 条件规则
【发布时间】:2017-04-05 22:26:21
【问题描述】:

如何在 CLIPS 中创建条件规则来查找输出

例如

(deftemplate holiday
(slot hotel (allowed-symbols nice good poor))
(slot weather (allowed-symbols sunny raining))
)
(deftemplate output
(slot option (allowed-symbols go plan stay))
)

有了这个,我们如何创建这样的规则

if hotel = poor then stay
if hotel = poor and weather = raining then stay
if (hotel = poor and weather = sunny) or (hotel = good and weather = raining) then plan

谢谢

【问题讨论】:

    标签: if-statement clips


    【解决方案1】:
     (defrule hotel-rule1
           (holiday (hotel ?hotel&:(eq ?hotel poor)))
           =>
           (assert (output (option stay)))
        )
    
    (defrule hotel-rule2
           (holiday (hotel ?hotel&:(eq ?hotel poor)) (weather ?weather&:(eq ?weather raining)))
           =>
           (assert (output (option stay)))
        )
    

    我会将您最后一条规则的“或”条件拆分为两个不同的规则,类似于我写的示例。

    再见 尼克

    【讨论】:

    • 谢谢尼克。我收到一个错误:[EXPRNPSR3] 缺少选项的函数声明。我做错了吗?
    • 对不起,它正在工作。我没有正确复制你的代码。谢谢
    • 您可以直接匹配常量,而不是绑定变量并调用 eq 函数。例如,使用 (holiday (hotel ?hotel&:(eq ?hotel Poor)) (weather ?weather&:(eq ?weather raining))) 代替 (holiday (hotel ?hotel&:(eq ?hotel Poor))),使用 (holiday (hotel 差) (weather raining))
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 2021-02-26
    • 1970-01-01
    • 1970-01-01
    • 2015-01-04
    • 2011-08-08
    • 1970-01-01
    相关资源
    最近更新 更多