expert system - CLIPS infinite facts -


i developing expert system make admission decisions using pyclips. however, code kept generating 'out of memory' errors. think have isolated problem. wrong clips file. hoping can see i'm doing wrong here. simple version of code....i simplified in order debug it: here's template, , sake of argument, there's 1 rule: if transcript received, app-complete attribute marked true.

; template application facts (deftemplate application "structure of application" (slot app-id (type integer)) (slot app-complete (type symbol)) (slot transcript-received (type symbol))  )   (defrule complete "rule app completeness"  ?f <- (application         (transcript-received yes)         ) =>     (modify ?f         (app-complete true)     ) ) ; end. 

so when (assert (application (app-id 123) (transcript-received yes))) then, fact added. when click run though....the window in clips starts getting overloaded thousands of facts...the app-complete attribute looks marked true, however, facts keep looping , looping, nonstop. when gets many facts, i'm talking 100k or something...then clips quits....any idea i'm doing wrong in here? syntax messed somehow? intentions have sqlite db able read 'facts' db system able make decisions....but can't past this! in advance feedback!!!!

the important point remember when modify deftemplate fact, fact retracted , new (modified) fact asserted. rule matching modified fact, again modified , matched, etc., resulting in infinite loop. if watch facts , activations when run code, see this:

<== f-1     (application (app-id 123) (app-complete nil) (transcript-received yes)) ==> f-2     (application (app-id 123) (app-complete true) (transcript-received yes)) ==> activation 0      complete: f-2 <== f-2     (application (app-id 123) (app-complete true) (transcript-received yes)) ==> f-3     (application (app-id 123) (app-complete true) (transcript-received yes)) ==> activation 0      complete: f-3 <== f-3     (application (app-id 123) (app-complete true) (transcript-received yes)) ==> f-4     (application (app-id 123) (app-complete true) (transcript-received yes)) ==> activation 0      complete: f-4 (etc.) 

you can prevent matching applications aren't complete. here modified version of code adds default false value app-complete slot , matches applications not complete:

(deftemplate application "structure of application"   (slot app-id (type integer))   (slot app-complete (type symbol) (default false))   (slot transcript-received (type symbol)))  (defrule complete "rule app completeness"   ?f <- (application (transcript-received yes) (app-complete false))   =>   (modify ?f (app-complete true))) 

now, if watch facts , activations, should see following when assert fact , run:

clips> (assert (application (app-id 123) (transcript-received yes))) ==> f-0     (application (app-id 123) (app-complete false) (transcript-received yes)) ==> activation 0      complete: f-0 <fact-0> clips> (run) <== f-0     (application (app-id 123) (app-complete false) (transcript-received yes)) ==> f-1     (application (app-id 123) (app-complete true) (transcript-received yes)) clips> 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -