Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
IT University of Copenhagen
IT University of Copenhagen
Todays Program
[12:00-12:55]
Constraint Satisfaction Problems (CSPs)
Constraint Propagation
[13:05-14:00]
Backtracking
Forward Checking
Maintaining arc consistency (MAC) algorithm
[14:00-16:00]
Exercises
IT University of Copenhagen
IT University of Copenhagen
IT University of Copenhagen
Definition of CSPs
A CSP is a triple <X,D,C>, where:
X = {X1,,Xn} is a finite set of variables.
D = {D1,,Dn} is a set of domains of possible values for each
variable, where Di = {v1,,vki}
C = {C1,,Cm} is a set of constraints, where Ci = <scope, relation>
e.g.
X1{A,B}, X2{A,B}
CSP Solutions
Partial Assignment : Values assigned to only some
of the variables.
Complete Assignment : Each variable has a value
assigned.
IT University of Copenhagen
Types of Constraints
Different Arity
Unary constraints involve a single variable.
e.g. X 12
P = MIB /\ C = Black
10
IT University of Copenhagen
11
IT University of Copenhagen
12
Constraint Propagation
Node consistency : for every value vi of
variable X, all unary constraints of X are
satisfied.
Example
SA {red, green, blue}, SA {green}
SA {red, blue}
13
14
IT University of Copenhagen
15
Complexity of AC-3
Assume
n variables,
at most d values in domains
c binary constraints
Observations
An arc can at most be added d times
An arc can be revised in d2
Thus, worst case runtime is O(cd3)
IT University of Copenhagen
16
CSP Solving
IT University of Copenhagen
17
Search in CSP
Inference is not enough
Complexity
Branching factor b at the top level is nd
b = (n-l)d at depth l, hence n!dn leaves
But only dn complete assignments?!
IT University of Copenhagen
18
Backtracking Search
Insight:
If we assign the first k variables to values, it does not
matter in what order we did it in.
Thus, after choosing which variable to assign in a
node, do not change it.
Backtracking Algorithm:
Choose values for one variable at the time.
Backtrack when a variable has no legal values left.
IT University of Copenhagen
19
Backtracking Example
NT
WA
IT University of Copenhagen
SA
Q
NSW
V
T
20
Backtracking Example
NT
WA
IT University of Copenhagen
SA
Q
NSW
V
T
21
Backtracking Example
NT
WA
IT University of Copenhagen
SA
Q
NSW
V
T
22
Backtracking Example
NT
WA
IT University of Copenhagen
SA
Q
NSW
V
T
23
Backtracking Example
NT
WA
IT University of Copenhagen
SA
Q
NSW
V
T
24
Backtracking Example
NT
WA
IT University of Copenhagen
SA
Q
NSW
V
T
25
Backtracking Example
NT
WA
IT University of Copenhagen
SA
Q
NSW
V
T
26
Backtracking Example
NT
WA
SA
Q
NSW
V
T
IT University of Copenhagen
27
Backtracking Algorithm
IT University of Copenhagen
28
IT University of Copenhagen
29
Selecting Variable
NT
WA
SA
NSW
V
T
IT University of Copenhagen
30
Selecting Variable
NT
WA
SA
NSW
V
T
Degree heuristic
31
Selecting Value
NT
WA
SA
NSW
V
T
32
Backtracking Algorithm
IT University of Copenhagen
33
Forward Checking
NT
WA
SA
NSW
V
T
34
Forward Checking
NT
WA
SA
NSW
V
T
35
Forward Checking
NT
WA
SA
NSW
V
T
36
Forward Checking
NT
WA
SA
NSW
V
T
37
38
Forward Checking
Forward checking propagates information from assigned to
unassigned variables, but doesn't provide early detection for all
failures:
NT
WA
SA
NSW
V
IT University of Copenhagen
39
Arc Consistency
NT
WA
SA
NSW
V
T
IT University of Copenhagen
40
Arc Consistency
NT
WA
SA
NSW
V
T
IT University of Copenhagen
41
Arc Consistency
NT
WA
SA
NSW
V
T
IT University of Copenhagen
42
MAC
function MAC-SEARCH(csp) returns a solution or failure
run AC-3(csp)
return RECURSIVE-MAC({},csp)
function RECURSIVE-MAC(assignment,csp) returns a solution or failure
if assigment is complete then return assigment
var SELECT-UNASSIGNED-VARIABLE(VARIABLES[csp],assigment,csp)
for each value in ORDER-DOMAIN-VALUES(var, assigment, csp) do
if value is consisten with assigment do
add{var=value} to assigment
inferences AC-3(csp)
if inferencesfailure then
add inferences to assigment and update csp
resultRECURSIVE-MAC(assigment, csp)
if resultfailure then
result result
remove {var=value} and inferences from assigment and csp
return failure
IT University of Copenhagen
43