Presentation is loading. Please wait.

Presentation is loading. Please wait.

Computer Science CPSC 322 Lecture 13 Arc Consistency (4.5, 4.6 ) Slide 1.

Similar presentations


Presentation on theme: "Computer Science CPSC 322 Lecture 13 Arc Consistency (4.5, 4.6 ) Slide 1."— Presentation transcript:

1 Computer Science CPSC 322 Lecture 13 Arc Consistency (4.5, 4.6 ) Slide 1

2 Announcements Assignment 2 out later today – Due Friday Feb. 13 Can already start doing the first 2 questions after today’s class Remember that I have posted in Connect: Learning goals for the whole course Short questions on material for the whole course. Both midterm and final will have questions very similar, or even verbatim, from this set ( about 40-60% of overall mark) You can answer these questions by studying the slides and texbook –Cover questions as we proceed through the material, come to see us if you have doubts on how to answer –BUT DO STUDY THE REVELANT MATERIAL FIRST! Do not wait until just before the midterm to review the questions, if you start now it will be much easier to cover all the relevant ones before the exam 2

3 Lecture Overview Recap of Lecture 12 Arc Consistency for CSP Domain Splitting 3

4 Search-Based Approach Constraint Satisfaction (Problems): State: assignments of values to a subset of the variables Successor function: assign values to a “free” variable Goal test: all variables assigned a value and all constraints satisfied? Solution: possible world that satisfies the constraints Heuristic function: none (all solutions at the same distance from start) Planning : State Successor function Goal test Solution Heuristic function Inference State Successor function Goal test Solution Heuristic function V 1 = v 1 V 2 = v 1 V 1 = v 1 V 2 = v 2 V 1 = v 1 V 2 = v k V 1 = v 1 V 2 = v 1 V 3 = v 2 V 1 = v 1 V 2 = v 1 V 3 = v 1 {} V 1 = v 1 V 1 = v k 4

5 Explore search space via DFS but evaluate each constraint as soon as all its variables are bound. Any partial assignment that doesn’t satisfy the constraint can be pruned. Backtracking algorithms Check unary constraints on V 1 If not satisfied = PRUNE Check constraints on V 1 and V 2 If not satisfied = PRUNE V 1 = v 1 V 2 = v 1 V 1 = v 1 V 2 = v 2 V 1 = v 1 V 2 = v k V 1 = v 1 V 2 = v 1 V 3 = v 2 V 1 = v 1 V 2 = v 1 V 3 = v 1 {} V 1 = v 1 V 1 = v k 5

6 Backtracking relies on one or more heuristics to select which variables to consider next. -E.g, variable involved in the largest number of constraints: “If you are going to fail on this branch, fail early!” But we will look at an alternative approach that can do much better Arc Consistency: Key idea: prune the domains as much as possible before searching for a solution. Selecting variables in a smart way 6

7 Constraint Networks Def. A constraint network is defined by a graph, with - one node for every variable (drawn as circle) - one node for every constraint (drawn as rectangle) -undirected edges running between variable nodes and constraint nodes whenever a given variable is involved in a given constraint. {2,3} {3} A B A< B A>C {1,2} C 7 -Three variables: A, B, C -Two constraints: A<B, A>C

8 Arc Consistency Definition: An arc 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. {1,2,3}{2,3} A B A< B Not arc consistent: No value in domain of B that satisfies A<B if A=3 Arc consistent: Both B=2 and B=3 have ok values for A (e.g. A=1) 8

9 Arc Consistency Definition (arc consistency) An arc is arc consistent if for each value in there is some value in such that is satisfied. A.Both arcs are consistent B.Left consistent, right inconsistent C.Left inconsistent, right consistent D.Both arcs are inconsistent Left = Right = 2, 5 3, 6, 12 X Y X< Y/2 9

10 Arc Consistency Definition: An arc 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 ok values for Y (e.g. Y= ) 10

11 Arc Consistency Algorithm How can we enforce Arc Consistency? If an arc is not arc consistent - Delete all values x in dom(X) for which there is no corresponding value in dom(Y) - This deletion makes the arc arc consistent. -This removal can never rule out any models/solutions WHY? 11 2,3,4 1,2,3 X Y X< Y Download this example (SimpleCSP) from Schedule page Save to a local file and the open file in

12 Lecture Overview Recap of Lecture 12 Arc Consistency for CSP Domain Splitting 12

13 Arc Consistency Algorithm How can we enforce Arc Consistency? If an arc is not arc consistent - Delete all values x in dom(X) for which there is no corresponding value in dom(Y) - This deletion makes the arc arc consistent. -This removal can never rule out any models/solutions Algorithm: general idea Go through all the arcs in the network Make each arc consistent by pruning the appropriate domain, when needed Reconsider arcs that could be turned back to being inconsistent by this pruning Eventually reach a ‘fixed point’: all arcs consistent 13

14 Arc Consistency {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) Try to build this simple network in AISpace 14

