Constraint processing An efficient alternative for search.

Slides:



Advertisements
Similar presentations
Constraint Satisfaction Patrick Prosser. An Example, Exam Timetabling Someone timetables the exams We have a number of courses to examine how many? Dept.
Advertisements

Informed search algorithms
1 Constraint Satisfaction Problems A Quick Overview (based on AIMA book slides)
1 CMSC 471 Fall 2002 Class #6 – Wednesday, September 18.
Constraint processing An efficient alternative for search.
1 Finite Constraint Domains. 2 u Constraint satisfaction problems (CSP) u A backtracking solver u Node and arc consistency u Bounds consistency u Generalized.
PROBLEM SOLVING AND SEARCH
ICS-271:Notes 5: 1 Lecture 5: Constraint Satisfaction Problems ICS 271 Fall 2008.
MBD and CSP Meir Kalech Partially based on slides of Jia You and Brian Williams.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 – CHAPTER 4 GRAPHS 1.
Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni.
CSC 423 ARTIFICIAL INTELLIGENCE
Best-First Search: Agendas
Backtracking COP Backtracking  Backtracking is a technique used to solve problems with a large search space, by systematically trying and eliminating.
Backtracking What is backtracking?
Constraint Logic Programming Ryan Kinworthy. Overview Introduction Logic Programming LP as a constraint programming language Constraint Logic Programming.
Constraint Satisfaction CSE 473 University of Washington.
Constraint Satisfaction Problems
Foundations of Constraint Processing, Fall 2005 Sep 20, 2005BT: A Theoretical Evaluation1 Foundations of Constraint Processing CSCE421/821, Fall 2005:
Constraint Satisfaction Problems
SAT-solving An old AI technique becomes very popular in modern A.I.
Relaxation and Hybrid constraint processing Different relaxation techniques Some popular hybrid techniques.
CS 403: Programming Languages Lecture 19 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
CPS 270: Artificial Intelligence More search: When the path to the solution doesn’t matter Instructor: Vincent.
HISTORY The problem was originally proposed in 1848 by the chess player Max Bezzel, and over the years, many mathematicians, including Gauss have worked.
Computer Science CPSC 322 Lecture 13 Arc Consistency (4.5, 4.6 ) Slide 1.
CSIS 123A Lecture 9 Recursion Glenn Stevenson CSIS 113A MSJC.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Searching by Constraint CMSC Artificial Intelligence January 24, 2008.
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,
Prof. Amr Goneid, AUC1 Analysis & Design of Algorithms (CSCE 321) Prof. Amr Goneid Department of Computer Science, AUC Part 8. Greedy Algorithms.
Honors Track: Competitive Programming & Problem Solving Optimization Problems Kevin Verbeek.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
Agenda Review: –Planar Graphs Lecture Content:  Concepts of Trees  Spanning Trees  Binary Trees Exercise.
Chapter 5 Constraint Satisfaction Problems
Review Test1. Robotics & Future Technology Future of Intelligent Systems / Ray Kurzweil futurist Ray Kurzweil / A Long Bet A Long Bet / Robot Soccer.
Goal-based Problem Solving Goal formation Based upon the current situation and performance measures. Result is moving into a desirable state (goal state).
Problem Reduction So far we have considered search strategies for OR graph. In OR graph, several arcs indicate a variety of ways in which the original.
Constraint Satisfaction Problems University of Berkeley, USA
Arc Consistency CPSC 322 – CSP 3 Textbook § 4.5 February 2, 2011.
Chapter 13 Backtracking Introduction The 3-coloring problem
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.
Constraint Propagation Artificial Intelligence CMSC January 22, 2002.
Constraint Satisfaction CSE 473 University of Washington.
1 CSC 384 Lecture Slides (c) , C. Boutilier and P. Poupart CSC384: Lecture 16  Last time Searching a Graphplan for a plan, and relaxed plan heuristics.
Biointelligence Lab School of Computer Sci. & Eng. Seoul National University Artificial Intelligence Chapter 8 Uninformed Search.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
Automatic Test Generation
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Constraint Satisfaction Problems Lecture # 14, 15 & 16
Constraint Satisfaction
Constraint Satisfaction
Lecture 7 Constraint Satisfaction Problems
Empirical Comparison of Preprocessing and Lookahead Techniques for Binary Constraint Satisfaction Problems Zheying Jane Yang & Berthe Y. Choueiry Constraint.
CS 188: Artificial Intelligence
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Constraint Satisfaction Problems
Artificial Intelligence
Constraints and Search
Intelligent Backtracking Algorithms: A Theoretical Evaluation
Intelligent Backtracking Algorithms: A Theoretical Evaluation
Intelligent Backtracking Algorithms: A Theoretical Evaluation
Artificial Intelligence
Search.
Intelligent Backtracking Algorithms: A Theoretical Evaluation
Constraint Satisfaction Problems
Constraint Satisfaction Problems (CSP)
Presentation transcript:

