Re: JESS: Question on Modules+execution Control

2006-02-22 Thread Andreas Andreakis
Thanx for the prev. tipps. I4ve you implemented your suggestion (having 
not only one fact but many: weblog, tag, entry, ...) and the code runs 
faster now, about twice as fast - from 3sec ~ 1,5 sec.
Now, I understand the modules concept in more detail, even if rules are 
not fired (when they dont have the focus) a complexity results from the 
pattern mathing (like you4ve already said).


Maybe this could be an optimization in future Jess versions ? I mean why 
are you doing pattern matching to rules of Modules, which are not 
focused =?




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]




Re: JESS: Question on Modules+execution Control

2006-02-22 Thread ejfried
I think Andreas Andreakis wrote:

> But, when I ran it with both rules it takes more then 3 secs. I 
> understand why this happens (pattern mathing problem), but I dont 
> understand why I face the same problem while using Modules. The docs 
> say, that rules contained in a Module do not consider information in 
> other modules, unless they are referensed directly over their Modules 
> namespace. Maybe I missunderstood ?
> 

I think you've made things more complex in your head than they really
are. The template "triple" is shared by all modules. It doesn't matter
what module a fact is asserted in. All rules that match that template
see all the facts.

> I will try your suggestion. But in general I_m interessted to see 
> whether it is possible to solve the performance issue using the more 
> generic triple Fact.

Writing something like

(defrule foo
(triple ...)
(triple ...)
(triple ...)
(triple ...)

Is equivalent to something in Java like

List triples = ...

for (int i=0; ihttp://herzberg.ca.sandia.gov


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]




Re: JESS: Question on Modules+execution Control

2006-02-22 Thread Andreas Andreakis




Hi,

thanx for your response.

  


  Yes. Jess has to root through all your data to find anything.
  
  
That may well be, but it won't impact performance at all. Your
performance issue is in pattern matching, not in rule firing. Rule
firing is rarely the issue.

  


When I run the RuleEngine using only rule1 or rule 2 it takes about 300
ms (each). Like I said in my first email, you get corerct results if
you would run rule1 first, get new facts, then run rule2 and then get
the final results. Now, you could assume that rule1 creates so many new
assertions that rule2 gets slowed down. In the isolated test (while
testing only rule2) I put much more facts inside then in the rule1
test. It didn´t take more then 700 ms. This means for me: 300 + 700 =
about 1000 ms.

But, when I ran it with both rules it takes more then 3 secs. I
understand why this happens (pattern mathing problem), but I dont
understand why I face the same problem while using Modules. The docs
say, that rules contained in a Module do not consider information in
other modules, unless they are referensed directly over their Modules
namespace. Maybe I missunderstood ?

So that means, if I have the following code, rule1 get fired on every
appliable fact and if the agenda is empty, then rule2 will be
activated. I would be very thankful if you could help me achiving this,
if possible.

(defmodule M-RULE-1)
(defrule RULE-1
    ...)

(defmodule M-RULE-2)
(defrule RULE-2
    ...)

(focus M-RULE-2)
(focus M-RULE-1)


  
  
So I need an execution Control.

  
  
No, you need better data structures! Define separate templates for
"weblog entries" and "entry tags" and "weblog tags" and such.
  

I will try your suggestion. But in general I´m interessted to see
whether it is possible to solve the performance issue using the more
generic triple Fact.


best regards,
Andreas




Re: JESS: Question on Modules+execution Control

2006-02-22 Thread ejfried
I think Andreas Andreakis wrote:
> 
> I defined the following Fact:
> 
> (deftemplate triple
> (slot subject)
> (slot property)
> (slot object))
> 

Yuk. This is like deciding that an entire Java application is going to
use only this class:

class Triple {
  public String subject;
  public String property;
  public String object;
}

You wouldn't do that, would you?

...

> I?m currently experiencing a performance problem

Yes. Jess has to root through all your data to find anything.


> In my usecase it would be semanticly correct if rule1 fires first until 
> no other facts are available and then rule2. 

That may well be, but it won't impact performance at all. Your
performance issue is in pattern matching, not in rule firing. Rule
firing is rarely the issue.

> So I need an execution Control.

No, you need better data structures! Define separate templates for
"weblog entries" and "entry tags" and "weblog tags" and such.


> (defrule RULE-2
> (MAIN::triple (subject ?X) (property "Weblog.tag") (object ?T))
> (MAIN::triple (subject ?T) (property "Tag.value") (object ?V))
> (MAIN::triple (subject ?Y) (property "Weblog.tag") (object ?G))
> (MAIN::triple (subject ?G) (property "Tag.value") (object ?V))


The above could be improved by reversing the third and fourth
patterns; the sooner the join of the two "?Vs" is done, the fewer
partial matches will be formed, and that's good for performance
too. This will hold true even after you change to using more specific
templates. 


-
Ernest Friedman-Hill  
Advanced Software Research  Phone: (925) 294-2154
Sandia National LabsFAX:   (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://herzberg.ca.sandia.gov


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]