计算剪辑规则右侧的现有事实

发布于 2024-09-16 17:52:20 字数 582 浏览 7 评论 0原文

如何测试 Clips 中规则的 RHS 中是否存在事实?我正在努力 设计一个规则,通过计算存在多少个目标事实来对当前状态进行“评分”。很明显如何在 LHS 中测试事实,但我找不到如何在 RHS 中进行等效操作。

我想做这样的事情,尽管这不是有效的 Clips 代码:

(defrule score-state ""
    ?score <- (score (value ?value))
    =>
    (modify ?score (value (+ (exists (goal-1)) (exists (goal-2)) (exists (goal-3))))))

这样,如果没有任何目标状态存在,那么就会存在事实(分数(值 0))。相反,如果所有目标状态都存在,则事实(分数(值3))就会存在。

参考手册提到了函数fact-existp,但这似乎需要它传递一个事实地址。我尝试像 (fact-existp (goal-1)) 一样使用它,但 Clips 给了我一个语法错误。

How do you test for fact existence in the RHS of rules in Clips? I'm trying to
design a rule that will "score" the current state by counting how many goal facts exist. It's obvious how to test for facts in the LHS, but I can't find how to do the equivalent in the RHS.

I want to do something like this, albeit this isn't valid Clips code:

(defrule score-state ""
    ?score <- (score (value ?value))
    =>
    (modify ?score (value (+ (exists (goal-1)) (exists (goal-2)) (exists (goal-3))))))

So that if none of the goal states exist, then there would exist the fact (score (value 0)). Conversely, if all the goal states existed, then there would exist the fact (score (value 3)).

The reference manual mentions the function fact-existp, but this seems to require it's passed a fact address. I tried using it like (fact-existp (goal-1)), but Clips gives me a syntax error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月野兔 2024-09-23 17:52:20
(deftemplate score
   (slot value))

(deftemplate goal-1)

(deftemplate goal-2)

(deftemplate goal-3)

(deffacts start
   (score (value undefined))
   (goal-1)
   (goal-3))

(deffunction ecount (?g)
   (if (any-factp ((?f ?g)) TRUE)
      then (return 1)
      else (return 0)))

(defrule score-state ""
    ?score <- (score (value undefined))
    =>
    (modify ?score (value (+ (ecount goal-1) (ecount goal-2) (ecount goal-3)))))
(deftemplate score
   (slot value))

(deftemplate goal-1)

(deftemplate goal-2)

(deftemplate goal-3)

(deffacts start
   (score (value undefined))
   (goal-1)
   (goal-3))

(deffunction ecount (?g)
   (if (any-factp ((?f ?g)) TRUE)
      then (return 1)
      else (return 0)))

(defrule score-state ""
    ?score <- (score (value undefined))
    =>
    (modify ?score (value (+ (ecount goal-1) (ecount goal-2) (ecount goal-3)))))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文