Computer Science CPSC 502 Lecture 3 Constraint Satisfaction Problems (Ch. 4 )

Slides:



Advertisements
Similar presentations
Constraint Satisfaction Problems
Advertisements

1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
This lecture topic (two lectures) Chapter 6.1 – 6.4, except 6.3.3
1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni.
Constraint Satisfaction problems (CSP)
CPSC 322, Lecture 10Slide 1 Finish Search Computer Science cpsc322, Lecture 10 (Textbook Chpt 3.6) January, 28, 2008.
CPSC 322, Lecture 4Slide 1 Search: Intro Computer Science cpsc322, Lecture 4 (Textbook Chpt ) January, 12, 2009.
CPSC 322, Lecture 18Slide 1 Planning: Heuristics and CSP Planning Computer Science cpsc322, Lecture 18 (Textbook Chpt 8) February, 12, 2010.
CPSC 322, Lecture 10Slide 1 Finish Search Computer Science cpsc322, Lecture 10 (Textbook Chpt 3.6) January, 25, 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.
Constraint Satisfaction Problems
CPSC 322, Lecture 11Slide 1 Constraint Satisfaction Problems (CSPs) Introduction Computer Science cpsc322, Lecture 11 (Textbook Chpt 4.0 – 4.2) January,
4 Feb 2004CS Constraint Satisfaction1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3.
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.
Constraint Satisfaction Problems
Constraint Satisfaction
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 §
Computer Science CPSC 322 Lecture 3 AI Applications 1.
Slide 1 Constraint Satisfaction Problems (CSPs) Introduction Jim Little UBC CS 322 – CSP 1 September 27, 2014 Textbook §
Computer Science CPSC 322 Lecture 4 Search: Intro (textbook Ch: ) 1.
Local Search CPSC 322 – CSP 5 Textbook §4.8 February 7, 2011.
Branch & Bound, CSP: Intro CPSC 322 – CSP 1 Textbook § & January 28, 2011.
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
Constraint Satisfaction Problems Chapter 6. Review Agent, Environment, State Agent as search problem Uninformed search strategies Informed (heuristic.
Chapter 5 Section 1 – 3 1.  Constraint Satisfaction Problems (CSP)  Backtracking search for CSPs  Local search for CSPs 2.
Computer Science CPSC 322 Lecture 13 Arc Consistency (4.5, 4.6 ) Slide 1.
Hande ÇAKIN IES 503 TERM PROJECT CONSTRAINT SATISFACTION PROBLEMS.
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
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.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
Lecture 3: Uninformed Search
Chapter 5 Constraint Satisfaction Problems
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.
1. 2 Outline of Ch 4 Best-first search Greedy best-first search A * search Heuristics Functions Local search algorithms Hill-climbing search Simulated.
CPSC 322, Lecture 4Slide 1 Search: Intro Computer Science cpsc322, Lecture 4 (Textbook Chpt ) Sept, 12, 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.
Computing & Information Sciences Kansas State University Friday, 08 Sep 2006CIS 490 / 730: Artificial Intelligence Lecture 7 of 42 Friday, 08 September.
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.
Dr. Shazzad Hosain Department of EECS North South University Lecture 01 – Part C Constraint Satisfaction Problems.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
Constraint Satisfaction Problems
CS 561, Session 8 1 This time: constraint satisfaction - Constraint Satisfaction Problems (CSP) - Backtracking search for CSPs - Local search for CSPs.
Constraint Satisfaction Problems (CSPs) Introduction
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Artificial Intelligence (AI) Computer Science cpsc502, Lecture 3
Computer Science cpsc322, Lecture 13
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Constraint Satisfaction Problems (CSPs) Introduction
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Computer Science cpsc322, Lecture 13
Constraint Satisfaction Problems
Artificial Intelligence
Constraint satisfaction problems
Constraint Satisfaction Problems. A Quick Overview
Domain Splitting CPSC 322 – CSP 4 Textbook §4.6 February 4, 2011.
CS 8520: Artificial Intelligence
Constraint Satisfaction Problems
Constraint satisfaction problems
Presentation transcript:

Computer Science CPSC 502 Lecture 3 Constraint Satisfaction Problems (Ch. 4 )

2 Lecture Overview Finish Search Constraint Satisfaction Problems Variables/Features Constraints CSPs Generate-and-Test Search Arc Consistency

Course Overview Environment Problem Type Query Planning Deterministic Stochastic Constraint Satisfaction Search Arc Consistency Search Logics STRIPS Vars + Constraints Value Iteration Variable Elimination Belief Nets Decision Nets Markov Processes Static Sequential Representation Reasoning Technique Variable Elimination First Part of the Course

Standard Search vs. CSP First studied general state space search in isolation Standard search problem: search in a state space State is a “black box” - any arbitrary data structure that supports three problem-specific routines: goal test: goal(state) finding successor nodes: neighbors(state) if applicable, heuristic evaluation function: h(state) We’ll see more specialized versions of search for various problems 4

Constraint Satisfaction Problems (CPS): State Successor function Goal test Solution Heuristic function Query : State Successor function Goal test Solution Heuristic function Planning State Successor function Goal test Solution Heuristic function Search in Specific R&R Systems

Course Overview Environment Problem Type Query Planning Deterministic Stochastic Constraint Satisfaction Search Arc Consistency Search Logics STRIPS Vars + Constraints Value Iteration Variable Elimination Belief Nets Decision Nets Markov Processes Static Sequential Representation Reasoning Technique Variable Elimination We’ll start from CPS

Slide 7 CSPs: Crossword Puzzles - Proverb Source: Michael Littman

Slide 8 CSPs: Radio link frequency assignment Source: INRIA Assigning frequencies to a set of radio links defined between pairs of sites in order to avoid interferences. Constraints on frequency depend on position of the links and on physical environment. Sample Constraint network

Constraint Satisfaction Problems (CSP) In a CSP –state is defined by a set of variables V i with values from domain D i –goal test is a set of constraints specifying 1.allowable combinations of values for subsets of variables (hard constraints) 2.preferences over values of variables (soft constraints)

Dimensions of Representational Complexity (from lecture 2) Reasoning tasks (Constraint Satisfaction / Logic&Probabilistic Inference / Planning) Deterministic versus stochastic domains Some other important dimensions of complexity: Explicit state or features or relations Flat or hierarchical representation Knowledge given versus knowledge learned from experience Goals versus complex preferences Single-agent vs. multi-agent Explicit state or features or relations

Variables/Features and Possible Worlds Variable: a synonym for feature We denote variables using capital letters Each variable V has a domain dom(V) of possible values Variables can be of several main kinds: Boolean: |dom(V)| = 2 Finite: the domain contains a finite number of values Infinite but discrete: the domain is countably infinite Continuous: e.g., real numbers between 0 and 1 Possible world: complete assignment of values to each variable This is equivalent to a state as we have defined it so far Soon, however, we will give a broader definition of state, so it is best to start distinguishing the two concepts.

Example (lecture 2) Mars Explorer Example Weather Temperature Longitude Latitude One possible world (state) Number of possible (mutually exclusive) worlds (states) {S, C} [-40, 40] [0, 359] [0, 179]

Example (lecture 2) Mars Explorer Example Weather Temperature Longitude Latitude One possible world (state) Number of possible (mutually exclusive) worlds (states) {S, -30, 320, 210} 2 x 81 x 360 x 180 {S, C} [-40, 40] [0, 359] [0, 179] Product of cardinality of each domain … always exponential in the number of variables

How many possible worlds? Crossword Puzzle 1: variables are words that have to be filled in domains are English words of correct length possible worlds: all ways of assigning words Number of English words? Let’s say 150,000 Of the right length? Assume for simplicity: 15,000 for each length Number of words to be filled in? 63 How many possible worlds? (assume any combination is ok) 15,

How many possible worlds? Crossword 2: variables are cells (individual squares) domains are letters of the alphabet possible worlds: all ways of assigning letters to cells Number of empty cells? 15*15 – 32 = 193 Number of letters in the alphabet? 26 How many possible worlds? (assume any combination is ok) In general: (domain size) #variables

Examples: variables, domains, possible worlds Scheduling Problem: variables are different tasks that need to be scheduled (e.g., course in a university; job in a machine shop) domains are the different combinations of times and locations for each task (e.g., time/room for course; time/machine for job) possible worlds: time/location assignments for each task

Constraint Satisfaction Problems (CSP) Allow for usage of useful general-purpose algorithms with more power than standard search algorithms They exploit the multi-dimensional nature of the problem and the structure provided by the goal set of constraints, *not* black box.

Constraints Constraints are restrictions on the values that one or more variables can take Unary constraint: restriction involving a single variable k-ary constraint: restriction involving k different variables it turns out that k-ary constraints can always be represented as binary constraints, so we'll mainly only talk about this case Constraints can be specified by 1.listing all combinations of valid domain values for the variables participating in the constraint 2.giving a function that returns true when given values for each variable which satisfy the constraint

Example: Map-Coloring Variables WA, NT, Q, NSW, V, SA, T Domains D i = {red,green,blue} Constraints: adjacent regions must have different colors e.g., Or WA NT SA NT QU …………..

Example: Map-Coloring Variables WA, NT, Q, NSW, V, SA, T Domains D i = {red,green,blue} Constraints: adjacent regions must have different colors e.g., WA ≠ NT, NT ≠ SA, NT ≠ QU, ….., Or WA NT RedGreen RedBue GreenRed GreenBlue Red BlueGreen NT SA RedGreen RedBue GreenRed GreenBlue Red BlueGreen NT QU RedGreen RedBue GreenRed GreenBlue Red BlueGreen …………..

Examples Crossword Puzzle 1: variables are words that have to be filled in domains are valid English words constraints: words have the same letters at points where they intersect h 1 [0] = v 1 [0] h 1 [1] = v 2 [0] ….. ~225 constraints h1h1 v1v1

Eight Queen problem: place 8 queens on a chessboard so that no queen can attack the others Constraints: No queens can be in the same row, column or diagonal Example: Eight Queen problem

Example 2: 8 queens Variables: V 1,.. V n. V i = Row occupied by the i th queen in the i th column Domains: D Vi = {1,2,3,4,5,6,7,8} Constraints: : Two queens cannot be on the same row or on the same diagonal We can specify the constraints by enumerating explicitly, for each pair of columns, what positions are allowed. Ex: Constr(V 1, V 2 ) = {(1,3), (1,4),..(1,8)(2,4)(2,5)…(8,6)}

Constraints Constraints are restrictions on the values that one or more variables can take Unary constraint: restriction involving a single variable k-ary constraint: restriction involving k different variables We will mostly deal with binary constraints Constraints can be specified by 1.listing all combinations of valid domain values for the variables participating in the constraint 2.giving a function that returns true when given values for each variable which satisfy the constraint A possible world satisfies a set of constraints if the values for the variables involved in each constraint are consistent with that constraint 1.Elements of the list of valid domain values 2.Function returns true for those values

Models and Possible Worlds 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. V = {V 1,V 2 } – dom(V 1 ) = {1,2,3} – dom(V 2 ) = {1,2} C = {C 1,C 2,C 3 } – C 1 : V 2  2 – C 2 : V 1 + V 2 < 5 – C 3 : V 1 > V 2 Possible worlds for this CSP: {V 1 =1, V 2 =1} {V 1 =1, V 2 =2} {V 1 =2, V 2 =1} {V 1 =2, V 2 =2} {V 1 =3, V 2 =1} {V 1 =3, V 2 =2} {V 1 =2, V 2 =1} (a model) {V 1 =3, V 2 =1} (a model) end

Example: Map-Coloring WA = red, NT = green, Q = red, NSW = green, V = red,SA = blue, T = green 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.

Finite Constraint Satisfaction Problem: Definition Definition: A finite constraint satisfaction problem (FCSP) is a CSP with a finite set of variables and a finite domain for each variable. We will only study finite CSPs here but many of the techniques carry over to countably infinite and continuous domains. We use CSP here to refer to FCSP.

Constraint Satisfaction Problems: Variants We may want to solve the following problems with a CSP: determine whether or not a model exists find a model find all of the models count the number of models find the best model, given some measure of model quality this is now an optimization problem determine whether some property of the variables holds in all models

Solving Constraint Satisfaction Problems Even the simplest problem of determining whether or not a model exists in a general CSP with finite domains is NP-hard There is no known algorithm with worst case polynomial runtime. We can't hope to find an algorithm that is polynomial for all CSPs. However, we can try to: find efficient (polynomial) consistency algorithms that reduce the size of the search space identify special cases for which algorithms are efficient work on approximation algorithms that can find good solutions quickly, even though they may offer no theoretical guarantees find algorithms that are fast on typical (not worst case) cases

30 Lecture Overview Finish Search Constraint Satisfaction Problems Variables/Features Constraints CSPs Generate-and-Test Search Arc Consistency

Systematically check all possible worlds -Possible worlds: cross product of domains dom(V 1 )  dom(V 2 ) ...  dom(V n ) Generate and Test: -Generate possible worlds one at a time -Test constraints for each one. Example: 3 variables A,B,C Generate and Test (GT) Algorithms For a in dom(A) For b in dom(B) For c in dom(C) if {A=a, B=b, C=c} satisfies all constraints return {A=a, B=b, C=c} fail

If there are k variables, each with domain size d, and there are c constraints, the complexity of Generate & Test is -There are d k possible worlds -For each one need to check c constraints Generate and Test (GT) Algorithms 32 Need to find a better way, that exploits the “insights” that we have on the goal expressed in terms of constraints Why does GT fail to do this?

CSP as a Search Problem: one formulation States: partial assignment of values to variables Start state: empty assignment Successor function: states with the next variable assigned E.g., follow a total order of the variables V 1, …, V n A state assigns values to the first k variables: {V 1 = v 1,…,V k = v k } Neighbors of node {V 1 = v 1,…,V k = v k }: nodes {V 1 = v 1,…,V k = v k, V k+1 = x} for each x  dom(V k+1 ) Goal state: complete assignments of values to variables that satisfy all constraints That is, models Solution: assignment (the path doesn't matter)

V 1 = v 1 V 2 = v 1 V 1 = v 1 V 2 = v 2 V 1 = v 1 V 2 = v k CSP as a Search Problem: one formulation 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

Slide 35 CSPs as Search Problems Which search strategy will work well for a CSP formulated this way? If there are n variables every solution is at depth……. Is there a role for a heuristic function? the tree is always finite and has no cycles, so which one is better BFS or IDS or DFS?

Is there any way to prune the DFS Search tree? 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. Example: -3 variables A, B, C each with domain {1,2,3,4} -{A = 1, B = 1} is inconsistent with constraint A  B regardless of the value of the other variables  Fail! Prune! CSP as Search problem

V 1 = v 1 V 2 = v 1 V 1 = v 1 V 2 = v 2 V 1 = v 1 V 2 = v k CSP as Graph Searching 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 Problem? 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 CSP as Graph Searching 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 Problem? Performance heavily depends on the order in which variables are considered Check unary constraints on V 1 If not satisfied = PRUNE Check constraints on V 1 and V 2 If not satisfied = PRUNE

Slide 39 Solving CSPs by DFS: Example Variables: A,B,C Domains: {1, 2, 3, 4} Constraints: A < B, B < C Good ordering, lots of pruning happens right away

Slide 40 Solving CSPs by DFS: Example Efficiency Variables: A,B,C Domains: {1, 2, 3, 4} Constraints: A < B, B < C Much worse ordering, keeps more branches around A=1 A=2A=3 A=4 C=1C=2C=3C=4 C=1C=2C=3C=4 C=1C=2C=3C=4 C=1C=2C=3C=4

Backtracking relies on one or more heuristics to select which variables to consider next. -E.g, variable involved in the largest number of constraints (“Degree heuristics”) But we will look at an alternative approach that can do much better Selecting variables in a smart way

Standard Search vs. Specific R&R systems 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

43 Lecture Overview Finish Search Constraint Satisfaction Problems Variables/Features Constraints CSPs Generate-and-Test Search Arc Consistency

Graph Searching Repeats Work 3 Variables: A,B,C. All with domains = {1,2,3,4} Constraints: A<B, B<C, A ≠ 4, C ≠ 1 A ≠ 4 is rediscovered 3 times. So is C ≠ 1 -Solution: remove values from A’s domain and C’s, once and for all

Can we do better than Search? Key idea prune the domains as much as possible before searching for a solution. Example: dom(V 2 ) = {1, 2, 3, 4}. Variable V 2 is not domain consistent with the constraint - It is domain consistent once we remove from its domain. Trivial for unary constraints. Trickier for k-ary ones. Def.: A variable is domain consistent if no value of its domain is ruled impossible by any unary constraints. V 2  2

Example: -Two variables X and Y -One constraint: X<Y XY X< Y 46 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. Constraint network: definition

Example Constraint Network 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

Example Constraint Network Example: Variables: A,B,C Domains: {1, 2, 3, 4} 3 Constraints: A < B, B < C, B = 3 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. 5 edges/arcs in the constraint network: 〈 A,A<B 〉, 〈 B,A<B 〉 〈 B,B<C 〉, 〈 C,B<C 〉 〈 B, B=3 〉

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,3 2,4 A B A< B 2,3 3,4 A B A< B 49 T T TF

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,3 2,4 A B A< B 2,3 3,4 A B A< B Not arc consistent: No value in domain of B that satisfies A<B if B = 2 Both arcs are consistent: Each value in B(A) have ok values for A(B) - e.g. for B=3, A = 2 50

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. TF TF 2,5,7 2,3,13 A B A< B/2 Is this 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) 51

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? Try this simple example in (easy to create from scratch in AI space) 2,3,4 1,2,3 X Y X< Y 52

Arc Consistency Algorithm: high level strategy Consider the arcs in turn, making each arc consistent Reconsider arcs that could be made inconsistent again by this pruning of the domains Eventually reach a ‘fixed point’: all arcs consistent Run ‘simple problem 1’ in AIspace for an example: 53

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 - If an arc  X,c'  was arc consistent before, it will still be arc consistent - Nothing changes for arcs of constraints not involving X Which arcs need to be reconsidered? 54 every arc  Z,c'  where c’  c involves Z and X: Z1Z1 c1c1 Z2Z2 c2c2 Z3Z3 c3c3 Y c THESETHESE X A c4c4

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 55 Which arcs need to be reconsidered?

Arc consistency algorithm (for binary constraints) 56 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 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 TDA: ToDoArcs, blue arcs in AIspace

Slide 57 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 The max number of binary constraints is ~n(n-1)/2 or O(n 2 ). How many times 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 )

