I added a call to "(facts)" in the Jess code right before run-until- halt, and I see:

From Person: name My Coyne
From Person: age 0
Finish initialize
in BeanSupport, add property change
in PersonStageReasoner.run() prev_age=0 age now=12
f-0 (MAIN::PersonStageReasoner (age 12) (class <Java- Object:java.lang.Class>) (OBJECT <Java- Object:person.PersonStageReasoner>))
For a total of 1 facts in module MAIN.
in PersonStageReasoner.run() prev_age=12 age now=24
in PersonStageReasoner.run() prev_age=24 age now=144

Look at the new line in the output, starting with "f-0 (MAIN::PersonSta..." I highlighted "(age 12)" in red. Basically what's happening is that the instant you create your PersonStageReasoner, it increments the age to 12. By the time Jess sees it, it's already 12, and the rule (which matches ages below 12) never fires. If you change PersonStageReasoner.run() to put the sleep at the beginning rather than the end, you'll find the program works as you expect! Threads are tricky things...




On Jul 1, 2010, at 1:26 PM, [email protected] wrote:

BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; } Attached please find all the codes in java and Jess rule. This is the first time I use the forum and not sure if the attachements will going through. Please let me know if I should cut-and-paste the codes, directly here.




My Coyne
[email protected]
(cel): 301-399-6351

On Thu 01/07/10 1:14 PM , "Ernest Friedman-Hill" [email protected] sent:

If the problem is something subtle, then we're not going to be able to
help you unless you show us the real code, because most likely the
problem is in something you're not showing here. As far as this goes,
it looks more or less OK, but as they say, "the devil is in the
details."

On Jul 1, 2010, at 12:28 PM, [email protected] wrote:

> BODY { font-family:Arial, Helvetica, sans-serif;font-size:12px; }
> Please help, my *very simple* rule in JEss is not fired. I follow
> the HVAC example, chapter 14 of the book Jess in Action. But my
> simple rule never fired.
>
> Example rule: if a person with age < 24 months then it is a toddler.
>
> The exercise is written in Java with the rule in Jess
>
> IDE environement: Eclipse
>
> Java class
>
> public class Person {
>
> private String m_name;
>
> private int m_age;
>
> // set and get funciton
>
> // in order to test out the different rules, a method is
> writen to increase the age of an object.
>
> public void increaseAge() {
>
> }
>
> }
>
> // same code from the Jess Action book, chater 14. The class is to
> add / remove property change listener and
>
> public abstract class BeanSupport {
>
> }
>
> // class PersonStageReasoner. This class will start a thread with a
> forever-loop to change a person age
>
> public class PersonStageReasoner extends BeanSupport implements
> Runnable {
>
> // constructor that will instantiage a person object and start
> a thread
>
> public PersonStageReasoner (Person p) {
>
> m_person = new Person(p);
>
> new Thread(this).start();
>
> }
>
> public int getAge() {return m_person.getAge()); }
>
> public void run() {
>
> while (true) {
>
> prev_age := m_person.getAge();
>
> m_person.increaseAge();
>
> int age_now = m_person.getAge()
>
> m_pcs.firedPropertyChange("age", prev_age, age);
>
> try { Thread.sleep (1000); }
>
> catch (InterruptedException ie) { return; }
>
> } // end while true
>
> }
>
>
> }
>
>
> Jess:
>
> !! Add rules
>
>
>
> (bind?p(new person.Person"firstname lastname" 0))
>
>
>
>
> (
>
>
> defclassPersonStageReasoner person.PersonStageReasoner)
>
>
> (definstancePersonStageReasoner
>
>
>
> (new person.PersonStageReasoner?p))
>
>
>
>
> (defruleperson-stage-todler
>
>
>
>
> (PersonStageReasoner(age?a&:(< ?a 12)))
>
>
>
>
> =>
>
> (printout t "toddler" crlf)
>
> (halt))
>
>
>
>
>
> (run-until-halt)
>
> (exit)
>
>
>
> I know that defclass, definstance are fine, because the Java code,
> espeically the PersonStageReasoner thread is spawn in is in the
> forever loop (while true), the person age is changing. But the rule
> in defrule was never fired.
>
>
> I thank you for any and all help.
>
>
>
>
>
>
> My Coyne
> [email protected]
> (cel): 301-399-6351
>

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com







--------------------------------------------------------------------
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] .
--------------------------------------------------------------------


< Person .java > < BeanSupport .java><PersonStageReasoner.java><PersonClassificationRules.clp>

---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences, Sandia National Laboratories
PO Box 969, MS 9012, Livermore, CA 94550
http://www.jessrules.com






Reply via email to