0
votes

I have a problem with my code that is to recommend a herbicide and an application rate for it as appropriate in a given field situation.

(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)))

The error is the following: Function = expected argument#1 to be of type integer or float

1

1 Answers

0
votes

Your code has an extra ) at the end.

In defrule check-input, you have a test:

(test (= orgmatter ?orgmatter1))

Which is comparing a SYMBOL orgmatter with the variable ?orgmatter1. The = test works only with numerals. If you want to compare SYMBOLs or STRINGs, you need to use the eq function.

(test (eq orgmatter ?orgmatter1))

Nevertheless if you are not using ?orgmatter1 anywhere else, it is more effective to do a literal match rather than a test.

(Herbicide (orgmatter orgmatter) 
           (sencor ?sencor1) 
           (lasso ?lasso1) 
           (bicep ?bicep1))