Michael Neale wrote:
Nice - will this be JIT like the extractors - or will it be part of the compiler step?

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

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 alpha nodes become dirty from a rule add/remove we drop the class for that ObjectType and rebuild it.

On Jan 14, 2008 8:26 AM, Mark Proctor <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>> wrote:

    I can now generate an alpha network, currently  java as a string.
    We can
    change this to generate a class with  ASM bytecode  - so thats one
    class
    per one  ObjectType. So the main thing is it shows  the algorithm
    works,
    including node sharing and hashing via the case statement.

    package org.drools.benchmark.manners

    rule rule1
       when
           context : Context( state == Context.START_UP )
           guest : Guest( name ==  "mark", sex != Sex.M, hobby ==
     Hobby.H1)
           count : Count()
       then
    end

    rule rule2
      when
           context : Context( state == Context.START_UP )
           guest : Guest( name ==  "mark", sex != Sex.M , hobby ==
    Hobby.H2)
           count : Count()
      then
    end

    rule rule3
      when
           context : Context( state == Context.START_UP )
guest : Guest( name == "luke", sex != Sex.M, hobby == Hobby.H3)
           count : Count()
      then
    end

    rule rule4
      when
           context : Context( state == Context.START_UP )
           guest : Guest( name ==  "mark", sex != Sex.M, hobby ==
     Hobby.H4 )
           count : Count()
      then
    end

    The following is produced for above (obviously doesn't compile,  but
    shows  the algo works):
    public class Compiled[ClassObjectType
    class=org.drools.benchmark.manners.Count ]AlphaNetwork implements
    RightTupleSink {
       RightTupleSink sink10;
       RightTupleSink sink17;
       RightTupleSink sink26;
       RightTupleSink sink33;
       public void assertObject(....) {
           sink10.assertRight (handle, wm, context);
           sink17.assertRight(handle, wm, context);
           sink26.assertRight(handle, wm, context);
           sink33.assertRight(handle, wm, context);
       }
    }

    public class Compiled[ClassObjectType
    class=org.drools.benchmark.manners.Context]AlphaNetwork implements
    RightTupleSink {
       AlphaNodeFieldConstraint alphaNodeConstraint2;
       RightTupleSink sink3;
       public void assertObject(....) {
           if ( alphaNodeConstraint2.isAllowed(handle, wm) ) {
               sink3.assertRight(handle, wm, context);
           }
       }
    }

    public class Compiled[ClassObjectType
    class=org.drools.benchmark.manners.Guest]AlphaNetwork implements
    RightTupleSink {
       AlphaNodeFieldConstraint alphaNodeConstraint5;
       AlphaNodeFieldConstraint alphaNodeConstraint6;
       AlphaNodeFieldConstraint alphaNodeConstraint30;
       RightTupleSink sink31;
       AlphaNodeFieldConstraint alphaNodeConstraint7;
       RightTupleSink sink8;
       AlphaNodeFieldConstraint alphaNodeConstraint14;
       RightTupleSink sink15;
       AlphaNodeFieldConstraint alphaNodeConstraint21;
       AlphaNodeFieldConstraint alphaNodeConstraint22;
       AlphaNodeFieldConstraint alphaNodeConstraint23;
       RightTupleSink sink24;
       public void assertObject(....) {
           if ( alphaNodeConstraint5.isAllowed(handle, wm) ) {
               if ( alphaNodeConstraint6.isAllowed (handle, wm) ) {
                   HashKey key = new HashKey(handle);
                   swtich
    ((RightTupleSink)this.hashedSinkedMap(key)).getId() {
                       case 7: {
                           sink8.assertRight (handle, wm, context);
                       };
                       case 14: {
                           sink15.assertRight(handle, wm, context);
                       };
                       case 30: {
                            sink31.assertRight(handle, wm, context);
                       };
                   };
               }
           }
           if ( alphaNodeConstraint21.isAllowed(handle, wm) ) {
               if ( alphaNodeConstraint22.isAllowed (handle, wm) ) {
                   if ( alphaNodeConstraint23.isAllowed(handle, wm) ) {
                       sink24.assertRight(handle, wm, context);
                   }
               }
           }
       }
    }






--
Michael D Neale
home: www.michaelneale.net <http://www.michaelneale.net>
blog: michaelneale.blogspot.com <http://michaelneale.blogspot.com>

_______________________________________________
rules-dev mailing list
[email protected]
https://lists.jboss.org/mailman/listinfo/rules-dev

Reply via email to