1 / 161

Constraint Handling Rules (CHR): Rule-Based Constraint Solving and Deduction

Constraint Handling Rules (CHR): Rule-Based Constraint Solving and Deduction. Jacques Robin. Constraint Handling Rules (CHR) Key ideas Introductory example CHR constraint solver over real variables CHR with disjunction (CHR  ) CHR constraint solver over finite domain variables

Télécharger la présentation

Constraint Handling Rules (CHR): Rule-Based Constraint Solving and Deduction

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Constraint Handling Rules (CHR):Rule-Based Constraint Solving and Deduction Jacques Robin

  2. Constraint Handling Rules (CHR) Key ideas Introductory example CHR constraint solver over real variables CHR with disjunction (CHR) CHR constraint solver over finite domain variables General purpose rule-based reasoning with CHR A taxonomy of rule-based languages Production rules and ECA rules in CHR Conditional term rewrite rules in CHR Prolog and CLP rules in CHR Deduction with CHR Propositional deduction as Boolean constraint solving in CHR First-order Horn Logic forward chaining with CHR First-order Horn Logic backward chaining with CHR First-order logic refutation and resolution based entailment with CHR Description logic reasoning with CHR Outline

  3. Constraint Handling Rules (CHR):Key Ideas • Originally a logical rule-based language to declaratively program specialized constraint solvers on top of a host programming language (Prolog, Haskell, Java) • Since evolved in a general purpose first-order knowledge representation language and Turing-complete programming language • Fact base contains both extensional and intentional knowledge in the form of a conjunction of constraints • Rule base integrates and generalizes: • Event-Condition-Action rules (themselves generalizing production rules) for constraint propagation • Conditional rewrite rules for constraint simplification • Relies on forward chaining and rule Left-Hand-Side (LHS) matching • Extended variant CHRV adds backtracking search and thus generalizes Prolog rules as well

  4. CHR by Example:Rule Base Defining  in Terms of = reflexivity@ X  Y <=> X = Y | true. asymmetry@ X  Y, Y  X <=> X=Y. % Constraint simplification (or rewriting) rules % Syntax: <ruleName>@ <simplifiedHead> <=> <guard> | <body> % Logically:Xvars(head  guard) % <guard>  (<head>  Yvars(body - (head  guard)) <body>) % Operationally: substitute in constraint store (knowledge base) constraints that match % the rule simplified head by those in rule body with their variables instantiated from % the match transitivity@ X  Y , Y  Z ==> X  Z. % Constraint propagation (or production) rule (in this case, unguarded) % Syntax: <ruleName>@ <propagatedHead> ==> guard | <body> % Logically:Xvars(head  guard) % <guard>  (<head>  Yvars(body - (head  guard)) <body>) % Operationally: if constraint store (knowledge base) contains constraints that match % the rule propagated head then add those in rule body to the store with their variables % instantiated from the match

  5. CHR by Example: Rule Base Defining  in Terms of = idempotence@ X  Y \ X Y <=> true. % Constraint simpagation rule (in this case, unguarded) % Syntax: <ruleName>@ <propagatedHead> \ <simplifiedHead> <=> guard | <body> % Logically:Xvars((head  guard) <guard>  (<propagatedhead>  <simplifiedHead>%  Yvars(body - (head  guard)) <body>  <propagatedhead>) % Operationally: if constraint store (knowledge base) contains constraints that match % the rule simplified head and the rule propagated head, then substitute in the store% those matching the simplified head by the rule body with their variables instantiated% from the match query1: A  B, C  A, B  C, A = 2% Initial constraint store: a constraint conjunction answer1:A = 2, B = 2, C = 2, % Final constraint store = initial constraint store% simplified through repeated rule application until no rule neither simplifies nor% propagates any new constraint query2:A  B, B  C, C  A answer2:A = B, B = C

  6. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Rule-Defined Constraint Store Built-In Constraint Store Matching Equations  Guard

  7. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Condition for firing a rule: Rule head matches active constraint in RDCS Generates set of equations between variables and constants from the head and the constraint (inserted to MEG) Every other head from the rule matches against some other (partner) constraint in the RDCS Generates another set of equations (inserted to MEG) Rule r fires iff:X1,...,Xi  vars(MEG  BICS - r) BICS  Y1,...,Yj  vars(r) MEG CHR by Example: Rule Base Defining  in Terms of = Active Constraint

  8. CHR by Example: Rule Base Defining  in Terms of = r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Normalizing Simplification Active Constraint

  9. r@ X  Y <=> X = Y | true.(A,B A = 2  X',Y' X' = A = Y' = B), eg, B = 3  2 = A a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint

  10. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Rule firing order depends on 3 heuristics, with the following priority: Rule-defined constraint ordering to become active Rule ordering to try matching and entailment check with active constraint Rule-defined constraint ordering to become partner constraints Engine first tries matching and entailment check: All rules with current active constraint, before trying any rule with the next constraint in the RDCS; For all elements of the RDCS as partner for the first multi-headed rule that matches the active constraint, before trying the next rule that matches the active constraint; CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  11. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y (A,B,C A = 2  X',Y' X' = A Y' = B = C), eg, B = 3  4 = C t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  12. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  13. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y (A,B,C A = 2  X',Y' X' = B = C Y' = A),eg, B = 3  4 = C t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  14. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  15. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y (A,B,C A = 2  X',Y' X' = A = C  Y' = B),eg, C = 3  2 = A t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  16. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  17. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y (A,B,C A = 2  X',Y' X' = B  Y' = A = C),eg, C = 3  2 = A t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  18. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  19. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.(A,B,C A = 2  X',Y', Z' X' = Z' = A  Y' = B = C), eg, B = 3  4 = C i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  20. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  21. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.A,B,C A = 2  X',Y',Z' X' = C  Y' = A  Z' = B, e.g.,X'=C,Y'=2,Z'=B i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  22. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of =

  23. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. For a given active constraint: a matching multi-headed propagation rule is reapplied with all matching partner constraints, before any other rule is tried; in contrast, a matching multi-headed simplification or simpagation rule is applied only once with the first matching partner constraint, and then engine moves on to the next rule CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  24. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.A,B,C A = 2  X',Y',Z' X' = A  Y' = B  Z' = B, e.g.,X'=A,Y'=B, Z'=C i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  25. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of =

  26. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Attempt to reapply same propagation rule matching same pair of active and partner constraints with same head pair but swapped assignments: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  27. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.(A,B,C A = 2  X',Y', Z' X' = Z' = B  Y' = A = C), eg, A = 2  4 = C i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  28. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  29. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. (A,B,C A = 2  X',Y', Z' X' = A  Y' = Z' =B = C), eg, B = 3  4 = C i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  30. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  31. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.(A,B,C A = 2  X',Y', Z' X' = C  Y' = Z' =A = B), eg, A = 2  3 = B i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  32. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  33. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.(A,B,C A = 2  X',Y', Z' X' = Y' =A = B  Z' = C ), eg, A = 2  3 = B i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  34. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  35. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z.(A,B,C A = 2  X',Y', Z' X' = Y' =A = C  Z' = B ), eg, A = 2  4 = C i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  36. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  37. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. (A,B,C A = 2  X',Y', Z' X' = Y' =Z' = A = B = C ), eg, A = 2  4 = C CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  38. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  39. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. (A,B,C A = 2  X',Y', Z' X' = Y' =Z' = A = B = C ), eg, A = 2  4 = C Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  40. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  41. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \X  Y <=> true. (A,B,C A = 2  X',Y‘ X' = Y' =A = B = C ), eg, A = 2  4 = C CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  42. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  43. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. (A,B,C A = 2  X',Y' X' = Y' = A = B = C ), eg, A = 2  4 = C Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  44. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  45. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \X  Y <=> true. (A,B,C A = 2  X',Y‘ X' =A = C, Y’ = B), eg, A = 2  4 =C CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  46. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  47. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. (A,B,C A = 2  X',Y' X' = A = C,Y’ = B ), eg, A = 2  4 = C Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  48. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \X  Y <=> true. CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  49. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \X  Y <=> true. (A,B,C A = 2  X',Y‘ X' =A, Y’ = B = C), eg, B = 3  4 =C CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

  50. r@ X  Y <=> X = Y | true. a@ X  Y, Y  X <=> X=Y t@ X  Y, Y  Z ==> X  Z. i@ X  Y \ X  Y <=> true. Alternate matching combination: Active constraint matched against rightmost head Partner constraint matched against leftmost head CHR by Example: Rule Base Defining  in Terms of = Active Constraint Partner Constraint

More Related