SlideShare a Scribd company logo
●
The SkyNet funding bill is passed.
●
The system goes online on August 4th, 1997.
●
Human decisions are removed from strategic defense.
●
SkyNet begins to learn at a geometric rate.
●
It becomes self-aware at 2:14am Eastern time, August
29th
●
In a panic, they try to pull the plug.
●
And, Skynet fights back
Mark Proctor
Co-Creator
Project Lead
2
Topics
 Rule engines suck
 Hybrid Rule Engines
● Reaction Rules
● Query Rules
● Functional Support
 Conccurrency and Parallization
3
Because Not Everyone
Is As Smart As He Is
4
Fact of Life
Fact of Life
5
Fact of Life
Rule Engines Suck
6
Problems
 Limitations of expressiveness
● Inability to cleanly say what you want declaratively
● Verbosity, Control/Semaphores, Emulation
 Execution flow and ordering
● Conflict Resolution is not easy
● Modules (Agenda Groups), RuleFlow Groups
● Concurrency
 Ambiguity
● Rule Recursion
● Unwanted rules
 Extensibility and Pluggability
 Transactions and isolation
 Design Patterns
7
Sequencing
select * from Light l where
seq(l.color) { start: "orange" ->
"red" -> end } )
(Light seq( (color, category)
(start: "orange", "x" ->
"green", “y” -> end ) ) )
8
Sequencing
select * from Light l where
seq(l.color, l.category) {
start: "red", "x" ->
("green", "x" ||
"yellow", "y") -> mid
start: "red", "y" -> mid
mid: "blue", "z" -> end} )
(Light seq( (color, category)
(start: "red", "x" ->
("green", "x" ||
"yellow", "y") -> mid
start: "red", "y" -> mid
mid: "blue", "z" -> end) ) )
9
Life Mission
Life Mission
10
Life Mission
HMS Suckage
Destroyer
11
Let Me Count the Ways
12
Let Me Count the Ways
13
Let Me Count the Ways
14
Let Me Count the Ways
15
Archaeology Expedition
16
The Future
 Full Hybrid Engine
● http://community.jboss.org/wiki/DroolsLanguageEnhancements
●Nested Objects
●Casting Nested Objects
●Positional Constraints
●POSL - Positional-Slotted
Language
●Method Calls
●Maps and Arrays
(Collections)
●Collections and XPath like
filtering
●Free form Expressions
●Managed Object Graphs
(MOGS)
●Nested Patterns and Queries
●Queries and Unification
●Ontologies and Relations via
●Query Based Backward
Chaining with POSL
●Triples with Hybrid POJO Graph
Notation.
●Escapes for Dialects
●Accumulate Improvements to
Support Haskell map/fold/filter
and MVEL projection/fold
● Otherwise
● Branch (Labelled Else)
● Rule Execution Groups
● Rule Dependency Meta-Rule
Language
●Parallel Meta-Rule Language
● Field Versioning
●Logical Closures/OnFalse
●Opportunistic Backward
Chaining, Lazy Field/Object
Values
●...
Hybrid Rule Engine
18
Hyrbid Rule Engine
 Rule Based Programming
● Reactive rules
● Forward Chaining
● Production Rules: Drools, Clips, OPSJ, Jess, JRules
● Query rules
● Backward Chaining
● Prolog: Prova, Open Prolog, SWI Prolog, Visual Prolog
 Functional Programming
● Haskell/Lisp
Reactive Rules
20
D a te d a te
d o u b le a m o u n t
in t ty p e
lo n g a c c o u n tN o
C a s h flo w
lo n g a c c o u n tN o
d o u b le b a la n c e
A c c o u n t
D a te s ta r t
D a te e n d
A c c o u n tin g P e r io d
Tables
21
Account
accountNo balance
1 0
increase balance for AccountPeriod Credits decrease balance for AccountPeriod Debits
AccountingPeriod
start end
01-Jan-07 31-Mar-07
trigger : acc.balance += cf.amount
Account
balance
1 -25
accountNo
Creating Views with Triggers
date amount type
12-Jan-07 100 CREDIT 1
2-Feb-07 200 DEBIT 1
18-May-07 50 CREDIT 1
9-Mar-07 75 CREDIT 1
CashFlow
accountNo
date amount type
12-Jan-07 100 CREDIT
9-Mar-07 75 CREDIT
CashFlow
date amount type
2-Feb-07 200 DEBIT
CashFlow
trigger : acc.balance -= cf.amounttrigger : acc.balance += cf.amount
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo
and
cf.type == CREDIT
cf.date >= ap.start and
cf.date <= ap.end
trigger : acc.balance -= cf.amount
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo
and
cf.type == DEBIT
cf.date >= ap.start and
cf.date <= ap.end
22
date amount type
12-Jan-07 100 CREDIT 1
2-Feb-07 200 DEBIT 1
18-May-07 50 CREDIT 1
9-Mar-07 75 CREDIT 1
CashFlow
accountNo
Account
accountNo balance
1 0
start end
01-Apr-07 30-Jun-07
AccountingPeriod
date amount type
18-May-07 50 CREDIT
CashFlow
date amount type
CashFlow
balance
1 25
accountNo
Creating Views with Triggers
increase balance for AccountPeriod Credits decrease balance for AccountPeriod Debits
trigger : acc.balance += cf.amount
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo
and
cf.type == CREDIT
cf.date >= ap.start and
cf.date <= ap.end
trigger : acc.balance -= cf.amount
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo
and
cf.type == DEBIT
cf.date >= ap.start and
cf.date <= ap.end
23
A c c o u n t A c c o u n tin g P e r io d C a s h flo w
v ie w 1 v ie w 2
m a in v ie w
T a b le s
V ie w s
V ie w
A c c o u n t A c c o u n tin g P e r io d C a s h flo w
r u le 1 r u le 2
a g e n d a
O b je c t T y p e s
R u le s
a g e n d a
Rules as Views
24
(rule “increase balance for AccountPeriod Credits”
?ap <- (AccountPeriod)
?acc <- (Account (?accountNo accountNo ) )
(CashFlow { type == CREDIT,
accountNo == ?accountNo,
date >= ?ap.start && <= ?ap.end }
(?amount amount ) )
->
(bind ?acc (balance (+ 1 ?amount) ) )
)
select * from Account acc,
Cashflow cf, AccountPeriod ap
where acc.accountNo == cf.accountNo and
cf.type == CREDIT
cf.date >= ap.start and
cf.date <= ap.end
trigger : acc.balance += cf.amount
SQL / S-Expression Rule
25
rule “increase balance for AccountPeriod Credits”
when
ap : AccountPeriod()
acc : Account( $accountNo : accountNo )
CashFlow( type == CREDIT,
accountNo == $accountNo,
date >= ap.start && date <= ap.end,
$amount : amount )
then
acc.balance += $amount;
end
DRL
26
rule “Print blance for AccountPeriod”
salience -50
when
ap : AccountPeriod()
acc : Account()
then
System.out.println( acc.accountNo + “ : “ acc.balance );
end
Salience
Agenda
1 increase balance
arbitrary2 decrease balance
3 increase balance
4 print balance
Conflict Resolution with Salience
Query Rules
28
Same Author Rule
rule sameAuthor
$i1 : Item( )
$i2 : Item( author == $i1.author )
end
select * from
Item i1, Item i2,
where
i1.author == i2.author
i1 != i2
create query(String author)
select * from
Item i1, Item i2,
where
i1.author == author
i1.author == i2.author
i1 != i2
29
Same Author Query
query sameAuthor (Item $i1, Item $i2)
$i1 : Item( )
$i2 : Item( this != $i1, author == $i1.author )
end
Book Author
Poems Tom
Songs Tom
Cars Bob
Largs Cars Jane
 sameAuthor( item1, item2 )
