Title: Constraints
1Constraints
2Constraint Models
- In constraint programming, we express the problem
using - Variables, representing unknowns and parameters
- Constraints, describing the relationship between
the variables
3Constraint
- A constraint consists of
- a list of n variables
- a relation with n columns
4Constraint
- A constraint consists of
- a list of n variables
- a relation with n columns
- Relation can be defined
- implicitly
- X Y 5
5Constraint
- A constraint consists of
- a list of n variables
- a relation with n columns
- Relation can be defined (X, Y)
- implicitly or explicitly
- X Y 5
6Constraint Models
- A constraint model is
- a conjunctive set of constraints
7Constraint Models
- A constraint model is
- a conjunctive set of constraints
- a program that generates conjunctions of
constraints
8Constraint Models
- A constraint model is
- a conjunctive set of constraints
- a program that generates conjunctions of
constraints - (not even limited to conjunctions)
9Solving Constraint Models
- Finding a solution
- Algorithmically
- Uniform class of constraints
- Constraint solving
- Search propagation
- General purpose, less efficient
- Constraint satisfaction
- Both
10Constraint Solving
- Given a signature ?
- naming relevant function and predicate symbols
and their arities - A constraint domain consists of
- a language
- describes what formulas are constraints
- a structure
- defines the set of values
- defines the meaning of function and predicate
symbols as functions and relations
11Constraint Solving
- Linear arithmetic constraints over the real
numbers - ? , -, , lt, ?, 0, 1, 2, , -1, -2,
- Terms are constructed by , -, and numerals
- Primitive constraints
- term term, term lt term, term ? term
- Constraints are conjunctions of primitive
constraints
12Constraint Solving
- Linear arithmetic constraints over the real
numbers - The structure consists of
- The set of values R
- Mapping
- numerals to the corresponding number
- to addition
- - to subtraction
- , lt, ? to equality, less-than, less-than-or-equal
13Constraint Solving
- Linear equations over the real/rational numbers
- Gauss, Gauss-Jordan algorithms
- Equations over Herbrand terms
- Unification algorithm
- Linear equations and inequalities over the
real/rational numbers - Simplex algorithm, interior point algorithms
- Polynomial equations and inequalities over the
real numbers - Collins method
14Constraint Solving
- Transcendental equations and inequalities over
the real numbers - undecidable
- Linear equations and inequalities over the
integers - NP-complete
- Polynomial equations and inequalities over the
integers - undecidable
15Constraint Solving
- Constraints that are easy to solve
- Bounds on real/rational numbers
- Bounds on integers
- Bounds on sets
- Bounds on multisets/bags
- Membership of finite sets
16Constraint Satisfaction Problems
- CSPs are used to formalize a class of conjunctive
constraint problems - A CSP is a tuple ltV, D, Cgt where
- V is a set of variables
- D maps each variable to its domain the set of
its possible values, usually finite - C is a set of constraints
17Rock Star Dressing Problem
- A rock star has
- red, green, orange and blue shirts
- pink and yellow ties
- black, khaki, purple and blue pants
- Fashion sense
- A yellow tie only goes with red, green or blue
shirts - A pink tie only goes with blue shirts
- etc
- Find a satisfactory outfit
18Rock Star Dressing Problem
- Variables shirt, tie pants
- Domains
- D(shirt) red, green, orange, blue
- D(tie) pink, yellow
- D(pants) black, khaki, purple, blue
- There are three constraints, specifying the
colours of pairs of items of clothing that are
compatible
19Rock Star Dressing Problem
- Constraints
- C1 C2
C3 - C1(P,S), C2(S,T), C3(T,P)
20Binary CSPs
- A binary CSP is one where all relations involve 2
variables (or fewer) - Binary CSPs can be represented as graphs
21Rock Star Dressing Problem
blue black purple khaki
red green orange blue
C1
C2
C3
yellow pink
22Rock Star Dressing Problem
blue black purple khaki
red green orange blue
C
C
C
yellow pink
Equivalent formulation using only one relation
23Binary CSPs
- Binary CSPs are universal
- Every CSP can be encoded as a binary CSP
- Variables range over tuples in constraints of
original CSP - Constraints permit only tuples that are
compatible in original CSP
24CSP Satisfiability
- The satisfiability problems for CSPs is
NP-complete - In NP because a solution is a PTIME checkable
certificate - NP-hard by reduction from 3SAT
- 8 primitive constraints, corresponding to 8
3-clauses - All domains are 0, 1
25CSP Satisfiability
Rpnn
- X ? ?Y ? ?Z
- Bool var 0/1 var
- clause constraint
- SAT problem CSP
26Binary CSPs
- Binary CSPs are universal
- Every CSP can be encoded as a binary CSP
- Variables range over tuples in constraints of
original CSP - Constraints permit only tuples that are
compatible in original CSP
27Binary CSPs
- A binary CSP is arc-consistent if
- for every variable x in V,
- and every constraint c(x, y) involving x,
- for every value d in D(x)
- there is a value d' in D(y)
- such that c(d, d') is true ?
- (equivalently, the tuple (d, d') is in c)
- d is called a support for d
28Binary CSPs
- If a CSP is arc-consistent, then
- all the information about possible variable
values (i.e. domains) - that can be extracted from the constraints
(looked at one-at-a-time) - is represented in the domains
- Sometimes called domain consistency
- By making a CSP arc-consistent, we simplify the
problem, without losing solutions
29Binary CSPs
- We can make a CSP arc consistent by deleting all
domain values that do not have a support - these are values that cannot participate in a
solution - By making a CSP arc-consistent, we simplify the
problem, without losing solutions - For table constraints, arc-consistency can be
enforced in O(nD2) - n constraints
- maximum domain size D
30Rock Star Dressing Problem
blue black purple khaki
red green orange blue
C1
C2
C3
yellow pink
31Rock Star Dressing Problem
blue black purple khaki
red green orange blue
C1
C2
C3
yellow pink
32Rock Star Dressing Problem
blue black purple khaki
red green orange blue
C1
C2
C3
yellow pink
33Generalized Arc Consistency
- A CSP is generalized arc-consistent if
- for every variable x in V,
- and every constraint c(x, y1, , yn),
- for every value d in D(x)
- there are values d1dn in D(y1), , D(yn)
- such that c(d, d1dn) is true ?
- (equivalently, the tuple (d, d1dn) is in c)
- Complexity O(nDk) for constraints of arity k
34(No Transcript)
35Rock Star Dressing Problem
blue black purple khaki
red green orange blue
C1
C2
C3
yellow pink