Download presentation
Presentation is loading. Please wait.
1
Constraint Handling Rules with Disjunction (CHRv)
Cleyton Rodrigues, M. Sc.
2
CHR: Key Ideas Originally a logical rule-based language to declaratively program specialized constraint solvers; Since evolved in a general purpose first-order knowledge representation language; Relies on forward chaining and rule Left-Hand-Side (LHS) matching; Extended variant CHRV adds backtracking search and thus generalizes Prolog rules as well; Committed choice; Matching; Backtracking within a single rule.
3
CHR: Concrete Syntax Rule syntax: K \ R <=> G | B., with: - K (keep heads), and R (remove heads), both conjunctions of First- Order Logic (FOL) atoms called Rule-Defined Constraints (RDC); - G guards, conjunction of FOL atoms called Built-In Constraints (BIC); - B bodies, disjunction of conjunctions of FOL atoms, either RDC or BIC;
4
CHR Concrete Syntax CHR propagation rule K ==> G | B,
syntactic variant of simpagation rule K \ true <=> G | B. CHR simplification rule R <=> G | B, syntactic variant of simpagation rule true \ R <=> G | B. Constraint store S (volatile CHR KB) = Sr Sb with Sr conjunction of RDC and Sb conjunction of BIC. Query Q: conjunction of FOL atoms, either RDC or BIC.
5
CHR: Locical Semantics
Rule logical semantics: VGH (G ((KR) (VB\GH B K))), where: VGH = vars(G) vars(K) vars(R), VB\GH = vars(B) \ VGH K \ R <=> G | B.
6
CHR: Key Ideas Rule base integrates and generalizes:
Event-Condition-Action rules (themselves generalizing production rules) for constraint propagation; Conditional rewrite rules for constraint simplification; Prolog-rules.
7
CHR by Example: Rule Base Defining in Terms of =
X Y <=> X = Y | true. X Y, Y X <=> X=Y. X Y , Y Z ==> X Z. X Y \ X Y <=> true.
8
CHR by Example: Rule Base Defining in Terms of =
X Y <=> X = Y | true. X Y, Y X <=> X=Y. % Constraint simplification (or rewriting) rules % 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 X Y , Y Z ==> X Z. % Constraint propagation (or production) rule (in this case, unguarded) % % 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
9
CHR by Example: Rule Base Defining in Terms of =
X Y \ X Y <=> true. % Constraint simpagation rule (in this case, unguarded) % 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
10
Examples
11
CHR by Example: Rule Base Defining in Terms of =
X Y <=> X = Y | true. X Y, Y X <=> X=Y X Y, Y Z ==> X Z. X Y \ X Y <=> true. Rule RDCS BICS A B, C A, B C A = 2 Rule-Defined Constraint Store Built-In Constraint Store
12
CHR Base Example: Defining min in Terms of , and =
min(X,Y,Z) <=> X Y | Z = X min(X,Y,Z) <=> Y X | Z = Y. min(X,Y,Z) <=> Z < X | Y = Z. min(X,Y,Z) <=> Z < Y | X = Z. min(X,Y,Z) ==> Z X, Z Y. Rule RDCS BICS min(1,2,M)
13
CHR Base Example: Define max in Terms of , , =
14
CHRV
15
CHR Base Example: Map Coloring Problem
t r3 r4 r5 r1 r7 d(r1,C) ==> (C = r ; C = b ; C = g). d(r7,C) ==> (C = r ; C = b). d(r4,C) ==> (C = r ; C = b). d(r3,C) ==> (C = r ; C = b). d(r2,C) ==> (C = b ; C = g). d(r5,C) ==> (C = r ; C = g). d(r6,C) ==> (C = r ; C = g; C = t). m <=> n(r1,r2), n(r1,r3), n(r1,r4), n(r1,r7), n(r2,r6), n(r3,r7), n(r4,r5), n(r4,r7), n(r5,r6), n(r5,r7). n(Ri,Rj), d(Ri,Ci), d(Rj,Cj) ==> Ci = Cj | false. l([ ],[ ]) <=> true. l([R|Rs],[C|Cs]) <=> d(R,C), l(Rs,Cs). Rule RDCS BICS m, l([r1,r7,r4,r3,r2,r5,r6],[C1,C7,C4,C3,C2,C5,C6]). true
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.