Computer Science cpsc322, Lecture 13

Slides:



Advertisements
Similar presentations
Constraint Satisfaction Problems
Advertisements

Local Search Jim Little UBC CS 322 – CSP October 3, 2014 Textbook §4.8
CPSC 322, Lecture 14Slide 1 Local Search Computer Science cpsc322, Lecture 14 (Textbook Chpt 4.8) Oct, 5, 2012.
Constraint Satisfaction Problems
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.
ICS-271:Notes 5: 1 Lecture 5: Constraint Satisfaction Problems ICS 271 Fall 2008.
Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni.
CPSC 322, Lecture 5Slide 1 Uninformed Search Computer Science cpsc322, Lecture 5 (Textbook Chpt 3.4) January, 14, 2009.
CPSC 322, Lecture 16Slide 1 Stochastic Local Search Variants Computer Science cpsc322, Lecture 16 (Textbook Chpt 4.8) February, 9, 2009.
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 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 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 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
CPSC 322, Lecture 22Slide 1 Logic: Domain Modeling /Proofs + Top-Down Proofs Computer Science cpsc322, Lecture 22 (Textbook Chpt 5.2) March, 8, 2010.
Chapter 5 Outline Formal definition of CSP CSP Examples
Constraint Satisfaction Problems
Slide 1 CSPs: Arc Consistency & Domain Splitting Jim Little UBC CS 322 – Search 7 October 1, 2014 Textbook §
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 )
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.
Computer Science CPSC 322 Lecture 9 (Ch , 3.7.6) Slide 1.
Solving Constraint Satisfaction Problems (CSPs) using Search CPSC 322 – CSP 2 Textbook § January 31, 2011.
Solving Constraint Satisfaction Problems (CSPs) using Search
CHAPTER 5 SECTION 1 – 3 4 Feb 2004 CS Constraint Satisfaction 1 Constraint Satisfaction Problems.
Arc Consistency CPSC 322 – CSP 3 Textbook § 4.5 February 2, 2011.
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.
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.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
CPSC 322, Lecture 22Slide 1 Logic: Domain Modeling /Proofs + Top-Down Proofs Computer Science cpsc322, Lecture 22 (Textbook Chpt 5.2) Oct, 30, 2013.
Automatic Test Generation
Constraint Satisfaction Problems (CSPs) Introduction
Uniformed Search (cont.) Computer Science cpsc322, Lecture 6
Search: Advanced Topics Computer Science cpsc322, Lecture 9
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
Planning: Representation and Forward Search
Advanced Artificial Intelligence
Computer Science cpsc322, Lecture 14
Search: Advanced Topics Computer Science cpsc322, Lecture 9
Uniformed Search (cont.) Computer Science cpsc322, Lecture 6
Planning: Heuristics and CSP Planning
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Planning: Representation and Forward Search
Constraint Propagation
Computer Science cpsc322, Lecture 14
Constraint Satisfaction Problems
Search: Advanced Topics Computer Science cpsc322, Lecture 9
Logic: Domain Modeling /Proofs + Computer Science cpsc322, Lecture 22
Constraint satisfaction problems
Domain Splitting CPSC 322 – CSP 4 Textbook §4.6 February 4, 2011.
CS 8520: Artificial Intelligence
Constraint Satisfaction Problems
Constraint satisfaction problems
Constraint Satisfaction Problems (CSP)
Planning: Representation and Forward Search
Presentation transcript:

Computer Science cpsc322, Lecture 13 CSPs: Arc Consistency & Domain Splitting Computer Science cpsc322, Lecture 13 (Textbook Chpt 4.5 ,4.6) Oct, 04, 2013 Lecture 13 CPSC 322, Lecture 13

Recap (CSP as search & Constraint Networks) Arc Consistency Algorithm Lecture Overview Recap (CSP as search & Constraint Networks) Arc Consistency Algorithm Domain splitting CPSC 322, Lecture 13

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: set of constraints 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 Query Allows useful general-purpose algorithms with more power than standard search algorithms CPSC 322, Lecture 11

Recap: We can do much better.. Build a constraint network: Enforce domain and arc consistency AIspace simple1withUnary problem CPSC 322, Lecture 13

Arc Consistency Algorithm Lecture Overview Recap Arc Consistency Algorithm Abstract strategy Details Complexity Interpreting the output Domain Splitting CPSC 322, Lecture 13

Arc Consistency Algorithm: high level strategy Consider the arcs in turn, making each arc consistent. BUT, arcs may need to be revisited whenever…. the domains of other variables are reduced. AIspace simple1withUnary problem NOTE - Regardless of the order in which arcs are considered, we will terminate with the same result CPSC 322, Lecture 13