Arc Consistency Algorithm: Interpreting Outcomes Three possible outcomes (when all arcs are arc consistent): 1. Each domain has a single value, e.g. We have a (unique) solution. 2. At least one domain is empty, e.g. No solution! (All values are ruled out for this variable.) 3. Some domains have more than one value, e.g. There may be one solution, many solutions, or none. Need to solve this new CSP (usually simpler) problem: same constraints, domains have been reduced

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

Domain splitting (or case analysis) Arc consistency ends: Some domains have more than one value  may or may not have a solution A. Apply Depth-First Search with Pruning or B. Split the problem in a number of disjoint cases: CSP with dom(X) = {x 1, x 2, x 3, x 4 } becomes CSP 1 with dom(X) = {x 1, x 2 } and CSP 2 with dom(X) = {x 3, x 4 } Solution to CSP is the union of solutions to CSP i 60

Domain splitting Each smaller CSP is easier to solve Arc consistency might already solve it For each subCSP, which arcs have to be on the ToDoArcs list when we get the subCSP by splitting the domain of X? A1A1 c1c1 A2A2 c2c2 A3A3 c3c3 Y c X A c4c4

Domain splitting Each smaller CSP is easier to solve Arc consistency might already solve it For each subCSP, which arcs have to be on the ToDoArcs list when we get the subCSP by splitting the domain of X? A1A1 c1c1 A2A2 c2c2 A3A3 c3c3 Y c THESETHESE X A c4c4 THISTHIS

If domains with multiple values Split on one Searching by domain splitting 63 CSP, apply AC CSP 1, apply AC CSP 2, apply AC If domains with multiple values …Split on one If domains with multiple values…..Split on one

3 variables: A, B, C Domains: all {1,2,3,4} A=B, B=C, A  C Let’s trace arc consistency + domain splitting for this network for “Simple Problem 2” in AIspace Domain Splitting in Action: 64

Arc consistency + domain splitting: example ({1,2,3,4}, {1,2,3,4}, {1,2,3,4}) ({1,3}, {1,2,3,4}, {1,2,3,4}) ({1,3}, {1,3}, {1,3}) ({2,4}, {1,2,3,4}, {1,2,3,4}) ({1,3}, {1}, {1,3}) AC ({}, {}, {}) ({1,3}, {3}, {1,3}) ({}, {}, {}) AC ({2,4}, {2,4}, {2,4}) ({2,4}, {2}, {2,4}) AC ({}, {}, {}) ({2,4}, {4}, {2,4}) ({}, {}, {}) AC A {1,3}A {2,4} B {1}B {3}B {2} B {4} 3 variables: A, B, C Domains: all {1,2,3,4} A=B, B=C, A  C No solution ({1,2,3,4}, {1,2,3,4}, {1,2,3,4}) AC (arc consistency)

