The second version won't work either, for the same reason that the
first doesn't work.
Here's one solution: look in the FAQ at
http://herzberg.ca.sandia.gov/jess/FAQ.html for "How do I make Jess
run forever?" Instead of using an "(idle)" fact, use a (time (time))
fact. Then have your rule-1 match the time fact to get the time,
instead of calling (time). If you update the time once a second, then
whenever there are no other rules to fire, cleanup will occur. If
cleanup is urgent, don't make the salience low -- leave it at the
default.
Also, instead of sleeping, you might just call
(call (engine) waitForActivations)
if it's OK that cleanup doesn't happen unless there are other rules to
fire.
I think =?iso-8859-1?Q?D=E1rio_Mour=E3o?= wrote:
[Charset iso-8859-1 unsupported, filtering to ASCII...]
> ;Begin-code
> (deftemplate state
> "structure of a state"
> (slot sname)
> (slot stime))
>
> (defrule rule1
> ?fact <- (state (sname ?sn) (stime ?st))
> (test (> (- (time) ?st) 10))
> =>
> (retract ?fact))
>
> (defrule rule2
> ?fact <- (state (sname ?sn) (stime ?st))
> =>
> (if (> (- (time) ?st) 10) then
> (retract ?fact)))
>
> (assert (state (sname s1) (stime (time))))
> ;End-Code
>
>
> Hi,
> it's the first time i send a question...:-)
> I have a problem with this situation:
> I want to have a structure called state with a field stime which holds a
> time-stamp to say when a particular state was generated. (see deftemplate
> state... )
> I also want that states which are, lets say, more than 10 seconds old, be
> removed from the system.
> My system performs an infinite loop, in which states are inserted and the
> run is executed.
> The problem is that when rule1 is loaded and if in that particular instant
> some state (lets call it s1) is only 5 seconds old, for instance, s1 will
> never be deleted, not even after it completes 10 seconds of life, because
> rule1 does not refreshes... it seems that the rule needs some sord of
> refreshement, so that when (run) is executed all the facts can be considered
> again...
> I tried use rule2, but it didn't solve the question. The only solution i see
> is to load the rule each time in the loop, but that's a bad solution because
> it is computationally heavy.
> Can you see another solution for this problem?
> Is there any command to refresh the rules?
>
> Thanx for the attention.
> D_rio
>
>
>
>
>
---------------------------------------------------------
Ernest Friedman-Hill
Distributed Systems Research Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
Org. 8920, MS 9012 [EMAIL PROTECTED]
PO Box 969 http://herzberg.ca.sandia.gov
Livermore, CA 94550
---------------------------------------------------------------------
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]
---------------------------------------------------------------------