Constraint Satisfaction 101 Foundations of Constraint Processing CSCE

  • Slides: 53
Download presentation
Constraint Satisfaction 101 Foundations of Constraint Processing CSCE 421/821, Fall 2004: www. cse. unl.

Constraint Satisfaction 101 Foundations of Constraint Processing CSCE 421/821, Fall 2004: www. cse. unl. edu/~choueiry/F 04 -421 -821/ Berthe Y. Choueiry (Shu-we-ri) Avery Hall, Room 123 B choueiry@cse. unl. edu Tel: +1(402)472 -5444 Overview: 1

Outline 1. Motivating example, application areas 2. CSP: Definition, representation 3. Some simple modeling

Outline 1. Motivating example, application areas 2. CSP: Definition, representation 3. Some simple modeling examples 4. More on definition and formal characterization 5. Basic solving techniques (Implementing backtrack search) Advanced solving techniques Issues & research directions Overview: 1

Motivating example I • Context: You are a senior in college • Problem: You

Motivating example I • Context: You are a senior in college • Problem: You need to register in 4 courses for the Spring semester • Possibilities: Many courses offered in Math, CSE, EE, CBA, etc. • Constraints: restrict the choices you can make – Unary: Courses have prerequisites you have/don't have Courses/instructors you like/dislike – Binary: Courses are scheduled at the same time – n-ary: In CE: 4 courses from 5 tracks such as at least 3 tracks are covered • You have choices, but are restricted by constraints – Make the right decisions!! Overview: 1

Motivating example II • Given – A set of variables: 4 courses at UNL

Motivating example II • Given – A set of variables: 4 courses at UNL – For each variable, a set of choices (values) – A set of constraints that restrict the combinations of values the variables can take at the same time • Questions – Does a solution exist? (classical decision problem) – How two or more solutions differ? How to change specific choices without perturbing the solution? – If there is no solution, what are the sources of conflicts? Which constraints should be retracted? – etc. Overview: 1

Practical applications Adapted from E. C. Freuder • • • Radio resource management (RRM)

Practical applications Adapted from E. C. Freuder • • • Radio resource management (RRM) Databases (computing joins, view updates) Temporal and spatial reasoning Planning, scheduling, resource allocation Design and configuration Graphics, visualization, interfaces Hardware verification and software engineering HC Interaction and decision support Molecular biology Robotics, machine vision and computational linguistics Transportation Qualitative and diagnostic reasoning Overview: 1

Constraint Processing • is about. . . – Solving a decision problem… – …

Constraint Processing • is about. . . – Solving a decision problem… – … While allowing the user to state arbitrary constraints in an expressive way and – Providing concise and high-level feedback about alternatives and conflicts • Related areas: – AI, OR, Algorithmic, DB, TCS, Prog. Languages, etc. Overview: 1

Power of Constraints Processing • Flexibility & expressiveness of representations • Interactivity users can

Power of Constraints Processing • Flexibility & expressiveness of representations • Interactivity users can relax reinforce Overview: 1 constraints

Outline ü Motivating example, application areas ü CSP: Definition, representation ü Some simple modeling

Outline ü Motivating example, application areas ü CSP: Definition, representation ü Some simple modeling examples ü More on definition and formal characterization ü Basic solving techniques Overview: 1

Definition of a Problem • General template of any computational problem – Given: •

Definition of a Problem • General template of any computational problem – Given: • Example: a set of objects, their relations, etc. – Query/Question: • Example: Find x such that the condition y is satisfied • How about the Constraint Satisfaction Problem? Overview: 1

Definition of a CSP • Given P = (V, D, C ) – V

Definition of a CSP • Given P = (V, D, C ) – V is a set of variables, – D is a set of variable domains (domain values) – C is a set of constraints, • Query: can we find a value for each variable such that all constraints are satisfied? Overview: 1

Other queries… • • Find a solution Find all solutions Find the number of

Other queries… • • Find a solution Find all solutions Find the number of solutions Find a set of constraints that can be removed so that a solution exists • Etc. Overview: 1

