如何做逻辑或CLIPS? [英] How to do a logical or in CLIPS?

查看:109
本文介绍了如何做逻辑或CLIPS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新的代码: 在何处添加?f<-(practice-is-on-off OFF)

Updated code: where to add the check for ?f<-(practice-is-on-off OFF)

 (defrule no-practice "Rules for when practice cannot be held"

        (or ?f <- (practice (number-of-paddlers ?p&:(< ?p 6)))
            ?f <- (practice (number-of-coaches ?c&:(< ?c 1))))

        =>
        (modify ?f (practice-is-on-off OFF)))

    ;end


我正在CLIPS中定义模板,并且正在使用逻辑运算符OR. 但是,当我加载模板时,它会抛出一个错误


I am defining a template in CLIPS and I am using logical operator OR. However, when I load the template, it is throwing an error saying

[TMPLTDEF1] Invalid slot or not defined in corresponding deftemplate practice.

ERROR:
(defrule MAIN::no-practice "Rules for when practice cannot be held"
   ?f <- (practice (or

这是我所拥有的: 预先感谢您的任何见解.谢谢

Here's what I have: Thanks in advance for any insight. Thanks

(deftemplate practice "structure of a practice"

    (slot number-of-paddlers (type NUMBER))
    (slot number-of-coaches (type NUMBER))
    (slot practice-is-on-off (type SYMBOL) (default ON))
    (slot practice-id (type NUMBER))

)


(defrule no-practice "Rules for when practice cannot be held"
    ?f <- (practice 
    (or
            (number-of-paddlers
                ?v_number-of-paddlers&:(
                    < ?v_number-of-paddlers 6))

            (number-of-coaches
                ?v_number-of-coaches&:(
                    < ?v_number-of-coaches 1))

    )
    )

    =>
        (modify ?f (practice-is-on-off OFF)
        )
)

推荐答案

该错误告诉您您正在尝试匹配practice deftemplate中名为或"的插槽,并且该插槽不存在.这是"no-practice"规则的两个替代版本,可以完成您尝试做的事情.

The error is telling you that you are attempting to match a slot named "or" in the practice deftemplate and that slot does not exist. Here are two alternate versions of the "no-practice" rule that will accomplish what you are trying to do.:

版本1:

(defrule no-practice "Rules for when practice cannot be held"
    (or ?f <- (practice (practice-is-on-off ON)
                        (number-of-paddlers ?p&:(< ?p 6)))
        ?f <- (practice (practice-is-on-off ON)
                        (number-of-coaches ?c&:(< ?c 6))))
    =>
    (modify ?f (practice-is-on-off OFF)))

请注意,除非您还检查CE中的practice-is-on-off是否为"ON",否则上述规则可能会为practice触发两次.

Note that the rule above may fire twice for a practice unless you also check that practice-is-on-off is "ON" in the CE's.

版本2:

(defrule no-practice "Rules for when practice cannot be held"
    ?f <- (practice (practice-is-on-off ON)
                    (number-of-paddlers ?p) (number-of-coaches ?c))
    (test (or (< ?p 6) (< ?c 6)))
    =>
    (modify ?f (practice-is-on-off OFF)))

这篇关于如何做逻辑或CLIPS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