15 Arc Consistency {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 After pruning A= 3: Not arc consistent anymore: For C=2, there is no value in dom(A) that satisfies A>C: prune! 15

16 When we reduce the domain of a variable X to make an arc  X,c  arc consistent, which arcs do we need to reconsider? Which arcs need to be reconsidered? every arc  Z,c'  where c’  c involves Z and X: Z1Z1 c1c1 Z2Z2 c2c2 Z3Z3 c3c3 Y c THESETHESE X A c4c4 16

17 When we reduce the domain of a variable X to make an arc  X,c  arc consistent, which arcs do we need to reconsider? Which arcs need to be reconsidered? every arc  Z,c'  where c’  c involves Z and X: Z1Z1 c1c1 Z2Z2 c2c2 Z3Z3 c3c3 Y c THESETHESE X A c4c4 Pruning elements of Dom(x) may remove values that made one or more of  Z,c'  consistent 17

18 When we reduce the domain of a variable X to make an arc  X,c  arc consistent, which arcs do we need to reconsider? You do not need to reconsider other arcs - If arc  Y,c  was arc consistent before, it will still be arc consistent “ Consistent before” means each element y i in Y must have an element x i in X that satisfies the constraint. Those x i would not be pruned from Dom(X), so arc  Y,c  stays consistent - If an arc  X,c i  was arc consistent before, it will still be arc consistent The domains of Z i have not been touched - Nothing changes for arcs of constraints not involving X Which arcs need to be reconsidered? Z1Z1 c1c1 Z2Z2 c2c2 Z3Z3 c3c3 Y c THESETHESE X A c4c4 18

19 Consider the arcs in turn, making each arc consistent Reconsider arcs that could be made inconsistent again by this pruning DO trace on ‘simple problem 1’ and on ‘scheduling problem 1’, trying to predict - which arcs are not consistent and - which arcs need to be reconsidered after each removal in Which arcs need to be reconsidered? 19

20 Arc consistency algorithm (for binary constraints) Procedure GAC(V,dom,C) 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 arc-consistent domains for each variable Local D X is a set of values for each variable X TDA is a set of arcs 1: for each variable X do 2: D X ←dom(X) 3: TDA ←{〈X,c〉| X ∈ V, c ∈ C and X ∈ scope(c)} 4: while (TDA  {}) 5: select 〈X,c〉 ∈TDA 6: TDA ←TDA \ {〈X,c〉} 7: ND X ←{x| x ∈ D X and  y ∈ D Y s.t. (x, y ) satisfies c} 8: if (ND X  D X ) then 9: TDA ←TDA ∪ { 〈Z,c'〉 | X ∈ scope(c'), c'  c, Z ∈ scope(c') \ {X} } 10: D X ←ND X 11: return {D X | X is a variable} Scope of constraint c is the set of variables involved in that constraint ND X : 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 20

21 A. O(n*d) B. O(d n ) C. O(n d ) D. O(n * d 2 ) Arc Consistency Algorithm: Complexity Let’s determine Worst-case complexity of this procedure (compare with DFS) let the max size of a variable domain be d let the number of variables be n Worst-case time complexity of Backtracking (DFS with pruning?) Check unary constraints on V 1 If not satisfied = PRUNE Check constraints on V 1 and V 2 If not satisfied = PRUNE V 1 = v 1 V 2 = v 1 V 1 = v 1 V 2 = v 2 V 1 = v 1 V 2 = v k V 1 = v 1 V 2 = v 1 V 3 = v 2 V 1 = v 1 V 2 = v 1 V 3 = v 1 {} V 1 = v 1 V 1 = v k 21

22 Arc Consistency Algorithm: Complexity Let’s determine Worst-case complexity of this procedure (compare with DFS……O(d n )……..) let the max size of a variable domain be d let the number of variables be n The max number of binary constraints is ? A.n * d B.d * d C.(n * (n-1)) / 2 D.(n * d) / 2 22

23 B. O(d) C. O(n*d) A. O(n) Arc Consistency Algorithm: Complexity Let’s determine Worst-case complexity of this procedure (compare with DFS O(d n )) let the max size of a variable domain be d let the number of variables be n The max number of binary constraints is ? (n * (n-1)) / 2 How many times, at worst, the same arc can be inserted in the ToDoArc list? D. O(d 2 ) 23

24 Arc Consistency Algorithm: Complexity Let’s determine Worst-case complexity of this procedure (compare with DFS O(d n ) ) let the max size of a variable domain be d let the number of variables be n The max number of binary constraints is ? (n * (n-1)) / 2 How many times, at worst, the same arc can be inserted in the ToDoArc list? O(d) How many steps are involved in checking the consistency of an arc? A. O(n 2 ) B. O(d) C. O(n * d) D. O(d 2 ) 24

25 Arc Consistency Algorithm: Complexity Let’s determine Worst-case complexity of this procedure (compare with DFS O(d n ) ) let the max size of a variable domain be d let the number of variables be n The max number of binary constraints is ? (n * (n-1)) / 2 How many times, at worst, the same arc can be inserted in the ToDoArc list? O(d) How many steps are involved in checking the consistency of an arc? O(d 2 ) Overall complexity: O(n 2 d 3 ) Compare to O(d N ) of DFS!! Arc consistency is MUCH faster 25

26 Can we have an arc consistent network with non-empty domains that has no solution? YES Example: vars A, B, C with domain {1, 2} and constraints A ≠ B, B ≠ C, A ≠ C Or see AIspace CSP applet Simple Problem 2 26

27 Learning Goals for CSP Define/read/write/trace/debug the arc consistency algorithm. Compute its complexity and assess its possible outcomes ------------------------------------ To Do Start Assignment 2 Do Practice Exercises 4a and 4b Read Stocastic Local Search (4.8.1) 27


Download ppt "Computer Science CPSC 322 Lecture 13 Arc Consistency (4.5, 4.6 ) Slide 1."

Similar presentations


Ads by Google