Representation I • Given P = (V, D, C ), where • Find a

Representation I • Given P = (V, D, C ), where • Find a consistent assignment for variables Constraint Graph • Variable node (vertex) • Domain node label • Constraint arc (edge) between nodes Overview: 1

Representation II • Given P = (V, D, C ), Example I: where V

Representation II • Given P = (V, D, C ), Example I: where V 1 {1, 2, 3, 4} v 1 < v 2 { 3, 6, 7 } V 2 v 1+v 3 < 9 • Define C ? v 2 < v 3 V 3 { 3, 4, 9 } Overview: 1 v 2 > v 4 { 3, 5, 7 } V 4

Outline ü Motivating example, application areas ü CSP: Definition, representation ü Some simple modeling

Outline ü Motivating example, application areas ü CSP: Definition, representation ü Some simple modeling examples ü More on definition and formal characterization ü Basic solving techniques Overview: 1

Example II: Temporal reasoning • Give one solution: ……. • Satisfaction, yes/no: decision problem

Example II: Temporal reasoning • Give one solution: ……. • Satisfaction, yes/no: decision problem Overview: 1

Example III: Map coloring Using 3 colors (R, G, & B), color the US

Example III: Map coloring Using 3 colors (R, G, & B), color the US map such that no two adjacent states have the same color • Variables? • Domains? • Constraints? Overview: 1

Example III: Map coloring Using 3 colors (R, G, & B), color the US

Example III: Map coloring Using 3 colors (R, G, & B), color the US map such that no two adjacent states have the same color Overview: 1

