2016-12-18 51 views
0

我卡在這裏這個剪輯項目。我真的不知道如何解決我的問題。任何幫助? this is the project新增到剪輯和不知道如何處理這個基本項目

這裏是我的代碼:

 CLIPS> (assert (saving 30000)) 
<Fact-1> 
CLIPS> (assert (income 50000)) 
<Fact-2> 
CLIPS> (assert (job steady)) 
<Fact-3> 
CLIPS> (assert (expenses 10000)) 
<Fact-4> 
CLIPS> (defglobal ?*s* = 30000) 
CLIPS> (defglobal ?*i* = 50000) 
CLIPS> (defglobal ?*e* = 10000) 
CLIPS> (defglobal ?*x* = 0.5) 
CLIPS> (defrule rule1 
    (test (> ?*s* (* ?*x* ?*i*))) 
    => 
    (assert (savingst good))) 
CLIPS> (defrule rule2 
(job steady) 
(test(> ?*i* ?*e*)) 
=> (assert (incomest good)) 
) 
CLIPS> (defrule rule3 
(and (savingst good)(incomest good)) 
=> 
(printout t "Advise is invest money in stocks" crlf) 
(assert (investment ok)) 
) 
CLIPS> (run) 
Advise is invest money in stocks 
CLIPS> (bsave "C:/Users/Home/Desktop/pro") 
TRUE 
CLIPS> (save file.clp) 

首先我不知道我應該怎麼導出* .clp文件。但我做到了,如上所示。當我加載這個文件然後運行它時,它只運行rule1。 有沒有人可以幫助我?

回答

0

如果打開file.clp,您會看到assert語句不存在。 save函數只保存結構(例如defrule,defglobal,deftemplate,...),而不是函數/命令。使用deffacts構建以表明應使用(復位)命令每次斷言事實:

(deffacts initial 
    (saving 30000) 
    (income 50000) 
    (job steady) 
    (expenses 10000)) 

您不必輸入您的結構在CLIPS命令提示符,然後保存。只需使用文本編輯器(一個單獨的純文本編輯器或CLIPS Windows和Mac OS IDE附帶的文本編輯器)。這使得創建/複製/編輯結構更容易。然後可以使用命令提示符主要用於執行/調試命令。

這裏是你的問題的一個更好的辦法:

CLIPS> 
(deftemplate client 
    (slot name) 
    (slot income (default 0)) 
    (slot savings (default 0)) 
    (slot job (allowed-values steady part-time unemployed unknown)) 
    (slot expenses (default 0))) 
CLIPS> 
(deftemplate analysis 
    (slot client) 
    (slot attribute) 
    (slot value)) 
CLIPS>   
(deffacts clients 
    (client (name "John Doe") 
      (income 50000) 
      (savings 30000) 
      (job steady))) 
CLIPS>    
(defrule advise-stock-investment 
    (analysis (client ?client) 
      (attribute income) 
      (value good)) 
    (analysis (client ?client) 
      (attribute savings) 
      (value good)) 
    => 
    (assert (analysis (client ?client) 
        (attribute advice) 
        (value "invest money in stocks")))) 
CLIPS> 
(defrule good-saver 
    (client (name ?client) 
      (savings ?savings) 
      (income ?income)) 
    (test (> ?savings (* 0.5 ?income))) 
    => 
    (assert (analysis (client ?client) 
        (attribute savings) 
        (value good)))) 
CLIPS>    
(defrule good-income 
    (client (name ?client) 
      (job ?status) 
      (income ?income) 
      (expenses ?expenses)) 
    (test (or (eq ?status steady) 
      (> ?income ?expenses))) 
    => 
    (assert (analysis (client ?client) 
        (attribute income) 
        (value good)))) 
CLIPS>      
(defrule print-advice 
    (analysis (client ?client) 
      (attribute advice) 
      (value ?text)) 
    => 
    (printout t ?client " should " ?text "." crlf)) 
CLIPS> (watch rules) 
CLIPS> (reset) 
CLIPS> (run) 
FIRE 1 good-saver: f-1 
FIRE 2 good-income: f-1 
FIRE 3 advise-stock-investment: f-3,f-2 
FIRE 4 print-advice: f-4 
John Doe should invest money in stocks. 
CLIPS> 
+0

太謝謝你了:)這是完美的。 – shaaidaa

+0

我用這個代碼加我的事實: 'CLIPS>(defrule insertFacts =>(斷言(工作穩步)) (斷言(收入50000)) (斷言(節省30000)) (斷言(費用10000) ))' 但你的邏輯更合理。 – shaaidaa

相關問題