2017-06-15 46 views
0

是否有任何可能将CLIPS中的每个多插槽与其他不同事实匹配?我有一个简短的示例规则: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

使用所有条件元素:

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> 
相关问题