Non-Binary Constraint Satisfaction Toby Walsh Cork Constraint Computation Center.

Slides:



Advertisements
Similar presentations
Constraint Satisfaction Problems
Advertisements

Artificial Intelligence 15. Constraint Satisfaction Problems
DCS Lecture how to solve it Patrick Prosser. Put a different number in each circle (1 to 8) such that adjacent circles cannot take consecutive numbers.
Levels of Consistency Node Consistency (NC) Arc-consistency (AC) Path Consistency (PC) Generalised arc-consistency (GAC) Bounds consistency Inverse Path.
Constraints and Search Toby Walsh Cork Constraint Computation Centre (4C) Logic & AR Summer School, 2002.
Non-binary Constraints Toby Walsh
Constraint Programming Peter van Beek University of Waterloo.
Constraint-based problem solving n Model problem ä specify in terms of constraints on acceptable solutions ä define variables (denotations) and domains.
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
University of Toronto Mechanical & Industrial Engineering An Introduction to Constraint Programming J. Christopher Beck Dept. of Mechanical & Industrial.
Modelling & Solving with Constraints Prof. Toby Walsh University College Cork/Uppsala University.
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Global Constraints Toby Walsh NICTA and University of New South Wales
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
Constraint Programming Toby Walsh UNSW and NICTA.
Constraint Satisfaction Problems
Constraint Satisfaction Problems
Distributed Constraint Satisfaction Problems M OHSEN A FSHARCHI.
Global Constraints Toby Walsh National ICT Australia and University of New South Wales
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)
1 CMSC 471 Fall 2002 Class #6 – Wednesday, September 18.
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.
Constraint Satisfaction problems (CSP)
Non-binary constraints: modelling Toby Walsh Cork Constraint Computation Center.
Non-binary constraints Toby Walsh Dept of CS University of York England.
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
CP Summer School Modelling for Constraint Programming Barbara Smith 1.Definitions, Viewpoints, Constraints 2.Implied Constraints, Optimization,
Relaxation and Hybrid constraint processing Different relaxation techniques Some popular hybrid techniques.
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
Constrainedness Including slides from Toby Walsh.
CONSTRAINT PROGRAMMING Computer Science Seminar April 9 th, 2004 Kerem Kacel.
Constraint Satisfaction Problems (CSPs) CPSC 322 – CSP 1 Poole & Mackworth textbook: Sections § Lecturer: Alan Mackworth September 28, 2012.
Modelling for Constraint Programming Barbara Smith CP 2010 Doctoral Programme.
On Algorithms for Decomposable Constraints Kostas Stergiou Ian Gent, Patrick Prosser, Toby Walsh A.P.E.S. Research Group.
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.
Artificial Intelligence CS482, CS682, MW 1 – 2:15, SEM 201, MS 227 Prerequisites: 302, 365 Instructor: Sushil Louis,
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.
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.
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:
Put a different number in each circle (1 to 8) such that adjacent circles cannot take consecutive numbers.
Eliminating non- binary constraints Toby Walsh Cork Constraint Computation Center.
Chapter 5 Team Teaching AI (created by Dewi Liliana) PTIIK Constraint Satisfaction Problems.
1 Constraint Satisfaction Problems (CSP). Announcements Second Test Wednesday, April 27.
ARTIFICIAL INTELLIGENCE (CS 461D) Dr. Abeer Mahmoud Computer science Department Princess Nora University Faculty of Computer & Information Systems.
Automatic Test Generation
Constraint Satisfaction Problems (CSPs) Introduction
Constraint Programming
Computer Science cpsc322, Lecture 13
Constraint Satisfaction
Constraint Satisfaction Problems (CSPs) Introduction
Lecture 7 Constraint Satisfaction Problems
Empirical Comparison of Preprocessing and Lookahead Techniques for Binary Constraint Satisfaction Problems Zheying Jane Yang & Berthe Y. Choueiry Constraint.
Computer Science cpsc322, Lecture 13
Constraints and Search
CSP Search Techniques Backtracking Forward checking
Constraints and Search
Presentation transcript:

Non-Binary Constraint Satisfaction Toby Walsh Cork Constraint Computation Center

Overview Introduction to CSPs –Local Consistencies, search algorithms Modelling (4 case studies) –Auxiliary variables, implied constraints –Redundant models and channelling constraints Eliminating non-binary constraints –Encodings, decomposition Theoretical properties –Tightness, relational consistencies

Resources Course links – Benchmark problems – Constraints solvers –LP based like ECLIPSE, Java based liked Jsolver, open source like Choco, …

Constraint programming Ongoing dream of declarative programming –State the constraints –Solver finds a solution Paradigm of choice for many hard combinatorial problems –Scheduling, assignment, routing, …

