0

更新的代码:在哪里添加检查?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。但是,当我加载模板时,它会抛出一个错误说

[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

这就是我所拥有的:提前感谢您的任何见解。谢谢

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

1 回答 1

0

该错误告诉您您正在尝试匹配practicedeftemplate 中名为“或”的插槽并且该插槽不存在。以下是“禁止练习”规则的两个替代版本,可以完成您尝试做的事情:

版本 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)))

请注意,上面的规则可能会为 a 触发两次,practice除非您还检查practice-is-on-off了 CE 中的“ON”。

版本 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)))
于 2013-04-25T21:34:40.080 回答