Constraints and Search

Slides:



Advertisements
Similar presentations
Constraint Satisfaction Problems
Advertisements

Slides by Peter van Beek Edited by Patrick Prosser.
Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C) Logic & AR Summer School, 2002.
Non-Binary Constraint Satisfaction Toby Walsh Cork Constraint Computation Center.
Constraint Satisfaction Problems Russell and Norvig: Chapter
This lecture topic (two lectures) Chapter 6.1 – 6.4, except
Lecture 11 Last Time: Local Search, Constraint Satisfaction Problems Today: More on CSPs.
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.
Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni.
Constraint Satisfaction problems (CSP)
4 Feb 2004CS Constraint Satisfaction1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3.
Foundations of Constraint Processing, Fall 2004 November 8, 2004Ordering heuristics1 Foundations of Constraint Processing CSCE421/821, Fall 2004:
Constraint Satisfaction CSE 473 University of Washington.
Artificial Intelligence Constraint satisfaction Chapter 5, AIMA.
Constraint Satisfaction Problems
Constraint Satisfaction
4/18/2005EE5621 EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS Lecture 8, 4/28/2005 University of Washington, Department of Electrical Engineering Spring.
Chapter 5 Outline Formal definition of CSP CSP Examples
4/18/2005EE5621 EE562 ARTIFICIAL INTELLIGENCE FOR ENGINEERS Lecture 7, 4/25/2005 University of Washington, Department of Electrical Engineering Spring.
Constraint Satisfaction Not all problems are solved by a sequential series of steps. How do we solve other types of problems?
Constraint Satisfaction Problems
CP Summer School Modelling for Constraint Programming Barbara Smith 1.Definitions, Viewpoints, Constraints 2.Implied Constraints, Optimization,
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
Constrainedness Including slides from Toby Walsh.
N Model problem ä specify in terms of constraints on acceptable solutions ä define variables (denotations) and domains ä define constraints in some language.
Constraint Satisfaction Read Chapter 5. Model Finite set of variables: X1,…Xn Variable Xi has values in domain Di. Constraints C1…Cm. A constraint specifies.
CP Summer School Modelling for Constraint Programming Barbara Smith 2. Implied Constraints, Optimization, Dominance Rules.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
Searching by Constraint CMSC Artificial Intelligence January 24, 2008.
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
1 Chapter 5 Constraint Satisfaction Problems. 2 Outlines  Constraint Satisfaction Problems  Backtracking Search for CSPs  Local Search for CSP  The.
Chapter 5 Constraint Satisfaction Problems
Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C) Logic & AR Summer School, 2002.
Review Test1. Robotics & Future Technology Future of Intelligent Systems / Ray Kurzweil futurist Ray Kurzweil / A Long Bet A Long Bet / Robot Soccer.
Maintaining Arc Consistency (MAC) MAC is the same as Back-tracking, but with calls to AC-3 interleaved... function Backtracking-Search(csp) returns.
An Introduction to Artificial Intelligence Lecture 5: Constraint Satisfaction Problems Ramin Halavati In which we see how treating.
1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3 Grand Challenge:
CHAPTER 5 SECTION 1 – 3 4 Feb 2004 CS Constraint Satisfaction 1 Constraint Satisfaction Problems.
Constraint Satisfaction Problems University of Berkeley, USA
Constraint Satisfaction Problems
1. 2 Outline of Ch 4 Best-first search Greedy best-first search A * search Heuristics Functions Local search algorithms Hill-climbing search Simulated.
Chapter 5 Team Teaching AI (created by Dewi Liliana) PTIIK Constraint Satisfaction Problems.
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.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Constraint Satisfaction Problems (CSPs)
Constraint Satisfaction Problems Lecture # 14, 15 & 16
Constraint Satisfaction
Constraint Satisfaction
Lecture 7 Constraint Satisfaction Problems
CSPs: Search and Arc Consistency Computer Science cpsc322, Lecture 12
Constraint Propagation
Constraints and Search
Constraint Satisfaction Problems
Heuristic Ordering for Asynchronous Backtracking
Chapter 5: General search strategies: Look-ahead
at Glasgow (and Strathclyde till mid April)
Constraint satisfaction problems
Constraint Satisfaction Problems. A Quick Overview
Constraint Satisfaction
CS 8520: Artificial Intelligence
Constraint Satisfaction Problems
Constraint satisfaction problems
Constraint Satisfaction Problems (CSP)
Presentation transcript:

Constraints and Search Logic & AR Summer School, 2002 Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C) tw@4c.ucc.ie

Constraint satisfaction Constraint satisfaction problem (CSP) is a triple <V,D,C> where: V is set of variables Each X in V has set of values, D_X Usually assume finite domain {true,false}, {red,blue,green}, [0,10], … C is set of constraints Goal: find assignment of values to variables to satisfy all the constraints