Example IV: Resource Allocation { a, b, c } { a, b } {

Example IV: Resource Allocation { a, b, c } { a, b } { a, c, d } { b, c, d } What is the CSP formulation? Overview: 1

Example IV: Resource Allocation { a, b, c } { a, b } {

Example IV: Resource Allocation { a, b, c } { a, b } { a, c, d } { b, c, d } Constraint Graph T 1 { R 1, R 3 } Interval Order T 2 T 3 { R 1, R 3 } T 1 { R 1, R 3 } { R 1, R 3, R 4 } T 4 { R 1, R 3 } { R 1, R 2, R 3 } T 5 { R 2, R 4 } T 6 { R 2, R 4 } T 7 T 2 Overview: 1 { R 1, R 2, R 3 } { R 1, R 3 } T 4 T 3 { R 1, R 3 } T 6 { R 2, R 4 } { R 1, R 2, R 3 } T 5 T 7

Example V: Puzzle Given: • Four musicians: Fred, Ike, Mike, and Sal, play bass,

Example V: Puzzle Given: • Four musicians: Fred, Ike, Mike, and Sal, play bass, drums, guitar and keyboard, not necessarily in that order. • They have 4 successful songs, ‘Blue Sky, ’ ‘Happy Song, ’ ‘Gentle Rhythm, ’ and ‘Nice Melody. ’ • Ike and Mike are, in one order or the other, the composer of ‘Nice Melody’ and the keyboardist. • etc. . . Query: Who plays which instrument and who composed which song? Overview: 1

Example V: Puzzle Formulation 1: • Variables: Bass, Drums, Guitar, Keyboard, Blue Sky, Happy

Example V: Puzzle Formulation 1: • Variables: Bass, Drums, Guitar, Keyboard, Blue Sky, Happy Song Gentle Rhythm and Nice Melody. • Domains: Fred, Ike, Mike, Sal • Constraints: … Formulation 2: • Variables: Fred's-instrument, Ike's-instrument, …, Fred's-song, Ikes's-song, Mike’s-song, …, etc. • Domains: { bass, drums, guitar, keyboard } { Blue Sky, Happy Song, Gentle Rhythm, Nice Melody} • Constraints: … Overview: 1

Example VI: Product Configuration Train, elevator, car, etc. Given: • Components and their attributes

Example VI: Product Configuration Train, elevator, car, etc. Given: • Components and their attributes (variables) • Domain covered by each characteristic (values) • Relations among the components (constraints) • A set of required functionalities (more constraints) Find: a product configuration i. e. , an acceptable combination of components that realizes the required functionalities Overview: 1

Examples of Constraint Types • Example I: algebraic constraints V 1 v 1 <

Examples of Constraint Types • Example I: algebraic constraints V 1 v 1 < v 2 {1, 2, 3, 4} v 1+v 3 < 9 { 3, 6, 7 } V 2 v 2 > v 4 v 2 < v 3 V 3 { 3, 4, 9 } { 3, 5, 7 } V 4 • Example II: (algebraic) constraints of bounded difference • Example III & IV: coloring, mutual exclusion, difference constraints Constraint Graph T 1 { R 1, R 3 } T 4 { R 2, R 4 } { R 1, R 3 } T 3 { R 1, R 3 } { R 1, R 2, R 3 } { R 2, R 4 } T 5 • Example V & VI: elements of C must be made explicit Overview: 1 T 6 { R 1, R 2, R 3 } T 7

More examples • Example VII: Databases – Join operation in relational DB is a

More examples • Example VII: Databases – Join operation in relational DB is a CSP – View materialization is a CSP • Example VIII: Interactive systems – Data-flow constraints – Spreadsheets – Graphical layout systems and animation – Graphical user interfaces • Example IX: Molecular biology (bioinformatics) – Threading, etc Overview: 1

Outline ü Motivating example, application areas ü CSP: Definition, representation ü Some simple modeling

Outline ü Motivating example, application areas ü CSP: Definition, representation ü Some simple modeling examples ü More on definition and formal characterization ü Basic solving techniques Overview: 1

Representation (again) Macrostructure G(P): V 1 - constraint graph for binary constraints - constraint

Representation (again) Macrostructure G(P): V 1 - constraint graph for binary constraints - constraint network for non-binary constraints V 2 a, c (V 1, a ) Micro-structure (P): (V 2, a ) (V 2, c) (V 1, a ) Co-microstructure co- (P): (V 2, a ) (V 2, c) Overview: 1 a, b b, c V 3 (V 1, b) (V 3, b ) (V 3, c) no goods (V 3, c)

Constraint arity I • Given P = (V, D, C ) , where V

Constraint arity I • Given P = (V, D, C ) , where V 1 {1, 2, 3, 4} v 1 < v 2 { 3, 6, 7 } V 2 v 1+v 3 < 9 v 2 < v 3 V 3 { 3, 4, 9 } • How to represent the constraint V 1 + V 2 + V 4 < 10 ? Overview: 1 v 2 > v 4 { 3, 5, 7 } V 4

Constraint arity II • Given P = (V, D, C ) , where Constraints:

Constraint arity II • Given P = (V, D, C ) , where Constraints: universal, unary, binary, ternary, … , global. A Constraint Network: Overview: 1

Domain types • P = (V, D, C ) where • Domains: – Finite

Domain types • P = (V, D, C ) where • Domains: – Finite (discrete), enumeration works – Continuous, sophisticated algebraic techniques are needed Overview: 1

Constraint terminology • Arity: – universal, unary, binary, ternary, …, global • Scope: –

Constraint terminology • Arity: – universal, unary, binary, ternary, …, global • Scope: – The set of variables to which the constraint applies • Definition: – Intention, extension • Implementation: – predicate, set of tuples, binary matrix, etc. Overview: 1

Complexity of CSP Characterization: – Decision problem – In general, NP-complete by reduction from

Complexity of CSP Characterization: – Decision problem – In general, NP-complete by reduction from 3 SAT Overview: 1

Proving NP-completeness 1. Show that 1 is in NP 2. Given a problem 1

Proving NP-completeness 1. Show that 1 is in NP 2. Given a problem 1 in NP, show that an known NP-complete problem 2 can be efficiently reduced to 1 – – – Select a known NP-complete problem 2 (e. g. , SAT) Construct a transformation f from 2 to 1 Prove that f is a polynomial transformation (Check Chapter 3 of Garey & Johnson) Overview: 1

What is SAT? Given a sentence: – Sentence: conjunction of clauses – Clause: disjunction

What is SAT? Given a sentence: – Sentence: conjunction of clauses – Clause: disjunction of literals – Literal: a term or its negation – Term: Boolean variable Question: Find an assignment of truth values to the Boolean variables such the sentence is satisfied. Overview: 1

CSP is NP-Complete • Verifying that an assignment for all variables is a solution

CSP is NP-Complete • Verifying that an assignment for all variables is a solution – Provided constraints can be checked in polynomial time • Reduction from 3 SAT to CSP – Many such reductions exist in the literature (perhaps 7 of them) Overview: 1

Problem reduction Example: CSP into SAT (proves nothing, just an exercise) Notation: variable-value pair

Problem reduction Example: CSP into SAT (proves nothing, just an exercise) Notation: variable-value pair = vvp • vvp term – V 1 = {a, b, c, d} yields x 1 = (V 1, a), x 2 = (V 1, b), x 3 = (V 1, c), x 4 = (V 1, d), – V 2 = {a, b, c} yields x 5 = (V 2, a), x 6 = (V 2, b), x 7 = (V 2, c). • The vvp’s of a variable disjunction of terms – V 1 = {a, b, c, d} yields • (Optional) At most one VVP per variable Overview: 1

CSP into SAT (cont. ) Constraint: 1. Way 1: Each inconsistent tuple one disjunctive

CSP into SAT (cont. ) Constraint: 1. Way 1: Each inconsistent tuple one disjunctive clause – 2. For example: how many? Way 2: a) b) Consistent tuple conjunction of terms Each constraint disjunction of these conjunctions transform into conjunctive normal form (CNF) Question: find a truth assignment of the Boolean variables such that the sentence is satisfied Overview: 1