Arc consistency + domain splitting: another example ({1,2,3,4}, {1,2,3,4}, {1,2,3,4}) ({1,3}, {1,2,3,4}, {1,2,3,4}) ({1,3}, {1,3}, {1,3}) ({2,4}, {1,2,3,4}, {1,2,3,4}) ({1,3}, {1}, {1,3}) AC ({1}, {1}, {1}) ({1,3}, {3}, {1,3}) ({3}, {3}, {3}) AC ({2,4}, {2,4}, {2,4}) ({2,4}, {2}, {2,4}) AC ({2}, {2}, {2}) ({2,4}, {4}, {2,4}) ({4}, {4}, {4}) AC A {1,3}A {2,4} B {1}B {3}B {2} B {4} 3 variables: A, B, C Domains: all {1,2,3,4} A=B, B=C, A=C Solution ({1,2,3,4}, {1,2,3,4}, {1,2,3,4}) AC (arc consistency)

Another formulation of CSP as search Arc consistency with domain splitting States: vector (D(V 1 ), …, D(V n )) of remaining domains, with D(V i )  dom(V i ) for each V i Start state: vector of original domains (dom(V 1 ), …, dom(V n )) Successor function: reduce one of the domains + run arc consistency Goal state: vector of unary domains that satisfies all constraints That is, only one value left for each variable The assignment of each variable to its single value is a model Solution: that assignment 67

