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

时间:2017-06-15 19:27:41

标签: matching clips expert-system

是否有可能将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是一个多字段,我希望每个值与匹配第二行的事实匹配。显然我需要与成员$匹配,但我不知道如何将每个成员与我的事实基础中的不同事实相匹配。有没有可能这样做?匹配的一小部分完整事实将如下所示:

(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,但由于不同的问题,我不能再这样做了

1 个答案:

答案 0 :(得分:1)

使用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>