Constraint processing An efficient alternative for search

2 Constraint Processing: Overview  Illustrating the idea with examples:  Numerical constraint nets, Spreadsheets  Defining constraint problems  Techniques for solving them:  A variety of backtracking techniques  Consistency and relaxation  Hybrid constraint techniques  Some applications:  Understanding line drawings  Disambiguating natural language

X A B X CD Variable box Multiply box 1.1 Ex.: Numerical constraint nets Given any set of equations: There is an associated constraint net: C = A * B D = C * B B =

X A B X CD Variable box Multiply box 1.1 There is an associated constraint net: Numerical constraint nets (2)

5 Example: Spreadsheets AB 1Ratio X Ratio Y th year 5Income X Income Y Expenses 9000 CD 2 nd year3 rd year 8Total = B1 * B5 = B1 * C5 = B2 * B6= B2 * C6 = B7 = C7 = B5+B6 -B7 = C5+C6 - C7 =D5+D6 -D7

6 Spreadsheets (2) AB 1Ratio X Ratio Y th year 5Income X Income Y Expenses 9000 CD 2 nd year3 rd year 8Total = B1 * B5 = B1 * C5 = B2 * B6= B2 * C6 = B7 = C7 = B5+B6 -B7 = C5+C6 - C7 =D5+D6 -D7 = B1 * B5 = B1 * C = B2 * B6= B2 * C = B7 = C B7 - C7 -D7 = B5+B6= C5+C6=D5+D

X A B X CD Variable box Multiply box 1.1 There is an associated constraint net: Numerical constraint nets (3) 3630 OR OR

Defining Constraint problems Definition File rouge

9 Defining Constraint problems  Definition: A constraint problem (or consistent labeling problem) consists of:  a finite set of variables: z1, z2, …, zn  for each variable: an associated finite domain of possible values di = {ai 1,ai 2, …, ai ni }  for each two variables zi, zj, i  j, a constraint c(zi, zj)  ex.: zi  zj  zi + i  zj - j  we restrict ourselves to binary CPS  Problem: build efficient techniques to assign to each zi a value ai j from its domain di such that all c(zi, zj) are true.

10 Example: q-queens: … is a solution  Given: a q X q chess board  Problem: find (all possible) ways of placing q queens on the board, such that no 2 queens attack each other.  4-queens:

11 Confused q-queens: = identical, BUT each 2 queens MUST attack each other.  C-4-queens:

12 Constraint formulation?  Q-queens and C-q-queens define a set of constraint problems:  depends on choice of domains, constraints  One possibility:  for each queen: a variable zi  for each zi, domain di is all possible board positions:  di = { (1,1), (1,2), …, (1,q), (2,1), (2,2), … }  c(zi, zj) = row(zi)  row(zj)  col(zi)  col(zj)  |row(zi) - row(zj)|  |col(zi) - col(zj)|

13 A ‘better’ formulation:  We agree that each queen is placed on a specific row: z1 z2 z3 z41234  for queen on row i: a variable zi  The representation:  for each zi, domain di = { 1, 2, …, q}  c(zi, zj) = zi  zj  |zi - zj|  |i - j|

14 Notes on C-q-queens:  For C-q-queens, the new second representation defines a slightly different problem: … is no longer a solution  Now C-q-queens always has q+2 solutions !  Advantage for complexity studies.  Exception: q = 3: are extra

Representing the search Or-tree representation Constraint Networks

16 The OR-tree representation: Select an order on the variables: z1, z2, …, zn z a1 1 a1 2 … … … … … … … a1 n1 z a2 1 a2 2 … … a2 n2 c(z1,z2) x v … … v c(z1,z2) x v … … v z a3 1 a3 2 … … … a3 n3 c(z1,z3)... v v … … … x c(z1,z3)... v v … … … x c(z2,z3)... x v … … … c(z2,z3)... x v … … …

17 OR-tree: explicitly  For each layer (i) in the OR-tree:  Create a branch for every possible assignment to zi  Verify all constraints c(zj, zi), j  i  If all constraints are satisfied, proceed to level i+1  NOTE: this is only a representation for the search  search itself consists of building a (small) part of this tree (as in search techniques)

