剪辑:避免连接约束
clips: avoiding connective constraints
假设我们有以下 CLIPS 模板和规则:
;; The queue sequence starts at 0.
;; -1 is a placeholder value to identify a newly inserted element.
;; The idea is to put a newly inserted element at the end of the queue.
(deftemplate queue-element
(slot order (type INTEGER) (default -1))
(deftemplate put-at-the-end
?e1 <- (queue-element (order -1))
?e2 <- (queue-element (order ?o1))
(not (queue-element (order ?o2&:(> ?o2 ?o1))))
=>
(modify ?e1 (order (+ ?o1 + 1))))
有没有办法将 "connective constraint" (> ?o2 ?o1)
移出模式并将其移至类似于 (test (> ?o2 ?o1))
构造的东西?
我们的想法是彻底避免这些内嵌条件。
您可以使用 and 条件元素将多个条件元素放置在 not 条件元素中。
CLIPS>
(deftemplate queue-element
(slot order (type INTEGER) (default -1)))
CLIPS>
(defrule put-at-the-end
?e1 <- (queue-element (order -1))
?e2 <- (queue-element (order ?o1))
(not (and (queue-element (order ?o2))
(test (> ?o2 ?o1))))
=>
(modify ?e1 (order (+ ?o1 1))))
CLIPS>
假设我们有以下 CLIPS 模板和规则:
;; The queue sequence starts at 0.
;; -1 is a placeholder value to identify a newly inserted element.
;; The idea is to put a newly inserted element at the end of the queue.
(deftemplate queue-element
(slot order (type INTEGER) (default -1))
(deftemplate put-at-the-end
?e1 <- (queue-element (order -1))
?e2 <- (queue-element (order ?o1))
(not (queue-element (order ?o2&:(> ?o2 ?o1))))
=>
(modify ?e1 (order (+ ?o1 + 1))))
有没有办法将 "connective constraint" (> ?o2 ?o1)
移出模式并将其移至类似于 (test (> ?o2 ?o1))
构造的东西?
我们的想法是彻底避免这些内嵌条件。
您可以使用 and 条件元素将多个条件元素放置在 not 条件元素中。
CLIPS>
(deftemplate queue-element
(slot order (type INTEGER) (default -1)))
CLIPS>
(defrule put-at-the-end
?e1 <- (queue-element (order -1))
?e2 <- (queue-element (order ?o1))
(not (and (queue-element (order ?o2))
(test (> ?o2 ?o1))))
=>
(modify ?e1 (order (+ ?o1 1))))
CLIPS>