최대

2010-03-04 2 views
0

을 찾는 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 none) (utility 0.0) (final 1)) 

:

그러나
(action (name eat) (utility 0.5) (final 1)) 

, 클립으로 평가 발견 - 최종 - 행동 룰이 결코 활성화되지 않음을 나타냅니다. 왜 이런거야? 어떻게 일련의 사실들을 반복하고 최소/최대 슬롯 값을 가진 것을 찾으십니까?

답변

1

규칙에 몇 가지 오류가 있습니다.

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

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

중간 계산 복수 규칙 발생 저장 요구하지 않는 다른 방법이있다 : 여기서, 수정 된 버전이다

관련 문제