<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
  <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Michael Neale wrote:
<blockquote
 cite="mid:96ab3ced0801131518h258cac93w834d3e60013c0f09@mail.gmail.com"
 type="cite">Nice - will this be JIT like the extractors - or will it
be part of the compiler step? <br>
  <br>
I think the ASM bit is harder then you think though. If its in compiler
MVEL templating plus compiling can be used, but obviously not if it is
JIT in the core (in which case, yes, ASM is needed, but fiddly to do
and get right - will take a while to flush out all the invalid class
errors). <br>
</blockquote>
Yes the idea is to JIT it - and ASM is never easy :) but the end result
here would be worth while. I'm just showing the algorithm itself isn't
hard, including keeping alpha node hashing.<br>
<br>
So the original AlphaNode network exists but we compile each
ObjectType's network into a class and attach that to the ObjectTypeNode
and propagate into that instead. If the ObjectTypeNode or any of it's&nbsp;
alpha nodes become dirty from a rule add/remove we drop the class for
that ObjectType and rebuild it.<br>
<blockquote
 cite="mid:96ab3ced0801131518h258cac93w834d3e60013c0f09@mail.gmail.com"
 type="cite"><br>
  <div class="gmail_quote">On Jan 14, 2008 8:26 AM, Mark Proctor &lt;<a
 moz-do-not-send="true" href="mailto:mproctor@codehaus.org">mproctor@codehaus.org</a>&gt;
wrote:<br>
  <blockquote class="gmail_quote"
 style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">I
can now generate an alpha network, currently &nbsp;java as a string. We can<br>
change this to generate a class with &nbsp;ASM bytecode &nbsp;- so thats one class<br>
per one &nbsp;ObjectType. So the main thing is it shows &nbsp;the algorithm
works,
    <br>
including node sharing and hashing via the case statement.<br>
    <br>
package org.drools.benchmark.manners<br>
    <br>
rule rule1<br>
&nbsp; &nbsp;when<br>
&nbsp; &nbsp; &nbsp; &nbsp;context : Context( state == Context.START_UP )<br>
&nbsp; &nbsp; &nbsp; &nbsp;guest : Guest( name == &nbsp;"mark", sex != Sex.M, hobby == &nbsp;Hobby.H1)<br>
&nbsp; &nbsp; &nbsp; &nbsp;count : Count()<br>
&nbsp; &nbsp;then<br>
end<br>
    <br>
rule rule2<br>
&nbsp; when<br>
&nbsp; &nbsp; &nbsp; &nbsp;context : Context( state == Context.START_UP )<br>
&nbsp; &nbsp; &nbsp; &nbsp;guest : Guest( name == &nbsp;"mark", sex != Sex.M
, hobby == Hobby.H2)<br>
&nbsp; &nbsp; &nbsp; &nbsp;count : Count()<br>
&nbsp; then<br>
end<br>
    <br>
rule rule3<br>
&nbsp; when<br>
&nbsp; &nbsp; &nbsp; &nbsp;context : Context( state == Context.START_UP )<br>
&nbsp; &nbsp; &nbsp; &nbsp;guest : Guest( name == &nbsp;"luke", sex != Sex.M, hobby == &nbsp;
Hobby.H3)<br>
&nbsp; &nbsp; &nbsp; &nbsp;count : Count()<br>
&nbsp; then<br>
end<br>
    <br>
rule rule4<br>
&nbsp; when<br>
&nbsp; &nbsp; &nbsp; &nbsp;context : Context( state == Context.START_UP )<br>
&nbsp; &nbsp; &nbsp; &nbsp;guest : Guest( name == &nbsp;"mark", sex != Sex.M, hobby == &nbsp;Hobby.H4
)<br>
&nbsp; &nbsp; &nbsp; &nbsp;count : Count()<br>
&nbsp; then<br>
end<br>
    <br>
