The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

mirkata (11) [Avatar] Offline
#1
Hi,
I have the following problem. I want to implement something like switch in jess. But to fire all the conditions that validate, not the first one. So I have defined several rules(conditions). If some of them evaluates to true it is put in a list. Then for all of the conditions in this list I have a global rule. So I activate this rule. It should check which conditions are true and then activate those who are in the list.

The problem is how can I check whether the conditions have been evaluated. Should I set somehow some delay for the global event and how can I do that and how long should it be. After thsi global rule has finished evaluating the conditions it should be deactivated. So if some of the conditions are validated later they would/should not fire. I have to add too, that the conditions are evaluating only while the global condition is active via an "active" attribute.


Thank you for the help in advance,
Miroslav
ejfried (326) [Avatar] Offline
#2
Re: implement switch in jess
Why not simply have each individual rule do whatever needs to be done for the one condition?

Otherwise, you can (1) use salience to keep the global rule from firing while the individual rules are active; (2) use "accumulate" in Jess 7 to loop over facts; or (3) use module focus, so that the global rule is in a module that doesn't get the focus until the individual rules fire. There are other possibilities as well.
mirkata (11) [Avatar] Offline
#3
Re: implement switch in jess
Thank you for the answer.

I cannot let each rule to execute on its own, cause the globul rule should at the end use the result from these subrules(conditions). They save some things if validated that the global rule uses. So another rule sets a parameter to active and thus starts the golab rule as well as the subrules.

I think the best will be to use salience. I will assign big numbers for the conditions (like 50) and lets us say 0 for the global rule. So when they are all started I will be sure that the subrules wil fire first, do their work and then will fire the global rule. I hope this is correct. I have only one question, this salience is only for the LHS of the rule or for the RHS too. Because if the subrules fire first but they havent still written the data I will need in the global rule and the global rule fires, it will not use this data.

The data for instance is in a form of a global variable of type list. Let say gathers the names of the conditions that validate and prints it out. But if salience is only for the LHS I should consider another way to solve this problem.

regards,
Miroslav