Outline ü Motivating example, application areas ü CSP: Definition, representation ü Some simple modeling

Outline ü Motivating example, application areas ü CSP: Definition, representation ü Some simple modeling examples ü More on definition and formal characterization ü Basic solving techniques • Modeling and consistency checking • Constructive, systematic search • Iterative improvement, local search Overview: 1

How to solve a CSP? Search 1. Constructive, systematic 2. Iterative repair, local search

How to solve a CSP? Search 1. Constructive, systematic 2. Iterative repair, local search Overview: 1

Before starting search! Consider: • Importance of modeling/formulation: – To control the size of

Before starting search! Consider: • Importance of modeling/formulation: – To control the size of the search space • Preprocessing – A. k. a. constraint filtering/propagation, consistency checking – reduces size of search space Overview: 1

Importance of modeling • N-queen: formulation 1 1 V 1 – Variables? 4 Rows

Importance of modeling • N-queen: formulation 1 1 V 1 – Variables? 4 Rows 4 Column positions – Domains? – Size of CSP? V 2 V 3 V 4 • N-queens: formulation 2 V 11 V 12 V 13 V 14 – Variables? 16 Cells {0, 1} – Domains? – Size of CSP? V 21 V 22 V 23 V 24 V 31 V 32 V 33 V 34 V 41 V 42 V 43 V 44 Overview: 1 2 3 4