Constraints are everywhere! No meetings before 10am Network traffic < 100 Gbytes/sec PCB width < 21cm Salary > 45k Euros …

Constraint satisfaction Constraint satisfaction problem (CSP) is a triple 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

Example CSP Course timetabling –Variable for each course X1, X2.. –Domain are possible times for course Wed9am, Fri10am,.. –Constraints: X1 \= Wed9am Capacity constraints: atmost(3,[X1,X2..],Wed9am) Lecturer constraints: alldifferent([X1,X5,…])

Constraint optimization CSP + objective function –E.g. objective is Profit = Income - Costs Find assignment of vals to vars that: –Satisfies constraints –Maximizes (minimizes) objective Often solved as sequence of satisfaction problems Profit > 0, Profit > Ans1, Profit > Ans2, …

Constraint programming v. Constraint logic programming Constraints declaratively specify problem –Logic programming natural approach Assert constraints, call labelling strategy (backtracking search predicate) But can also define constraint satisfaction or optimization within an imperative of functional language Popular toolkits in C++, Java, CAML, …

Constraints Constraints are tuples where –S is the scope, [X1,X2, … Xm] list of variables to which constraint applies –R is relation specifying allowed values (goods) Subset of D_X1 x D_X2 x … x D_Xm May be specified intensionally or extensionally

Constraints Extensional specification –List of goods (or for tight constraints, nogoods) Intensional specification –X1 =/= X2 –5*X1 + 6*X2 < X3 –alldifferent([X1,X2,X3,X4]), …

Constraint tightness Informally, tight constraints admit few tuples –E.g. on 0/1 vars X1 =/= X2 is loose as half tuples satisfy X1+X2+X3+X4+X5 <= 1 is tight as only 5 out of 32 tuples satisfy More formal definition later

Binary v non-binary Binary constraint –Scope covers 2 variables –E.g. not-equals constraint: X1 =/= X2. –E.g. ordering constraint: X1 < X2 Non-binary constraint –Scope covers 3 or more variables –E.g. alldifferent(X1,X2,X3). –E.g. tour(X1,X2,X3,X4). Non-binary constraints usually do not include unary constraints!

Constraint graph Nodes = variables Edge between 2 nodes iff constraint between 2 associated variables –Few constraints, sparse constraint graph –Lots of constraints, dense constraint graph

Some non-binary examples Timetabling –Variables: Lecture1, Lecture2, … –Values: time1, time2, … –Constraint that lectures taught by same lecturer do not conflict: alldifferent(Lecture1,Lecture5,…).

Some non-binary examples Scheduling –Variables: Job1. Job2, … –Values: machine1, machine2, … –Constraint on number of jobs on each machine: atmost(2,[Job1,Job2,…],machine1), atmost(1,[Job1,Job2,…],machine2).

Why use non-binary constraints? Binary constraints are NP-complete –Any non-binary constraint can be represented using binary constraints –E.g. alldifferent(X1,X2,X3) is equivalent to X1 =/= X2, X1 =/= X3, X2 =/= X3 In theory therefore theyre not needed –But in practice, they are!

Modelling with non-binary constraints Benefits include: –Compact, declarative specifications (discussed next) –Efficient constraint propagation (discussed second)

Modelling with non-binary constraints Consider writing your own alldifferent constraint: alldifferent([]). alldifferent([Head|Tail]):- onediff(Head,Tail), alldifferent(Tail). onediff(El,[]). onediff(El,[Head|Tail]):- El #\= Head, onediff(El,Tail).

Modelling with non-binary constraints Its possible but its not very pleasant! Nor is it very compact –alldifferent([X1,…Xn]) expands into n(n-1)/2 binary not-equals constraints, Xi \= Xj –one non-binary constraint or O(n^2) binary constraints? And there exist very efficient algorithms for reasoning efficiently with many specialized non-binary constraints

Constraint solvers Two main approaches –Systematic, tree search algorithms –Local search or repair based procedures Other more exotic possibilities –Hybrid algorithms –Quantum algorithms

Systematic solvers Tree search –Assign value to variable –Deduce values that must be removed from future/unassigned variables Propagation to ensure some level of consistency –If 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, …

Local search Repair based methods –Generate complete assignment –Change value to some variable in a violated constraint Number of choices –Violated constraint, variable within it, … Unable to exploit powerful constraint propagation techniques

Constraint propagation 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 –A problem is AC iff every constraint is AC

Enforcing arc-consistency Remove all values that are not AC (i.e. have no support) May remove support from other values (often queue based algorithm) Best AC algorithms (AC7, AC-2000) run in O(ed^2) –Optimal if we know nothing else about the constraints

