Presentation is loading. Please wait.

Presentation is loading. Please wait.

Orcas Constraint Handling Rules May, 2005 Jairson Vitorino and Marcos Aurélio ORCAS Orcas.

Similar presentations


Presentation on theme: "Orcas Constraint Handling Rules May, 2005 Jairson Vitorino and Marcos Aurélio ORCAS Orcas."— Presentation transcript:

1 Orcas Constraint Handling Rules May, 2005 Jairson Vitorino and Marcos Aurélio ORCAS Orcas

2 Contents CHR –Introduction –Syntax –Operational Semantics –Example CHR- –Introduction –Operational Semantics –Example References

3 Orcas CHR Constraint Handling Rules

4 Orcas Introduction Constraint Logic Programming –Logic Programming + Constraint Solving CHR: Language for writing Constraint Solvers: –rule-based –Flexible to define new domains –Constraint resolution via rules (declarative)

5 Orcas Introduction CHR –Rewrite rules (pattern matching + simplify rules) –Plus propagation rules –Similiar to production rules (forward chaining), but with a well defined semantics –CHR + disjunction is turing-complete, first- order knowledge language and monotonic Current CSP software packages have fixed domains and constraints, answer: CHR

6 Orcas Syntax Constraints –User-defined Ex: noattack(Q1,Q2), connected(X,Y,3) –Built-In Ex: A>B, A=B, ground(A)

7 Orcas Syntax: typical rule H1,...,Hn G1,...Gn | B1,...,Bn Multiple Heads GuardsBody Commited choice: When the engine picks a rule there will not be any backtracking, so in CHR order matters! (Only user-defined) (Only built-in) Both constraint categories

8 Orcas Syntax Rules –Simplification H1,...,Hn G1,...Gn | B1,...,Bn –Propagation H1,...,Hn =>G1,...Gn | B1,...,Bn –Simpagation H1,...,Hn / Hn1,...Hnn G1,...Gn | B1,...,Bn

9 Orcas Operational Semantics State Goal or query User defined Constraints Store (UDCS) Built-in Constraint Store (BICS) CHR ENGINE Logical meaning: y Goal  UDCS  BICS CHR Program Or Base Rule Final State: true or false

10 Orcas Operational Semantics Transitions –Solve and Introduce –Propagate –Simplify Commited-choice and Confluence “The confluence property of a program guarantees that any computation starting from an arbitrary given initial state, i.e. any possible order of rule applications, results in the same final state.”

11 Orcas Operational Semantics Transitions (Solve) X=Y, G1, G2 Goal U1,..., Un UDCS B1,..., Bn BICS Solve: G1, G2 Goal U1,..., Un UDCS B1,..., Bn, X=Y BICS Built-in

12 Orcas Operational Semantics Transitions (Introduce) C(a,b), G1,..., Gn Goal U1,..., Un UDCS B1,..., Bn BICS Solve: G1, G2 Goal C(a,b), U1,..., Un UDCS B1,..., Bn BICS User-defined

13 Orcas Operational Semantics Transitions (Simplify) U1,U2  B1| U3,U4 U5..., Un Goal U1, U2,V1,..., Vn UDCS B1,..., Bn BICS Simplify: U5,..., Un Goal U3, U4, V1,..., Vn UDCS B1,..., Bn BICS Rule in CHR program

14 Orcas Operational Semantics Transitions (Propagate) U1,U2  B1| U3,U4 Un Goal U1, U2,..., Un UDCS B1,..., Bn BICS Propagate: U1, U2,..., Un Goal U3, U4, U1, U2,..., Un UDCS B1,..., Bn BICS Rule in CHR program

15 Orcas Operational Semantics Transitions (Simpagate) U1,U2 / U5  B1| U3,U4 U4,..., Un Goal U1, U2,U5,..., Un UDCS B1,..., Bn BICS Simpagate: U6,..., Un Goal U3,U4, U1,U2..., Un UDCS B1,..., Bn BICS Rule in CHR program

16 Orcas Example CHR Program X= X=Y | true. X= X=Y. X= X=<Z. Initial state: A<=B, C<=A, B<=C Goal true UDCS true BICS

17 Orcas Example Introduce: C<=A, B<=C Goal A<=B UDCS true BICS Introduce: B<=C Goal C<=A, A<=B UDCS true BICS

