簡體   English   中英

剪輯規則RHS中的現有事實計數

[英]Counting Existing Facts in the RHS of Clips Rules

您如何測試Clips中規則的RHS中的事實存在? 我正在嘗試設計一個規則,通過計算存在多少目標事實來“得分”當前狀態。 顯而易見,如何在LHS中測試事實,但是我找不到在RHS中如何做同樣的事情。

我想做這樣的事情,盡管這不是有效的剪輯代碼:

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

因此,如果不存在任何目標狀態,則將存在事實(得分(值0))。 相反,如果所有目標狀態都存在,則將存在事實(得分(值3))。

參考手冊中提到了事實事實功能,但這似乎需要傳遞事實地址。 我試過像(fact-existp(goal-1))一樣使用它,但是Clips給了我一個語法錯誤。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM