Drools and Rule Based Systems Srinath Perera
Rule Engine Terms Expert Systems / Business rules engine / Production Systems / Inference Engines are used to address rule engines based on their implementations.  Usually a Rule engine usually includes three parts.  Facts represented as working memory or another set of rules e.g. Prolog  road(a,b) or Drools objects Set of rules that declaratively define conditions or situations e.g. Prolog route(X,Z) <- road(X,Z) Actions executed or inference derived based on the rules
Rules Allow users to specify the requirements declarative, using a logic based languages. (Say what should happen, not how to do it). Rules may trigger other rules.  Four types of rules (from http://www.w3.org/2000/10/swap/doc/rule-systems) Derivation or Deduction Rules – Each rules express if some  statements are true, another statement must be true. Called logical implication.  E.g. Prolog Transformation Rules- transform between knowledge bases, e.g. therom proving Integrity Constraints – verification rules  Reaction or Event-Condition-Action (ECA) Rules – includes a actions in addition to inference.  e.g. Drools
Production Systems  Drools belongs to the category of rule engines called  production systems [1] (which execute actions based on conditions) Drools use forward  chaining[2] (start with data and execute actions to infer more data ) Priorities assigned to rules are used to decide the order of rule execution They remember all results and use that to optimize new derivations (dynamic programming like) http://en.wikipedia.org/wiki/AI_production http://en.wikipedia.org/wiki/Forward_chaining
Why rule engines? ~[1],[2][3] Simplify complicated requirements with declarative logic, raising the level of abstraction of the system Externalize the business logic (which are too dynamic) from comparatively static code base Intuitive and readable than code, easily understood by business people/ non technical users Create complex interactions which can have powerful results, even from simple facts and rules. Different approach to the problem, some problem are much easier using rules. Ability to specify explicit time and dates for rules to take effect Real-World Rule Engines  http://www.infoq.com/articles/Rule-Engines   Why are business rules better than traditional code?  http://www.edmblog.com/weblog/2005/11/why_are_busines.html   Rules-based Programming with JBoss Rules/Drools  www.codeodor.com
When not to use rule engines? It is slower then usual code most of the time, so unless one of the following is true is should not be used Complexity of logic is hard to tackle Logic changes too often Required to use by non technical users Interactions between rules could be quite complex, and one mistake could change the results drastically and unexpected way e.g recursive rules Due to above testing and debugging is  required, so if results are hard to verified it should not be used.
Drools Facts as a Object repository of java objects New objects can be added, removed or updated support if <query> then <action> type rules Queries use OOP format  Support  not, or, and, forall  and  exists  completing first order logic
Patterns Have a OOP based intuitive rule format. We presents examples using a insurance quota example.  Following rule reject all customers whose age less than 17.  rule &quot;MinimumAge&quot; when     c : Customer(age < 17) then     c.reject(); end Conditions support <, >, ==, <=, >=, matches / not matches, contains / not contains. And following rules provide a discount if customer is married or older than 25.  rule &quot;Discount&quot; when     c : Customer( married == true || age > 25) then     c.addDiscount(10); end
OR, AND, eval() OR – true if either of the statements true E.g. Customer(age > 50) or Vehicle( year > 2000) AND – provide logical, if no connectivity is define between two statements, “and” is assumed by default. For an example.  c : Customer( timeSinceJoin > 2);  not (Accident(customerid == c.name)) and c : Customer( timeSinceJoin > 2) and      not (Accident(customerid == c.name))  are the same.  eval(boolean expressions) – with eval(..) any Boolean expression can be used.  E.g.  C:Customer(age > 20) eval(C.calacuatePremium() > 1000)
Not Not – negation or none can be found. E.g.  not Plan( type = “home”)   is true if no plan of type home is found. Following is true if customer has take part in no accidents.  rule &quot;NoAccident&quot; when     c : Customer( timeSinceJoin > 2);      not (Accident(customerid == c.name)) then     c.addDiscount(10); end
For all True if all objects selected by first part of the query satisfies rest of the conditions. For an example following rule give 25 discount to customers who has brought every type of plans offered.  rule &quot;OtherPlans&quot; when     forall ($plan : PlanCategory() c : Customer(plans contains $plan)) then     c.addDiscount(25); end
Exists True if at least one matches the query,  This is Different for just having Customer(), which is like for each which get invoked for each matching set. Following rule give a discount for each family where two members having plans rule “FamilyMembers&quot; when   $c : Customer()      exists (Customer( name contains $c.family)) then     c.addDiscount(5); end
Conflict resolution Each rule may define attributes There are other parameters you can found from [1]. E.g.  rule &quot;MinimumAge&quot; salience  = 10 when     c : Customer(age < 17) then     c.reject(); end salience define priority of the rule and decide their activation order.  http://labs.jboss.com/drools/documentation.html
Drools Performance Measuring Rule engine performance is tricky.  Main factors are number of objects and number of rules. But results depends on nature of rules.  A user feedback [1] claims Drools about 4 times faster than JRules [4].  [2] shows a comparison between Drools, Jess [5] and Microsoft rule engine. Overall they are comparable in performance.   http://blog.athico.com/2007/08/drools-vs-jrules-performance-and-future.html http://geekswithblogs.net/cyoung/articles/54022.aspx   Jess -  http://herzberg.ca.sandia.gov/jess/ JRules  http://www.ilog.com/products/jrules/   (Sequential\Rete) 16ms/15ms 4ms/4ms 100 1219 JRules Drools Objects rules
Drools Performance Contd. I have ran the well known rule engine bench mark [1] implementation provided with Drools. (On linbox3 - 1GB memory,  4 CPU 3.20GHz  ) http://www.cs.utexas.edu/ftp/pub/ops5-benchmark-suite/HOW.TO.USE  2642 1305 34 1661 1001 34 956 697 34 420 393 34 Waltz DB 9030 3873 31 1582 958 31 Waltz Time (ms) Object  Count Rule Count Bench Marks
Data Mining Use Case
Rule based Solution We represent Queries as Objects that include bounds and list of selected data products  We represent Data products as Objects that include location and time it was collected.  Then following two rules will solve the problem Rule 1. For each data item, if it match spatial and temporal boundaries, add it to data collected for query Rule 2. When temporal end time is passed, invoke the data mining workflow with collected data
 
Concrete Rules RULE 1. For each data item, if it match spatial and temporal boundaries of a Query, add it to data collected for query  when       q: Query(completed = false);       d: Data( x > q.minX && x < q.maxX  && y > q.minY && y < q.maxY  && timeStamp > q.start && timestamp < q.end)  then       q.addDataProduct(d);  end  RULE 2. When temporal end time is passed, invoke the data mining workflow with collected data when       system:System()       q: Query(completed = false, end < system.currentTime);  then       q.completed = true;       q.runDataMiningAndInvokeWorkflow();  end
Conclusion Drools provide a OOP based intuitive rule language based on Rete (which is state of art public algorithm) It has good  performance, comparable with Jess (which I not free).  It is Open source, has a healthy and active community and JBoss cooperation backing it Extensively used in business rule community

More Related Content

PDF
Introducing Drools
PDF
Rules Programming tutorial
PDF
Developing Configurable and High Performance Apps in Drools
PPTX
JBoss Drools - Pure Java Rule Engine
PPT
Introduction to Drools
PPTX
Rule Engine & Drools
PDF
Drools
PPTX
Rule Engine: Drools .Net
Introducing Drools
Rules Programming tutorial
Developing Configurable and High Performance Apps in Drools
JBoss Drools - Pure Java Rule Engine
Introduction to Drools
Rule Engine & Drools
Drools
Rule Engine: Drools .Net

What's hot (19)

ODP
Drools BeJUG 2010
ODP
Drools & jBPM Info Sheet
PPTX
Drools Ecosystem
PDF
Rules Engine - java(Drools) & ruby(ruleby)
PPTX
Jboss drools 4 scope - benefits, shortfalls
PPTX
Drools
PPTX
Rules engine
PPTX
Data structures
ODP
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
PDF
Brms best practices_2011_oct_final
PPT
Effective Spring Transaction Management
PPTX
[Java eeconf 2016] spring jta principles of work with transactions. Dmytro S...
KEY
SOLID Principles
DOCX
TY.BSc.IT Java QB U2
PPT
Spring Transaction
PPS
CS101- Introduction to Computing- Lecture 23
ODP
Java Persistence API
PDF
Meg bernal insight2014 4219
PPT
Slice: OpenJPA for Distributed Persistence
Drools BeJUG 2010
Drools & jBPM Info Sheet
Drools Ecosystem
Rules Engine - java(Drools) & ruby(ruleby)
Jboss drools 4 scope - benefits, shortfalls
Drools
Rules engine
Data structures
What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference
Brms best practices_2011_oct_final
Effective Spring Transaction Management
[Java eeconf 2016] spring jta principles of work with transactions. Dmytro S...
SOLID Principles
TY.BSc.IT Java QB U2
Spring Transaction
CS101- Introduction to Computing- Lecture 23
Java Persistence API
Meg bernal insight2014 4219
Slice: OpenJPA for Distributed Persistence
Ad

Similar to Droolsand Rule Based Systems 2008 Srping (20)

PPTX
Drools rule Concepts
ODP
Buenos Aires Drools Expert Presentation
ODP
2011-03-29 London - drools
ODP
JBoss World 2011 - Drools
ODP
JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTE
PPT
Flex 360 Rules Engine
PPT
Flex 360 Rules Engine
PPT
Obey The Rules: Implementing a Rules Engine in Flex
ODP
rules, events and workflow
PDF
Drools JBoss Rules 5 0 developer s guide develop rules based business logic u...
ODP
Drools New York City workshop 2011
PPT
Introduction to Rule-based Applications
PPTX
Jboss drools 3 key drools functionalities
PDF
JBoss Drools - Open-Source Business Logic Platform
PDF
Drools5 Community Training Module#1: Drools5 BLiP Introduction
PPT
Drools Presentation for Tallink.ee
PPT
Expert Systems & Prolog
ODP
Developing applications with rules, workflow and event processing (it@cork 2010)
PDF
Drools Introduction
ODP
Drooling for drools (JBoss webex)
Drools rule Concepts
Buenos Aires Drools Expert Presentation
2011-03-29 London - drools
JBoss World 2011 - Drools
JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTE
Flex 360 Rules Engine
Flex 360 Rules Engine
Obey The Rules: Implementing a Rules Engine in Flex
rules, events and workflow
Drools JBoss Rules 5 0 developer s guide develop rules based business logic u...
Drools New York City workshop 2011
Introduction to Rule-based Applications
Jboss drools 3 key drools functionalities
JBoss Drools - Open-Source Business Logic Platform
Drools5 Community Training Module#1: Drools5 BLiP Introduction
Drools Presentation for Tallink.ee
Expert Systems & Prolog
Developing applications with rules, workflow and event processing (it@cork 2010)
Drools Introduction
Drooling for drools (JBoss webex)
Ad

More from Srinath Perera (20)

PDF
Book: Software Architecture and Decision-Making
PDF
Data science Applications in the Enterprise
PDF
An Introduction to APIs
PDF
An Introduction to Blockchain for Finance Professionals
PDF
AI in the Real World: Challenges, and Risks and how to handle them?
PDF
Healthcare + AI: Use cases & Challenges
PDF
How would AI shape Future Integrations?
PDF
The Role of Blockchain in Future Integrations
PDF
Future of Serverless
PDF
Blockchain: Where are we? Where are we going?
PDF
Few thoughts about Future of Blockchain
PDF
A Visual Canvas for Judging New Technologies
PDF
Privacy in Bigdata Era
PDF
Blockchain, Impact, Challenges, and Risks
PPTX
Today's Technology and Emerging Technology Landscape
PDF
An Emerging Technologies Timeline
PDF
The Rise of Streaming SQL and Evolution of Streaming Applications
PDF
Analytics and AI: The Good, the Bad and the Ugly
PDF
Transforming a Business Through Analytics
PDF
SoC Keynote:The State of the Art in Integration Technology
Book: Software Architecture and Decision-Making
Data science Applications in the Enterprise
An Introduction to APIs
An Introduction to Blockchain for Finance Professionals
AI in the Real World: Challenges, and Risks and how to handle them?
Healthcare + AI: Use cases & Challenges
How would AI shape Future Integrations?
The Role of Blockchain in Future Integrations
Future of Serverless
Blockchain: Where are we? Where are we going?
Few thoughts about Future of Blockchain
A Visual Canvas for Judging New Technologies
Privacy in Bigdata Era
Blockchain, Impact, Challenges, and Risks
Today's Technology and Emerging Technology Landscape
An Emerging Technologies Timeline
The Rise of Streaming SQL and Evolution of Streaming Applications
Analytics and AI: The Good, the Bad and the Ugly
Transforming a Business Through Analytics
SoC Keynote:The State of the Art in Integration Technology

Recently uploaded (20)

PPTX
Internet of Everything -Basic concepts details
PDF
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
PDF
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
PDF
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
PPTX
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
PDF
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
PDF
Statistics on Ai - sourced from AIPRM.pdf
PDF
giants, standing on the shoulders of - by Daniel Stenberg
PDF
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
PDF
NewMind AI Weekly Chronicles – August ’25 Week IV
PDF
Comparative analysis of machine learning models for fake news detection in so...
PDF
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
PDF
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
Convolutional neural network based encoder-decoder for efficient real-time ob...
PDF
Flame analysis and combustion estimation using large language and vision assi...
PDF
Rapid Prototyping: A lecture on prototyping techniques for interface design
PPTX
Training Program for knowledge in solar cell and solar industry
PDF
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
PPTX
future_of_ai_comprehensive_20250822032121.pptx
Internet of Everything -Basic concepts details
Accessing-Finance-in-Jordan-MENA 2024 2025.pdf
“A New Era of 3D Sensing: Transforming Industries and Creating Opportunities,...
Transform-Your-Supply-Chain-with-AI-Driven-Quality-Engineering.pdf
AI IN MARKETING- PRESENTED BY ANWAR KABIR 1st June 2025.pptx
Transform-Your-Factory-with-AI-Driven-Quality-Engineering.pdf
Statistics on Ai - sourced from AIPRM.pdf
giants, standing on the shoulders of - by Daniel Stenberg
Produktkatalog für HOBO Datenlogger, Wetterstationen, Sensoren, Software und ...
NewMind AI Weekly Chronicles – August ’25 Week IV
Comparative analysis of machine learning models for fake news detection in so...
Transform-Your-Streaming-Platform-with-AI-Driven-Quality-Engineering.pdf
AI.gov: A Trojan Horse in the Age of Artificial Intelligence
sustainability-14-14877-v2.pddhzftheheeeee
Convolutional neural network based encoder-decoder for efficient real-time ob...
Flame analysis and combustion estimation using large language and vision assi...
Rapid Prototyping: A lecture on prototyping techniques for interface design
Training Program for knowledge in solar cell and solar industry
5-Ways-AI-is-Revolutionizing-Telecom-Quality-Engineering.pdf
future_of_ai_comprehensive_20250822032121.pptx

Droolsand Rule Based Systems 2008 Srping

  • 1. Drools and Rule Based Systems Srinath Perera
  • 2. Rule Engine Terms Expert Systems / Business rules engine / Production Systems / Inference Engines are used to address rule engines based on their implementations. Usually a Rule engine usually includes three parts. Facts represented as working memory or another set of rules e.g. Prolog  road(a,b) or Drools objects Set of rules that declaratively define conditions or situations e.g. Prolog route(X,Z) <- road(X,Z) Actions executed or inference derived based on the rules
  • 3. Rules Allow users to specify the requirements declarative, using a logic based languages. (Say what should happen, not how to do it). Rules may trigger other rules. Four types of rules (from http://www.w3.org/2000/10/swap/doc/rule-systems) Derivation or Deduction Rules – Each rules express if some statements are true, another statement must be true. Called logical implication. E.g. Prolog Transformation Rules- transform between knowledge bases, e.g. therom proving Integrity Constraints – verification rules Reaction or Event-Condition-Action (ECA) Rules – includes a actions in addition to inference. e.g. Drools
  • 4. Production Systems Drools belongs to the category of rule engines called production systems [1] (which execute actions based on conditions) Drools use forward chaining[2] (start with data and execute actions to infer more data ) Priorities assigned to rules are used to decide the order of rule execution They remember all results and use that to optimize new derivations (dynamic programming like) http://en.wikipedia.org/wiki/AI_production http://en.wikipedia.org/wiki/Forward_chaining
  • 5. Why rule engines? ~[1],[2][3] Simplify complicated requirements with declarative logic, raising the level of abstraction of the system Externalize the business logic (which are too dynamic) from comparatively static code base Intuitive and readable than code, easily understood by business people/ non technical users Create complex interactions which can have powerful results, even from simple facts and rules. Different approach to the problem, some problem are much easier using rules. Ability to specify explicit time and dates for rules to take effect Real-World Rule Engines http://www.infoq.com/articles/Rule-Engines Why are business rules better than traditional code? http://www.edmblog.com/weblog/2005/11/why_are_busines.html Rules-based Programming with JBoss Rules/Drools www.codeodor.com
  • 6. When not to use rule engines? It is slower then usual code most of the time, so unless one of the following is true is should not be used Complexity of logic is hard to tackle Logic changes too often Required to use by non technical users Interactions between rules could be quite complex, and one mistake could change the results drastically and unexpected way e.g recursive rules Due to above testing and debugging is required, so if results are hard to verified it should not be used.
  • 7. Drools Facts as a Object repository of java objects New objects can be added, removed or updated support if <query> then <action> type rules Queries use OOP format Support not, or, and, forall and exists completing first order logic
  • 8. Patterns Have a OOP based intuitive rule format. We presents examples using a insurance quota example. Following rule reject all customers whose age less than 17. rule &quot;MinimumAge&quot; when     c : Customer(age < 17) then     c.reject(); end Conditions support <, >, ==, <=, >=, matches / not matches, contains / not contains. And following rules provide a discount if customer is married or older than 25. rule &quot;Discount&quot; when     c : Customer( married == true || age > 25) then     c.addDiscount(10); end
  • 9. OR, AND, eval() OR – true if either of the statements true E.g. Customer(age > 50) or Vehicle( year > 2000) AND – provide logical, if no connectivity is define between two statements, “and” is assumed by default. For an example. c : Customer( timeSinceJoin > 2); not (Accident(customerid == c.name)) and c : Customer( timeSinceJoin > 2) and     not (Accident(customerid == c.name)) are the same. eval(boolean expressions) – with eval(..) any Boolean expression can be used. E.g. C:Customer(age > 20) eval(C.calacuatePremium() > 1000)
  • 10. Not Not – negation or none can be found. E.g. not Plan( type = “home”) is true if no plan of type home is found. Following is true if customer has take part in no accidents. rule &quot;NoAccident&quot; when     c : Customer( timeSinceJoin > 2);     not (Accident(customerid == c.name)) then     c.addDiscount(10); end
  • 11. For all True if all objects selected by first part of the query satisfies rest of the conditions. For an example following rule give 25 discount to customers who has brought every type of plans offered. rule &quot;OtherPlans&quot; when     forall ($plan : PlanCategory() c : Customer(plans contains $plan)) then     c.addDiscount(25); end
  • 12. Exists True if at least one matches the query, This is Different for just having Customer(), which is like for each which get invoked for each matching set. Following rule give a discount for each family where two members having plans rule “FamilyMembers&quot; when $c : Customer()     exists (Customer( name contains $c.family)) then     c.addDiscount(5); end
  • 13. Conflict resolution Each rule may define attributes There are other parameters you can found from [1]. E.g. rule &quot;MinimumAge&quot; salience = 10 when     c : Customer(age < 17) then     c.reject(); end salience define priority of the rule and decide their activation order. http://labs.jboss.com/drools/documentation.html
  • 14. Drools Performance Measuring Rule engine performance is tricky. Main factors are number of objects and number of rules. But results depends on nature of rules. A user feedback [1] claims Drools about 4 times faster than JRules [4]. [2] shows a comparison between Drools, Jess [5] and Microsoft rule engine. Overall they are comparable in performance. http://blog.athico.com/2007/08/drools-vs-jrules-performance-and-future.html http://geekswithblogs.net/cyoung/articles/54022.aspx Jess - http://herzberg.ca.sandia.gov/jess/ JRules http://www.ilog.com/products/jrules/ (Sequential\Rete) 16ms/15ms 4ms/4ms 100 1219 JRules Drools Objects rules
  • 15. Drools Performance Contd. I have ran the well known rule engine bench mark [1] implementation provided with Drools. (On linbox3 - 1GB memory, 4 CPU 3.20GHz ) http://www.cs.utexas.edu/ftp/pub/ops5-benchmark-suite/HOW.TO.USE 2642 1305 34 1661 1001 34 956 697 34 420 393 34 Waltz DB 9030 3873 31 1582 958 31 Waltz Time (ms) Object Count Rule Count Bench Marks
  • 17. Rule based Solution We represent Queries as Objects that include bounds and list of selected data products We represent Data products as Objects that include location and time it was collected. Then following two rules will solve the problem Rule 1. For each data item, if it match spatial and temporal boundaries, add it to data collected for query Rule 2. When temporal end time is passed, invoke the data mining workflow with collected data
  • 18.  
  • 19. Concrete Rules RULE 1. For each data item, if it match spatial and temporal boundaries of a Query, add it to data collected for query when      q: Query(completed = false);      d: Data( x > q.minX && x < q.maxX && y > q.minY && y < q.maxY && timeStamp > q.start && timestamp < q.end) then      q.addDataProduct(d); end RULE 2. When temporal end time is passed, invoke the data mining workflow with collected data when      system:System()      q: Query(completed = false, end < system.currentTime); then      q.completed = true;      q.runDataMiningAndInvokeWorkflow(); end
  • 20. Conclusion Drools provide a OOP based intuitive rule language based on Rete (which is state of art public algorithm) It has good performance, comparable with Jess (which I not free). It is Open source, has a healthy and active community and JBoss cooperation backing it Extensively used in business rule community