2016-06-22 5 views
0

ich arbeite in CLIPS, Anzeige habe ich diese deftemplate:in Multi-Slot-Clips eine von mehr gleichen Werten löschen

(deftemplate K-agent (multislot content) (slot free) (slot waste) 

Eine mögliche K-Agent Tatsache sein könnte:

(K-agent (content normal normal) (free 0) (waste no)) 

Ich mag anzuwenden diese Regel:

?k <- (K-agent (content $?cont) (free ?f)) 
=> (modify ?k (content (delete-member$ $?cont normal)) (free =(+ ?f 1))) 

und diese zu erhalten:

(K-agent (content normal) (free 1) (waste no)) 

sondern dies ist die Wirkung meiner Regel:

(K-agent (content) (free 1) (waste no)) 

Gibt es eine Möglichkeit nur einen von den gleichen Werten in einem Multi-Slot zu entfernen? Danke

Antwort

0

Hier ist eine Art und Weise:

CLIPS> (clear) 
CLIPS> 
(deftemplate K-agent 
    (multislot content) 
    (slot free) 
    (slot waste)) 
CLIPS>  
(deffacts start 
    (K-agent (content normal normal) (free 0) (waste no))) 
CLIPS>  
(defrule example 
    ?k <- (K-agent (content $?begin normal $?end) (free ?f)) 
    (test (or (member$ normal ?begin) 
      (member$ normal ?end))) 
    => 
    (modify ?k (content (delete-member$ ?begin normal) 
         normal 
         (delete-member$ ?end normal)) 
      (free =(+ ?f 1)))) 
CLIPS> (reset) 
CLIPS> (run) 
CLIPS> (facts) 
f-0  (initial-fact) 
f-2  (K-agent (content normal) (free 1) (waste no)) 
For a total of 2 facts. 
CLIPS> 

Und ein anderer:

CLIPS> (undefrule example) 
CLIPS> 
(deffunction count$ (?list ?value) 
    (bind ?count 0) 
    (foreach ?l ?list 
     (if (eq ?l ?value) 
     then 
     (bind ?count (+ ?count 1)))) 
    (return ?count)) 
CLIPS> 
(deffunction delete-duplicates$ (?list ?value) 
    (bind ?count (count$ ?list ?value)) 
    (if (<= ?count 1) 
     then 
     (return ?list)) 
    (loop-for-count (- ?count 1) 
     (bind ?pos (member$ ?value ?list)) 
     (bind ?list (delete$ ?list ?pos ?pos))) 
    (return ?list)) 
CLIPS>  
(defrule example 
    ?k <- (K-agent (content $?cont) (free ?f)) 
    (test (> (count$ ?cont normal) 1)) 
    => 
    (modify ?k (content (delete-duplicates$ ?cont normal)) 
      (free =(+ ?f 1)))) 
CLIPS> (reset) 
CLIPS> (run) 
CLIPS> (facts) 
f-0  (initial-fact) 
f-2  (K-agent (content normal) (free 1) (waste no)) 
For a total of 2 facts. 
CLIPS> 
+0

Dank für die Antwort danken. Die zweite Option ist gut für meinen Fall (weil "Inhalt Inhalt" ist immer anders), aber meine Clips-Version unterstützt leider nicht die foreach-Konstrukt ... –

+0

Verwendung Prognose $: (Prognose $ (? L? Liste) .. . –

Verwandte Themen