JESS: How to stop firing rules??

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

JESS: How to stop firing rules??

Félix Gómez Cordero
Hello everybody and thanks in advanced,
 
I've got the next problem, once I've run the engine to check some facts status I would need to add more facts and they are dependents between them so there are some functions which have miss references because of all the necessaries facts to make it works properly are not still asserted. My query is, how can I stop runing the engine in order to assert a group of facts?? I've tryed to use halt() on the engine in many diferents ways but no one works... Any idea?? Thanks,
 
 
        Félix.
Reply | Threaded
Open this post in threaded view
|

RE: JESS: How to stop firing rules??

Alan Moore-5
Felix,

You have not given us much information about your problem so we will need more detailed information before we can help you.

In general:

1) If you have one thread that has called the Rete#runUntilHalt() method, calling the halt() method (on another thread), or having one of your Jess rules/functions call the (halt) function, will cause the first thread to exit the #runUntilHalt() method.

2) Since the Rete class and it's methods are thread-safe, you don't need to halt the firing of Jess rules while you are asserting facts. If you are getting unexpected results, your rules might need to be rewritten to protect themselves against firing when only some of your facts have been asserted.

3) Many people use Jess without calling the Rete#runUntilHalt() method. If this applies to you, just assert your facts, call Rete#run(), get your results as needed, assert more facts, call Rete#run(), etc. etc.

4) Use the (watch) function to help debug your rules.

Please send more information about your specific problem and we will try to help.

alan


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Filix Gsmez Cordero
Sent: Tuesday, July 26, 2005 2:18 PM
To: [hidden email]
Subject: JESS: How to stop firing rules??


Hello everybody and thanks in advanced,

I've got the next problem, once I've run the engine to check some facts status I would need to add more facts and they are dependents between them so there are some functions which have miss references because of all the necessaries facts to make it works properly are not still asserted. My query is, how can I stop runing the engine in order to assert a group of facts?? I've tryed to use halt() on the engine in many diferents ways but no one works... Any idea?? Thanks,


        Filix.


--------------------------------------------------------------------
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: How to stop firing rules??

Félix Gómez Cordero
Hi Alan,

I'm sorry, when I've read my mail againg I've realize that it was confused.
I will try to explain my problem clearer. I'm using  runUntilHalt function
on my one thread program. I stop the engine calling halt from a rule with an
established salience of -100. This rule is fired when there is no one else
left. As I said in my last mail, I have to assert facts by groups and these
groups of facts have dependences between them therefore I can't allow the
engine to fire rules while I'm asserting those facts. If I assert all those
facts in once, instead of  whaching some facts status and make the
assertions by steps there is no problem. But when I run the engine to check
some fact's status (I'm forced to do this) and I keep asseting, then I get
errors because there are some facts with miss references due to they have to
wait for the rest of  facts assertion.

    I had thought about adding one constraint at the begining of each rule,
something like you said. That could prevent them from being fired while I'm
asserting more facts. That would work but I would like to fix the problem
using a different solution, if that is possible and not too much annoying
for you, of course .Or at least I'd like knowing what I was doing wrongly
and why I can not stop the engine totally once I've run it the first time.
Thanks a million for your help,

        Filix.




----- Original Message -----
From: "Alan Moore" <[hidden email]>
To: <[hidden email]>
Sent: Tuesday, July 26, 2005 11:52 PM
Subject: RE: JESS: How to stop firing rules??


