Bookkeeping Constraint Satisfaction • HW 2 questions? AI Class 7 — Ch. 6.1–6.4 (skip 6.3.3) ) … • Please note: it must be due COB Blackboard time • 11:59: XX is late! • We will not let this slide again. Based on slides by: Marie desJardin, Paula Matuszek, Luke • Need to upload .py files – see Nikhil if it’s not working Zettlemoyer, Dan Klein, Stuart Russell, Andrew Moore Cynthia Matuszek – CMSC 671 2 Today’s Class Constraint Satisfaction • Con • straint /k ə n ˈ str ā nt/, (noun): • Constraint Satisfaction Problems • Something that limits or restricts someone or something. 1 • A.K.A., Constraint Processing / CSP paradigm • Control that limits or restricts someone’s actions or behavior. 1 Constraint (n): A relation … • Algorithms for CSPs • A relation … between the values of one or more mathematical between the values of one or variables (e.g., x>3 is a constraint on x). 2 • Search Terminology more mathematical variables • Assigns values to variables so that all constraints are true. 2 (e.g., x>3 is a constraint on x). • General Idea Constraint satisfaction assigns • View a problem as a set of variables values to variables so that all • To which we have to assign values constraints are true. • 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… • The path to the goal is the important thing • Paths have various costs, depths • Algorithms for CSPs • Heuristics to guide, fringe to keep backups • Identification : assignments to variables representing • Backtracking (systematic search) unknowns • Constraint agati0agation (k-consistency) • The goal itself is important, not the path • Variable and value ordering heuristics • 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 • Given: • Find some solution 1. A finite set of variables 2. Each with a domain of possible values • Find all solutions they can take (often finite) 3. A set of constraints that limit the values the variables can take on • Find the “best solution” • Solution : an assignment of a value • According to some metric (objective function) to each variable such that the constraints are all satisfied. • Does that mean “optimal”? 7 8 Informal Example: Map Coloring Map Coloring II • Variables: A, B, C, D, E • Color a map, such that: • Domains: RGB = {red, green, blue} • Using three colors (red, green, blue) • No two adjacent regions have the same color • Constraints: A ≠ B, A ≠ C, A ≠ E, A ≠ D, B ≠ C, C ≠ D, D ≠ E • One solution: A=red, B=green, C=blue, D=green, E=blue E E E D A D A D A B B B C C C 9 10 Example: N-Queens (1) Slightly Less Informal • Standard search problems: • Formulation 1: • State is a “black box”: arbitrary data structure • Variables: • Goal test: any function over states • Domains: • Successor function can be anything • Constraints: • Constraint satisfaction problems (CSPs): • A special subset of search problems • State is defined by variables X i with values from a domain D • Sometimes D depends on i • Goal test is a set of constraints specifying allowable combinations of values for subsets of variables 2
Example: N-Queens (2) Example: SATisfiability • Given a set of propositions containing variables, find • Formulation 2: an assignment of the variables to { false , true } that • Variables: satisfies them. Special case! • Domains: • For example, the clauses: • Constraints: • (A ∨ B ∨ ¬ C) ∧ ( ¬ A ∨ D) • (equivalent to (C → A) ∨ (B ∧ D → A) Implicit: are satisfied by -or- A = false Explicit: B = true C = false D = false 14 Formal Definition: Real-World Problems Constraint Network (CN) A constraint network (CN) consists of • Scheduling • Graph layout • A set of variables X = { x 1 , x 2 , … x n } • Temporal reasoning • Network management • Each with an associated domain of values { d 1 , d 2 , … d n }. • Building design • Natural language • The domains are typically finite processing • Planning • A set of constraints { c 1 , c 2 … c m } where • Molecular biology / • Each constraint defines a predicate which is a relation over • Optimization/ genomics some subset of X . satisfaction • VLSI design • E.g., c i involves variables { X i1 , X i2 , … X ik } and defines the • Vision relation R i ⊆ D i1 × D i2 × … D ik 15 16 Constraint Restrictions Formal Definition of a CN (cont.) • Unary constraint: only involves one variable • An instantiation is an assignment of a value • e.g.: C can’t be green. d x ∈ D t o some subset of variables S . • Ex: Q 2 = {2,3} ∧ Q 3 = {1,1} instantiates Q 2 and Q 3 • Binary constraint: only involves two variables • e.g.: E ≠ D • An instantiation is legal iff it does not violate E any constraints D A • A solution is an instantiation of all variables B • A correct solution is a legal instantiation of all variables C 17 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: • Introducing additional variables • Find one solution • Dual graph construction: one variable for each constraint; one • Find all solutions binary constraint for each pair of original constraints that share variables • Given a partial instantiation, do any of the above • Can represent a binary CSP as a constraint graph with: • Transform the CN into an equivalent CN that • A node for each variable is easier to solve • An arc between two nodes iff there is a constraint on the two variables • Unary constraint appears as a self-referential arc 19 20 Example: Sudoku Running Example: Sudoku • Constraints (implicit/intensional) v 11 3 v 13 1 • Variables v 11 3 3 v 13 1 1 • C R : ∀ i, ∪ j v ij = D v 21 1 v 23 4 • v i,j is the value in the (every value appears in every row) 1 4 v 21 1 v 23 4 • C C : ∀ j, ∪ i v ij = D j th cell of the i th row 3 4 1 2 (every value appears in every column) v 41 v 42 4 v 44 3 3 4 4 1 1 2 2 • C B : ∀ k, ∪ ( v ij | ij ∈ B k ) = D • Domains (every value appears in every block) v 41 v 42 4 v 44 • D i,j = D = {1, 2, 3, 4} 4 • Alternative representation: pairwise inequality constraints • I R : ∀ i, j ≠ j ’ : v ij ≠ v ij ’ • Blocks: Advantage of the (no value appears twice in any row) second • I C : ∀ j, i ≠ i ’ : v ij ≠ v i ’ j • B 1 = {11, 12, 21, 22}, …, B 4 = {33, 34, 43, 44} (no value appears twice in any column) representation: all • I B : ∀ k, ij ∈ B k , i ’ j ’ ∈ B k , ij ≠ i ’ j ’ :v ij ≠ v i ’ j ‘ binary constraints! (no value appears twice in any block) 21 22 Sudoku Constraint Network Solving Constraint Problems 1. Systematic search • Generate and test 3 1 v 11 3 v 13 1 • Backtracking v 11 v 13 v 21 1 1 v 23 4 4 2. Constraint propagation (consistency) v 21 v 23 3 3 4 4 1 1 2 2 3. Variable ordering heuristics v 41 v 42 4 4 v 44 v 41 v 42 v 44 4. Value ordering heuristics 5. Backjumping and dependency-directed backtracking 23 24 4
Recommend
More recommend