Constraint solver Tree search Number of choices Assign value to variable Deduce values that must be removed from future/unassigned variables Constraint propagation If any future variable has no values, backtrack else repeat Number of choices Variable to assign next, value to assign Some important refinements like nogood learning, non-chronological backtracking, …

Constraint propagation Enfrocing arc-consistency (AC) A binary constraint r(X1,X2) is AC iff for every value for X1, there is a consistent value (often called support) for X2 and vice versa E.g. With 0/1 domains and the constraint X1 =/= X2 Value 0 for X1 is supported by value 1 for X2 Value 1 for X1 is supported by value 0 for X2 … A problem is AC iff every constraint is AC

Tree search Backtracking (BT) Forward checking (FC) Maintaining arc-consistency (MAC) Limited discrepany search (LDS) Non-chronological backtracking & learning

Example: n-queens Place n-queens on an n  n board so that no pair of queens attacks each other

Example: 4-queens Variables: x1, x2 , x3 , x4 Domains: {1, 2, 3, 4} Constraints: xi  xj and | xi - xj |  | i - j | x1 x2 x3 x4 1 2 3 4

Example: 4-queens One solution: x1  2 x2  4 x3  1 x4  3 x1 x2 x3

BT on 4-queens x1 x2 x3 x4 Try: x1  1 1 Q 2 3 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  1 1 Q Q 2 3 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  1 Backtrack 1 Q Q 2 3 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  2 1 Q 2 Q 3 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  2 Backtrack 1 Q 2 Q 3 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 1 Q 2 3 Q 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  1 1 Q Q 2 3 Q 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  1 Backtrack 1 2 3 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  2 1 Q 2 Q 3 Q 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  2 Backtrack 1 2 3 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  3 1 Q 2 3 Q Q 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  3 Backtrack 1 2 3 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  4 1 Q 2 3 Q 4 Q

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 x3  4 Backtrack 1 2 3 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 1 Q 2 3 4 Q

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 x3  1 1 Q Q 2 3 4 Q

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 x3  1 Backtrack 1 2 3 4

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 x3  2 1 Q 2 Q 3 4 Q

BT on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 x3  2 And so on! 1 2 3

BT search tree for 4-queens x1 1 2 3 4 … x2 … x3 x4 (2,4,1,3) (3,1,4,2)

Forward checking (FC) Maintains limited form of arc-consistency Makes constraints involving current var and any future var arc-consistent Only looks at each constraint once! No need to re-visit constraints to ensure support remains when a domain value is pruned Very cheap, little extra cost over BT

FC on 4-queens x1 x2 x3 x4 Try: x1  1 1 Q 2 3 4

FC on 4-queens x1 x2 x3 x4 Try: x1  1 Forward check 1 2 3 4 Q X X X X

FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 1 Q X X X 2 X 3 Q X 4 X

FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 Forward check 1 2 3 4 Q

FC on 4-queens Try: x1  1 x2  3 Domian wipeout for x3 x1 x2 x3 x4 1

FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 Backtrack 1 2 3 4 Q X X

FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  3 Backtrack 1 2 3 4 Q X X

FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 1 Q X X X 2 X 3 X 4 Q X

FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 Forward check 1 2 3 4 Q

FC on 4-queens Try: x1  1 x2  4 x3  2 x1 x2 x3 x4 1 2 3 4 Q X X X X

FC on 4-queens Try: x1  1 x2  4 x3  2 Forward check x1 x2 x3 x4 1 2

FC on 4-queens Try: x1  1 x2  4 x3  2 Domain wipeout for x4 x1 x2

FC on 4-queens x1 x2 x3 x4 Try: x1  1 x2  4 Backtrack 1 2 3 4 Q X X

FC on 4-queens x1 x2 x3 x4 Try: x1  1 Backtrack 1 Q X X X 2 X 3 X 4 X

FC on 4-queens x1 x2 x3 x4 Try: x1  2 1 2 Q 3 4

FC on 4-queens x1 x2 x3 x4 Try: x1  2 Forward check 1 2 3 4 X Q X X X

FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 1 X 2 Q X X X 3 X 4 Q X

FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 Forward check 1 2 3 4 X

FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 x3  1 1 2 3 4 X Q Q X X

FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 x3  1 Forward check 1 2

FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 x3  1 x4  3 1 2 3 4 X

FC on 4-queens x1 x2 x3 x4 Try: x1  2 x2  4 x3  1 x4  3 1 2 3 4 Q

Maintaining arc-consistency (MAC) Enforces arc-consistency at each node in the search tree Much more expensive than FC But can save exploring many fruitless subtrees

MAC on 4-queens x1 x2 x3 x4 Try: x1  1 1 Q 2 3 4

MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC 1 Q 2 3 4

MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC 1 2 3 4 Q X X X X X

MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC 1 2 3 4 Q X X X X X

MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC 1 2 3 4 Q X X X X X

MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC 1 2 3 4 Q X X X X X

MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC Domain wipeout for x3 1 Q X X X 2 X X 3 X X 4 X X

MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC Backtrack 1 2 3 4 Q

MAC on 4-queens x1 x2 x3 x4 Try: x1  1 Enforce AC Backtrack 1 Q 2 3 4

MAC on 4-queens x1 x2 x3 x4 Try: x1  2 1 2 Q 3 4

MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Enforce AC 1 2 Q 3 4

MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Enforce AC 1 2 3 4 X Q X X X X

MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Enforce AC 1 2 3 4 X Q X X X X

MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Enforce AC 1 2 3 4 X Q X X X X

MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Enforce AC 1 2 3 4 X X Q X X X

Each var has single value MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Each var has single value Gives solution 1 X X 2 Q X X X 3 X X 4 X X

Each var has single value MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Each var has single value Gives solution 1 X Q X 2 Q X X X 3 X X Q 4 Q X X

Each var has single value MAC on 4-queens x1 x2 x3 x4 Try: x1  2 Each var has single value Gives solution 1 Q 2 Q 3 Q 4 Q

Heuristics for backtracking algorithms Variable ordering (important) what variable to branch on next Value ordering (not yet so important) given a choice of variable, what order to try values Constraint ordering (not so important) what order to propagate constraints most likely to fail or cheapest propagated first

Variable ordering Domain dependent heuristics Domain independent heuristics Static variable ordering fixed before search starts Dynamic variable ordering chosen during search

Variable ordering: Possible goals Minimize expected depth of any branch Encourage constraint propagation Minimize expected number of branches Minimize size of search space explored by backtracking algorithm intractable to find “best” variable

Basic idea Assign a heuristic value to a variable that estimates how difficult it is to find a satisfying value for that variable Principle: most likely to fail first or don’t postpone the hard part

Some variable ordering heuristics minimum domain size (dom) maximum degree (deg) most constraining plus: combining — tie break strategies e.g., dom + deg, dom / deg

Value ordering All solutions One solution value ordering not so important One solution if a solution exists, there exists a perfect value ordering

Value ordering: Intuition Goal: minimize size of search space explored Principle: given that we have already chosen the next variable to instantiate, choose first the values that are most likely to succeed

Comparing algorithms How do BT, FC and MAC compare? Theoretical comparison based on size of their search tree MAC beats FC beats BT Experimental comparison MAC is more expensive at each node!

Theoretical comparison Alg1 dominates Alg2 (written Alg1 >= Alg2) iff given same fixed variable and value ordering Alg1 visits search node implies Alg2 also visits this node Alg1 strictly dominates Alg2 (written Alg1 > Alg2) iff Alg1 domiantes Alg2 it visits fewer nodes on at least one problem

Theoretical comparison MAC > FC > BT Homework exercise! Exist problems on which search trees are exponentially smaller But do such problems turn up in practice? Only experiment will tell you if MAC is better than FC for your class of problems Usually it is!

Limited discrepancy search Often first decision is wrong Depth-first search (used in BT/FC/MAC) can take long time to undo this decision E.g. in 4-queens, first decision was x1=1 But first solution has x1=2

Limited discrepancy search Explore search tree in order of number of discrepancies “discrepancy” = branch against heuristic LDS search goes in waves: 0th iteration, explore heuristic branch 1st iteration, explore all branches with 1 branch against heuristic 2nd iteration, explore all branches with 2 branches agaisnt heuristic …

LDS 0th iteration Follow heuristic to root (or backtrack point)

LDS 1st iteration Follow all banches that go against heuristic once

LDS 2nd iteration Follow all banches that go against heuristic twice

Non-chronological backtracking Backjumping (BJ) Conflict directed backjumping (CBJ) Key idea in each of these is to backtrack to a “relevant” variable, decision that led to failure Ignore decisions that didn’t contribute to the failure Can combine with FC or MAC E.g. FC-CBJ and MAC-CBJ

Backjumping For each var xi, keep index of deepest var which xi performed consistency check If xi has no consistent values, jump back to that var

Backjumping For each var xi, keep index of deepest var which xi performed consistency check If xi has no consistent values, jump back to that var Only last backtrack down branch is non-chronological

Conflict-directed backjumping For each var xi, keep conflict set Set of vars which ruled out values from xi If xi has no consistent values, jump back to deepest var Not only first backtrack can be non-chronological Multiple “backjumps” across conflicts possible

Theoretical comparison We can apply the same dominance ordering MAC-CBJ > FC-CBJ > CBJ > BJ > BT FC > BJ

Learning Another use for conflict sets At end of branch, identify cause for failure This is a conflict set Heuristically add to set of constraints Heuristics include size bounded and relevance bounded learning

Local search Initial assignment 1 2 Pick queen in conflict Q x1 x2 x3 Move to min. conflicts Q x1 x2 x3 x4 2 Pick queen in conflict Q x1 x2 x3 x4

Summary Search important part of constraint solving Backtracking algorithms often perform inference/constraint propagation at each node Exist various refinements of chronological backtracking like CBJ, LDS, …