Computer Science CPSC 322
Lectur ture 9 e 9 Arc Consistency
(4. (4.5, 4. 4.6) 6)
Slide 1
Lectur ture 9 e 9 Arc Consistency (4. (4.5, 4. 4.6) 6) Slide - - PowerPoint PPT Presentation
Computer Science CPSC 322 Lectur ture 9 e 9 Arc Consistency (4. (4.5, 4. 4.6) 6) Slide 1 Lect cture re O Overvi rview Recap of Lecture 8 Arc Consistency for CSP Domain Splitting 2 Course rse O Overvi rview
Slide 1
2
Representation Reasoning Technique
3
4
Definition: A constraint satisfaction problem (CSP) consists of:
We will mostly deal with binary constraints
participating in the constraint
variable which satisfy the constraint
WA NT NT Red Green Red Bue Green Red Green Blue Blue Red Blue Green NT NT SA SA Red Green Red Bue Green Red Green Blue Blue Red Blue Green NT NT QU Red Green Red Bue Green Red Green Blue Blue Red Blue Green
6
Definition: A model of a CSP is an assignment of values to all of its variables (i.e., a possible world) that satisfies all of its constraints. Definition: A constraint satisfaction problem (CSP) consists of:
WA = red, NT = green, Q = red, NSW = green, V = red, SA = blue, T = green
size of the search space
quickly, even though they may offer no theoretical guarantees
8
V1 = v1 V2 = v1 V1 = v1 V2 = v2 V1 = v1 V2 = vk V1 = v1 V2 = v1 V3 = v2 V1 = v1 V2 = v1 V3 = v1 {} V1 = v1 V1 = vk
9
Check unary constraints on V1 If not satisfied = PRUNE Check constraints on V1 and V2 If not satisfied = PRUNE V1 = v1 V2 = v1 V1 = v1 V2 = v2 V1 = v1 V2 = vk V1 = v1 V2 = v1 V3 = v2 V1 = v1 V2 = v1 V3 = v1 {} V1 = v1 V1 = vk
10
“If you are going to fail on this branch, fail early!”
11
12
domain.
13
nodes whenever a given variable is involved in a given constraint. {2,3} {3} A B A< B A>C {1,2} C
A>C
14
nodes whenever a given variable is involved in a given constraint.
5 edges/arcs in the constraint network: 〈A,A<B〉 , 〈B,A<B〉 〈B,B<C〉 , 〈C,B<C〉 〈B, B=3〉
15
16
17
18
19
1,2,3 2,3 A B A< B Not arc consistent: No value in domain of B that satisfies A<B if Arc consistent: Both B=2 and B=3 have ok values for A
20
1,2,3 2,3 A B A< B
Not arc consistent: No value in domain of B that satisfies A<B if Arc consistent: Both B=2 and B=3 have ok values for A
21
2, 5 3, 6, 12 X Y X< Y/2
Definition: An arc <x, r(x,y)> is arc consistent if for each value x in dom(X) there is some value y in dom(Y) such that r(x,y) is satisfied. A network is arc consistent if all its arcs are arc consistent.
2, 5 3, 6, 12 X Y X< Y/2
23
Definition: An arc <x, r(x,y)> is arc consistent if for each value x in dom(X) there is some value y in dom(Y) such that r(x,y) is satisfied. A network is arc consistent if all its arcs are arc consistent.
2,5, 3,5,12 X Y X< Y/2
Not arc consistent: No value in domain of X that satisfies X< Y/2 if Arc consistent: Both X=2 and X=5 have
Y= )
24
2,5, 3,5,12 X Y X< Y/2
Not arc consistent: No value in domain of X that satisfies X< Y/2 if Y = 3 Arc consistent: Both X=2 and X=5 have
Y= 12 )
25
value in dom(Y)
WHY?
26
2,3,4 1,2,3 X Y X< Y
Download this example (SimpleCSP) from Schedule page Save to a local file and then open file in the Aispace applet Consistency Based CSP Solver
value in dom(Y)
27
{2,3} {3} A B A< B A>C {1,2} C Try to build this simple network in AISpace 28
{2,3} {3} A B A< B A>C {1,2} C Arc consistent: For each value in dom(C), there is one in dom(A) that satisfies A>C (namely A=3) Try to build this simple network in AISpace 29
{2,3} {3} A B A< B A>C {1,2} C Arc consistent: For each value in dom(C), there is one in dom(A) that satisfies A>C (namely A=3) 30 Not arc consistent: No value in domain of B that satisfies A<B if A=3
{2,3} {3} A B A< B
Not arc consistent: No value in domain of B that satisfies A<B if A=3
A>C {1,2} C
Arc consistent: For each value in dom(C), there is one in dom(A) that satisfies A>C (namely A=3)
{2,3} {3} A B A< B A>C {1,2} C
31
Pruning A=3 makes this arc consistent
{2,3} {3} A B A< B
Not arc consistent: No value in domain of B that satisfies A<B if A=3
A>C {1,2} C
Arc consistent: For each value in dom(C), there is one in dom(A) that satisfies A>C (namely A=3)
{2,3} {3} A B A< B A>C {1,2} C
But after pruning A= 3: Not arc consistent anymore: For C=2, there is no value in dom(A) that satisfies A>C: prune!
32
arc consistent
Which of these other arcs need to be reconsidered?
33
〈X,c〉 arc consistent, it need to reconsider the following arcs (that were already consistent)
every arc 〈Zi, ci〉 where c’ ≠ c involves Z and X:
34
arc 〈X,c〉 arc consistent, does it need to reconsider the following arcs (that were already consistent)?
every arc 〈Zi, ci〉 where c’ ≠ c involves Z and X:
35
Pruning elements of Dom(x) may remove values that made one or more of 〈Zi,ci〉 consistent
arc 〈X,c〉 arc consistent, does it need to reconsider the following arcs (that were already consistent)?
every arc 〈X, ci〉 where c’ ≠ c
36
arc 〈X,c〉 arc consistent, does it need to reconsider the following arcs (that were already consistent)?
every arc 〈X,ci〉 where c’ ≠ c
37
If an arc 〈X,ci〉 was arc consistent before, it will still be arc consistent. The domains of Zi have not been touched
arc 〈X,c〉 arc consistent, does it need to reconsider the following arcs (that were already consistent)?
The arc 〈Y, c〉 related to the constraint c involved in 〈X, c〉 , which caused the pruning of Dom(X) :
38
arc 〈X,c〉 arc consistent, does it need to reconsider the following arcs (that were already consistent)?
The arc 〈Y, c〉 related to the constraint c involved in 〈X, c〉 , which caused the pruning of Dom(X) :
39
If arc 〈Y,c〉 was arc consistent before, it will still be arc consistent “Consistent before” means each element yi in Y must have an element xi in X that satisfies the constraint. Those xi would not be pruned from Dom(X), so arc 〈Y,c〉 stays consistent
40
Arc <Y, x=y> is consistent because each value of Y (1,2) has a corresponding value in X that satisfies x =y Arc <X, x=y> is not consistent so X needs to be pruned in relation to this arc (not some other arc in the network). This is the situation described in the last clicker question. But only items that were not involved in making <Y, x=y> consistent may end up being pruned (3 in this case). Those who were involved (i.e. 1,2 here) *must* have a counterpart value in Y, since <Y, x=y> is consistent
“Consistent before” means each element yi in Y must have an element xi in X that satisfies the constraint. Those xi would not be pruned from Dom(X), so arc 〈Y,c〉 stays consistent
The domains of Zi have not been touched
Z1 c1 Z2 c2 Z3 c3 Y c T H E S E X A c4
41
42
Procedur edure GAC(V,dom,C) Input Inputs V: a set of variables dom: a function such that dom(X) is the domain of variable X C: set of constraints to be satisfied Output utput arc-consistent domains for each variable Loc Local DX is a set of values for each variable X TDA is a set of arcs 1: for for eac each variable X do do 2: DX ←dom(X) 3: TDA ←{〈X,c〉| X ∈ V, c ∈ C and X ∈ scope(c)} 4: while ile (TDA ≠ {}) 5: se sele lect 〈X,c〉 ∈TDA 6: TDA ←TDA \ {〈X,c〉} 7: NDX ←{x| x ∈ DX and ∃ y ∈ DY s.t. (x, y) satisfies c} 8: if if (NDX ≠ DX) then then 9: TDA ←TDA ∪ { 〈Z,c'〉 | X ∈ scope(c'), c' ≠ c, Z ∈ scope(c') \ {X} } 10: DX ←NDX 11: retur eturn {DX| X is a variable} Scope of constraint c is the set of variables involved in that constraint NDX: values x for X for which there is a value for y supporting x X’s domain changed: ⇒ arcs (Z,c’) for variables Z sharing a constraint c’ with X could become inconsistent, thus are added to TDA TDA: ToDoArcs, blue arcs in AIspace If arc was inconsistent Domain is reduced
43
procedure (compare with DFS)
with pruning?)
44
procedure (compare with DFS)
with pruning?)
Check unary constraints
If not satisfied = PRUNE Check constraints on V1 and V2 If not satisfied = PRUNE V1 = v1 V2 = v1 V1 = v1 V2 = v2 V1 = v1 V2 = vk V1 = v1 V2 = v1 V3 = v2 V1 = v1 V2 = v1 V3 = v1 {} V1 = v1 V1 = vk
45
procedure (compare with DFS)
with pruning?)
Check unary constraints
If not satisfied = PRUNE Check constraints on V1 and V2 If not satisfied = PRUNE V1 = v1 V2 = v1 V1 = v1 V2 = v2 V1 = v1 V2 = vk V1 = v1 V2 = v1 V3 = v2 V1 = v1 V2 = v1 V3 = v1 {} V1 = v1 V1 = vk
46
procedure (compare with DFS……O(dn)……..)
47
the ToDoArc list?
48
this procedure (compare with DFS O(dn) )
d
? (n (n * (n (n-1) 1)) / 2
arc can be inserted in the ToDoArc list? O(d) d)
49
procedure (compare with DFS O(dn))
(n (n * (n (n-1)) )) / 2
can be inserted in the ToDoArc list? O(d) d)
the consistency of an arc? O(d2)
50
procedure (compare with DFS O(dn))
(n (n * (n (n-1)) )) / 2
can be inserted in the ToDoArc list? O(d) d)
the consistency of an arc? O(d2)
51
52
e.g. built-in AISpace example “Scheduling problem 1” We have: a (unique) solution.
We have: No solution! All values are ruled out for this variable. e.g. try this graph (can easily generate it by modifying Simple Problem 2)
53
54
55
e.g. built-in AISpace example “Scheduling problem 1” We have: a (unique) solution.
We have: No solution! All values are ruled out for this variable. e.g. try this graph (can easily generate it by modifying Simple Problem 2)
There may be: one solution, multiple ones, or none Need to solve this new CSP (usually simpler) problem: – same constraints, domains have been reduced
56
between:
whether it is a model, a solution)
disadvantages.
state). Compare strategies for CSP search. Implement pruning for DFS search in a CSP.
its complexity and assess its possible outcomes
57