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

Slides:



Advertisements
Similar presentations
CPSC 322, Lecture 14Slide 1 Local Search Computer Science cpsc322, Lecture 14 (Textbook Chpt 4.8) Oct, 5, 2012.
Advertisements

CPSC 322, Lecture 4Slide 1 Search: Intro Computer Science cpsc322, Lecture 4 (Textbook Chpt ) Sept, 11, 2013.
This lecture topic (two lectures) Chapter 6.1 – 6.4, except
1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
1 CMSC 471 Fall 2002 Class #6 – Wednesday, September 18.
This lecture topic (two lectures) Chapter 6.1 – 6.4, except 6.3.3
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.4) January, 14, 2009.
Uninformed Search Jim Little UBC CS 322 – Search 2 September 12, 2014
CPSC 322, Lecture 9Slide 1 Search: Advanced Topics Computer Science cpsc322, Lecture 9 (Textbook Chpt 3.6) January, 23, 2009.
CPSC 322, Lecture 23Slide 1 Logic: TD as search, Datalog (variables) Computer Science cpsc322, Lecture 23 (Textbook Chpt 5.2 & some basic concepts from.
CPSC 322, Lecture 4Slide 1 Search: Intro Computer Science cpsc322, Lecture 4 (Textbook Chpt ) January, 12, 2009.
CPSC 322, Lecture 14Slide 1 Local Search Computer Science cpsc322, Lecture 14 (Textbook Chpt 4.8) February, 3, 2010.
CPSC 322, Lecture 18Slide 1 Planning: Heuristics and CSP Planning Computer Science cpsc322, Lecture 18 (Textbook Chpt 8) February, 12, 2010.
CPSC 322, Lecture 9Slide 1 Search: Advanced Topics Computer Science cpsc322, Lecture 9 (Textbook Chpt 3.6) January, 22, 2010.
CPSC 322, Lecture 13Slide 1 CSPs: Arc Consistency & Domain Splitting Computer Science cpsc322, Lecture 13 (Textbook Chpt 4.5,4.6) February, 01, 2010.
4 Feb 2004CS Constraint Satisfaction1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3.
CPSC 322, Lecture 23Slide 1 Logic: TD as search, Datalog (variables) Computer Science cpsc322, Lecture 23 (Textbook Chpt 5.2 & some basic concepts from.
CPSC 322, Lecture 12Slide 1 CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12 (Textbook Chpt ) January, 29, 2010.
CPSC 322, Lecture 13Slide 1 CSPs: Arc Consistency & Domain Splitting Computer Science cpsc322, Lecture 13 (Textbook Chpt 4.5,4.8) February, 02, 2009.
CPSC 322, Lecture 14Slide 1 Local Search Computer Science cpsc322, Lecture 14 (Textbook Chpt 4.8) February, 4, 2009.
Constraint Satisfaction Problems
Constraint Satisfaction
CPSC 322, Lecture 17Slide 1 Planning: Representation and Forward Search Computer Science cpsc322, Lecture 17 (Textbook Chpt 8.1 (Skip )- 8.2) February,
Constraint Satisfaction Problems Russell and Norvig: Chapter 3, Section 3.7 Chapter 4, Pages Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm.
CPSC 322, Lecture 22Slide 1 Logic: Domain Modeling /Proofs + Top-Down Proofs Computer Science cpsc322, Lecture 22 (Textbook Chpt 5.2) March, 8, 2010.
Constraint Satisfaction Problem Solving Chapter 5.
Chapter 5 Outline Formal definition of CSP CSP Examples
Constraint Satisfaction Problems
1 Constraint Satisfaction Problems Slides by Prof WELLING.
Slide 1 CSPs: Arc Consistency & Domain Splitting Jim Little UBC CS 322 – Search 7 October 1, 2014 Textbook §
Relaxation and Hybrid constraint processing Different relaxation techniques Some popular hybrid techniques.
Computer Science CPSC 322 Lecture 4 Search: Intro (textbook Ch: ) 1.
CPSC 322, Lecture 22Slide 1 Logic: Domain Modeling /Proofs + Top-Down Proofs Computer Science cpsc322, Lecture 22 (Textbook Chpt 5.2) Oct, 26, 2010.
Local Search CPSC 322 – CSP 5 Textbook §4.8 February 7, 2011.
Computer Science CPSC 502 Lecture 3 Constraint Satisfaction Problems (Ch. 4 )
Computer Science CPSC 322 Lecture 9 (Ch , 3.7.6) Slide 1.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Solving Constraint Satisfaction Problems (CSPs) using Search CPSC 322 – CSP 2 Textbook § January 31, 2011.
Solving Constraint Satisfaction Problems (CSPs) using Search
Chapter 5: Constraint Satisfaction ICS 171 Fall 2006.
Search with Costs and Heuristic Search 1 CPSC 322 – Search 3 January 17, 2011 Textbook §3.5.3, Taught by: Mike Chiang.
Computer Science CPSC 322 Lecture 6 Iterative Deepening and Search with Costs (Ch: 3.7.3, 3.5.3)
Problem Reduction So far we have considered search strategies for OR graph. In OR graph, several arcs indicate a variety of ways in which the original.
1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3 Grand Challenge:
CHAPTER 5 SECTION 1 – 3 4 Feb 2004 CS Constraint Satisfaction 1 Constraint Satisfaction Problems.
Constraint Satisfaction Problems University of Berkeley, USA
Arc Consistency CPSC 322 – CSP 3 Textbook § 4.5 February 2, 2011.
CPSC 322, Lecture 6Slide 1 Uniformed Search (cont.) Computer Science cpsc322, Lecture 6 (Textbook finish 3.5) Sept, 17, 2012.
Arc Consistency and Domain Splitting in CSPs CPSC 322 – CSP 3 Textbook Poole and Mackworth: § 4.5 and 4.6 Lecturer: Alan Mackworth October 3, 2012.
Chapter 5 Team Teaching AI (created by Dewi Liliana) PTIIK Constraint Satisfaction Problems.
Domain Splitting, Local Search CPSC 322 – CSP 4 Textbook §4.6, §4.8 February 4, 2011.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.5) Sept, 13, 2013.
Constraint Satisfaction Problems/Programming ZUI 2012/2013.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
ARTIFICIAL INTELLIGENCE (CS 461D) Dr. Abeer Mahmoud Computer science Department Princess Nora University Faculty of Computer & Information Systems.
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Computer Science cpsc322, Lecture 13
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Constraint Satisfaction Problems Lecture # 14, 15 & 16
Planning: Forward Planning and CSP Planning
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Constraint Propagation
Computer Science cpsc322, Lecture 13
Constraint Satisfaction Problems
Logic: Domain Modeling /Proofs + Computer Science cpsc322, Lecture 22
Constraint satisfaction problems
Domain Splitting CPSC 322 – CSP 4 Textbook §4.6 February 4, 2011.
Constraint Graph Binary CSPs
Constraint satisfaction problems
Presentation transcript:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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