Enforcing arc-consistency X2 \= X3 is AC X1 \= X2 is not AC –X2=1 has no support so can this value can be pruned X2 \= X3 is now not AC –No support for X3=2 –This value can also be pruned Problem is now AC {1} {1,2}{2,3} \= X1 X3X2

Properties of AC Unique maximal AC subproblem –Or problem is unsatisfiable Enforcing AC can process constraints in any order –But order does affect (average-case) efficiency

Non-binary constraint propagation Most popular is generalized arc-consistency (GAC) –A non-binary constraint is GAC iff for every value for a variable there are consistent values for all other variables in the constraint –We can again prune values that are not supported GAC = AC on binary constraints

GAC on alldifferent alldifferent(X1,X2,X3) –Constraint is not GAC –X1=2 cannot be extended X2 would have to be 3 No value left then for X3 –X1={1} is GAC {1,2} {2,3} X1 X2 X3

Enforcing GAC Enforcing GAC is expensive in general –GAC schema is O(d^k) On k-ary constraint on vars with domains of size d Trick is to exploit semantics of constraints –Regins all-different algorithm –Achieves GAC in just O(k^2 d^2) On k-ary all different constraint with domains of size d Based on finding matching in value graph

Other types of constraint propagation (i,j)-consistency [due to Freuder, JACM 85] –Non-empty domains –Any consistent instantiation for i variables can be extended to j others Describes many different consistency techniques

(i,j)-consistency Generalization of arc-consistency –AC = (1,1)-consistency –Path-consistency = (2,1)-consistency Strong path-consistency = AC + PC –Path inverse consistency = (1,2)-consistency

Enforcing (i,j)-consistency problem is (1,1)-consistent (AC) BUT is not (2,1)-consistent (PC) –X1=2, X2=3 cannot be extended to X3 –Need to add constraints: not(X1=2 & X2=3) not(X1=2 & X3=3) Nor is it (1,2)-consistent (PIC) –X1=2 cannot be extended to X2 & X3 (so needs to be deleted) {1,2} {2,3} \= X1 X3X2 \=

Other types of constraint propagation Singleton arc-consistency (SAC) –Problem resulting from instantiating any variable can be made AC Restricted path-consistency (RPC) –AC + if a value has just one support then any third variable has a consistent value

Other types of consistency problem is (1,1)-consistent (AC) BUT is not singleton AC (SAC) –Problem with X1=2 cannot be made AC (so value should be deleted) Nor is it restricted PC (RPC) –X1=2 has only one support in X2 (the value 3) but X3 then has no consistent values –X1=2 can therefore be deleted {1,2} {2,3} \= X1 X3X2 \=

Other types of constraint propagation Neighbourhood inverse consistency (NIC) –For all vals for a var, there are consistent vals for all vars in the immediate neighbourhood Bounds consistency (BC) –With ordered domains –Enforce AC just on max/min elements

Comparing local consistencies Formal definition of tightness introduced by Debruyne & Bessiere [IJCAI-97] A-consistency is tighter than B-consistency iff If a problem is A-consistent -> it is B-consistent We write A >= B

Properties Partial ordering –reflexive A A –transitive A B & B C implies A C Defined relations –tighter A > B iff A B & not B A –incomparable B iff neither A B nor B A

Comparison of consistency techniques Exercise for the reader, prove the following identities! Strong PC > SAC > PIC > RPC > AC > BC NIC > PIC SAC Strong PC NB gaps can reduce search exponentially!

Which to choose? For binary constraints, AC is often chosen –Space efficient Just prune domains (cf PC) –Time efficient For non-binary constraints GAC is often chosen –If we can exploit the constraint semantics to keep it cheap!

Why consider these other consistencies? Promising experimental results –Useful pruning for their additional cost Theoretical value –E.g. GAC on non-binary constraints may exceed SAC on equivalent binary model

Maintaining a local consistency property Tree search –Assign value to variable –Enforce some level of local consistency Remove values/add new constraints –If any future variable has no values, backtrack else repeat Two popular algorithms –Maintaining arc-consistency (MAC) –Forward checking (very restricted form of AC maintained)

Forward checking Binary constraints (FC) –Make constraints involving current variable and one future variable arc-consistent –No need to look at any other constraints! Non-binary constraints –Several choices as to how to do forward checking

Forward checking with non-binary constraints nFC0 makes AC only those k-ary constraints with k-1 variables set nFC1 applies one pass of AC on constraints and projections involving current var and one future var nFC2 applies one pass of GAC on constraints involving current var and at least one future var nFC3 enforces GAC on this set nFC4 applies one pass of GAC on constraints involving at least one past and one future var nFC5 enforces GAC on this set

Summary Constraint solving –Constraint propagation central part of many algorithms Binary v non-binary constraints –Compact, more efficient representation