Arc consistency AC5, AC2001, MAC. AC5 A generic arc-consistency algorithm and its specializations AIJ 57 (2-3) October 1992 P. Van Hentenryck, Y. Deville,

Slides:



Advertisements
Similar presentations
Levels of Consistency Node Consistency (NC) Arc-consistency (AC) Path Consistency (PC) Generalised arc-consistency (GAC) Bounds consistency Inverse Path.
Advertisements

Non-Binary Constraint Satisfaction Toby Walsh Cork Constraint Computation Center.
Non-binary Constraints Toby Walsh
Constraint Satisfaction Patrick Prosser. An Example, Exam Timetabling Someone timetables the exams We have a number of courses to examine how many? Dept.
Constraint Satisfaction Problems Russell and Norvig: Chapter
Arc consistency ac3, ac4, ac6/7/8. Di = {1,2,3,4,5} V1 V3 V2 V4 V4  V3 V1  V4  1 V4 + V2 = 5 V1  V2 V2  V3  6 AR33 figure 18, page 35 What can you.
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Exercise 1 Generics and Assignments. Language with Generics and Lots of Type Annotations Simple language with this syntax types:T ::= Int | Bool | T =>
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.
ICS-271:Notes 5: 1 Lecture 5: Constraint Satisfaction Problems ICS 271 Fall 2008.
Artificial Intelligence Constraint satisfaction problems Fall 2008 professor: Luigi Ceccaroni.
Counting the bits Analysis of Algorithms Will it run on a larger problem? When will it fail?
Constraint Optimization Presentation by Nathan Stender Chapter 13 of Constraint Processing by Rina Dechter 3/25/20131Constraint Optimization.
Foundations of Constraint Processing More on Constraint Consistency 1 Foundations of Constraint Processing CSCE421/821, Spring
Specialised N-ary Constraint for the Stable Marriage Problem By Chris Unsworth and Patrick Prosser.
What’s the problem? Something like stable marriage problem … but without sex.
Outline. Theorem For the two processor network, Bit C(Leader) = Bit C(MaxF) = 2[log 2 ((M + 2)/3.5)] and Bit C t (Leader) = Bit C t (MaxF) = 2[log 2 ((M.
1 Refining the Basic Constraint Propagation Algorithm Christian Bessière and Jean-Charles Régin Presented by Sricharan Modali.
4 Feb 2004CS Constraint Satisfaction1 Constraint Satisfaction Problems Chapter 5 Section 1 – 3.
©2007 Tarik Hadzic1 Lecture 11: Consistency Techniques 1. Arc Consistency 2. Directional Consistency 3. Generalized Arc Consistency Efficient AI Programming.
Constraint Satisfaction Problems
Constraint Satisfaction
Jean-Charles REGIN Michel RUEHER ILOG Sophia Antipolis Université de Nice – Sophia Antipolis A global constraint combining.
Constraint Satisfaction Problems Russell and Norvig: Chapter 3, Section 3.7 Chapter 4, Pages Slides adapted from: robotics.stanford.edu/~latombe/cs121/2003/home.htm.
Constraint Satisfaction Problem Solving Chapter 5.
26 April 2013Lecture 5: Constraint Propagation and Consistency Enforcement1 Constraint Propagation and Consistency Enforcement Jorge Cruz DI/FCT/UNL April.
Chapter 5 Outline Formal definition of CSP CSP Examples
From Constraints to Finite Automata to Filtering Algorithms Mats Carlsson, SICS Nicolas Beldiceanu, EMN
Constraint Satisfaction Problems
1 Constraint Programming: An Introduction Adapted by Cristian OLIVA from Peter Stuckey (1998) Ho Chi Minh City.
Subgraph Isomorphism Problem Simple algorithms. Given two graphs G = (V,E) and H = (W,F) is there a subgraph of H that is isomorphic to G?
Called as the Interval Scheduling Problem. A simpler version of a class of scheduling problems. – Can add weights. – Can add multiple resources – Can ask.
Slide 1 CSPs: Arc Consistency & Domain Splitting Jim Little UBC CS 322 – Search 7 October 1, 2014 Textbook §
CP Summer School Modelling for Constraint Programming Barbara Smith 1.Definitions, Viewpoints, Constraints 2.Implied Constraints, Optimization,
Constrainedness Including slides from Toby Walsh.
Implementing Constraints. 2 Overview  A look at the literature CSPs Arc consistency algorithms  Implementation in ECLiPSe: Low level:Suspensions and.
Introduction Algorithms and Conventions The design and analysis of algorithms is the core subject matter of Computer Science. Given a problem, we want.
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
Constraint Satisfaction Problems Chapter 6. Review Agent, Environment, State Agent as search problem Uninformed search strategies Informed (heuristic.
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.
Constraint Satisfaction CPSC 386 Artificial Intelligence Ellen Walker Hiram College.
1 CS B551: Elements of Artificial Intelligence Instructor: Kris Hauser
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
Problem Solving with Constraints Lookahead Schemas 1 Foundations of Constraint Processing CSCE496/896, Fall
Chapter 5: Constraint Satisfaction ICS 171 Fall 2006.
CSCI 5582 Fall 2006 CSCI 5582 Artificial Intelligence Fall 2006 Jim Martin.
A Logic of Partially Satisfied Constraints Nic Wilson Cork Constraint Computation Centre Computer Science, UCC.
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.
Chapter 2) CSP solving-An overview Overview of CSP solving techniques: problem reduction, search and solution synthesis Analyses of the characteristics.
Maintaining Arc Consistency (MAC) MAC is the same as Back-tracking, but with calls to AC-3 interleaved... function Backtracking-Search(csp) returns.
CHAPTER 5 SECTION 1 – 3 4 Feb 2004 CS Constraint Satisfaction 1 Constraint Satisfaction Problems.
1 Constraint Satisfaction Problems: Formulation, Arc Consistency & Propagation 1 Brian C. Williams October 13 th, 2004 Slides adapted from:
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.
Lecture 8CSE Intro to Cognitive Science1 Interpreting Line Drawings II.
Where are the hard problems?. Remember Graph Colouring? Remember 3Col?
CS 561, Session 8 1 This time: constraint satisfaction - Constraint Satisfaction Problems (CSP) - Backtracking search for CSPs - Local search for CSPs.
Empirical Comparison of Preprocessing and Lookahead Techniques for Binary Constraint Satisfaction Problems Zheying Jane Yang & Berthe Y. Choueiry Constraint.
CS B551: Elements of Artificial Intelligence
Computer Science cpsc322, Lecture 13
Multi-Way Search Trees
Constraints and Search
More on Constraint Consistency
More on Constraint Consistency
Problem Solving With Constraints
Constraint Satisfaction Problems. A Quick Overview
Presentation transcript:

Arc consistency AC5, AC2001, MAC

AC5 A generic arc-consistency algorithm and its specializations AIJ 57 (2-3) October 1992 P. Van Hentenryck, Y. Deville, and C.M. Teng

ac5 Ac5 is a “generic” ac algorithm and can be specialised for special constraints (i.e. made more efficient when we know something about the constraints) Ac5 is at the heart of constraint programming It can be “tweaked” to become ac3, or “tweaked” to become ac4 But, it can exploit the semantics of constraints, and there’s the win

ac5 ac5 processes a queue of tuples (i,j,w) w has been removed from Dj we now need to reconsider constraint Cij to determine the unsupported values in Di A crucial difference between ac3 and ac5 ac3 revise(i,j) because Dj has lost some values seek support for each and every value in Di ac5 process(i,j,w) because Dj has lost the value w (very specific) seek support, possibly, for select few (1?) value in Di Therefore, by having a queue of (i,j,w) we might be able to do things much more efficiently

ac5, the intuition take an OOP approach constraint is a class that can then be specialised have a method to revise a constraint object allow specialisation have basic methods such as revise when lwb increases revise when upb decreases revise when a value is lost revise when variable instantiated revise initially methods take as arguments the variable in the constraint that has changed possibly, what values have been lost Example: IntDomainVar x = pb.makeBoundIntVar(“x”,1,10); IntDomainVar y = pb.makeBoundIntVar(“y”,1,10); Constraint c = pb.lt(x,y);

[ac5() : boolean -> let Q := {} in for (i,j)  {(i,j) | C ij in C} do let delta := arcCons(i,j) in d[i] := d[i] \ delta Q := enqueue(i,delta,Q) while Q ≠ {} do let (i,j,w) := dequeue(Q) delta := localArcCons(i,j,w) in Q := enqueue(i,delta,Q) d[i] := d[i] \ delta return allDomainsNonEmpty(d)] ac5, a sketch ac5 has 2 phases Phase 1, lines to - revise all the constraints - build up the Q of tuples (i,j,w) Phase 2, lines to -process the queue - propagate effect of deleted values - exploit knowledge of semantics of constraints - add new deletion tuples to Q

ac5, the algorithm This is just like revise, but delivers the set s of unsupported values in d[i] over the constraint C ij s is the set of disallowed values in d[i] remember check(i,x,j,y) is shorthand for C ij (x,y) [arcCons(i,j) : set -> let s := {} in for x  d[i] do let supported := false in for y  d[j] while ¬supported do supported := check(i,x,j,y) if ¬supported then s := s  {x} return s] Can be specialised!

ac5, the algorithm [localArcCons(i,j,w) : set -> arcCons(i,j)] Ignores the value w and becomes revise! We can specialise this method if we know something about the semantics of C ij We might then do much better that arcCons in terms of complexity What we have above is the dummy’s version, or when we know nothing about the constraint (and we get AC3!) Revise the constraint C ij because d[j] lost the value w

[enqueue(i,delta,q) : set -> for (k,i)  {(k,i) | C ki in C} do for w  delta do q := q  {(k,i,w} return q] ac5, the algorithm The domain d[i] has lost values delta Add to the queue of “things to do” the tuple (k,i,w) - For all w is in delta - For all C ki in C

[ac5() : boolean -> let Q := {} in for (i,j)  {(i,j) | C ij in C} phase 1 do let delta := arcCons(i,j) in d[i] := d[i] \ delta Q := enqueue(i,delta,Q) while Q ≠ {} phase 2 do let (i,j,w) := dequeue(Q) delta := localArcCons(i,j,w) in Q := enqueue(i,delta,Q) d[i] := d[i] \ delta return allDomainsNonEmpty(d)] ac5, the algorithm ac5 has 2 phases - revise all the constraints and build up the Q using arcCons - process the queue and propagate using localArcCons, exploiting knowledge on deleted values and the semantics of constraints

Complexity of ac5 If arcCons is O(d 2 ) and localArcCons is O(d) then ac5 is O(e.d 2 ) If arcCons is O(d) and localArcCons is O(  ) then ac5 is O(e.d) See AIJ 57 (2-3) page 299 Remember - ac3 is O(e.d 3 ) - ac4 is O(e.d 2 )

Functional constraints

If c is functional We can specialise arcCons and localArcCons for functional constraints A constraint C_i,j is functional, with respect to a domain D, if and only if for all x in D[i] there exists at most one value y in D[j] such that C ij (x,y) holds and for all y in D[j] there exists at most one value in D[i] such that C ji (y,x) holds The relation is a bijection An example: 3.x = y

If c is functional Let f(x) = y and f’(y) = x (f’ is the inverse of f) [arcCons(i,j) : set -> let s := {} f := C ij in for x  d[i] do if f(x)  d[j] then s := s  {x} return s]

If c is functional Let inverse(f) deliver the f’, the inverse of function f [localArcCons(i,j,w) : set -> let f := C ij g := C ji in if g(w)  d[i]) then return {g(w)} else return {}] In our picture, assume d[j] looses the value 2 g(2) = 3 localArcCons(i,j,2) = {3}

Anti-functional constraints

If c is anti-functional The value w in d[j] conflicts with only one value in d[i] an example: x + 4 ≠ y [localArcCons(i,j,w) : set -> let f := C ij g := C ji in if card(d[i]) = 1 & {g(w)} = d[i] then return d[i] else return {}] If d[i] has more than one value, no problem!

Other kinds of constraints that can be specialised monotonic     localArcCons tops and tails domains but domains must be ordered piecewise functional piecewise anti-functional piecewise monotonic See: AIJ 57 & AR33 section 7

The AIJ57 paper by van Hentenryck, Deville, and Teng is a remarkable paper they tell us how to build a constraint programming language they tell us all the data structures we need for representing variables, their domains, etc they introduce efficient algorithms for arc-consistency they show us how to recognise special constraints and how we should process them they show us how to incorporate ac5 into the search process they explain all of this in easy to understand, well written English It is a classic paper, in my book! AIJ57

A choco example NOTE: old version of choco

x[0] = max(x[1],x[2],…,x[n-1])

The lower bound of vars[idx] has increased vars[0] cannot take a value less than that Therefore vars[0].setInf(vars[idx].getInf())

x[0] = max(x[1],x[2],…,x[n-1]) The upper bound of vars[idx] has decreased

x[0] = max(x[1],x[2],…,x[n-1]) idx > 0 Find the largest upper bound of variables vars[1] to vars[n-1]

x[0] = max(x[1],x[2],…,x[n-1]) idx > 0 Find the largest upper bound of variables vars[1] to vars[n-1] Reduce the upper bound of vars[idx] to be the largest upper bound

x[0] = max(x[1],x[2],…,x[n-1]) idx = 0 and upper bound of vars[idx] has decreased

x[0] = max(x[1],x[2],…,x[n-1]) No variable vars[1] to vars[n-1] can take a value greater than upper bound of vars[0]

x[0] = max(x[1],x[2],…,x[n-1]) On first posting the constraint, at top of search

x[0] = max(x[1],x[2],…,x[n-1]) Variable vars[idx] is instantiated

Challenge/Homework Using only toolkit constraints such as leq, geq, … model x = max(y,z) where x, y, and z are constrained integer variables

AC2001 Taken from IJCAI01 “Making AC-3 an Optimal Algorithm” by Y Zhang and R. Yap and “Refining the basic constraint propagation algorithm” by Christian Bessiere & Jean-Charles Regin

The complexity of ac3A beautiful proof A constraint C ij is revised iff it enters the Q C ij enters Q iff some value in d[j] is deleted C ij can enter Q at most d times (the size of domain d[j])  A constraint can be revised at most d times There are e constraints in C (the set of constraints)  revise is executed at most e.d times the complexity of revise is O(d 2 )  the complexity of ac3 is then O(e.d 3 )

[revise(d:array,c:tuple,i:integer,j:integer) : boolean ->let revised := false in (for x in copy(d[i]) (let supported := false in (for y in d[j] // this is naive (if check(c,x,y) (supported := true, return())), if not(supported) (delete(d[i],x), revised := true))), CONSISTENT := d[i] != {}, revised)] When searching for a support for x in d[j] we always start from scratch This is naïve.

Assume domains are totally ordered Let resumePoint[i,j,x] = y where y is the first value in d[j] that supports x in d[i] i.e. C_i,j is satisfied by the pair (x,y) Assume succ(y,d) delivers the successor of y in domain d (and nil if no successor exists) When we revise constraint C_i,j, we look for support for x in d[j] get the resumePoint for x in domain d[j] over the constraint call this value y if y is in d[j] then x is supported! Do nothing! If y is not in d[j] then we search through the remainder of d[j] looking for support we use a successor function to get next y in d[j] if we find a y that satisfies the constraint set resumePoint[i,j,x] = y

[succ(x:integer,l:list) : integer -> if (l = nil) -1 else if (l[1] > x) l[1] else succ(x,cdr(l))] // // find the successor of x in ordered list l // NOTE: in the ac2001 algorithms we assume // we can do this in O(1) //

[existsY(d:array,c:tuple,i:integer,j:integer,x:integer) : boolean -> let y := RP[i][j][x] in (if (y % d[j]) true else let supported := false in (y := succ(y,list!(d[j])), while (y > 0 & not(supported)) (if check(c,x,y) (RP[i][j][x] := y, supported := true) else y := succ(y,list!(d[j]))), supported))] // // find the first value y in d[j] that supports x in d[i] // if found return true otherwise false //

[revise(d:array,c:tuple,i:integer,j:integer) : boolean -> let revised := false in (for x in copy(d[i]) (if not(existsY(d,c,i,j,x)) (delete(d[i],x), revised := true)), revised)]

In the two papers, the algorithm is shown to be optimal, for arbitrary binary csp’s

arc-consistency is at the heart of constraint programming it is the inferencing step used inside search it has to be efficient data structures and algorithms are crucial to success ac is established possibly millions of times when solving it has to be efficient we have had an optimal algorithm many times ac4, ac6, ac7, ac2001 ease of implementation is an issue we like simple things but we might still resort to empirical study!

MAC What’s that then

Maintain arc-consistency Instantiate a variable v[i] := x impose unary constraint d[i] = {x} make future problem ac if domain wipe out backtrack and impose constraint d[i]  x make future ac and so on pb.solve(false)

Maintain arc-consistency why use instantiation? Domain splitting? resolve disjunctions first for example (V1 < V2 OR V2 < V1)

You now know enough to go out and build a reasonably efficient and useful CP toolkit

Now its time to start using a CP toolkit