Constraint checking Arc-consistency B A C: [ 6. . 15 ] [ 5. .

Constraint checking Arc-consistency B A C: [ 6. . 15 ] [ 5. . 18] 2 B<C [ 1. . 10 ] 2<C-A<5 1 - B: [ 5. . 14 ] 13 14 A<B 2 - A: [ 2. . 10 ] C: [ 6. . 14 ] 6 [ 4. . 15] Overview: 1 3 - B: [ 5. . 13 ] 14 C

Constraint checking Arc-consistency: every combination of two adjacent variables 3 -consistency, k-consistency (k n)

Constraint checking Arc-consistency: every combination of two adjacent variables 3 -consistency, k-consistency (k n) Constraint filtering, constraint checking, etc. . Eliminate non-acceptable tuples prior to search Warning: arc-consistency does not solve the problem still is not a solution! Overview: 1

Systematic search 1. 2. 3. 4. Starting from a root node Consider all values

Systematic search 1. 2. 3. 4. Starting from a root node Consider all values for a variable V 1 For every value for V 1, consider all values for V 2 etc. . 5. For n variables, each of domain size d 6. Maximum depth? fixed! 7. Maximum number of paths? size of search space, size of CSP Overview: 1

Systematic search (I) Back-checking • Systematic search generates dn possibilities • Are all possibilities

Systematic search (I) Back-checking • Systematic search generates dn possibilities • Are all possibilities acceptable? Expand a partial solution only when it is consistent This yields early pruning of inconsistent paths Overview: 1

Systematic search (II) Chronological backtracking What if only one solution is needed? • Depth-first

Systematic search (II) Chronological backtracking What if only one solution is needed? • Depth-first search & Chronological backtracking • DFS: Soundness? Completeness? Overview: 1

Systematic search (III) Intelligent backtracking What if the reason for failure was higher up

Systematic search (III) Intelligent backtracking What if the reason for failure was higher up in the tree? Backtrack to source of conflict !! Backjumping, conflict-directed backjumping, etc. Overview: 1

Systematic search (IV) Ordering heuristics • Which variable to expand first? • Heuristics: –

Systematic search (IV) Ordering heuristics • Which variable to expand first? • Heuristics: – most constrained variable first (reduce branching factor) – most promising value first (find quickly first solution) Overview: 1

Systematic search (V) Back-checking • Search tree with only backtrack search? Root node Q

Systematic search (V) Back-checking • Search tree with only backtrack search? Root node Q Q 2 1 Q Q 1 2 3 4 Q 1 2 3 4 1 2 4 3 1 1 2 3 Solution! 26 nodes visited. Overview: 1

Systematic search (VI) Forward checking Search Tree with domains filter by Forward Check Root

Systematic search (VI) Forward checking Search Tree with domains filter by Forward Check Root node Q Q Q 2 1 Q Q 3 4 4 Domain 2 Wipe Out V 3 Domain Wipe Out V 4 1 3 Solution! 8 nodes visited. Overview: 1

Summary of backtrack search • Constructive, systematic, exhaustive – In general sound and complete

Summary of backtrack search • Constructive, systematic, exhaustive – In general sound and complete • Back-checking: expands nodes consistent with past • Backtracking: Chronological vs. intelligent • Ordering heuristics: – Static – Dynamic variable-value pairs • Looking ahead: – Partial look-ahead • Forward checking (FC) • Directional arc-consistency (DAC) – Full (a. k. a. Maintaining Arc-consistency or MAC) Overview: 1

CSP: a decision problem (NP-complete) 1. Modeling: abstraction and reformulation 2. Preprocessing techniques: •

CSP: a decision problem (NP-complete) 1. Modeling: abstraction and reformulation 2. Preprocessing techniques: • eliminate non-acceptable tuples prior to search 3. Systematic search: • • potentially dn paths of fixed lengths chronological backtracking intelligent backtracking variable/value ordering heuristics 4. Search ‘hybrids: ’ • Mixing consistency checking with search: look-ahead strategies Overview: 1

Non-systematic search • Iterative repair, local search: modifies a global but inconsistent solution to

Non-systematic search • Iterative repair, local search: modifies a global but inconsistent solution to decrease the number of violated constraints • Examples: Hill climbing, taboo search, simulated annealing, GSAT, Walk. SAT, Genetic Algorithms, Swarm intelligence, etc. • Features: Incomplete & not sound – Advantage: anytime algorithm – Shortcoming: cannot tell that no solution exists Overview: 1

Outline of CSP 101 • We have seen ü Motivating example, application areas ü

Outline of CSP 101 • We have seen ü Motivating example, application areas ü CSP: Definition, representation ü Some simple modeling examples ü More on definition and formal characterization ü Basic solving techniques • We will move to Ø (Implementing backtrack search) Advanced solving techniques Issues & research directions Overview: 1