18 Constraint Networks z2z1z3 z4 c(z1,z2) c(z1,z4) c(z1,z3) c(z2,z3) c(z3,z4) c(z2,z4) {a1 1, a1 2, …, a1 n1 } {a4 1, a4 2, …, a4 n4 } {a2 1, a2 2, …, a2 n2 } {a3 1, a3 2, …, a3 n3 } + relaxation = select an arc (constraint) and remove the inconsistent domain values

19 z2 z1 z3 z4 c(z1,z2) c(z1,z4) c(z1,z3) c(z2,z3) c(z3,z4) c(z2,z4) {a1 1, a1 2, …, a1 n1 } {a4 1, a4 2, …, a4 n4 } {a2 1, a2 2, …, a2 n2 } {a3 1, a3 2, …, a3 n3 } Relaxation: c(z1,z4) a4 1 c(a1 i, a4 1 ) is never true!

Backtrack algorithms Chronological Backtracking BackjumpingBackmarking Intelligent Backtracking Dynamic Search Rearrangement

21 Example: 4-queens: Chronological Backtracking Traverse the OR-tree depth-first, left-to-right. z z c(z1,z2).... x c(z1,z2).... x 2 x 3 v z c(z1,z3) x c(z1,z3) x 2 v c(z2,z3) x c(z2,z3) x 3 v x 4 v x 4 v 1 x 2 v v z c(z1,z4) x v v x c(z1,z4) x v v x c(z2,z4) x v c(z2,z4) x v c(z3,z4) x c(z3,z4) x

22 The backtrack algorithm: Backtr( depth ) For k= 1 to n depth do z depth := a depth,k ; z depth := a depth,k ; Check all constraints c(z i, z depth ) Check all constraints c(z i, z depth ) with 1  i  depth until one fails; with 1  i  depth until one fails; If none failed then If none failed then If depth = n then return( z1, z2, …, zn) return( z1, z2, …, zn) End-For End-ForElse depth := depth + 1; depth := depth + 1; Backtr( depth ) ; Backtr( depth ) ; depth := depth - 1; depth := depth - 1; Call : Backtr( 1 ) z depth.... a depth,k c(z1,z depth )... v c(z1,z depth )... v c(z2,z depth )... x c(z2,z depth )... x c(z1,z depth )... v c(z2,z depth )... x c(z1,z depth )... v c(z1,z depth )... v c(z2,z depth )... v c(z2,z depth )... v c(z depth-1,z depth ) v c(z depth-1,z depth ) v z depth+1.. a depth+1,1

Backjumping Avoid trashing

24 Trashing: Example: c-4-queens: z z c(z1,z2).... v c(z1,z2).... v 2 v 3 v z3.... c(z2,z3).... c(z2,z3).... c(z1,z3).. c(z1,z3).. 4 x z4... c(z1,z4).. c(z1,z4).. c(z2,z4)... c(z2,z4)... c(z3,z4) c(z3,z4) x2vv3x4vx1x2vv3x4vx1x2vv3x4vv 1x2vx3x4x 1x2vvv3x4x1x2vx3x4x1x2vx3x4x Only z1 and z2 are tested against the values of z4: z3 is not even considered! Useless to backtrack over z3 ! Redundant computation !

25 Trashing: solution z z c(z1,z2).... v c(z1,z2).... v 2 v 3 v z3.... c(z2,z3).... c(z2,z3).... c(z1,z3).. c(z1,z3).. 4 x z4... c(z1,z4).. c(z1,z4).. c(z2,z4)... c(z2,z4)... c(z3,z4) c(z3,z4) x2vv3x4vx1x2vv3x4vx1x2vv3x4vv 1x2vx3x4x 1x2vvv3x4x1x2vx3x4x1x2vx3x4x Backjump

26 Trashing: Another occurrence z z c(z1,z2).... v c(z1,z2).... v 2 v 3 v z3.... c(z2,z3).... c(z2,z3).... c(z1,z3).. c(z1,z3).. 4 x z4... c(z1,z4).. c(z1,z4).. c(z2,z4)... c(z2,z4)... c(z3,z4) c(z3,z4) x2vv3x4vx1x2vv3x4vx1x2vv3x4vv 1x2vx3x4x 1x2vvv3x4x1x2vx3x4x1x2vx3x4x Backjump

27 Backjumping (Gaschnig’78) If all the assignments to zi fail, If all the assignments to zi fail,  The principle: and c(zk, zi) is the deepest constraint causing the fail Then backjump to change the assignment of zk zi ai 1 ai 2... ai ni c(z1,zi) x v v x c(z1,zi) x v v x c(z2,zi) x v c(z2,zi) x v c(zk,zi) x c(zk,zi) x … … all fail ! deepest fail-level: k

