我被这个剪辑项目困住了。我真的不知道如何解决我的问题。有帮助吗?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。有谁能帮我吗?
发布于 2016-12-19 07:50:27
如果打开file.clp,您将看到assert语句不存在。save函数仅保存构造(如defrule、defglobal、deftemplate等),而不保存函数/命令。使用deffacts结构来指示每次使用(重置)命令时应断言的事实:
(deffacts initial
(saving 30000)
(income 50000)
(job steady)
(expenses 10000))不必在CLIPS命令提示下输入构件,然后保存它们。只需使用文本编辑器(可以是单独的纯文本编辑器,也可以是剪辑Windows和Mac中包含的编辑器)。这使得创建/复制/编辑构造变得更容易。然后,您可以将命令提示符主要用于执行/调试命令。
这里有一个更好的方法来解决你的问题:
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> https://stackoverflow.com/questions/41209477
复制相似问题