使用FuzzyJess:未定义模糊匹配

时间:2013-09-22 21:09:02

标签: eclipse fuzzy jess

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

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

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

1 个答案:

答案 0 :(得分:2)

虽然 Jess in Action 但遗憾的是没有告诉你这一点,你必须明确加载模糊函数,即使用FuzzyMain启动也是如此。在Jess代码顶部附近添加以下行,它将按预期工作:

(load-package nrc.fuzzy.jess.FuzzyFunctions)