28 The backjump algorithm: BackJ( depth, out: jumpback ) For k= 1 to n depth do z depth := a depth,k ; z depth := a depth,k ; Check all constraints c(z i, z depth ) Check all constraints c(z i, z depth ) with 1  i  depth until one fails; with 1  i  depth until one fails; If none failed then If none failed then If depth = n then return( z1, z2, …, zn) return( z1, z2, …, zn) End-For End-For c(z1,z depth )... v c(z1,z depth )... v c(z2,z depth )... x c(z2,z depth )... x z depth.... a depth,k checkdepth k = 2 z depth.... a depth,l c(z1,z depth )... v c(z1,z depth )... v c(z2,z depth )... v c(z2,z depth )... v c(z m,z depth )... x c(z m,z depth )... x checkdepth l = m checkdepth k := deepest i checked; Else depth := depth + 1; depth := depth + 1; BackJ( depth, jumpback); BackJ( depth, jumpback); depth := depth - 1; depth := depth - 1; If jumpback  depth then return; If jumpback  depth then return; jumpback := max(checkdepth k )

Backmarking Avoiding other redundancies

30 More redundant checks: z z c(z1,z2).... v c(z1,z2).... v 2 v 3 v z3.... c(z2,z3).... c(z2,z3).... c(z1,z3).. c(z1,z3).. 4 x z4... c(z1,z4).. c(z1,z4).. c(z2,z4)... c(z2,z4)... c(z3,z4) c(z3,z4) x2vv3x4vx1x2vv3x4vx1x2vv3x4vv 1x2vx3x4x 1x2vvv3x4x1x2vx3x4x1x2vx3x4x z1 is checked against z3 BUT we only back- track over z2 !

31 Occur very often: z z c(z1,z2).... v c(z1,z2).... v 2 v 3 v z3.... c(z2,z3).... c(z2,z3).... c(z1,z3).. c(z1,z3).. 4 x z4... c(z1,z4).. c(z1,z4).. c(z2,z4)... c(z2,z4)... c(z3,z4) c(z3,z4) x2vv3x4vx1x2vv3x4vx1x2vv3x4vv 1x2vx3x4x 1x2vvv3x4x1x2vx3x4x1x2vx3x4x

32 Trashing compared to Redundant Checks: z4... c(z1,z4).. c(z1,z4).. c(z2,z4)... c(z2,z4)... c(z3,z4) c(z3,z4) 1x2vx3x4x Only when a complete BLOCK of checks FAILS. Only when a complete BLOCK of checks FAILS.  Trashing: Also for SUCCESSFUL checks and for the checks performed on 1 ROW only. Also for SUCCESSFUL checks and for the checks performed on 1 ROW only.  Redundant Checks: z3.... c(z2,z3).... c(z2,z3).... c(z1,z3).. c(z1,z3).. 1x2vv3x4vx1x2vv3x4vx

33 Avoiding redundant checks:  2 approaches: 1. TABULATION:  lemma generation (store results of checks in a table) + lemma application (table look-up for new checks)  improves speed to some extent  but does not really avoid the redundant checks  increases the storage requirements 2. BACKMARKING:  ~ TOTALLY speed saving (no redundant checks)  only limited space-overhead (2 arrays)

34 Backmarking (Gaschnig ‘77):  The 2 arrays: zk.... c(z2,zk).... c(z2,zk).... c(z1,zk).. c(z1,zk).. ak 1 x ak 2 v x … v v … v ak nk v x ak 1 … ak nk c(z k-1,zk) c(z k-1,zk) = checkdepth zk, l. = checkdepth zk, l.  Checkdepth(k,l): checkdepth zk,1 = 1 checkdepth zk,2 = 2 checkdepth zk,… = k-1 checkdepth zk,nk = 2 ak 2

35 Backmarking (Gaschnig ‘77):  The 2nd array: zk.... c(z2,zk).... c(z2,zk).... c(z1,zk).. c(z1,zk).. ak 1 x ak 2 v v … v v … v ak nk v x ak 1 … ak nk c(z k-1,zk) c(z k-1,zk) ak 2 = to which (lowest) level did we backup between visiting these 2 blocks for zk. = to which (lowest) level did we backup between visiting these 2 blocks for zk.  Backup(k): zk-1 zk-2