What arcs need to be revisited? When we reduce the domain of a variable X to make an arc X,c arc consistent, we add…… every arc Z,c' where c' involves Z and X: You do not need to add other arcs X,c' , c  c‘ If an arc X,c' was arc consistent before, it will still be arc consistent (in the ``for all'' we'll just check fewer values) CPSC 322, Lecture 13

CPSC 322, Lecture 14

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                     DX is a set of values for each variable X                    TDA is a set of arcs 1:           for each variable X do 2:                     DX ←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:                     NDX ←{x| x ∈ DX and  y ∈ DY s.t. (x, y) satisfies c} 8:                     if (NDX  DX) then 9:                               TDA ←TDA ∪ { 〈Z,c'〉 | X ∈ scope(c'), c'  c, Z ∈ scope(c') \ {X} } 10:                             DX ←NDX                      11:           return {DX| X  is a variable} Scope of constraint c is the set of variables involved in that constraint TDA: ToDoArcs, blue arcs in AIspace X’s domain changed:  arcs (Z,c’) for variables Z sharing a constraint c’ with X are added to TDA NDX: values x for X for which there a value for y supporting x If arc was inconsistent Domain is reduced

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 * d d * d (n * (n-1)) / 2 (n * d) / 2 Every time a domain value is removed Some special cases are faster e.g., if the constraint graph is a tree, arc consistency is O(ed) I DO NOT THINK SO It is linear in the number of variables n (not quadratic as the general case) check with David and Kevin

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 How many times the same arc can be inserted in the ToDoArc list? A. n B. d C. n * d D. d2 How many steps are involved in checking the consistency of an arc? A. n2 B. d C. n * d D. d2 Every time a domain value is removed Some special cases are faster e.g., if the constraint graph is a tree, arc consistency is O(ed) I DO NOT THINK SO It is linear in the number of variables n (not quadratic as the general case) check with David and Kevin

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……. How many times the same arc can be inserted in the ToDoArc list? How many steps are involved in checking the consistency of an arc? Every time a domain value is removed Some special cases are faster e.g., if the constraint graph is a tree, arc consistency is O(ed) I DO NOT THINK SO It is linear in the number of variables n (not quadratic as the general case) check with David and Kevin CPSC 322, Lecture 13

Arc Consistency Algorithm: Interpreting Outcomes Three possible outcomes (when all arcs are arc consistent): One domain is empty  Each domain has a single value  Some domains have more than one value  may or may not be a solution in this case, arc consistency isn't enough to solve the problem: we need to perform search Otherwise, split a domain & apply arc consistency to each case. Spiltting in half the variable with the smallest domain usually works best (who know why) ACC: Show with Cispace, first “scheduling problem”, and then crossword 1 for splitting. What makes sense is to split the node with 6 vars to the right, show that it gets to an empty solution, backtrack, and do more s0plitting on the var with 2 values on the top-left. Done. WENT WELL CPSC 322, Lecture 13

Lecture Overview Recap Arc Consistency Domain splitting ACC: Show with Cispace, first “scheduling problem”, and then crossword 1 for splitting. What makes sense is to split the node with 6 vars to the right, show that it gets to an empty solution, backtrack, and do more s0plitting on the var with 2 values on the top-left. Done. WENT WELL CPSC 322, Lecture 13

Domain splitting (or case analysis) Arc consistency ends: Some domains have more than one value  may or may not be a solution Apply Depth-First Search with Pruning Split the problem in a number of (two) disjoint cases Set of all solution equals to…. Otherwise, split a domain & apply arc consistency to each case. Spiltting in half the variable with the smallest domain usually works best (who know why) ACC: Show with Cispace, first “scheduling problem”, and then crossword 1 for splitting. What makes sense is to split the node with 6 vars to the right, show that it gets to an empty solution, backtrack, and do more s0plitting on the var with 2 values on the top-left. Done. WENT WELL CPSC 322, Lecture 13

But what is the advantage? By reducing dom(X) we may be able to…. Simplify the problem using arc consistency No unique solution i.e., for at least one var, |dom(X)|>1 Split X For all the splits Restart arc consistency on arcs <Z, r(Z,X)> these are the ones that are possibly…………. Combining Arc Consistency and Domain Splitting Otherwise, split a domain & apply arc consistency to each case. Spiltting in half the variable with the smallest domain usually works best (who know why) ACC: Show with Cispace, first “scheduling problem”, and then crossword 1 for splitting. What makes sense is to split the node with 6 vars to the right, show that it gets to an empty solution, backtrack, and do more s0plitting on the var with 2 values on the top-left. Done. WENT WELL Disadvantage : you need to keep all these CSPs around (vs. lean states of DFS) CPSC 322, Lecture 13

Searching by domain splitting Combining Arc Consistency and Domain Splitting Otherwise, split a domain & apply arc consistency to each case. Spiltting in half the variable with the smallest domain usually works best (who know why) ACC: Show with Cispace, first “scheduling problem”, and then crossword 1 for splitting. What makes sense is to split the node with 6 vars to the right, show that it gets to an empty solution, backtrack, and do more s0plitting on the var with 2 values on the top-left. Done. WENT WELL CPSC 322, Lecture 13

More formally: Arc consistency with domain splitting as another formulation of CSP as search States: “remaining” domains (D(V1), …, D(Vn))for the vars with D(Vi)  dom(Vi) for each Vi Start state: run AC on vector of original domains (dom(V1), …, dom(Vn)) 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

Searching by domain splitting Apply AC to original domains If domains with multiple values Split on one apply AC to remaining domains apply AC to remaining domains If domains with multiple values Split on one If domains with multiple values…..Split on one How many CSPs do we need to keep around at a time? Assume solution at depth m and 2 children at each split A. It depends B. 2m C. m2 D. 2m

K-ary vs. binary constraints Not a topic for this course but if you are curious about it… Wikipedia example clarifies basic idea… http://en.wikipedia.org/wiki/Constraint_satisfaction_dual_problem The dual problem is a reformulation of a constraint satisfaction problem expressing each constraint of the original problem as a variable. Dual problems only contain binary constraints, and are therefore solvable by algorithms tailored for such problems. See also: hidden transformations CPSC 322, Lecture 13

Domain Splitting in Action: 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

Learning Goals for today’s class You can: 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 CPSC 322, Lecture 4

Next Class (Chpt. 4.8) Work on CSP Practice Ex: Local search: Exercise 4.A: arc consistency Exercise 4.B: constraint satisfaction problems Next Class (Chpt. 4.8) Local search: Many search spaces for CSPs are simply too big for systematic search (but solutions are densely distributed). Keep only the current state (or a few) Use very little memory / often find reasonable solution ….. Local search for CSPs CPSC 322, Lecture 13