JESS: Checking status: backward-chaining or logical?

classic Classic list List threaded Threaded
2 messages Options
hlc
Reply | Threaded
Open this post in threaded view
|

JESS: Checking status: backward-chaining or logical?

hlc
Hi,

I was trying to figure out a way of checking the "status" of some system.
To make things simpler, I have two kinds of facts, start and end, which
are added along time:
    (deftemplate start)
    (deftemplate end)

Then I want to say that I have an "active" system if it has started and
not ended yet. However, I want to avoid doing like
    (start) (not (end))
in every rule where I need to check if the system is active.

My first approach was to try backward chaining. In Prolog I would do
something like:
    active :- start, not(end).

However in Jess this gets more complicated, since doing something like:
    (deftemplate active
        (declare (backchain-reactive TRUE)) )
    (defrule do-active
        (need-active)
        (start)
        (not (end))
        =>
        (assert (active)) )

will assert the active fact, but then I need another rule to retract
active when end occurs...

I then turned to using the logical conditional element, which seems to
work fine:
    (defrule active-ctx
        (logical (not (end)))
        (start)
        =>
        (assert (active)) )

Is this the best way of doing it?

Thanks.

Henrique



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

Reply | Threaded
Open this post in threaded view
|

Re: JESS: Checking status: backward-chaining or logical?

Friedman-Hill, Ernest
That seems like an excellent solution.

On Jul 2, 2010, at 6:35 AM, Henrique Lopes Cardoso wrote:

> Hi,
>
> I was trying to figure out a way of checking the "status" of some  
> system.
> To make things simpler, I have two kinds of facts, start and end,  
> which
> are added along time:
>    (deftemplate start)
>    (deftemplate end)
>
> Then I want to say that I have an "active" system if it has started  
> and
> not ended yet. However, I want to avoid doing like
>    (start) (not (end))
> in every rule where I need to check if the system is active.
>
> My first approach was to try backward chaining. In Prolog I would do
> something like:
>    active :- start, not(end).
>
> However in Jess this gets more complicated, since doing something  
> like:
>    (deftemplate active
>        (declare (backchain-reactive TRUE)) )
>    (defrule do-active
>        (need-active)
>        (start)
>        (not (end))
>        =>
>        (assert (active)) )
>
> will assert the active fact, but then I need another rule to retract
> active when end occurs...
>
> I then turned to using the logical conditional element, which seems to
> work fine:
>    (defrule active-ctx
>        (logical (not (end)))
>        (start)
>        =>
>        (assert (active)) )
>
> Is this the best way of doing it?
>
> Thanks.
>
> Henrique
>
>
>
> --------------------------------------------------------------------
> To unsubscribe, send the words 'unsubscribe jess-users  
> [hidden email]'
> in the BODY of a message to [hidden email], NOT to the list
> (use your own address!) List problems? Notify [hidden email]
> .
> --------------------------------------------------------------------

---------------------------------------------------------
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 [hidden email]'
in the BODY of a message to [hidden email], NOT to the list
(use your own address!) List problems? Notify [hidden email].
--------------------------------------------------------------------