The following is produced for above (obviously doesn't compile, &nbsp;but<br>
shows &nbsp;the algo works):<br>
public class Compiled[ClassObjectType<br>
class=org.drools.benchmark.manners.Count
]AlphaNetwork implements<br>
RightTupleSink {<br>
&nbsp; &nbsp;RightTupleSink sink10;<br>
&nbsp; &nbsp;RightTupleSink sink17;<br>
&nbsp; &nbsp;RightTupleSink sink26;<br>
&nbsp; &nbsp;RightTupleSink sink33;<br>
&nbsp; &nbsp;public void assertObject(....) {<br>
&nbsp; &nbsp; &nbsp; &nbsp;sink10.assertRight
(handle, wm, context);<br>
&nbsp; &nbsp; &nbsp; &nbsp;sink17.assertRight(handle, wm, context);<br>
&nbsp; &nbsp; &nbsp; &nbsp;sink26.assertRight(handle, wm, context);<br>
&nbsp; &nbsp; &nbsp; &nbsp;sink33.assertRight(handle, wm, context);<br>
&nbsp; &nbsp;}<br>
}<br>
    <br>
public class Compiled[ClassObjectType
    <br>
class=org.drools.benchmark.manners.Context]AlphaNetwork implements<br>
RightTupleSink {<br>
&nbsp; &nbsp;AlphaNodeFieldConstraint alphaNodeConstraint2;<br>
&nbsp; &nbsp;RightTupleSink sink3;<br>
&nbsp; &nbsp;public void assertObject(....) {<br>
&nbsp; &nbsp; &nbsp; &nbsp;if ( alphaNodeConstraint2.isAllowed(handle, wm) ) {<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sink3.assertRight(handle, wm, context);<br>
&nbsp; &nbsp; &nbsp; &nbsp;}<br>
&nbsp; &nbsp;}<br>
}<br>
    <br>
public class Compiled[ClassObjectType<br>
class=org.drools.benchmark.manners.Guest]AlphaNetwork implements
    <br>
RightTupleSink {<br>
&nbsp; &nbsp;AlphaNodeFieldConstraint alphaNodeConstraint5;<br>
&nbsp; &nbsp;AlphaNodeFieldConstraint alphaNodeConstraint6;<br>
&nbsp; &nbsp;AlphaNodeFieldConstraint alphaNodeConstraint30;<br>
&nbsp; &nbsp;RightTupleSink sink31;<br>
&nbsp; &nbsp;AlphaNodeFieldConstraint alphaNodeConstraint7;
    <br>
&nbsp; &nbsp;RightTupleSink sink8;<br>
&nbsp; &nbsp;AlphaNodeFieldConstraint alphaNodeConstraint14;<br>
&nbsp; &nbsp;RightTupleSink sink15;<br>
&nbsp; &nbsp;AlphaNodeFieldConstraint alphaNodeConstraint21;<br>
&nbsp; &nbsp;AlphaNodeFieldConstraint alphaNodeConstraint22;
    <br>
&nbsp; &nbsp;AlphaNodeFieldConstraint alphaNodeConstraint23;<br>
&nbsp; &nbsp;RightTupleSink sink24;<br>
&nbsp; &nbsp;public void assertObject(....) {<br>
&nbsp; &nbsp; &nbsp; &nbsp;if ( alphaNodeConstraint5.isAllowed(handle, wm) ) {<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( alphaNodeConstraint6.isAllowed
(handle, wm) ) {<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;HashKey key = new HashKey(handle);<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;swtich
((RightTupleSink)this.hashedSinkedMap(key)).getId() {<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 7: {<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sink8.assertRight
(handle, wm, context);<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;};<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 14: {<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sink15.assertRight(handle, wm, context);<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;};<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;case 30: {<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
sink31.assertRight(handle, wm, context);<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;};<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;};<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
&nbsp; &nbsp; &nbsp; &nbsp;}<br>
&nbsp; &nbsp; &nbsp; &nbsp;if ( alphaNodeConstraint21.isAllowed(handle, wm) ) {<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( alphaNodeConstraint22.isAllowed
(handle, wm) ) {<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;if ( alphaNodeConstraint23.isAllowed(handle, wm) ) {<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sink24.assertRight(handle, wm, context);<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;}<br>
&nbsp; &nbsp; &nbsp; &nbsp;}<br>
&nbsp; &nbsp;}<br>
}<br>
    <br>
    <br>
    <br>
  </blockquote>
  </div>
  <br>
  <br clear="all">
  <br>
-- <br>
Michael D Neale<br>
home: <a moz-do-not-send="true" href="http://www.michaelneale.net">www.michaelneale.net</a><br>
blog: <a moz-do-not-send="true" href="http://michaelneale.blogspot.com">michaelneale.blogspot.com
  </a>
</blockquote>
<br>
</body>
</html>