2017-06-15 4 views
0

Existe-t-il une possibilité de faire correspondre chaque multislot dans CLIPS à d'autres faits? J'ai une règle à court exemple:CLIPS: correspondance multislot si toutes les valeurs correspondent à d'autres faits

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

actions est un cond-Multifield et je veux chaque valeur pour correspondre contre un fait qui correspond à la deuxième ligne. Évidemment, je dois correspondre au membre $, mais je ne sais pas comment faire correspondre chaque membre à un fait différent dans ma base factuelle. Est-il possible de faire cela? Une courte série de faits complets qui correspondent ressemblerait à ceci:

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

Mon ancienne solution était de supprimer id de tous les champs à l'achèvement de l'action, mais en raison d'un autre problème que je ne peux plus

Répondre

1

utilisation le premier élément conditionnel:

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>