Мне нужна функция, которая будет искать максимальное значение только фактов, которые удовлетворяют моим условиям.Найти максимум фактов в клипах УДОВЛЕТВОРЕНИЕ СОСТОЯНИЯ
(deftemplate tax
(field det (type SYMBOL))
(field oper (type INTEGER))
(field machine (type INTEGER))
(field time (type INTEGER))
)
(deffacts tax
(tax (det A) (oper 1) (machine 1) (time 10))
(tax (det A) (oper 2) (machine 2) (time 5))
(tax (det B) (oper 1) (machine 1) (time 8))
(tax (det B) (oper 2) (machine 5) (time 4))
(tax (det C) (oper 1) (machine 4) (time 10))
(tax (det C) (oper 2) (machine 2) (time 5))
(tax (det D) (oper 1) (machine 3) (time 6))
(tax (det D) (oper 2) (machine 2) (time 5))
(tax (det E) (oper 1) (machine 1) (time 7))
)
(deffunction my-predicate (?fact1 ?fact2)
(< (fact-slot-value ?fact1 time) (fact-slot-value ?fact2 time)))
(deffunction find-max (?template ?predicate)
(bind ?max FALSE)
(do-for-all-facts ((?f ?template)) TRUE
(test (eq oper 2)) ; It's my conditions. This may be something else.
(if (or (not ?max) (funcall ?predicate ?f ?max))
then
(bind ?max ?f)))
(return ?max))
(defrule find-max
=>
(bind ?tax (find-max tax my-predicate))
(if ?tax
then
(printout t "Fact " (fact-slot-value ?tax machine) " is the maximum" crlf)))
Но я получаю ошибку в функции find-max и rule find-max.
Большое спасибо. – aleator