Rule engine

5,062 views

Published on

Rule engine

  1. 1. Balaji Venugopal Vimal Kumar
  2. 2. Definition A rule engine is a piece of software, which having some knowledge is able to perform conclusions. Rules Engines are the pluggable software components that separate the business rules from the application code • A system that attempts to act as a domain expert
  3. 3. Some frequently asked questions Why use a Rule Engine? When should I use a rule engine? What advantage does a rule engine have over hand coded "if...then" approaches? We will attempt to address these questions…….
  4. 4. Why use a Rule Engine? If “Procedural Code” is available then why RULE ENGINE ? The Problem • Have you developed/seen code with so many nested if statements that actually looked like a nest?
  5. 5. Why use a Rule Engine? The Problem (Contd…) • Have you spent sleepless nights debugging code when you modified one of those 'if' statements and found that it distorted the next if statement? • Ever wondered how others implement these?
  6. 6. Why use a Rule Engine? The Solution • “Rule engines are a great way to collect complex decision-making logic and work with data sets too large for humans to effectively use.”
  7. 7. When should I use a Rule Engine? "when there is no satisfactory traditional programming approach to solve the problem." Complicated logic (not 1+1 = 2)‫‏‬
  8. 8. The Robot Example Teaching a robot to prepare breakfast cereal (in an optimal environment) START putOnTable(bowl) putOnTable(spoon) putOnTable(napkin) open(cereal-container) pour(cereal) open(milk-container) pour(milk) inviteOwner("You may begin eating") END
  9. 9. The Robot Example Teaching a robot to drive is much more difficult because the task vary according to environmental conditions a. Robot must not do the tasks for backing out of garage if the garage door is closed or if there is a little girl on a tricycle right behind the car b. Backing out will be different on warm days and cold days. Also, in a parking spaces, backing up procedures will be different in different Settings c. So many different circumstances lead to endless logic branching d. Solution: independent rules that are integrated in an inference engine: IF the engine has stalled THEN start car IF you hear sirens THEN pull over to the curb etc.
  10. 10. When should you use a Rule Engine? Changes often (whatever that means)‫‏‬ Traditional approaches are unmaintainable The problem is beyond any obvious algorithmic solution Domain experts (or business analysts) are readily available, but are nontechnical
  11. 11. Advantages of a Rule Engine Declarative Programming Logic and Data Separation Speed and Scalability Centralization of Knowledge Tool Integration Explanation Facility
  12. 12. High Level view of a Rule Engine
  13. 13. Working Memory. The data that rules work on. Also called the fact base. Production Memory. Knowledge and inferences are stored in rules, which are called production rules. Pattern Matcher. Determines which rules to apply to the data in working memory. • There are a number of algorithms used for Pattern Matching by Inference Engines including: • Linear • Rete • Treat • Leaps Agenda. Determines the order of execution of rules. Execution Engine. The part of the rules engine that is responsible for applying rules to data and then performing the action part of the rules that have fired.
  14. 14. Architecture of Typical Rule Based System observed data working memory select modify rule Inference memory fire output engine
  15. 15. Reasoning with production rules  Architecture of a typical production system: New information working memory select modify rule interpreter memory fire output
  16. 16. Reasoning with production rules  Architecture of a typical production system: New information select working memory modify rule interpreter memory fire output
  17. 17. Reasoning with production rules  Architecture of a typical production system: New information working memory select modify Inference rule engine memory output fire executes actions
  18. 18. Reasoning with production rules  Architecture of a typical production system: New information working memory select modify Inference rule engine memory fire executes output actions
  19. 19. Reasoning with production rules  Architecture of a typical production system: New information select working memory modify rule interpreter memory fire output
  20. 20. Reasoning with production rules  Architecture of a typical production system: New information working memory select modify Inference rule engine memory executes output fire actions
  21. 21. Reasoning with production rules  Architecture of a typical production system: New information working memory select modify Inference rule engine memory executes fire output actions
  22. 22. Methods of execution for a rule system Forward Chaining Backward Chaining Goal Goal Start Start
  23. 23. Forward Chaining Goal conclude the color of my pet Fritz Working Memory Rule Base he croaks 1. If X croaks and eats flies - Then X is a frog eats flies 2. If X chirps and sings - Then X is a canary 3. If X is a frog - Then X is green 4. If X is a canary - Then X is yellow
  24. 24. Working Memory Rule Base he croaks 1. If X croaks and eats flies - Then X is a frog eats flies 2. If X chirps and sings - Then X is a canary 3. If X is a frog - Then X is green 4. If X is a canary - Then X is yellow the color of my pet Fritz Working Memory GREEN he croaks eats flies frog
  25. 25. Backward Chaining Goal conclude the color of my pet Fritz Working Memory Rule Base he croaks 1. If X croaks and eats flies - Then X is a frog eats flies 2. If X is a frog - Then X is green 3. If X is a canary - Then X is yellow
  26. 26. Goal List Rule Base 1. conclude the color of my pet 1. If X croaks and eats flies - Then X is a frog Fritz 2. If X chirps and sings - Then X is a canary 3. If X is a frog - Then X is green 4. If X is a canary - Then X is yellow Goal List Working Memory 1. conclude the color of my pet Fritz he croaks 2. X is a frog eats flies 3. X is a canary So my pet Fritz Is frog Is Green He croaks and eats flies
  27. 27. Solutions Which Are Attracting The Use Of Business Rules For More Efficiency • Marketing/Campaign • Business Process/Workflow • Management Account • Data Validation/Formatting • Management/Personalization • Self-Service Web Inquiries Behavior Scoring • Regulatory Compliance • Product / Service Recommendation • Order Configuration • Underwriting • Call Center/CRM (Lending/Insurance) • Fraud Detection • Diagnostics/Problem Resolution • Authorization • Sales Commission Calculation • Benefits Analysis • Pension Portfolio Marketing • Manufacturing Process • Risk Analysis • Claims Processing • Compliance Enforcement • Database Migration Tool.
  28. 28. Rule Engines Drools BizTalk Blaze Advisor Jess JRules OpenRules PegaRules RulesPower
  29. 29. Heart of the System

×