在CLIPS Expert系统中汇总事实以找到最大值 [英] Aggregating Facts in the CLIPS Expert System to Find a Maximum

查看:128
本文介绍了在CLIPS Expert系统中汇总事实以找到最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图阐明我对Clips专家系统中语义的理解,所以我试图编写一些简单的规则来汇总事实列表,以找到具有最高插槽值的事实.我使用的隐喻是一个简单的代理,试图确定它应该进食还是入睡.描述座席状态的事实被扩展为潜在的动作,然后一条规则试图找到具有最高效用的最终动作.

I'm trying to clarify my understanding of semantics in the Clips expert system, so I'm trying to write some simple rules to aggregate a list of facts to find the fact with the highest slot value. The metaphor I'm using is that of a simple agent trying to decide whether it should eat or sleep. Facts describing the agent's states are expanded into potential actions, and then a rule tries to find the final action with the highest utility.

这是我的代码:

(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)

运行此命令后,我希望最终的操作是:

After running this, I would expect the final action to be:

(action (name eat) (utility 0.5) (final 1)) 

但是,剪辑将其评估为:

However, Clips evaluates it to:

(action (name none) (utility 0.0) (final 1)) 

表示find-final-action规则永远不会激活.为什么是这样?您将如何遍历一组事实并找到具有最小/最大时隙值的事实?

indicating the find-final-action rule never activates. Why is this? How would you iterate over a group of facts and find the one with the min/max slot value?

推荐答案

您的规则中有几个错误.这是更正的版本:

Your rule had a couple of errors in it. Here is the corrected version:

(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)) 
    (test (neq ?current_final_action ?other_action))
    (test (< ?current_final_utility ?other_utility)) 
    => 
    (modify ?current_final (name ?other_action) (utility ?other_utility)))

另一种不需要存储中间计算和多个规则触发的方法是:

An alternate method which does not require storing intermediate computations and multiple rule firings is this:

(defrule find-final-action-2 "" 
    (declare (salience -10)) ; lower salience to allow all actions to be asserted first
    (action (name ?action) (utility ?utility)) 
    (not (action (utility ?other_utility&:(> ?other_utility ?utility))))
    => 
    (printout t "Final action is " ?action crlf))

这篇关于在CLIPS Expert系统中汇总事实以找到最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