1

我已经下载了一个为 eclipse 和 FuzzyJ Toolkit 安装的 Jess 插件。现在我正在尝试运行以下简单代码:

(import nrc.fuzzy.*)

(bind ?temperature (new FuzzyVariable "temperature" 0 100 "°C"))
(bind ?pressure (new FuzzyVariable "pressure" 0.1 50 "MPa"))

(?temperature addTerm "cold" (new RightLinearFuzzySet 6 20))
(?temperature addTerm "warm" (new TrapezoidFuzzySet 15 20 25 30))
(?temperature addTerm "hot"  (new LeftLinearFuzzySet 25 50))

(?pressure addTerm "low"    (new RightLinearFuzzySet 0.9 5))
(?pressure addTerm "medium" (new TrapezoidFuzzySet 2 8 14 28))
(?pressure addTerm "high"  (new LeftLinearFuzzySet 22 50))

(deffunction about (?number ?fuzzyVariable)
    (bind ?delta (- (?fuzzyVariable getMaxUOD) (?fuzzyVariable getMinUOD)))
    (new FuzzyValue ?fuzzyVariable 
        (new TriangleFuzzySet 
            (- ?number (* ?delta 0.01))
        ?number   
            (+ ?number (* ?delta 0.01)) 
        )
    )
)

; (printout t ((about 34 ?temperature) plotFuzzyValue "*"))

(assert (Temperature (about 43 ?temperature)))

(defrule trivial-rule
    (Temperature ?t & :(fuzzy-match ?t "hot"))
    =>
    (assert (Pressure (new FuzzyValue ?pressure "low")))    
)

(defrule printing
    (Pressure ?p)
    =>
    (printout t (?p plotFuzzyValue "*"))    
)


(run)

但是,当我运行代码时,我只得到一个异常,说函数fuzzy-match 没有定义。我已经将主类更改为 FuzzyMain。我还尝试运行 FuzzyConsole 并从那里加载代码,以及尝试使用 addPackage 将 FuzzyFunctions 添加到引擎,但无论如何我仍然会收到该错误。

4

1 回答 1

2

尽管Jess in Action很遗憾没有告诉您这一点,但您必须显式加载模糊函数,即使使用FuzzyMain. 在您的 Jess 代码顶部附近添加以下行,它将按需要工作:

(load-package nrc.fuzzy.jess.FuzzyFunctions)
于 2013-09-23T21:25:49.663 回答