HW 2 Questions N Constraint Satisfaction E W S • Do you have the Ch. 6.1–6.4 (skip 6.3.3) ) latest version? 1 2 0 • Coords: (row, column) 0 • Start at (1,0) path path path • Arguments in: • ((start), (goal), [[array]]) 1 • What three algorithms path mountain path would you use? • Uninformed/Blind ! 2 • Informed • Local sand sand sand Based on slides by: Marie desJardin, Paula Matuszek, Luke Zettlemoyer, Dan Klein, Stuart Russell, Andrew Moore Cynthia Matuszek – CMSC 671 2 Today’s Class Constraint Satisfaction • What’s a Constraint Satisfaction Problem (CSP)? • Con • straint /k ə n ˈ str ā nt/, (noun): • Something that limits or restricts someone or something. 1 • A.K.A., Constraint Processing / CSP paradigm • A relation … between the values of one or more mathematical variables (e.g., x>3 is a constraint on x). 2 • How do we solve Constraint (n): A relation … between the values of one or • Assigns values to variables so that all constraints are true. 2 them? more mathematical variables • In search, constraints exist on? • Algorithms for CSPs (e.g., x>3 is a constraint on x). • General Idea • Search Terminology Constraint satisfaction assigns • View a problem as a set of variables values to variables so that all constraints are true. • To which we have to assign values • That satisfy a number of (problem-specific) constraints – http://foldoc.org/constraint [1] Merriam-Webster online. [2] The Free Online Computing Dictionary. 3 4 Overview Search Vocabulary • Constraint satisfaction : a problem-solving • We’ve talked about caring about goals (end states) vs. paths paradigm • These correspond to… • Constraint programming, constraint satisfaction • Planning : finding sequences of actions problems ( CSPs ), constraint logic programming… • Paths have various costs, depths • Heuristics to guide, frontier to keep backup possibilities • Algorithms for CSPs • Examples: chess moves; 8-puzzle; homework 2 • Backtracking (systematic search) • Identification : assignments to variables representing unknowns • Constraint propagation (k-consistency) • The goal itself is important, not the path • Variable and value ordering heuristics • Examples: Sudoku; map coloring; N queens • Backjumping and dependency-directed backtracking • CSPs are specialized for identification problems 6 5 1
Slightly Less Informal CSP Applications Definition of CSP • CSP = Constraint Satisfaction • Decide if a solution exists Problem • Find some solution • Given: 1. A finite set of variables • Find all solutions 2. Each with a domain of possible values they can take (often finite) 3. A set of constraints that limit the • Find the “best solution” values the variables can take on • According to some metric (objective function) • Solution : an assignment of values to variables that satisfies all constraints. • Does that mean “optimal”? 7 8 Informal Example: Map Coloring Slightly Less Informal • Standard search problems: • Given a 2D map, it is always possible to color • State is a “black box”: arbitrary data structure it u sing three colors (we’ll use red, green, blue) • Goal test: any function over states • Successor function can be anything Such that: • Constraint satisfaction problems (CSPs): E • No two adjacent • A special subset of search problems regions are the • State is defined by variables X i with values from a D A same color domain D B • Sometimes D depends on i • Start thinking: What are the C • Goal test is a set of constraints specifying allowable values, variables, constraints? combinations of values for subsets of variables 9 Example: N-Queens (1) Example: N-Queens (2) • Formulation 1: • Formulation 2: • Variables: • Variables: • Domains: • Domains: • Constraints: • Constraints: Implicit: -or- Explicit: 2
Example: SATisfiability Real-World Problems • Given a set of propositions containing variables, find • Scheduling • Graph layout an assignment of the variables to { false , true } that satisfies them. Special case! • Temporal reasoning • Network management • For example, the clauses: • Building design • Natural language • (A ∨ B ∨ ¬ C) ∧ ( ¬ A ∨ D) processing • (equivalent to (C → A) ∨ (B ∧ D → A)) • Planning • Molecular biology / are satisfied by • Optimization/ genomics A = false satisfaction B = true • VLSI design C = false • Vision D = false 13 14 Formal Definition: Map Coloring II Constraint Network (CN) • Variables: A, B, C, D, E A constraint network (CN) consists of • Domains: RGB = {red, green, blue} • A set of variables X = { x 1 , x 2 , … x n } • Constraints: A ≠ B, A ≠ C, A ≠ E, A ≠ D, B ≠ C, C ≠ D, D ≠ E • Each with an associated domain of values { d 1 , d 2 , … d n }. • The domains are typically finite • One solution: A=red, B=green, C=blue, D=green, E=blue • A set of constraints { c 1 , c 2 … c m } where E E • Each constraint defines a predicate, which is a relation over some subset of X . D A D A B B • E.g., c i involves variables { X i1 , X i2 , … X ik } and defines the C C relation R i ⊆ D i1 × D i2 × … D ik 15 16 Constraint Restrictions Formal Definition of a CN (cont.) • An instantiation is an assignment of a value • Unary constraint: only involves one variable d x ∈ D t o some subset of variables S . • e.g.: C can’t be green. • Any assignment of values to variables • Binary constraint: only involves two variables • Ex: Q 2 = {2,3} ∧ Q 3 = {1,1} instantiates Q 2 and Q 3 • e.g.: E ≠ D • An instantiation is legal iff it does not violate E ≠ any constraints D A B • A solution is an instantiation of all variables • A correct solution is a legal instantiation of all variables C “C ≠ green” 18 3
Typical Tasks for CSP Binary CSP • Binary CSP : all constraints are binary or unary • Solutions: • Does a solution exist? • Can convert a non-binary CSP à binary CSP by: • Find one solution • Introducing additional variables • One variable per constraint • Find all solutions • One binary constraint for each pair of original constraints • Given a partial instantiation , can we do these? that share variables • Transform the CN into an equivalent CN that • “Dual graph construction” is easier to solve 19 20 Binary CSPs: Why? Example: Sudoku • Can always represent a binary CSP as a constraint • Variables v 11 3 3 v 13 1 1 graph with: • v i,j is the value in the • A node for each variable v 21 1 1 v 23 4 4 j th cell of the i th row • An arc between two nodes iff there is a constraint on the 3 3 4 4 1 1 2 2 two variables • Domains • Unary constraint appears as a self-referential arc • D i,j = D = {1, 2, 3, 4} v 41 v 42 4 4 v 44 • Blocks: • B 1 = {11, 12, 21, 22}, …, B 4 = {33, 34, 43, 44} “C can’t be green” 21 22 Running Example: Sudoku Sudoku Constraint Network • Constraints (implicit/intensional) v 11 3 v 13 1 • C R : ∀ i, ∪ j v ij = D v 21 1 v 23 4 (every value appears in every row) 3 1 v 11 3 v 13 1 • C C : ∀ j, ∪ i v ij = D v 11 v 13 3 4 1 2 (every value appears in every column) v 21 1 1 v 23 4 4 v 41 v 42 4 v 44 • C B : ∀ k, ∪ ( v ij | ij ∈ B k ) = D v 21 v 23 (every value appears in every block) 3 3 4 4 1 1 2 2 • Alternative representation: pairwise inequality constraints • I R : ∀ i, j ≠ j ’ : v ij ≠ v ij ’ v 41 v 42 4 4 v 44 v 41 v 42 v 44 Advantage of the (no value appears twice in any row) second choice: all • I C : ∀ j, i ≠ i ’ : v ij ≠ v i ’ j (no value appears twice in any column) binary constraints! • I B : ∀ k, ij ∈ B k , i ’ j ’ ∈ B k , ij ≠ i ’ j ’ :v ij ≠ v i ’ j ‘ (no value appears twice in any block) 23 24 4
Recommend
More recommend