【问题标题】:Delete one of more equal values in multislot clips删除多槽剪辑中的多个相等值之一
【发布时间】:2016-06-23 08:41:04
【问题描述】:

我在 CLIPS 工作,我有这个 deftemplate:

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

一个可能的 K-agent 事实可能是:

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

我想应用这条规则:

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

并获得这个:

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

但这是我的规则的效果:

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

有什么方法可以只删除多槽中的一个相同值?谢谢

【问题讨论】:

    标签: clips


    【解决方案1】:

    这是一种方法:

    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>
    

    还有一个:

    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> 
    

    【讨论】:

    • 感谢您的回答。第二个选项适合我的情况(因为“内容的内容”总是不同的),但不幸的是我的剪辑版本不支持 foreach 构造......
    猜你喜欢
    • 2018-05-13
    • 1970-01-01
    • 2017-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-12
    • 2016-05-08
    • 1970-01-01
    相关资源
    最近更新 更多