18 Orcas Example Introduce: true Goal C<=A, A<=B, B<=C UDCS true BICS Propagate: X X<=Z. true Goal C<=B, C<=A, A<=B, B<=C UDCS true BICS

19 Orcas Example Introduce: true Goal C<=A, A<=B B<=C, C<=B UDCS true BICS Simplify: X X=Y. true Goal C<=A, A<=B UDCS B=C BICS

20 Orcas Example Solve: true Goal C<=A, A<=B UDCS B=C BICS Simplify: X X=Y. Goal true UDCS B=C, A=B BICS (Logo: C<=A equivale a B<=A) true

21 Orcas Example Solve: true Goal true UDCS B=C, A=B BICS Final State

22 Orcas CHR- Constraint Handling Rules with Disjunctions

23 Orcas Introduction Allows disjunctions in the bodies of rules and in goals It can be used as a general-purpose logic programming language

24 Orcas Operational Semantics State –Minimal set of subgoals Ex: a  (b  (c  d))  e –Logical meaning: y A –Initial State –Final State Successful Failed

25 Orcas Operational Semantics Transitions (Solve) Solve: a  (b  c)  (b  d)  e Goal a  (b  (c  d))  e Goal

26 Orcas Operational Semantics Solve –“To normalize the predefined means to produce a new state G’ that is (according to the logical theory T 0 ) logically equivalent to the state G”

27 Orcas Operational Semantics Transitions (Simplify) –b  c  f  g Simplify: a  (f  g)  (b  d)  e Goal a  (b  c)  (b  d)  e Goal

28 Orcas Operational Semantics Transitions (Split) Simplify: (b  (a  d  e  f))  (c  (a  d  e  f)) Goal (b  c)  (a  d  e  f) Goal

29 Orcas Example bird  albatross  penguin. penguin  flies  false. Initial state: bird  flies Goal

30 Orcas Example Simplify: bird  albatross  penguin. ( albatross  penguin)  flies Goal Split: ( albatross  flies)  (penguin  flies) Goal

31 Orcas Example Propagate: penguin  flies  false. ( albatross  flies)  false Goal Final State (no derivation step can be applied)

32 Orcas Example: K-coloring map main() true | color(X1), color(X2), color(X3), color(X4), connected(X1,X2), connected(X1,X3), connected(X3,X4), connected(X2,X4). connected(X1,X2) ground(X1), ground(X2), X1=X2 |false. color(X) ==> true | (X=1 ; X=2 ; X=3).

33 Orcas Example: 4-Queens main() true | c(X1), c(X2), c(X3), c(X4), // rainhas na(X1,X2,1), na(X1,X3,2), na(X1,X4,3), na(X2,X3,1), na(X2,X4,2), na(X3,X4,1), sol(X1,X2,X3,X4). na(X,Y,D) ground(X), ground(Y) | P=Y+D, M=Y~D, ne(X,Y), ne(X,P), ne(X,M). c(X) true | (X=1 ; X=2 ; X=3 ; X=4). sol(X1,X2,X3,X4) ground(X1), ground(X2), ground(X3), ground(X4) | write(X1), write(X2), write(X3), writeLn(X4).

34 Orcas Reference Theory and practice of Constraint Handling Rules (http://www.pst.informatik.uni- muenchen.de/personen/fruehwir/jlp-chr1/jlp- chr1.html)http://www.pst.informatik.uni- muenchen.de/personen/fruehwir/jlp-chr1/jlp- chr1.html A languagem for experimenting with Declarative Paradigms (http://citeseer.ist.psu.edu/611754.html)http://citeseer.ist.psu.edu/611754.html

35 Orcas Reference XSB Prolog –http://xsb.sf.nethttp://xsb.sf.net The ECLiPSe Constraint Logic Programming System –http://www.icparc.ic.ac.uk/eclipse/http://www.icparc.ic.ac.uk/eclipse/ WebCHR –http://bach.informatik.uni- ulm.de/~webchr/http://bach.informatik.uni- ulm.de/~webchr/ JACK – Java Constraint Kit –http://www.pms.ifi.lmu.de/software/jack/http://www.pms.ifi.lmu.de/software/jack/


Download ppt "Orcas Constraint Handling Rules May, 2005 Jairson Vitorino and Marcos Aurélio ORCAS Orcas."

Similar presentations


Ads by Google