If domains with multiple values Split on one Searching by domain splitting 68 How many CSPs do we need to keep around at a time? Assume solution at depth m and 2 children at each split CSP, apply AC CSP 1, apply AC CSP 2, apply AC If domains with multiple values Split on one If domains with multiple values…..Split on one

If domains with multiple values Split on one Searching by domain splitting 69 How many CSPs do we need to keep around at a time? Assume solution at depth m and 2 children at each split O(2m): It is DFS CSP, apply AC CSP 1, apply AC CSP 2, apply AC If domains with multiple values Split on one If domains with multiple values…..Split on one

Slide 70 Systematically solving CSPs: Summary Build Constraint Network Apply Arc Consistency One domain is empty  Each domain has a single value  Some domains have more than one value  Apply Depth-First Search with Pruning OR Split the problem in a number of disjoint cases Apply Arc Consistency to each case, and repeat

Slide 71 Limitation of Systematic Approaches Many CSPs are simply too big for systematic approaches If you have 10 5 vars with dom(var i ) = 10 4 Systematic Search Branching factor b = Solution depth d = Complexity = Constraint Network Size Complexity of AC Do this as an exerciseS

Learning Goals for CSP Define possible worlds in term of variables and their domains Compute number of possible worlds on real examples Specify constraints to represent real world problems differentiating between: Unary and k-ary constraints List vs. function format Verify whether a possible world satisfies a set of constraints (i.e., whether it is a model, a solution) Implement the Generate-and-Test Algorithm. Explain its disadvantages. Solve a CSP by search (specify neighbors, states, start state, goal state). Compare strategies for CSP search. Implement pruning for DFS search in a CSP. Define/read/write/trace/debug the arc consistency algorithm. Compute its complexity and assess its possible outcomes Define/read/write/trace/debug domain splitting and its integration with arc consistency 72