> Felix,
>
> You have not given us much information about your problem so we will need
> more detailed information before we can help you.
>
> In general:
>
> 1) If you have one thread that has called the Rete#runUntilHalt() method,
> calling the halt() method (on another thread), or having one of your Jess
> rules/functions call the (halt) function, will cause the first thread to
> exit the #runUntilHalt() method.
>
> 2) Since the Rete class and it's methods are thread-safe, you don't need
> to halt the firing of Jess rules while you are asserting facts. If you are
> getting unexpected results, your rules might need to be rewritten to
> protect themselves against firing when only some of your facts have been
> asserted.
>
> 3) Many people use Jess without calling the Rete#runUntilHalt() method. If
> this applies to you, just assert your facts, call Rete#run(), get your
> results as needed, assert more facts, call Rete#run(), etc. etc.
>
> 4) Use the (watch) function to help debug your rules.
>
> Please send more information about your specific problem and we will try
> to help.
>
> alan
>
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]] On
> Behalf Of Filix Gsmez Cordero
> Sent: Tuesday, July 26, 2005 2:18 PM
> To: [hidden email]
> Subject: JESS: How to stop firing rules??
>
>
> Hello everybody and thanks in advanced,
>
> I've got the next problem, once I've run the engine to check some facts
> status I would need to add more facts and they are dependents between them
> so there are some functions which have miss references because of all the
> necessaries facts to make it works properly are not still asserted. My
> query is, how can I stop runing the engine in order to assert a group of
> facts?? I've tryed to use halt() on the engine in many diferents ways but
> no one works... Any idea?? Thanks,
>
>
>        Filix.
>
>
> --------------------------------------------------------------------
> 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].
> --------------------------------------------------------------------
>
>


--------------------------------------------------------------------
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: How to stop firing rules??

Alan Moore-5
In reply to this post by Félix Gómez Cordero
Filix,

I'm really surprised (halt) doesn't stop the engine - are you sure your thread doesn't call Rete#runUntilHalt() again or another thread is calling runUntilHalt() also, or something like that?

One way to do what you want is to create a list of Facts/Strings/Objects you want to assert "all at once" (between rule firings) and then pass this list, or an iterator over it, into the Rete instance so that your rules can pattern match against it.

Then, one of your rules, running on the thread that called Rete#runUntilHalt() will fire and on the RHS run a loop to assert/definstance your required list of facts/strings/objects, etc.

Generally, like this:

ThreadA.java:

Rete rete = ....;
rete.runUtilHalt();

ThreadB.java:

List transaction = new LinkedList();
transaction.add( obj1 );
transaction.add( obj2 );
... etc.

Rete rete = getReteInstance(); // whatever...
rete.definstance("Iterator", transaction.iterator(), false);

In myRules.jess:

(defrule transactionalDefinstance
   ?f1 <- (Iterator (OBJECT ?iterator))
=>
   (while (?iterator hasNext)
      (bind ?obj (?iterator next))
      (definstance "ObjectTypeName" ?obj static) ;; whatever...
   )
   (retract ?f1) ;; done with the transaction
)

Disclaimer: the code above is not complete or tested.

Since the rule will run on ThreadA no other rules will fire while this rule is asserting/definstancing the objects.

Obviously, you will want to make this more specific to your application but I think you understand the general pattern.

Hope this helps...

alan

> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]] On Behalf Of Filix Gsmez Cordero
> Sent: Wednesday, July 27, 2005 1:04 PM
> To: [hidden email]
> Subject: Re: JESS: How to stop firing rules??
>
>
> Hi Alan,
>
> I'm sorry, when I've read my mail againg I've realize that it
> was confused. I will try to explain my problem clearer. I'm
> using  runUntilHalt function on my one thread program. I stop
> the engine calling halt from a rule with an established
> salience of -100. This rule is fired when there is no one
> else left. As I said in my last mail, I have to assert facts
> by groups and these groups of facts have dependences between
> them therefore I can't allow the engine to fire rules while
> I'm asserting those facts. If I assert all those facts in
> once, instead of  whaching some facts status and make the
> assertions by steps there is no problem. But when I run the
> engine to check some fact's status (I'm forced to do this)
> and I keep asseting, then I get errors because there are some
> facts with miss references due to they have to wait for the
> rest of  facts assertion.
>
>     I had thought about adding one constraint at the begining
> of each rule, something like you said. That could prevent
> them from being fired while I'm asserting more facts. That
> would work but I would like to fix the problem using a
> different solution, if that is possible and not too much
> annoying for you, of course .Or at least I'd like knowing
> what I was doing wrongly and why I can not stop the engine
> totally once I've run it the first time. Thanks a million for
> your help,
>
>         Filix.
>
>
>
>
> ----- Original Message -----
> From: "Alan Moore" <[hidden email]>
> To: <[hidden email]>
> Sent: Tuesday, July 26, 2005 11:52 PM
> Subject: RE: JESS: How to stop firing rules??
>
>
> > Felix,
> >
> > You have not given us much information about your problem
> so we will
> > need more detailed information before we can help you.
> >
> > In general:
> >
> > 1) If you have one thread that has called the Rete#runUntilHalt()
> > method, calling the halt() method (on another thread), or
> having one
> > of your Jess rules/functions call the (halt) function, will
> cause the
> > first thread to exit the #runUntilHalt() method.
> >
> > 2) Since the Rete class and it's methods are thread-safe, you don't
> > need to halt the firing of Jess rules while you are
> asserting facts.
> > If you are getting unexpected results, your rules might need to be
> > rewritten to protect themselves against firing when only
> some of your
> > facts have been asserted.
> >
> > 3) Many people use Jess without calling the Rete#runUntilHalt()
> > method. If this applies to you, just assert your facts, call
> > Rete#run(), get your results as needed, assert more facts, call
> > Rete#run(), etc. etc.
> >
> > 4) Use the (watch) function to help debug your rules.
> >
> > Please send more information about your specific problem
> and we will
> > try to help.
> >
> > alan
> >
> >
> > -----Original Message-----
> > From: [hidden email]
> [mailto:[hidden email]]
> > On Behalf Of Filix
> Gsmez Cordero
> > Sent: Tuesday, July 26, 2005 2:18 PM
> > To: [hidden email]
> > Subject: JESS: How to stop firing rules??
> >
> >
> > Hello everybody and thanks in advanced,
> >
> > I've got the next problem, once I've run the engine to check some
> > facts status I would need to add more facts and they are dependents
> > between them so there are some functions which have miss references
> > because of all the necessaries facts to make it works
> properly are not
> > still asserted. My query is, how can I stop runing the
> engine in order
> > to assert a group of facts?? I've tryed to use halt() on
> the engine in
> > many diferents ways but no one works... Any idea?? Thanks,
> >
> >
> >        Filix.
> >
> >
> > --------------------------------------------------------------------
> > 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].
> > --------------------------------------------------------------------
> >
> >
>
>
> --------------------------------------------------------------------
> 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].
> --------------------------------------------------------------------
>
>


--------------------------------------------------------------------
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: How to stop firing rules??

Félix Gómez Cordero
Hello Alan,

Thanks for your help, (halt) and Rete#runUntilHalt() work properly (as it
was obvious). It was my fault, I wasn't calling any run again, but when I
have been trying to fix the problem I added some engine.halt() in my Java
before asserting facts trying to stop the engine and it seems that those
calls caused my problem. Everything works perfectly now. Thanks again,

Felix.


----- Original Message -----
From: "Alan Moore" <[hidden email]>
To: <[hidden email]>
Sent: Thursday, July 28, 2005 12:09 AM
Subject: RE: JESS: How to stop firing rules??


