Rule based Systems
Home » Algorithms  »  Rule based Systems
Rule based Systems

General forward chaining Pseudo code :

  1. For all rules and assertions, find all matches i.e. Rule + Assertion combinations
  2. Check if any of the matches are defunct i.e. where consequent of the match is already in DB
  3. Run the first non defunct match
  4. Repeat until no match left to run
In forward chaining rule, please take special care for delete because it may lead to infinite loop.

General Backwards Chaining Pseudo Code:

  1. Check hypothesis against DB. If satisfied, exit
  2. Find all matching rule: any rule with a consequent that matches hypothesis
  3. For each rule
    1. Binding <-- Unify rule , consequent and hypothesis
    2. Subtree  <-- Antecedents_goal_tree(rule,rules,binding,DB)
    3. Optimization  <--  If subtree evaluation returns true we can short circuit subtree
return OR(rule subtree) Function Antecedents_goal_tree(rule,rules,binding,DB): For each antecedent:
  1. new_hypothesis <-- antecedent + Binding
  2. Check new_hypothesis against DB , if matched update Binding. If multiple matches found OR them to create new subtree.
  3. subtree <-- Run above function
  4. Optimization <-- Short circuit for AND & OR

Leave a Reply

Your email address will not be published. Required fields are marked *