我试图澄清我对 Clips 专家系统中语义的理解,因此我试图编写一些简单的规则来聚合事实列表以找到具有最高槽值的事实。我使用的比喻是一个简单的代理试图决定它应该吃还是睡。描述代理状态的事实被扩展为潜在的动作,然后一个规则试图找到具有最高效用的最终动作。
这是我的代码:
(clear)
(deftemplate state
(slot name)
(slot level (type NUMBER))
)
(deftemplate action
(slot name)
(slot utility (type NUMBER))
(slot final (type INTEGER) (default 0))
)
(defrule eat-when-hungry ""
(state (name hungry) (level ?level))
=>
(assert (action (name eat) (utility ?level)))
)
(defrule sleep-when-sleepy ""
(state (name sleepy) (level ?level))
=>
(assert (action (name sleep) (utility ?level)))
)
(defrule find-final-action ""
?current_final <- (action (name ?current_final_action) (utility ?
current_final_utility) (final 1))
(action (name ?other_action) (utility ?other_utility) (final 0))
(neq ?current_final_action ?other_action)
(< ?current_final_action ?other_action)
=>
(modify ?current_final (name ?other_action) (utility ?
other_utility))
)
(assert (action (name none) (utility 0.0) (final 1)))
(assert (state (name hungry) (level 0.5)))
(assert (state (name sleepy) (level 0.1)))
(run)
(facts)
运行此之后,我希望最终的操作是:
(action (name eat) (utility 0.5) (final 1))
但是,Clips 将其评估为:
(action (name none) (utility 0.0) (final 1))
表示 find-final-action 规则永远不会激活。为什么是这样?您将如何遍历一组事实并找到具有最小/最大槽值的事实?