> Filix,
>
> I'm really surprised (halt) doesn't stop the engine - are you sure your
> thread doesn't call Rete#runUntilHalt() again or another thread is calling
> runUntilHalt() also, or something like that?
>
> One way to do what you want is to create a list of Facts/Strings/Objects
> you want to assert "all at once" (between rule firings) and then pass this
> list, or an iterator over it, into the Rete instance so that your rules
> can pattern match against it.
>
> Then, one of your rules, running on the thread that called
> Rete#runUntilHalt() will fire and on the RHS run a loop to
> assert/definstance your required list of facts/strings/objects, etc.
>
> Generally, like this:
>
> ThreadA.java:
>
> Rete rete = ....;
> rete.runUtilHalt();
>
> ThreadB.java:
>
> List transaction = new LinkedList();
> transaction.add( obj1 );
> transaction.add( obj2 );
> ... etc.
>
> Rete rete = getReteInstance(); // whatever...
> rete.definstance("Iterator", transaction.iterator(), false);
>
> In myRules.jess:
>
> (defrule transactionalDefinstance
>   ?f1 <- (Iterator (OBJECT ?iterator))
> =>
>   (while (?iterator hasNext)
>      (bind ?obj (?iterator next))
>      (definstance "ObjectTypeName" ?obj static) ;; whatever...
>   )
>   (retract ?f1) ;; done with the transaction
> )
>
> Disclaimer: the code above is not complete or tested.
>
> Since the rule will run on ThreadA no other rules will fire while this
> rule is asserting/definstancing the objects.
>
> Obviously, you will want to make this more specific to your application
> but I think you understand the general pattern.
>
> Hope this helps...
>
> alan
>
>> -----Original Message-----
>> From: [hidden email]
>> [mailto:[hidden email]] On Behalf Of Filix Gsmez Cordero
>> Sent: Wednesday, July 27, 2005 1:04 PM
>> To: [hidden email]
>> Subject: Re: JESS: How to stop firing rules??
>>
>>
>> Hi Alan,
>>
>> I'm sorry, when I've read my mail againg I've realize that it
>> was confused. I will try to explain my problem clearer. I'm
>> using  runUntilHalt function on my one thread program. I stop
>> the engine calling halt from a rule with an established
>> salience of -100. This rule is fired when there is no one
>> else left. As I said in my last mail, I have to assert facts
>> by groups and these groups of facts have dependences between
>> them therefore I can't allow the engine to fire rules while
>> I'm asserting those facts. If I assert all those facts in
>> once, instead of  whaching some facts status and make the
>> assertions by steps there is no problem. But when I run the
>> engine to check some fact's status (I'm forced to do this)
>> and I keep asseting, then I get errors because there are some
>> facts with miss references due to they have to wait for the
>> rest of  facts assertion.
>>
>>     I had thought about adding one constraint at the begining
>> of each rule, something like you said. That could prevent
>> them from being fired while I'm asserting more facts. That
>> would work but I would like to fix the problem using a
>> different solution, if that is possible and not too much
>> annoying for you, of course .Or at least I'd like knowing
>> what I was doing wrongly and why I can not stop the engine
>> totally once I've run it the first time. Thanks a million for
>> your help,
>>
>>         Filix.
>>
>>
>>
>>
>> ----- Original Message -----
>> From: "Alan Moore" <[hidden email]>
>> To: <[hidden email]>
>> Sent: Tuesday, July 26, 2005 11:52 PM
>> Subject: RE: JESS: How to stop firing rules??
>>
>>
>> > Felix,
>> >
>> > You have not given us much information about your problem
>> so we will
>> > need more detailed information before we can help you.
>> >
>> > In general:
>> >
>> > 1) If you have one thread that has called the Rete#runUntilHalt()
>> > method, calling the halt() method (on another thread), or
>> having one
>> > of your Jess rules/functions call the (halt) function, will
>> cause the
>> > first thread to exit the #runUntilHalt() method.
>> >
>> > 2) Since the Rete class and it's methods are thread-safe, you don't
>> > need to halt the firing of Jess rules while you are
>> asserting facts.
>> > If you are getting unexpected results, your rules might need to be
>> > rewritten to protect themselves against firing when only
>> some of your
>> > facts have been asserted.
>> >
>> > 3) Many people use Jess without calling the Rete#runUntilHalt()
>> > method. If this applies to you, just assert your facts, call
>> > Rete#run(), get your results as needed, assert more facts, call
>> > Rete#run(), etc. etc.
>> >
>> > 4) Use the (watch) function to help debug your rules.
>> >
>> > Please send more information about your specific problem
>> and we will
>> > try to help.
>> >
>> > alan
>> >
>> >
>> > -----Original Message-----
>> > From: [hidden email]
>> [mailto:[hidden email]]
>> > On Behalf Of Filix
>> Gsmez Cordero
>> > Sent: Tuesday, July 26, 2005 2:18 PM
>> > To: [hidden email]
>> > Subject: JESS: How to stop firing rules??
>> >
>> >
>> > Hello everybody and thanks in advanced,
>> >
>> > I've got the next problem, once I've run the engine to check some
>> > facts status I would need to add more facts and they are dependents
>> > between them so there are some functions which have miss references
>> > because of all the necessaries facts to make it works
>> properly are not
>> > still asserted. My query is, how can I stop runing the
>> engine in order
>> > to assert a group of facts?? I've tryed to use halt() on
>> the engine in
>> > many diferents ways but no one works... Any idea?? Thanks,
>> >
>> >
>> >        Filix.
>> >
>> >
>> > --------------------------------------------------------------------
>> > 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].
>> > --------------------------------------------------------------------
>> >
>> >
>>
>>
>> --------------------------------------------------------------------
>> 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].
>> --------------------------------------------------------------------
>>
>>
>
>
> --------------------------------------------------------------------
> 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].
> --------------------------------------------------------------------
>
>

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