CLIPS:如果所有值都匹配不同的其他事实,则匹配多槽

CLIPS: Match multislot if all values match different other facts

是否有可能将 CLIPS 中的每个多时隙与其他不同的事实相匹配?我有一个简短的示例规则:

(stn-action (id ?id) (name lock-position) (state pending)
            (cond-actions) (opts ?r ?action ?to))
(stn-action (id ?other-id) (name lock-position) (state running|finished)
            (opts ?r ?action ?other-to&:~(eq ?other-to ?to)))

cond-actions 是一个多字段,我希望每个值都匹配与第二行匹配的事实。显然我需要与 member$ 匹配,但我不知道如何将每个成员与我的事实库中的不同事实进行匹配。有没有可能这样做?一小部分匹配的完整事实如下所示:

(stn-action (id 3) (name lock-position) (state pending) (duration 0)
            (cond-actions 1 2) (opts R-1 PICK-CC C-CS2-I) (active-robot R-1) (sync-id 1000003))
(stn-action (id 2) (name lock-position) (state running) (duration 0)
            (cond-actions 1) (opts R-1 GET-PROD C-CS2-O) (active-robot R-1) (sync-id 1000002))
(stn-action (id 1) (name lock-position) (state finished) (duration 0)
            (cond-actions) (opts R-1 GET-PROD C-BS-O) (active-robot R-1) (sync-id 1000001))

我以前的解决方案是在操作完成后从所有字段中删除 ID,但由于另一个问题我不能再这样做了

使用forall条件元素:

CLIPS> 
(deftemplate stn-action
   (slot id)
   (slot name)
   (slot state)
   (slot duration)
   (multislot cond-actions)
   (multislot opts)
   (slot active-robot)
   (slot sync-id))
CLIPS>    
(deffacts initial
   ;; id 3 will not match because PICK-CC doesn't match GET-PROD
   (stn-action (id 3) (name lock-position) (state pending) (duration 0)
               (cond-actions 1 2) (opts R-1 PICK-CC C-CS2-I) 
               (active-robot R-1) (sync-id 1000003))
   (stn-action (id 2) (name lock-position) (state running) (duration 0)
               (cond-actions 1) (opts R-1 GET-PROD C-CS2-O) 
               (active-robot R-1) (sync-id 1000002))
   (stn-action (id 1) (name lock-position) (state finished) (duration 0)
               (cond-actions) (opts R-1 GET-PROD C-BS-O) 
               (active-robot R-1) (sync-id 1000001))
   ;; id 6 will match
   (stn-action (id 6) (name lock-position) (state pending) (duration 0)
               (cond-actions 5 4) (opts R-1 PICK-CC C-CS2-I) 
               (active-robot R-1) (sync-id 1000003))
   (stn-action (id 5) (name lock-position) (state running) (duration 0)
               (cond-actions 4) (opts R-1 PICK-CC C-CS2-O) 
               (active-robot R-1) (sync-id 1000002))
   (stn-action (id 4) (name lock-position) (state finished) (duration 0)
               (cond-actions) (opts R-1 PICK-CC C-BS-O) 
               (active-robot R-1) (sync-id 1000001)))
CLIPS> 

(defrule match
   (stn-action (id ?id) 
               (name lock-position) 
               (state pending)
               (opts ?r ?action ?to))
   (forall (stn-action (id ?id) 
                       (cond-actions $? ?other-id $?))
           (stn-action (id ?other-id) 
                       (name lock-position) 
                       (state running | finished)
                       (opts ?r ?action ?other-to&~?to)))
   =>
   (printout t "id " ?id " has all cond-actions satisfied" crlf))
CLIPS> (reset)
CLIPS> (run)
id 6 has all cond-actions satisfied
CLIPS>