最大を検索するクリップエキスパートシステムでのファクトを集計
-
24-09-2019 - |
質問
私はクリップエキスパートシステムにおける意味論の私の理解を明確にしようとしているので、私は最高のスロット値との事実を見つけるために、事実のリストを集約するためにいくつかの簡単なルールを記述しようとしています。私が使用しているメタファーは、単純な、それは食べるべきかどうかを判断しようとしている薬や睡眠のことです。エージェントの状態を記述した事実は、潜在的なアクションに展開され、その後、ルールが最高のユーティリティを使用して、最終的なアクションを見つけようとします。
これは私のコードです:
(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))
はしかし、クリップにそれを評価します
(action (name none) (utility 0.0) (final 1))
を示す検索-最終アクションルールがアクティブにすることはありません。どうしてこれなの?どのように?事実のグループを反復処理し、最小/最大スロット値を持つものを見つけるだろう。
解決
あなたのルールは、それにエラーのカップルを持っていました。ここでは修正されたバージョンがあります:
(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)))
は、中間の計算や複数のルールの発火を格納する必要がない別の方法は、本であります
(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))
所属していません StackOverflow