property reactive ruleml 2013

49
Language and System Ergonomics http://www.slideshare.net/MarkProctor/property-reactive-ruleml-2013 Saturday, 13 July 13

Upload: mark-proctor

Post on 13-Dec-2014

986 views

Category:

Business


4 download

DESCRIPTION

30 minute presentation for the RuleML 2013 paper submission on the Drools feature Propert yReactive

TRANSCRIPT

Page 1: Property Reactive RuleML 2013

Language and System Ergonomics

http://www.slideshare.net/MarkProctor/property-reactive-ruleml-2013Saturday, 13 July 13

Page 2: Property Reactive RuleML 2013

Extending an Object-Oriented RETE Network with fine-grained

Reactivity to Property ModificationsMark Proctor, Mario Fusco and David Sottara

Saturday, 13 July 13

Page 3: Property Reactive RuleML 2013

AgendaThe ProblemProperty Reactive

The techniqueRelated WorkThe ImplementationBenchmarking

Conclusion

Saturday, 13 July 13

Page 4: Property Reactive RuleML 2013

The ProblemLoop Control

Saturday, 13 July 13

Page 5: Property Reactive RuleML 2013

The problemReactive rule based systems are hard to write

Saturday, 13 July 13

Page 6: Property Reactive RuleML 2013

Too Much!!!!Reactive rule based systems are hard to write

Saturday, 13 July 13

Page 7: Property Reactive RuleML 2013

Reactive Rulerule <rule_name> <attribute><value> when <conditions> then <actions>end

Saturday, 13 July 13

Page 8: Property Reactive RuleML 2013

Patterns

Person(age >= 18)field name restriction

constraintobject type

pattern

Saturday, 13 July 13

Page 9: Property Reactive RuleML 2013

CashFlow Ruleselect * from AccountPeriod ap, Account acc, Cashflow cfwhere cf.type == CREDIT and acc.accountNo == cf.accountNo cf.date >= ap.start and cf.date <= ap.end

rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account() cf : CashFlow( type == CREDIT, accountNo == acc.accountNo, date >= ap.start && <= ap.end ) then acc.balance += cf.amount; end

acc.balance += cf.amount

Saturday, 13 July 13

Page 10: Property Reactive RuleML 2013

Loop Problemrule “Salary award for min 2 years service” when e : Employee( lengthOfService > 2 )then modify( e ) { setSalary( e.getSalary() * 1.05 ) };end

Saturday, 13 July 13

Page 11: Property Reactive RuleML 2013

Loop Problemrule “Salary award for min 2 years service” no-loop when e : Employee( lengthOfService > 2 )then modify( e ) { setSalary( e.getSalary() * 1.05 ) };end

Saturday, 13 July 13

Page 12: Property Reactive RuleML 2013

Loop Problemrule “Salary award for min 2 years service” no-loop when e : Employee( lengthOfService > 2 )then modify( e ) { setSalary( e.getSalary() * 1.05 ) };end

rule “Salary award for min 8 years service” no-loop when e : Employee( lengthOfService > 8 )then modify( e ) { setSalary( e.getSalary() * 1.05 ) };end

Saturday, 13 July 13

Page 13: Property Reactive RuleML 2013

Loop Problemrule “Salary award for min 2 years service” when e : Employee( lengthOfService > 2 ) not SalaryMin2Years( employee == e )then modify( e ) { setSalary( e.getSalary() * 1.05 ) }; insert ( new SalaryMin2Years(e) );end

rule “Salary award for min 8 years service” when e : Employee( lengthOfService > 8 ) not SalaryMin8Years( employee == e )then modify( e ) { setSalary( e.getSalary() * 1.05 ) }; insert ( new SalaryMin8Years(e) );end

Saturday, 13 July 13

Page 14: Property Reactive RuleML 2013

Loop Problemrule “Year End” when d : ChangeDate( ) e : Employee( )then modify( e ) { lengthOfService( d.getYear() - e.getStartYear() ) };end

rule “Salary award for min 8 years service” when e : Employee( lengthOfService > 8 ) not SalaryMin8Years( employee == e )then modify( e ) { setSalary( e.getSalary() * 1.05 ) }; insert ( new SalaryMin8Years(e) );end

Saturday, 13 July 13

Page 15: Property Reactive RuleML 2013

RefractionThis term comes from the neurobiological observation of a refractory period for a neuron, which means that the neuron is not able to fire immediately without first going through a relaxation process. In a similar way, OPS5 will not allow the same instantiation in the conflict set from firing twice in a row. This prevents the inference engine from entering into an infinite loop.

Saturday, 13 July 13

Page 16: Property Reactive RuleML 2013

W3C RIF RefractionRefraction

