On Jan 14, 2008 8:26 AM, Mark Proctor <
mproctor@codehaus.org>
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);
}
}
}
}
}