36 A property of Checkdepth k,l The last check needs to be a FAIL. Otherwise, checking would have continued ! The last check can be either fail or succeed.  If Checkdepth k,l  k-1:  If Checkdepth k,l = k-1: zk.... ak,l zk.... ak,l c(z1,zk).. v c(z2,zk).. v … c(zk-1,zk). x/v zk.... ak,l zk.... ak,l c(z1,zk).. v c(z2,zk).. v … c(zi,zk)... x

37 Properties of Checkdepth versus Backup (1):  If checkdepth (k,l)  backup(k) : checkdepth(k,l) checkdepth(k,l)  k-1 The assignment ak,l to zk caused fail the previous time, and it will cause fail again this time (at the same depth) zk ak,l zk ak,l c(z1,zk)..... v c(z2,zk)..... v … c(zi,zk)......x … c(zk-1,zk) checkdepth(k,l) backup(k)

38 Properties of Checkdepth versus Backup (2):  If checkdepth (k,l)  backup(k) : zk ak,l zk ak,l c(z1,zk)..... v c(z2,zk)..... v … c(zi,zk)......v … c(zj,zk).... v/x c(zj,zk).... v/x checkdepth(k,l) backup(k) All checks for variables zm, with m lower than backup(k) succeeded before and will succeed again.

39 The Backmark algorithm: BackM( depth, out: checkdepth, backup ) For k= 1 to n depth do z depth := a depth,k ; z depth := a depth,k ; Check all constraints c(z i, z depth ) with 1  i  depth until one fails; Check all constraints c(z i, z depth ) with 1  i  depth until one fails; If none failed then If none failed then … … … End-For If checkdepth( depth, k )  backup( depth ) Then1 backup( depth ) *property 1 applied* *property 2 applied*

40 z Backmarking at work: z c(z1,z2).... v c(z1,z2).... v z3.... c(z2,z3).... c(z2,z3).... c(z1,z3).. c(z1,z3).. 1x2vv z4... c(z1,z4).. c(z1,z4).. c(z2,z4)... c(z2,z4)... 1x2vx3x4x 3x4vx v 2 v 1x2v 1x2v3x4x vv c(z3,z4) c(z3,z4) x4vx

41 At a much later stage: 3 v 1x2vv3x4vv 1x2vx3x4x1x2vx3x4x z z c(z1,z2).... c(z1,z2).... z3.... c(z2,z3).... c(z2,z3).... c(z1,z3).. c(z1,z3).. z4... c(z1,z4).. c(z1,z4).. c(z2,z4)... c(z2,z4)... c(z3,z4) c(z3,z4) x 3

42 Discussion and results: Note: initial values for checkdepth(k,l) and backup(k) are all 1  Experimental results:  For c-4-queens problem BTBJBMNodes Checks  Overall:  BackMarking = best algorithm (not absolute)  Combining BJ and BM? YES !  But does not produce the combined optimisation.

Dynamic Search rearrangement

44 Dynamic search rearrangement  = any backtrack algorithm +  select the order of the variables in the tree dynamically  Purpose: Decrease the size of the tree due to the “first-fail principle” If assigning a value to zi is more likely to fail than assigning to zj: Then: assing to zi first.  The first-fail principle:

45 Effect?  1. Suppose our guess was right… zi... c(z1,zi).. c(z1,zi).. c(z2,zi).. x c(z2,zi).. x ai1vx…aik x zj... c(z1,zj).. c(z1,zj).. c(z2,zj).. c(z2,zj).. aj1 v vaj2 xajl v v ai1vx…aik xai1vx…aik x zi... c(z1,zi).. c(z1,zi).. c(z2,zi). c(z2,zi). Done Smaller search tree !  … then we gain in any case

46 Effect (2)?  2. Suppose our guess was only partly right … ai1vv…aik xai1vv…aik x zi... c(z1,zi).. c(z1,zi).. c(z2,zi). c(z2,zi). Less checks are redone !  … we still gain: Assingment to zi does not fail, but has less successes ! zj... c(z1,zj).. c(z1,zj).. c(z2,zj).. c(z2,zj).. aj1 v vaj2 xajl v v zi... c(z1,zi).. c(z1,zi).. c(z2,zi).. x c(z2,zi).. x ai1vv…aik x zj... c(z1,zj).. c(z1,zj).. c(z2,zj).. c(z2,zj).. aj1 v vaj2 xajl v v

47 Some general first-fail heuristics:  Select the variable with the smallest domain first decreases the branching factor (less possibilities -> probably less successes)  Select the variable with the highest number of non- trivial constraints first: z2z1z3 z4 c(z1,z2) c(z1,z4) = “true” c(z1,z3) “true” = c(z2,z3) c(z3,z4) = “true” c(z2,z4)  + Heuristics based on problem at hand.