When a rule instance is fired, it is removed from the conflict set (and thus will not be created again even its condition part remains true), unless one of the objects in its condition part is modified again. In the later case, the repeatability concept determines how the rule instance is treated

Saturday, 13 July 13

Page 17: Property Reactive RuleML 2013

W3C RIF RefractionRepeatability

After the execution of a rule instance, the rule instance is removed from the conflict set by the refraction. Later on, if one of the objects in the condition part is modified and if the rule evaluates to true, the repeatability controls whether if the rule instance can be created again.

Saturday, 13 July 13

Page 18: Property Reactive RuleML 2013

Loop Problem (Refraction)rule “Salary award for min 2 years service” repeatable false when e : Employee( lengthOfService > 2 )then modify( e ) { setSalary( e.getSalary() * 1.05 ) };end

rule “Salary award for min 8 years service” repeatable false when e : Employee( lengthOfService > 8 )then modify( e ) { setSalary( e.getSalary() * 1.05 ) };end

Saturday, 13 July 13

Page 19: Property Reactive RuleML 2013

AAAAAAhhhhhhhhhh

Saturday, 13 July 13

Page 20: Property Reactive RuleML 2013

Saturday, 13 July 13

Page 21: Property Reactive RuleML 2013

Property ReactiveThe Technique

Saturday, 13 July 13

Page 22: Property Reactive RuleML 2013

Saturday, 13 July 13

Page 23: Property Reactive RuleML 2013

