Hello, everyone
I meet a very strange problem when I changed the slot value of a fact. I know it's 
time-consuming to read the source code. But I want to explain my problem clearly. I am 
a graduate student. This is part of my thesis. I am eager for help. 
 I defined a class beanTest which supports PropertyChangeSupport so that the value of 
its property can change dynamically. I define a property of FuzzyValue type in Fuzzy 
Java Toolkit which can be found in Contributions at 
http://herzberg.ca.sandia.gov/jess/. But when I changed its value, it didn't change 
dynamically.  Here is the source code.


import java.beans.*;
import nrc.fuzzy.*;
import jess.*;

public class beanTest {
  private FuzzyValue temperature;
  private String p1;
  private FuzzyVariable temp;
  public beanTest(String str) {
    try{
    // define our temperature fuzzy variable with terms hot,
    // cold, very hot and medium
      temp = new FuzzyVariable("temperature", 5.0, 65.0, "Degrees C");
      temp.addTerm("cold", new TrapezoidFuzzySet(5.0, 5.05, 10.0, 35.0));
      temp.addTerm("ok", new PIFuzzySet(36.0, 3.5));
      temp.addTerm("hot", new SFuzzySet(37.0, 60.0));
      p1 = "first";
      temperature = new FuzzyValue(temp, str);
    }
    catch (FuzzyException fe){
      System.err.println("Error initializing fuzzy variables/rules\n" + fe);
      System.exit(100);
    }
  }
  public void setp1val(String s){
    setP1(s);
  }
  public void setTempVal(String s){
    try{
      FuzzyValue fv = new FuzzyValue(temp, s);
      setTemperature(fv);
    }
    catch (FuzzyException fe){
      System.err.println("Error initializing fuzzy variables/rules\n" + fe);
      System.exit(100);
    }
  }

  public String getP1() {
    return p1;
  }
  public void setP1(String newP1) {
    String  oldP1 = p1;
    p1 = newP1;
    propertyChangeListeners.firePropertyChange("p1", oldP1, newP1);
  }
  public void setTemperature(FuzzyValue newTemperature) {
    FuzzyValue  oldTemperature = temperature;
    temperature = newTemperature;
    propertyChangeListeners.firePropertyChange("temperature", oldTemperature, 
newTemperature);
  }
  public FuzzyValue getTemperature() {
    return temperature;
  }

  private transient PropertyChangeSupport propertyChangeListeners = new 
PropertyChangeSupport(this);
  public synchronized void removePropertyChangeListener(PropertyChangeListener l) {
    propertyChangeListeners.removePropertyChangeListener(l);
  }
  public synchronized void addPropertyChangeListener(PropertyChangeListener l) {
    propertyChangeListeners.addPropertyChangeListener(l);
  }
}

In file beanTest.clp, type the following code:
(defclass bt beanTest)
(bind ?bt (new beanTest "hot"))
(definstance bt ?bt)

(defrule setTemperatureVal 
 ; to change the value of temperature in beanTest
(bt (OBJECT ?o))
=>
(?o setTempVal "ok"))

(defrule showTemperatureVal
; to show the value of temperature in two different ways
(declare (salience -100))
(bt (temperature ?t)(OBJECT ?o))
=>
(bind ?v (?o getTemperature))
(printout t (?t plotFuzzyValue "*") crlf)
(printout t (?v plotFuzzyValue "*") crlf))



Then in Jess Commandline,
Jess> (watch all)
TRUE
Jess> (batch "beanTest.clp")
 ==> f-0 (bt (class <External-Address:java.lang.Class>) (p1 "first") (temperatur
e <External-Address:nrc.fuzzy.FuzzyValue>) (OBJECT <External-Address:beanTest>))

==> Activation: setTemperatureVal :  f-0
setTemperatureVal: +1+1+t
==> Activation: showTemperatureVal :  f-0
showTemperatureVal: =1=1+t
TRUE
Jess> (run 1)
FIRE 1 setTemperatureVal f-0
1
Jess> (run 1)
FIRE 1 showTemperatureVal f-0
Fuzzy Value: temperature
Linguistic Value: hot (*)

 1.00                                            *******
 0.95                                           *
 0.90                                          *
 0.85                                         *
 0.80                                        *
 0.75                                       *
 0.70
 0.65                                      *
 0.60
 0.55                                     *
 0.50                                    *
 0.45
 0.40                                   *
 0.35
 0.30                                  *
 0.25                                 *
 0.20
 0.15                                *
 0.10                               *
 0.05                             **
 0.00*****************************
     |----|----|----|----|----|----|----|----|----|----|
    5.00     17.00     29.00     41.00     53.00     65.00
Fuzzy Value: temperature
Linguistic Value: ok (*)

 1.00                          *
 0.95                          *
 0.90
 0.85
 0.80                         *
 0.75
 0.70
 0.65                           *
 0.60
 0.55
 0.50
 0.45
 0.40
 0.35
 0.30                        *
 0.25
 0.20
 0.15                            *
 0.10
 0.05
 0.00************************     **********************
     |----|----|----|----|----|----|----|----|----|----|
    5.00     17.00     29.00     41.00     53.00     65.00
1
Jess>
As you can see, the value of slot temperature is not changed dynamically. It still 
keep to its previous value while the temperature value in object has already changed. 
It still keep to its previous value while the temperature value in object has already 
changed. It has already taken me several days to solve it, but no solution comes. 
Any help will be  greatly appreciated. 
Ivy





-----------------------------------------
�ҵ��������ҵ�����
http://name.etang.com/
���ƶ��ţ���������ʱ�й���
http://sms.etang.com
��׬200Ԫ�����ѵľ���
http://ecard.etang.com/progt/index.asp?s1=1&s2=1
ְҵ��˼¼
http://topic.etang.com/job/index.htm        

---------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the
list (use your own address!) List problems? Notify [EMAIL PROTECTED]
---------------------------------------------------------------------

Reply via email to