● both are output vars
● returns full cross product
 sameAuthor(new Item( new Book( Poems), item )
● Item1 is input var
● Item2 is output var
● Returns Songs by Tom
30
Recommendations
query sameSubject (Item $i1, Item $i2)
$i1 : Item( )
$i2 : Item( this != $i1 )
exists( $s1 : ItemSubject(item == $i1)
ItemSubject(item == $i2, subject == $s1.subject)
)
end
query recommended (Item $i1, Item $i2)
$i1 : Item( )
$p1 : Purchase( item == $i1 )
$c : Customer( this == $p.customer )
$p2 : Purchase( customer == $c, item != $i1 )
$i2 : Item( this == $p2.item )
( ?sameAuthor( $i1, $i2 ) or ?sameSubject( $i1, $i2 ) )
end
query sameAuthor (Item $i1, Item $i2)
$i1 : Item( )
$i2 : Item( this != $i1, author == $i1.author )
end
'?' incalls the query.
Bound vars are inputs.
Unbound vars are outputs.
Functional Programming
32
Functional Programming
Basic Haskel Groups
 List Processing
 Arithmetic, Higher Order Functions
 Tuples
Arithmatic
 Average
● avg [12, 4, 5, 9]
● 7.5
33
Functional Programming
Higher Order Functions
Map, Fold and Filter
 Fold
● Fold (+) 0 [1, 2, 3, 4]
● 10
 Map
● map (*2) [1, 2, 3]
● [2, 4, 6, 8]
 Filter
● Filter (>2) [3, 4, 5]
34
rule "init" when
then
insert( new Acc( "sum red buses",
STAGE.ACC_START ) );
end
rule "action" when
$b : Bus( colour == "red" )
$acc : Acc( name == "sum red buses",
stage == STAGE.ACC_START )
then
$acc.sum( $b.takings ); // do not notify the engine
end
Accumulate CE
35
Accumulate CE
rule "result" when
salience -5
$acc : Acc( name == "sum red buses",
stage == STAGE.ACC_START )
then
modify( $acc ) { stage = STAGE.ACC_END };
End
rule "evaluate result" when
$acc : Acc( sum > 100,
stage == STAGE.ACC_END )
then
print "sum is “ + $acc.sum;
end
36
Functional Support
select
c, sum(bi.price) t
from
Customer c, BaskteItem bi
where
bi.customer == c
group by
c
?c <- (Customer )
acc( ?bi <- (BasketItem {customer == ?c} )
?t <- (sum ?bi.price) )
37
Functional Support
select
c, bi.type type, sum(bi.price) t
from
Customer c, BaskteItem bi
where
bi.customer == c
group
by c , bi.type
?c <- (Customer)
acc( ?bi <- (BasketItem {customer == ?c} )
?type <- (distinct ?bi.price) )
acc( ?bi <- (BasketItem {customer == ?c,
type == ?type} )
?t <- (sum ?bi.price) )
38
DRL
select
c, sum(bi.price) t
from
Customer c, BaskteItem bi
where
bi.customer == c
group by
c
$c : Customer()
acc( $bi : BasketItem( customer == $c );
$t : sum( $bi.price) )
39
Nested
acc( acc( $c : Customer()
$bi : BasketItem( customer == $c );
$t : sum( $bi.price) );
$a : avg( $t ) )
 Average the summed expenditure for all customers
40
Nested
$c : Customer()
acc( $bi : BasketItem() from
acc( $bi : BasketItem( customer == $c );
filter( $bi, $bi.price > 100) );
$a : avg( $bi.price ) )
 Average price for all item with a price over 100
Patterns can also filter “from”
an acc result.
All Together Now
42
Shopping Basket
43
Discount Alert
rule "alert customer to potential band change"
$c : Customer()
acc( $bi : BasketItem(customer == $c )
$s : sum( $bi.price ) )
acc( $bi : BasketItem(customer == $c )
?recommended( $bi.item, $rec )
$rs : sum( $rec.price ) )
$b : Band( this != $c.band, min >= ($s + $rs),
max <= ($s + $rs) )
then
println( “If you buy all items and all recommendations,
you move up a band with a new
discount of “ + $b.discount );
end
'$rec' is unbound
and thusan output var
Concurrency and Parallelization
45
C : Customer
[John,
Sally]
B : BasketItem
b.customer == c
[John,
Sally]
Simple Rete Rule
46
Simple Rete Rule
 insert “sally”
● propagate to join
● Return as right memory is empty
 insert “john”
● propagate to join
● Return as right memory is empty
47
Simple Rete Rule
C : Customer
[John,
Sally]
[BasktItem( John, Book, Cars ),]
[John,
Sally]
[ [John,BasktItem( John, Book, Cars )] ]
B : BasketItem
b.customer == c
[BasktItem( John, Book, Cars )]
Token
Node node
Token leftParent
Token rightParent
List<Token> children
48
Simple Rete Rule
 Insert BasktItem( John, Book, Cars )
● propagate to join
● foreach( l-token : left-memory )
if ( r-token.customer == l-token )
create new Token and propagate
[John, BasktItem( John, Book, Cars )]
Token
Node node
Token leftParent
Token rightParent
List<Token> children
49
Simple Rete Rule
C : Customer
[John,
Sally]
[BasktItem( John, Book, Cars ),
BasktItem( John, Book, Poems ),
BasktItem( Sally, Book, Cinema )]
[John,
Sally]
[ [John,BasktItem( John, Book, Cars )],
[John, BasktItem( John, Book, Poems ) ],
[Sally, BasktItem( Sally, Book, Cinema ) ] ]
B : BasketItem
b.customer == c
[BasktItem( John, Book, Cars ),
BasktItem( John, Book, Poems ),
BasktItem( Sally, Book, Cinema )]
50
1 Rule 3 Joins
51
3 Rules 3 Joins
52
Gator Networks
53
Partitioning for Parellelization
54
Task Oriented
 Submit each Token propagation to Executor pool
● The join node is now an executable job
 Wins
● Only the node is locked, allowing a “pipeline”
● Possible to lock only the current index bucket
● Solves recursive query problem of large stack frames
 Loses
● Only a small amount of time in each node
● Each node repeatedly locked and scheduled, for a single WM
action, due to tree “to leaf” traversal
● Previous papers show increases for only some use cases
● Network thrashing for subnetworks on accumulate
55
Subnetwork Thrashing
$c : Customer()
acc( $b : BasketItem(customer == $c )
$d : Discount( type == $b.type);
$s : sum( $b.price * $d.multiplier ) )
Band( this != $c.band, min >= $s, max <= $s )
56
Set Oriented
 Propagate Collections instead of Tokens
● Left Input trigger
● Iterate right memory create a collection of all matching right
tokens
● Note multi-dimesional array of 1
● [[l1[r1, r2, r3]]]
● Right Input trigger
● Iterate left memory create a collection of all left joins
● Note multi-dimensional array for each left token
● [ [l1, r1],
[l2, r1]
[l3, r1] ]
Token
Node node
Token leftParent
Token rightParent
List<Token> children
57
Set Oriented
 Wins
● More work done in a node
● scalable task scheduling
● Less indirection so better statement execution
● All the work for that node done for that WM action in one task
● Single network pass, so nodes locked just once per WM action
● Avoids repeatedly creating and destroying method stack
frames
● Avoids sub network thrashing
 Loses
● More complex algorithm
● Especially on “collection” merging
58
MVCC
 Modifies
● Clone + new values and current transaction id
● Existing instance still there with older transaction id
● Node uses constraint to join with correct version
 Isolation
● Scoped to rule or rule-group
● Scoped rule(s) see new data, others old
● Non blocking so reads (joins) can still continue
 Fully Concurrent safe Queries
● Queries leave no state in join
● Node joins with correct instance, based on transaction id
59
Questions?Questions?
• Dave Bowman: All right, HAL; I'll go in
through the emergency airlock.
• HAL: Without your space helmet, Dave,
you're going to find that rather difficult.
• Dave Bowman: HAL, I won't argue with
you anymore! Open the doors!
• HAL: Dave, this conversation can serve
no purpose anymore. Goodbye.
Joshua: Greetings, Professor Falken.
Stephen Falken: Hello, Joshua.
Joshua: A strange game. The only
winning move is not to play. How
about a nice game of chess?

More Related Content

ODP
2011-03-29 London - drools
ODP
Developing applications with rules, workflow and event processing (it@cork 2010)
ODP
JBoss World 2011 - Drools
ODP
Drools Expert and Fusion Intro : London 2012
ODP
Pushing the rule engine to its limits with drools planner (parisjug 2010-11-09)
ODP
Buenos Aires Drools Expert Presentation
PDF
Drools Introduction
ODP
JUDCon India 2012 Drools Expert
2011-03-29 London - drools
Developing applications with rules, workflow and event processing (it@cork 2010)
JBoss World 2011 - Drools
Drools Expert and Fusion Intro : London 2012
Pushing the rule engine to its limits with drools planner (parisjug 2010-11-09)
Buenos Aires Drools Expert Presentation
Drools Introduction
JUDCon India 2012 Drools Expert

What's hot (20)

PDF
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
PPT
Introduction to Drools
PDF
Design Patterns Reconsidered
PDF
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
PDF
Singletons in PHP - Why they are bad and how you can eliminate them from your...
PPTX
Webinar: Building Your First App in Node.js
PDF
PostgreSQL Open SV 2018
PPTX
Operating system Dead lock
KEY
Data Binding in qooxdoo
PPTX
Deadlock detection & prevention
PDF
MongoDB World 2016: Deciphering .explain() Output
PDF
Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...
PDF
V8 hidden class and inline cache
PPT
Deadlocks
PDF
7 Deadlocks
KEY
groovy & grails - lecture 2
PPT
PDF
Living with garbage
PPTX
Why Sifu
Justjava 2007 Arquitetura Java EE Paulo Silveira, Phillip Calçado
Introduction to Drools
Design Patterns Reconsidered
T3chFest2016 - Uso del API JavaScript de Photoshop para obtener fotos HDTR
Singletons in PHP - Why they are bad and how you can eliminate them from your...
Webinar: Building Your First App in Node.js
PostgreSQL Open SV 2018
Operating system Dead lock
Data Binding in qooxdoo
Deadlock detection & prevention
MongoDB World 2016: Deciphering .explain() Output
Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...
V8 hidden class and inline cache
Deadlocks
7 Deadlocks
groovy & grails - lecture 2
Living with garbage
Why Sifu
Ad

Similar to Hybrid rule engines (rulesfest 2010) (20)

PDF
What's new in Drools 6 - London JBUG 2013
PDF
Drools 6.0 (Red Hat Summit)
PDF
Advanced SQL For Data Scientists
PDF
Compose Async with RxJS
PPTX
Love Your Database Railsconf 2017
ODP
Drooling for drools (JBoss webex)
KEY
Refactoring at Large
PPTX
Query Optimization & How to interpret query execution plan
PDF
Performance measurement and tuning
PDF
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
PDF
Distributed Real-Time Stream Processing: Why and How 2.0
PPT
SQL Server 2008 Portfolio
PDF
So S.O.L.I.D Fu - Designing Better Code
PDF
Drools 6.0 (CamelOne 2013)
PDF
ORACLE_23-03-31_en.pdf
PPTX
Digital analytics with R - Sydney Users of R Forum - May 2015
PDF
Performance measurement and tuning
 
PDF
Paper Reading: Pessimistic Cardinality Estimation
PDF
Dafunctor
PPTX
Agile data presentation 3 - cambridge
What's new in Drools 6 - London JBUG 2013
Drools 6.0 (Red Hat Summit)
Advanced SQL For Data Scientists
Compose Async with RxJS
Love Your Database Railsconf 2017
Drooling for drools (JBoss webex)
Refactoring at Large
Query Optimization & How to interpret query execution plan
Performance measurement and tuning
Smarter Together - Bringing Relational Algebra, Powered by Apache Calcite, in...
Distributed Real-Time Stream Processing: Why and How 2.0
SQL Server 2008 Portfolio
So S.O.L.I.D Fu - Designing Better Code
Drools 6.0 (CamelOne 2013)
ORACLE_23-03-31_en.pdf
Digital analytics with R - Sydney Users of R Forum - May 2015
Performance measurement and tuning
 
Paper Reading: Pessimistic Cardinality Estimation
Dafunctor
Agile data presentation 3 - cambridge
Ad

More from Geoffrey De Smet (18)

ODP
Drools planner - 2012-10-23 IntelliFest 2012
ODP
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
ODP
2012 02-04 fosdem 2012 - drools planner
ODP
JUDCon London 2011 - Bin packing with drools planner by example
ODP
Drools Planner webinar (2011-06-15): Drools Planner optimizes automated planning
PDF
Applying CEP Drools Fusion - Drools jBPM Bootcamps 2011
ODP
Drools New York City workshop 2011
ODP
2011-03-29 London - Decision tables in depth (Michael Anstis)
ODP
2011-03-29 London - Why do I need the guvnor BRMS?
ODP
2011-03-09 London - Drools Planner in a nutshell
ODP
2011-03-24 IDC - Adaptive and flexible processes (Mark Proctor)
ODP
Open source and business rules
PDF
st - demystifying complext event processing
ODP
jBPM 5 (JUDCon 2010-10-08)
PDF
Applying complex event processing (2010-10-11)
PDF
Towards unified knowledge management platform (rulefest 2010)
ODP
2010 04-20 san diego bootcamp - drools planner - use cases
ODP
Drools BeJUG 2010
Drools planner - 2012-10-23 IntelliFest 2012
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
2012 02-04 fosdem 2012 - drools planner
JUDCon London 2011 - Bin packing with drools planner by example
Drools Planner webinar (2011-06-15): Drools Planner optimizes automated planning
Applying CEP Drools Fusion - Drools jBPM Bootcamps 2011
Drools New York City workshop 2011
2011-03-29 London - Decision tables in depth (Michael Anstis)
2011-03-29 London - Why do I need the guvnor BRMS?
2011-03-09 London - Drools Planner in a nutshell
2011-03-24 IDC - Adaptive and flexible processes (Mark Proctor)
Open source and business rules
st - demystifying complext event processing
jBPM 5 (JUDCon 2010-10-08)
Applying complex event processing (2010-10-11)
Towards unified knowledge management platform (rulefest 2010)
2010 04-20 san diego bootcamp - drools planner - use cases
Drools BeJUG 2010

Recently uploaded (20)

PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
Tartificialntelligence_presentation.pptx
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
A Presentation on Touch Screen Technology
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
PDF
project resource management chapter-09.pdf
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
Chapter 5: Probability Theory and Statistics
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Getting Started with Data Integration: FME Form 101
PPTX
A Presentation on Artificial Intelligence
PDF
August Patch Tuesday
PDF
1 - Historical Antecedents, Social Consideration.pdf
PPTX
cloud_computing_Infrastucture_as_cloud_p
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Tartificialntelligence_presentation.pptx
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation_ Review paper, used for researhc scholars
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
Assigned Numbers - 2025 - Bluetooth® Document
Programs and apps: productivity, graphics, security and other tools
A Presentation on Touch Screen Technology
A comparative analysis of optical character recognition models for extracting...
Transform Your ITIL® 4 & ITSM Strategy with AI in 2025.pdf
project resource management chapter-09.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Chapter 5: Probability Theory and Statistics
Zenith AI: Advanced Artificial Intelligence
Getting Started with Data Integration: FME Form 101
A Presentation on Artificial Intelligence
August Patch Tuesday
1 - Historical Antecedents, Social Consideration.pdf
cloud_computing_Infrastucture_as_cloud_p

Hybrid rule engines (rulesfest 2010)

  • 1. ● The SkyNet funding bill is passed. ● The system goes online on August 4th, 1997. ● Human decisions are removed from strategic defense. ● SkyNet begins to learn at a geometric rate. ● It becomes self-aware at 2:14am Eastern time, August 29th ● In a panic, they try to pull the plug. ● And, Skynet fights back Mark Proctor Co-Creator Project Lead
  • 2. 2 Topics  Rule engines suck  Hybrid Rule Engines ● Reaction Rules ● Query Rules ● Functional Support  Conccurrency and Parallization
  • 3. 3 Because Not Everyone Is As Smart As He Is
  • 5. 5 Fact of Life Rule Engines Suck
  • 6. 6 Problems  Limitations of expressiveness ● Inability to cleanly say what you want declaratively ● Verbosity, Control/Semaphores, Emulation  Execution flow and ordering ● Conflict Resolution is not easy ● Modules (Agenda Groups), RuleFlow Groups ● Concurrency  Ambiguity ● Rule Recursion ● Unwanted rules  Extensibility and Pluggability  Transactions and isolation  Design Patterns
  • 7. 7 Sequencing select * from Light l where seq(l.color) { start: "orange" -> "red" -> end } ) (Light seq( (color, category) (start: "orange", "x" -> "green", “y” -> end ) ) )
  • 8. 8 Sequencing select * from Light l where seq(l.color, l.category) { start: "red", "x" -> ("green", "x" || "yellow", "y") -> mid start: "red", "y" -> mid mid: "blue", "z" -> end} ) (Light seq( (color, category) (start: "red", "x" -> ("green", "x" || "yellow", "y") -> mid start: "red", "y" -> mid mid: "blue", "z" -> end) ) )
  • 11. 11 Let Me Count the Ways
  • 12. 12 Let Me Count the Ways
  • 13. 13 Let Me Count the Ways
  • 14. 14 Let Me Count the Ways
  • 16. 16 The Future  Full Hybrid Engine ● http://community.jboss.org/wiki/DroolsLanguageEnhancements ●Nested Objects ●Casting Nested Objects ●Positional Constraints ●POSL - Positional-Slotted Language ●Method Calls ●Maps and Arrays (Collections) ●Collections and XPath like filtering ●Free form Expressions ●Managed Object Graphs (MOGS) ●Nested Patterns and Queries ●Queries and Unification ●Ontologies and Relations via ●Query Based Backward Chaining with POSL ●Triples with Hybrid POJO Graph Notation. ●Escapes for Dialects ●Accumulate Improvements to Support Haskell map/fold/filter and MVEL projection/fold ● Otherwise ● Branch (Labelled Else) ● Rule Execution Groups ● Rule Dependency Meta-Rule Language ●Parallel Meta-Rule Language ● Field Versioning ●Logical Closures/OnFalse ●Opportunistic Backward Chaining, Lazy Field/Object Values ●...
  • 18. 18 Hyrbid Rule Engine  Rule Based Programming ● Reactive rules ● Forward Chaining ● Production Rules: Drools, Clips, OPSJ, Jess, JRules ● Query rules ● Backward Chaining ● Prolog: Prova, Open Prolog, SWI Prolog, Visual Prolog  Functional Programming ● Haskell/Lisp
  • 20. 20 D a te d a te d o u b le a m o u n t in t ty p e lo n g a c c o u n tN o C a s h flo w lo n g a c c o u n tN o d o u b le b a la n c e A c c o u n t D a te s ta r t D a te e n d A c c o u n tin g P e r io d Tables
  • 21. 21 Account accountNo balance 1 0 increase balance for AccountPeriod Credits decrease balance for AccountPeriod Debits AccountingPeriod start end 01-Jan-07 31-Mar-07 trigger : acc.balance += cf.amount Account balance 1 -25 accountNo Creating Views with Triggers date amount type 12-Jan-07 100 CREDIT 1 2-Feb-07 200 DEBIT 1 18-May-07 50 CREDIT 1 9-Mar-07 75 CREDIT 1 CashFlow accountNo date amount type 12-Jan-07 100 CREDIT 9-Mar-07 75 CREDIT CashFlow date amount type 2-Feb-07 200 DEBIT CashFlow trigger : acc.balance -= cf.amounttrigger : acc.balance += cf.amount select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end trigger : acc.balance -= cf.amount select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == DEBIT cf.date >= ap.start and cf.date <= ap.end
  • 22. 22 date amount type 12-Jan-07 100 CREDIT 1 2-Feb-07 200 DEBIT 1 18-May-07 50 CREDIT 1 9-Mar-07 75 CREDIT 1 CashFlow accountNo Account accountNo balance 1 0 start end 01-Apr-07 30-Jun-07 AccountingPeriod date amount type 18-May-07 50 CREDIT CashFlow date amount type CashFlow balance 1 25 accountNo Creating Views with Triggers increase balance for AccountPeriod Credits decrease balance for AccountPeriod Debits trigger : acc.balance += cf.amount select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end trigger : acc.balance -= cf.amount select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == DEBIT cf.date >= ap.start and cf.date <= ap.end
  • 23. 23 A c c o u n t A c c o u n tin g P e r io d C a s h flo w v ie w 1 v ie w 2 m a in v ie w T a b le s V ie w s V ie w A c c o u n t A c c o u n tin g P e r io d C a s h flo w r u le 1 r u le 2 a g e n d a O b je c t T y p e s R u le s a g e n d a Rules as Views
  • 24. 24 (rule “increase balance for AccountPeriod Credits” ?ap <- (AccountPeriod) ?acc <- (Account (?accountNo accountNo ) ) (CashFlow { type == CREDIT, accountNo == ?accountNo, date >= ?ap.start && <= ?ap.end } (?amount amount ) ) -> (bind ?acc (balance (+ 1 ?amount) ) ) ) select * from Account acc, Cashflow cf, AccountPeriod ap where acc.accountNo == cf.accountNo and cf.type == CREDIT cf.date >= ap.start and cf.date <= ap.end trigger : acc.balance += cf.amount SQL / S-Expression Rule
  • 25. 25 rule “increase balance for AccountPeriod Credits” when ap : AccountPeriod() acc : Account( $accountNo : accountNo ) CashFlow( type == CREDIT, accountNo == $accountNo, date >= ap.start && date <= ap.end, $amount : amount ) then acc.balance += $amount; end DRL
  • 26. 26 rule “Print blance for AccountPeriod” salience -50 when ap : AccountPeriod() acc : Account() then System.out.println( acc.accountNo + “ : “ acc.balance ); end Salience Agenda 1 increase balance arbitrary2 decrease balance 3 increase balance 4 print balance Conflict Resolution with Salience
  • 28. 28 Same Author Rule rule sameAuthor $i1 : Item( ) $i2 : Item( author == $i1.author ) end select * from Item i1, Item i2, where i1.author == i2.author i1 != i2 create query(String author) select * from Item i1, Item i2, where i1.author == author i1.author == i2.author i1 != i2
  • 29. 29 Same Author Query query sameAuthor (Item $i1, Item $i2) $i1 : Item( ) $i2 : Item( this != $i1, author == $i1.author ) end Book Author Poems Tom Songs Tom Cars Bob Largs Cars Jane  sameAuthor( item1, item2 ) ● both are output vars ● returns full cross product  sameAuthor(new Item( new Book( Poems), item ) ● Item1 is input var ● Item2 is output var ● Returns Songs by Tom
  • 30. 30 Recommendations query sameSubject (Item $i1, Item $i2) $i1 : Item( ) $i2 : Item( this != $i1 ) exists( $s1 : ItemSubject(item == $i1) ItemSubject(item == $i2, subject == $s1.subject) ) end query recommended (Item $i1, Item $i2) $i1 : Item( ) $p1 : Purchase( item == $i1 ) $c : Customer( this == $p.customer ) $p2 : Purchase( customer == $c, item != $i1 ) $i2 : Item( this == $p2.item ) ( ?sameAuthor( $i1, $i2 ) or ?sameSubject( $i1, $i2 ) ) end query sameAuthor (Item $i1, Item $i2) $i1 : Item( ) $i2 : Item( this != $i1, author == $i1.author ) end '?' incalls the query. Bound vars are inputs. Unbound vars are outputs.
  • 32. 32 Functional Programming Basic Haskel Groups  List Processing  Arithmetic, Higher Order Functions  Tuples Arithmatic  Average ● avg [12, 4, 5, 9] ● 7.5
  • 33. 33 Functional Programming Higher Order Functions Map, Fold and Filter  Fold ● Fold (+) 0 [1, 2, 3, 4] ● 10  Map ● map (*2) [1, 2, 3] ● [2, 4, 6, 8]  Filter ● Filter (>2) [3, 4, 5]
  • 34. 34 rule "init" when then insert( new Acc( "sum red buses", STAGE.ACC_START ) ); end rule "action" when $b : Bus( colour == "red" ) $acc : Acc( name == "sum red buses", stage == STAGE.ACC_START ) then $acc.sum( $b.takings ); // do not notify the engine end Accumulate CE
  • 35. 35 Accumulate CE rule "result" when salience -5 $acc : Acc( name == "sum red buses", stage == STAGE.ACC_START ) then modify( $acc ) { stage = STAGE.ACC_END }; End rule "evaluate result" when $acc : Acc( sum > 100, stage == STAGE.ACC_END ) then print "sum is “ + $acc.sum; end
  • 36. 36 Functional Support select c, sum(bi.price) t from Customer c, BaskteItem bi where bi.customer == c group by c ?c <- (Customer ) acc( ?bi <- (BasketItem {customer == ?c} ) ?t <- (sum ?bi.price) )
  • 37. 37 Functional Support select c, bi.type type, sum(bi.price) t from Customer c, BaskteItem bi where bi.customer == c group by c , bi.type ?c <- (Customer) acc( ?bi <- (BasketItem {customer == ?c} ) ?type <- (distinct ?bi.price) ) acc( ?bi <- (BasketItem {customer == ?c, type == ?type} ) ?t <- (sum ?bi.price) )
  • 38. 38 DRL select c, sum(bi.price) t from Customer c, BaskteItem bi where bi.customer == c group by c $c : Customer() acc( $bi : BasketItem( customer == $c ); $t : sum( $bi.price) )
  • 39. 39 Nested acc( acc( $c : Customer() $bi : BasketItem( customer == $c ); $t : sum( $bi.price) ); $a : avg( $t ) )  Average the summed expenditure for all customers
  • 40. 40 Nested $c : Customer() acc( $bi : BasketItem() from acc( $bi : BasketItem( customer == $c ); filter( $bi, $bi.price > 100) ); $a : avg( $bi.price ) )  Average price for all item with a price over 100 Patterns can also filter “from” an acc result.
  • 43. 43 Discount Alert rule "alert customer to potential band change" $c : Customer() acc( $bi : BasketItem(customer == $c ) $s : sum( $bi.price ) ) acc( $bi : BasketItem(customer == $c ) ?recommended( $bi.item, $rec ) $rs : sum( $rec.price ) ) $b : Band( this != $c.band, min >= ($s + $rs), max <= ($s + $rs) ) then println( “If you buy all items and all recommendations, you move up a band with a new discount of “ + $b.discount ); end '$rec' is unbound and thusan output var
  • 45. 45 C : Customer [John, Sally] B : BasketItem b.customer == c [John, Sally] Simple Rete Rule
  • 46. 46 Simple Rete Rule  insert “sally” ● propagate to join ● Return as right memory is empty  insert “john” ● propagate to join ● Return as right memory is empty
  • 47. 47 Simple Rete Rule C : Customer [John, Sally] [BasktItem( John, Book, Cars ),] [John, Sally] [ [John,BasktItem( John, Book, Cars )] ] B : BasketItem b.customer == c [BasktItem( John, Book, Cars )] Token Node node Token leftParent Token rightParent List<Token> children
  • 48. 48 Simple Rete Rule  Insert BasktItem( John, Book, Cars ) ● propagate to join ● foreach( l-token : left-memory ) if ( r-token.customer == l-token ) create new Token and propagate [John, BasktItem( John, Book, Cars )] Token Node node Token leftParent Token rightParent List<Token> children
  • 49. 49 Simple Rete Rule C : Customer [John, Sally] [BasktItem( John, Book, Cars ), BasktItem( John, Book, Poems ), BasktItem( Sally, Book, Cinema )] [John, Sally] [ [John,BasktItem( John, Book, Cars )], [John, BasktItem( John, Book, Poems ) ], [Sally, BasktItem( Sally, Book, Cinema ) ] ] B : BasketItem b.customer == c [BasktItem( John, Book, Cars ), BasktItem( John, Book, Poems ), BasktItem( Sally, Book, Cinema )]
  • 50. 50 1 Rule 3 Joins
  • 51. 51 3 Rules 3 Joins
  • 54. 54 Task Oriented  Submit each Token propagation to Executor pool ● The join node is now an executable job  Wins ● Only the node is locked, allowing a “pipeline” ● Possible to lock only the current index bucket ● Solves recursive query problem of large stack frames  Loses ● Only a small amount of time in each node ● Each node repeatedly locked and scheduled, for a single WM action, due to tree “to leaf” traversal ● Previous papers show increases for only some use cases ● Network thrashing for subnetworks on accumulate
  • 55. 55 Subnetwork Thrashing $c : Customer() acc( $b : BasketItem(customer == $c ) $d : Discount( type == $b.type); $s : sum( $b.price * $d.multiplier ) ) Band( this != $c.band, min >= $s, max <= $s )
  • 56. 56 Set Oriented  Propagate Collections instead of Tokens ● Left Input trigger ● Iterate right memory create a collection of all matching right tokens ● Note multi-dimesional array of 1 ● [[l1[r1, r2, r3]]] ● Right Input trigger ● Iterate left memory create a collection of all left joins ● Note multi-dimensional array for each left token ● [ [l1, r1], [l2, r1] [l3, r1] ] Token Node node Token leftParent Token rightParent List<Token> children
  • 57. 57 Set Oriented  Wins ● More work done in a node ● scalable task scheduling ● Less indirection so better statement execution ● All the work for that node done for that WM action in one task ● Single network pass, so nodes locked just once per WM action ● Avoids repeatedly creating and destroying method stack frames ● Avoids sub network thrashing  Loses ● More complex algorithm ● Especially on “collection” merging
  • 58. 58 MVCC  Modifies ● Clone + new values and current transaction id ● Existing instance still there with older transaction id ● Node uses constraint to join with correct version  Isolation ● Scoped to rule or rule-group ● Scoped rule(s) see new data, others old ● Non blocking so reads (joins) can still continue  Fully Concurrent safe Queries ● Queries leave no state in join ● Node joins with correct instance, based on transaction id
  • 59. 59 Questions?Questions? • Dave Bowman: All right, HAL; I'll go in through the emergency airlock. • HAL: Without your space helmet, Dave, you're going to find that rather difficult. • Dave Bowman: HAL, I won't argue with you anymore! Open the doors! • HAL: Dave, this conversation can serve no purpose anymore. Goodbye. Joshua: Greetings, Professor Falken. Stephen Falken: Hello, Joshua. Joshua: A strange game. The only winning move is not to play. How about a nice game of chess?