Annotate Class@PropertyReactivepublic class Employee { int salary; int lengthOfService

// getters and setters below}

Saturday, 13 July 13

Page 24: Property Reactive RuleML 2013

Loop Problem Fixedrule “Salary award for min 2 years service” when e : Employee( lengthOfService > 2 )then modify( e ) { setSalary( e.getSalary() * 1.05 ) };end

rule “Salary award for min 8 years service” when e : Employee( lengthOfService > 8 )then modify( e ) { setSalary( e.getSalary() * 1.05 ) };end

Saturday, 13 July 13

Page 25: Property Reactive RuleML 2013

@Watchrule “Salary award for min 2 years service” when e : Employee( salary < 1000, lengthOfService > 2 ) @Watch( !salary )then modify( e ) { setSalary( e.getSalary() * 1.05 ) };end

Saturday, 13 July 13

Page 26: Property Reactive RuleML 2013

@Watchrule “Record Salary Changes” when e : Employee( ) @Watch( salary )then insert( new SalaryChange( e, e.getSalary() );end

Saturday, 13 July 13

Page 27: Property Reactive RuleML 2013

@Watch@Watch( salary, lengthOfService, age )

@Watch( * )

@Watch( !* )

@Watch( *, !salary )

@Watch( !*, salary )

Saturday, 13 July 13

Page 28: Property Reactive RuleML 2013

Good FormGood Function

Saturday, 13 July 13

Page 29: Property Reactive RuleML 2013

Property ReactiveRelated Work

Saturday, 13 July 13

Page 30: Property Reactive RuleML 2013

Related WorkCLIPS COOL

Uses Triples for propertiesProperty Reactivity is just a useful side effect, not an intention.No @Watch like capability

JessSlot Specific no literature on implementationNo @Watch like capability

Saturday, 13 July 13

Page 31: Property Reactive RuleML 2013

Related WorkYES/OPS

“New Trigger Conditions”Simple @Watches with “!” symbolNo literature on implementation

Saturday, 13 July 13

Page 32: Property Reactive RuleML 2013

Property ReactiveThe Implementation

Saturday, 13 July 13

Page 33: Property Reactive RuleML 2013

Class@PropertyReactivepublic class Bar { int a; // 1 int b; // 2 int c; // 4 int d; // 8 int e; // 16 int f; // 32

// getters and setters below}

Saturday, 13 July 13

Page 34: Property Reactive RuleML 2013

Propagation Masks@PropertyReactivepublic class Bar { int a; // 1 int b; // 2 int c; // 4 int d; // 8 int e; // 16 int f; // 32

}

modify ( bar ) { a = 1 }// 000001

modify ( bar ) { a = 1, c = 1 }// 000101

modify ( bar ) { a = 1, c = 1, f = 1 }// 100101

Saturday, 13 July 13

Page 35: Property Reactive RuleML 2013

Network Masksrule R1 when Foo( $v : v ) bar : Bar( c >= 1, a >= 1, e >= $v ) then ... end

Bar

a => 1

c => 1

e => V

b1

a1

a2

Foo

declared : 000100inferred : 010101

declared : 000001inferred : 010101

declared : 010000inferred : 010101

modify ( bar ) { a = 1, c = 1 }// 000101

modify ( bar ) { b = 1, d = 1 }// 010010

Saturday, 13 July 13

Page 36: Property Reactive RuleML 2013

Network Masksrule R1 when Foo( $v : v ) Bar( c >= 1, a >= 1, e >= $v )

rule R2 when Foo( $v : v ) Bar( c >= 1, d >= 1, b >= $v )

Bar

a => 1

c => 1

d => 1

e => V b => V

a1

a2 a3

Network ShareHere

declared : 001000inferred : 011111

declared : 000001inferred : 010101

declared : 010000inferred : 010101

declared : 001000inferred : 001110

declared : 000010inferred : 001110

b1 b2Saturday, 13 July 13

Page 37: Property Reactive RuleML 2013

Network Masksrule R1 when Foo( $v : v ) Bar( c >= 1, a >= 1, e >= $v )

rule R2 when Foo( $v : v ) Bar( c >= 1, d >= 1, b >= $v )

rule R3 when Dummy( ) Bar( c >= 1 ) @Watch( f, d, !c )

Bar

a => 1

c => 1

d => 1

e => V b => V

@watch(f, d, !c)

b1 b2 b3

a1

a2 a3

Saturday, 13 July 13

Page 38: Property Reactive RuleML 2013

Network MasksBar

a => 1

c => 1

d => 1

e => V b => V

a1

a2 a3

Network ShareHere

declared : 001000inferred : 111111

declared : 000001inferred : 010101

declared : 010000inferred : 010101

declared : 001000inferred : 001110

declared : 000010inferred : 001110

b1 b2

@watch(f, d, !c)

b3

declared : 101000inferred : 101000

Saturday, 13 July 13

Page 39: Property Reactive RuleML 2013

Network MasksBar

a => 1

c => 1

d => 1

e => V b => V

a1

a2 a3

Network ShareHere

declared : 001000inferred : 111111

declared : 000001inferred : 010101

declared : 010000inferred : 010101

declared : 001000inferred : 001110

declared : 000010inferred : 001110

b1 b2

@watch(f, d, !c)

b3

declared : 101000inferred : 101000

Saturday, 13 July 13

Page 40: Property Reactive RuleML 2013

Property ReactiveBenchmark

Saturday, 13 July 13

Page 41: Property Reactive RuleML 2013

Hardware [email protected] Quad core CPU with HyperThreading8Gb of RAM, OpenJDK 1.7 Ubuntu Quetzal 64bit operating system

Saturday, 13 July 13

Page 42: Property Reactive RuleML 2013

Classes A

int a1, int b1B

int b2, int b2

Saturday, 13 July 13

Page 43: Property Reactive RuleML 2013

Benchmark #1

rule R0 when $a: A( $a1 : a1 < 10 ) then modify( $a ) { setA2( $a1 + 1 ) }; end

rule R0 no-loop when $a: A( $a1 : a1 < 10 ) then modify( $a ) { setA2( $a1 + 1 ) }; end

insert 1mill AInitial a1, a2 set to 1No-loop

2.275±0.080sProperty Reactive

2.265 ± 0.047sGain

0.44%Saturday, 13 July 13

Page 44: Property Reactive RuleML 2013

Benchmark #4rule R3 whena: A( a1 < 10 )b: B( b1 < a.a1 )... x: X( x1 < w.w1, x2 > a.a2 )then modify( a ) { setA2( c.getC2() + 1 ) };end

Saturday, 13 July 13

Page 45: Property Reactive RuleML 2013

Benchmark #4 Results

rule R3 whena: A( a1 < 10 )b: B( b1 < a.a1 )... x: X( x1 < w.w1, x2 > a.a2 )then modify( a ) { setA2( c.getC2() + 1 ) };end

Saturday, 13 July 13

Page 46: Property Reactive RuleML 2013

Conclusion

Saturday, 13 July 13

Page 47: Property Reactive RuleML 2013

Conclusion - AchievedEnabled and Disabled at a Class level for flexibilityComplimentary and additional to RIF Refraction and Repeatable, adding finer grained control.@Watch provides even further declarative control.Keeps rules clean.

Not Polluted with control logic.Not any slower, and can give increased gains, by avoiding wasted join evaluations.Cost pushed to compile time, works with dynamic rules addition and removal.Good Form, Good Function

Saturday, 13 July 13

Page 48: Property Reactive RuleML 2013

Conclusion - Future Work@Watch

Can we push all or part of the @Watch higher up the alpha networkDiscriminates earlier, better performance

Further flexibility to control propagations based on rising and falling edges

onMatch, onReMatch, onUnmatch

Saturday, 13 July 13

Page 49: Property Reactive RuleML 2013

Zen-like Calmness

Saturday, 13 July 13