问题描述
我的代码有一个问题,就是在给定的田间情况下推荐一种除草剂和它的适当施用率。
(deftemplate plant
(multislot weed)
(multislot crop))
(deftemplate Herbicide
(slot orgmatter)
(slot sencor)
(slot lasso)
(slot bicep))
(deffacts p
(plant (weed B) (crop C S))
(plant (weed B G) (crop C S))
(plant (weed B G) (crop C)))
(deffacts H
(Herbicide (orgmatter 1) (sencor 0.0) (lasso 2.0) (bicep 1.5))
(Herbicide (orgmatter 2) (sencor 0.75) (lasso 1.0) (bicep 2.5))
(Herbicide (orgmatter 3) (sencor 0.75) (lasso 0.5) (bicep 3.0)))
(defrule read-input
=>
(printout t "what is type of crop? (C:Corn,S:Soyabeans): ")
(assert (crop(read)))
(printout t "what is type of weed? (B:broadleaf,G:gress): ")
(assert (weed(read)))
(printout t "what is the organic matter? (1:<2%,2: 2-4%,3: >4%: ")
(assert (orgmatter(read))))
(defrule check-input
(crop ?crop)
(weed ?weed)
(orgmatter ? orgmatter)
(plant (weed $?weed1) (crop $?crop1))
(Herbicide (orgmatter ?orgmatter1) (sencor ?sencor1) (lasso ?lasso1)(bicep ?bicep1))
(test (member$ ?crop ?crop1))
(test (member$ ?weed ?weed1))
(test (= orgmatter ?orgmatter1))
=>
(printout t "you can use" ?sencor1 " pt/ac of sencor" crlf)
(printout t "you can use" ?lasso1 " pt/ac of lasso" crlf)
(printout t "you can use" ?bicep1 " pt/ac of bicep" crlf)))
错误如下: Function = expected argument#1 to be of type integer or float
解决方法
您的代码末尾有一个额外的 )
。
在 defrule check-input
中,您有一个测试:
(test (= orgmatter ?orgmatter1))
这是将 SYMBOL orgmatter
与变量 ?orgmatter1
进行比较。 =
测试仅适用于数字。如果要比较 SYMBOL 或 STRING,则需要使用 eq
函数。
(test (eq orgmatter ?orgmatter1))
尽管如此,如果您不在其他任何地方使用 ?orgmatter1
,进行文字匹配比测试更有效。
(Herbicide (orgmatter orgmatter)
(sencor ?sencor1)
(lasso ?lasso1)
(bicep ?bicep1))