2013-05-23 5 views
0

결국 프로그램이 백분율 확실성을 인쇄한다고 가정하면 프로그램이 중단됩니다. 무엇이 잘못 되었을까요? 제거 할 때 백분율이 아닌 데이터가 인쇄되므로 백분율 계산 규칙이어야합니다.CLIPS 간단한 백분율 오류

(defmodule PRINT-RESULTS (import MAIN ?ALL)) 

(defrule PRINT-RESULTS::calculate-percentages 
?var <- (religion (name ?religion) (aspects $?aspects) (certainty ?certainty)) 
=> 
(modify ?var (certainty =(*(/ ?certainty 700)100)))) 

(defrule PRINT-RESULTS::print-religion 
?rel <- (religion (name ?religion) (aspects $?aspects) (certainty ?certainty)) 
=> 
(retract ?rel) 
(printout t crlf RELIGION: "    " 
       ?religion crlf ASPECTS: "    " 
       ?aspects crlf CERTAINTY: "    " 
       ?certainty crlf)) 

답변

0

무한 루프에 걸린 것처럼 보입니다. deftemplate 인스턴스를 수정하면 수정 된 인스턴스로 원본이 대체되며 상황에 따라 계속 calculate-percentages과 일치하게됩니다. 따라서이 무한 규칙 일치 루프를 막아야합니다.

모듈을 사용하고 있으므로 PRINT-RESULTS 이외의 모듈에서 확실성을 계산하는 것이 좋습니다 (다른 모듈은 UPDATE-CERTAINTY로 참조). 그런 다음 calculate-percentages 규칙의 then 부분에 UPDATE-CERTAINTY 모듈을 추가하여 규칙이 수정 된 사실과 일치하지 않도록 할 수 있습니다.

0

다른 방법으로, 당신은 계산이 (이 예에서는 상태 슬롯)는 사실에서 수행되었는지 여부를 표시하기 위해 귀하의 사실에 추가 슬롯을 사용할 수 있습니다

(defrule PRINT-RESULTS::calculate-percentages 
?var <- (religion (name ?religion) (status ~final) (aspects $?aspects) (certainty ?certainty)) 
=> 
(modify ?var (status final) (certainty =(*(/ ?certainty 700)100))))