Download presentation
Presentation is loading. Please wait.
Published byNorman Stevenson Modified over 8 years ago
1
1 Chapter 1: Constraints What are they, what do they do and what can I use them for.
2
2 Constraints u What are constraints? u Modelling problems u Constraint solving u Tree constraints u Other constraint domains u Properties of constraint solving
3
3 Constraints Variable: a place holder for values Function Symbol: mapping of values to values Relation Symbol: relation between values
4
4 Constraints Primitive Constraint: constraint relation with arguments Constraint: conjunction of primitive constraints
5
5 Satisfiability Valuation: an assignment of values to variables Solution: valuation which satisfies constraint
6
6 Satisfiability Satisfiable: constraint has a solution Unsatisfiable: constraint does not have a solution satisfiable unsatisfiable
7
7 Equivalent Constraints Two different constraints can represent the same information Two constraints are equivalent if they have the same set of solutions
8
8 Modelling with constraints u Constraints describe idealized behaviour of objects in the real world
9
9 Modelling with constraints start foundations interior walls exterior walls chimney roof doors tiles windows
10
10 Constraint Satisfaction u Given a constraint C two questions u satisfaction: does it have a solution? u solution: give me a solution, if it has one? u The first is more basic u A constraint solver answers the satisfaction problem
11
11 Constraint Satisfaction u How do we answer the question? u Simple approach try all valuations.
12
12 Constraint Satisfaction u The enumeration method won’t work for Reals (why not?) u A smarter version will be used for finite domain constraints u Solving Real constraints — one technique is Gauss-Jordan elimination
13
13 Gauss-Jordan elimination u Choose an equation c from C u Rewrite c into the form x = e u Replace x everywhere else in C by e u Continue until u all equations are in the form x = e u or an equation is equivalent to d = 0 (d != 0) u Return true in the first case else false
14
14 Gauss-Jordan Example 1 Replace X by 2Y+Z-1 Replace Y by -1 Return false
15
15 Gauss-Jordan Example 2 Replace X by 2Y+Z-1 Replace Y by -1 Solved form : constraints in this form are satisfiable
16
16 Solved Form u Non-parametric variable: appears on the left of one equation. u Parametric variable: appears on the right of any number of equations. u Solution: choose parameter values and determine non-parameters
17
17 Tree Constraints u Tree constraints represent structured data u Tree constructor: character string u cons, node, null, widget, f u Constant: constructor or number u Tree: u A constant is a tree u A constructor with a list of > 0 trees is a tree u Drawn with constructor above children
18
18 Tree Examples order(part(77665, widget(red, moose)), quantity(17), date(3, feb, 1994)) cons(red,cons(blue,con s(red,cons(…))))
19
19 Tree Constraints u Height of a tree: u a constant has height 1 u a tree with children t1, …, tn has height one more than the maximum of trees t1,…,tn u Finite tree: has finite height u Examples: height 4 and height
20
20 Terms u A term is a tree with variables replacing subtrees u Term: u A constant is a term u A variable is a term u A constructor with a list of > 0 terms is a term u Drawn with constructor above children u Term equation: s = t (s,t terms)
21
21 Term Examples order(part(77665, widget(C, moose)), Q, date(3, feb, Y)) cons(red,cons(B,cons(r ed,L)))
22
22 Tree Constraint Solving u Assign trees to variables so that the terms are identical u cons(R, cons(B, nil)) = cons(red, L) u Similar to Gauss-Jordan u Starts with a set of term equations C and an empty set of term equations S u Continues until C is empty or it returns false
23
23 Tree Constraint Solving u unify u unify(C) u Remove equation c from C u case x=x: do nothing u case f(s1,..,sn)=g(t1,..,tn): return false u case f(s1,..,sn)=f(t1,..,tn): u add s1=t1,.., sn=tn to C u case t=x (x variable, t not variable): add x=t to C u case x=t (x variable): add x=t to S u substitute t for x everywhere else in C and S
24
24 Tree Solving Example CS Like Gauss-Jordan, variables are parameters or non-parameters. A solution results from setting parameters (I.e T) to any value.
25
25 One extra case u Is there a solution to X = f(X) ? u NO! u if the height of X in the solution is n u then f(X) has height n+1 u Occurs check: u before substituting t for x u check that x does not occur in t
26
26 Tree Constraints Elsewhere u Tree constraints are used in Prolog u We’ll see terms and tree constraints elsewhere in the course – terms will describe types in the functional programming languages, and the “unify” solver will be used in type inference
27
27 Other Constraint Domains u There are many u Boolean constraints u Sequence constraints u Blocks world u Finite-domain constraints (discussed in detail in Chapter 3) u Many more, usually related to some well understood mathematical structure
28
28 Boolean Constraints Used to model circuits, register allocation problems, etc. An exclusive or gate Boolean constraint describing the xor circuit
29
29 Boolean Solver let m be the number of primitive constraints in C epsilon is between 0 and 1 and determines the degree of incompleteness for i := 1 to n do generate a random valuation over the variables in C if the valuation satisfies C then return true endif endfor return unknown
30
30 Boolean Constraints u Something new? u The Boolean solver can return unknown u It is incomplete (doesn’t answer all questions) u It is polynomial time, where a complete solver is exponential (unless P = NP) u Still, such solvers can be useful!
31
31 Blocks World Constraints Objects in the blocks world can be on the floor or on another object. Physics restricts which positions are stable. Primitive constraints are e.g. red(X), on(X,Y), not_sphere(Y). floor Constraints don't have to be mathematical
32
32 Blocks World Constraints A solution to a Blocks World constraint is a picture with an annotation of which variable is which block Y X Z
33
33 Solver Definition u A constraint solver is a function solv which takes a constraint C and returns true, false or unknown depending on whether the constraint is satisfiable u if solv(C) = true then C is satisfiable u if solv(C) = false then C is unsatisfiable
34
34 Properties of Solvers u We desire solvers to have certain properties u well-behaved: u set based: answer depends only on set of primitive constraints u monotonic: is solver fails for C1 it also fails for C1 /\ C2 u variable name independent: the solver gives the same answer regardless of names of vars
35
35 Properties of Solvers u The most restrictive property we can ask u complete: A solver is complete if it always answers true or false. (never unknown)
36
36 Constraints Summary u Constraints are pieces of syntax used to model real world behaviour u A constraint solver determines if a constraint has a solution u Real arithmetic and tree constraints u Properties of solver we expect (well- behavedness)
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.