Some Practical Applications of Con- straints � planning, scheduling, timetabling (see Outline ILOG solver esp ecially) � con�guration � what is a constraint � electrical circuit analysis, synthesis, and di- agnosis � the constraint logic p rogramming frame- w o rk � �nancial: options trading, �nancial plan- ning � decla rative and p ro cedural readings of CLP p rograms cutting sto ck p roblems � � the CLP(R) language and its implementa- � natural language p ro cessing tion � restriction site mapping (genetics applica- tion) � generating test data fo r communications p roto cols 1 2 De�nition of a Constraint Constraints in Constraint Logic Program- ming What is a constraint? Info rmally , a constraint is a relation that w e w ould lik e to b e satis�ed. The CLP and logic p rogramming communit y uses the follo wing mo re fo rmal de�nition of Examples: constraint. � t w o columns in a table b e of equal widths The fo rm and meaning of a constraint is sp ec- i�ed b y a D , including syntax fo r the domain � one windo w on a screen b e ab ove another constraints, p ermissible values fo r the va ri- windo w ables, and meanings of the symb ols in the con- straint. � a resisto r in a circuit simulation should Example: Y � Y < 1 means di�erent things fo r ob ey Ohm's La w integers, reals, o r complex numb ers. Advantages: decla rative, high-level, natural fo r De�nition: a consists of p rimitive constraint many applications, a constraint relation symb ol from D with the Disadvantages: easier to state than to satisfy , co rrect numb er of a rguments. Each a rgument debugging and usabilit y issues, complex inter- is constructed from va riables and the constants actions with state and object identit y and functions of D . 3 4
V aluations and Satis�abilit y Domains and Constraints Example domain: the real numb ers with the De�nition: a valuation � fo r a set V of va riables standa rd a rithmetic functions and relations. is an assignment of values from the domain to The domain is R , the function symb ols a re +, those va riables. F o r va riables V = f X ; : : : X g n 1 � ma y b e written f X ! d ; : : : X ! d g . � , � and = , and the constraint relation symb ols n n 1 1 a re =, < , � , � , and > . Let va rs ( e ) b e the va riables o ccuring in an ex- Some other domains: integers, b o oleans, trees p ression e , and va rs ( C ) b e the va riables o ccur- ing in a constraint C . (�nite o r in�nite). De�nition: a is of the fo rm If � is a valuation fo r V where va rs ( C ) � V constraint c ^ : : : ^ c where n � 0 and c ; : : : c a re p rim- then it is a solution of C if � ( C ) holds in the 1 n 1 n constraint domain. itive constraints. (Note: the UI p eople no rmally do not mak e A constraint C is satis�able if it has a solution. a distinction b et w een constraints and p rimitive Otherwise it is unsatis�able. constraints, and also rega rd fo r example + as a constraint itself, rather than a function sym- Tw o constraints a re equivalent , written C $ 1 b ol.) C if they have the same set of solutions. 2 5 6 Solver Prop erties Constraint solvers accept a constraint as input. Mini-Exercises (Rememb er these can b e comp osed of multiple p rimitive constraints.) Output is: Consider the domain of the reals. � true (constraints a re satis�able) Supp ose w e have a solver that alw a ys outputs unkno wn . Is this solver sound? Complete? � (constraints a re unsatis�able) false � unkno wn Supp ose w e have a solver that alw a ys outputs true . Is this solver sound? Complete? De�nition: a solver is complete if fo r every constraint in D the solver's output is either Let C b e the constraint X � 10 ^ X + 5 = Y . 1 true o r false . Is C satis�able? 1 W e will not b e interested in unsound solvers Give a valuation that is a solution fo r C , and 1 (which might output true fo r unsatis�able con- a valuation that is not a solution. straints o r false fo r satis�able constraints). W e p refer that solvers b e complete, but fo r Is C equivalent to X � 10 ^ Y � 5? 1 some domains this is not p ractical o r even p os- sible. 7 8
The CLP Scheme CLP( D ) is a language framew o rk, where D is the domain of the constraints. CLP( R ) { Domain and Solver Example CLP languages: CLP( R ) can solve a rbitra ry collections of linea r equalit y and inequalit y constraints. � Prolog It can also solve other kinds of constraints over � CHIP the reals if it can �nd the answ er using one- step deductions (�rst �nd this va riable using � Prolog I I I { domain is rationals, b o oleans, one constraint, then �nd another va riable using and trees another constraint, etc | but no simultaneous equations). � CLP (�*) { domain is regula r sets � CLP( R ) { domain is reals (plus trees, i.e. the data t yp es that Prolog uses) 9 10 CLP( R ) Examples CLP( R ) Examples CLP( R ) p rograms a re collections of and facts Sample goals (just using p rimitive constraints rules . { no user-de�ned rules): Sample rule: ?- X=Y+1, Y=10. X=11, Y=10 /* centigrade-fahrenheit relation */ cf(C,F) :- ?- 2*A+B=7, 3*A+B=9. F = 1.8*C + 32. A=2, B=3 Sample Goals: ? X>=2*Y, Y>=5, X<=10. ?- cf(100,A). X=10, Y=5. A=212.0 ?- X*X*X + X = 10. ?- cf(A,B), A>100, B<200. maybe no. (The last goal do es have a solution X=2 . The ?- cf(X,X). \ma yb e" answ er means the constraints a re to o X=-40.0 ha rd fo r CLP( R ) to solve.) 11 12
F o rmal De�nitions - CLP Constituents A user de�ned constraint is of the fo rm p ( t ; : : : t where p is an n -a ry p redicate and 1 n t ; : : : t a re exp ressions from the constraint do- n 1 main. A P is a sequence of constraint logic p rogram rules. A is either a p rimitive constraint o r a literal user-de�ned constraint. The de�nition of a p redicate p in a p rogram P A G is a sequence of literals. G has the is the sequence of rules app ea ring in P which goal fo rm L ; L ; : : : L where m � 0. If m = 0 the have a head involving p redicate p . (Mo re fo r- 1 2 m goal is and is rep resented b y empt y 2 mally \involving p redicate p " means that the head of those rules can b e uni�ed with p , in A R is of the fo rm A : � B where A is a rule other w o rds, w e can solve a tree equalit y con- user-de�ned constraint and B is a goal. A is straint b et w een them.) the head of the rule and B is the b o dy . (Read this as B implies A .) A fact is a rule with the empt y goal as the b o dy A : � 2 and is just written as A: (Read this as A is true.) 13 Evaluation in CLP Languages { Info rmal Discussion Rewriting { Mo re F o rmal De�nition Given an initial goal, a CLP interp reter rewrites Let a goal G b e of the fo rm any user-de�ned constraints in the goal using their de�nitions. L ; : : : L ; L ; L ; : : : L 1 i � 1 m i i +1 This ma y yield mo re user de�ned constraints, which a re then rewritten. where L is the user-de�ned constraint i p ( t ; : : : ; t ) and rule R is of the fo rm n 1 Primitive constraints a re k ept in a constraint re . sto p ( s ; : : : ; s ) : � B . 1 n W e continue until there a re only p rimitive con- A of G at L b y R using � is the goal rewriting straints, which a re solved b y the system. i Ho w ever, if the constraint sto re contains an L ; : : : L ; t = � ( s ) ; : : : ; t = � ( s ) ; � ( B ) ; 1 i � 1 1 1 n n unsatis�able set of constraints, w e can stop L ; : : : L m i +1 rewriting immediately . where is a renaming such that the va riables � W e ma y have multiple rules fo r a given user- in � ( R ) do not app ea r in G . de�ned constraint. W e try these in o rder, backtracking if one fails. 14 15
Recommend
More recommend