Constraint Satisfaction Patrick Prosser An Example Exam Timetabling
Constraint Satisfaction Patrick Prosser
An Example, Exam Timetabling • Someone timetables the exams • We have a number of courses to examine • how many? • Dept has 36 • Faculty? • University? • There are constraints • if a student S takes courses Cx and Cy • Cx and Cy cannot be at same time! • If Cy and Cz have no students in common • they can go in room R 1 if there is space • Temporal and resource constraints
An Example, Exam Timetabling • Represent as graph colouring • vertices are courses • colours are time • vertices have weight (room requirements) • edge connects vertices of diff colour • How complex is this • if we have n vertices and k times • an n-digit number to the base k? • How would you solve this • backtracking search? • Greedy? • Something else • GA? • SA, TS, GLS, HC, . . .
An Example, Exam Timetabling • How does the person solve this? • Is that person intelligent? • Is there always a solution? • If there isn’t, do we want to know why? • Do you think they can work out “why”?
A CSP • A csp has • n variables • each has a domain of (m) values • constraints define compatible tuples of values • n-ary, binary • find an assignment • of values to variables • that satisfies the constraints • or show none exists • O(mn)
An example 1 2 3 4 5 6 7 4 Make a crossword puzzle! Given the above grid and a dictionary, fill it. Then go get the clues (not my problem)
An example 1 2 3 4 5 6 7 1 A 4 D 2 D 4 A 4 1 A 1 across 4 D 4 down 2 D 2 down 4 A 4 across 7 D 7 down 7 D Variables
An example 1 2 3 4 5 6 7 1 A 4 D 2 D 4 A 4 1 A-4 D: 4 th of 1 A equals 1 st of 4 D 7 D 1 A-2 D: 2 nd of 1 A equals 1 st of 2 D 2 D-4 A: 4 th of 2 D equals 2 nd of 4 D 4 D-4 A: 4 th of 4 A equals 4 th of 4 D 4 A-7 D: 7 th of 4 A equals 2 nd of 7 D Constraints
An example 1 2 3 4 5 6 7 1 A 4 D 2 D 4 A 4 1 A: any 6 letter word 4 A: any 8 letter word 4 D: any 5 letter word 2 D: any 7 letter word 7 D: any 3 letter word 7 D Domains (also unary constraints!)
An example 1 2 3 4 5 6 7 1 A 4 D 2 D 4 A 4 Find an assignment of values to variables, from their domains, such that the constraints are satisfied (or show that no assignment exists) A CSP! 7 D
An example 1 2 3 4 5 6 7 1 A 4 D 2 D 4 A 4 Choose a variable Assign it a value 7 D Check compatibility If not compatible try a new value If no values remain re-assign previous variable Good old fashioned BT!
Questions? 1 2 3 4 5 6 7 1 A 4 D 2 D 4 A 4 What variable should I choose? What value should I choose? 7 D What reasoning can I do when making an assignment? What reasoning can I do on a dead end? Decisions, decisions!
Where’s the AI?
Scene Labelling David Waltz, MIT, 1975
In a trihedral world, these are the only scenarios
Label an edge as follows Walk along the edge in this direction and the object is on the right, and to your left is open space + This is an outside edge, with the object on both sides This is an inside edge
We now have the following cases + + + - - - - - + + -
The edges are the variables, labels their domains, meeting points are the constraints + + + - + - + + A consistent labelling is an interpretation
Another example: n-queens • Place n non-attacking queens on an n x n chess board • representations? That was BT There is a polynomial solution circa 1800
It’s all just depth first search, right?
BT Thrashes! past variable v[h] p a s t conflict with v[h] current variable v[i] future variable v[j] f u t u r e
Another example: n-queens • Forward Checking
Forward Checking 1 2 3 4 5 6 7 8 9 NOTE: arrows go forward!
• How to improve search • use a heuristic • variable and/or value ordering • dynamic or static • Fail First? • More inferencing at each search state • old trade off, knowledge versus search • maintain consistency
Consistency • arc consistency • what’s that then? • Propagate supports • deduce illegal values • polynomial at each search node • AC can be specialised for special constraints • MAC • the heart of constraint programming
Give us a demo?
Not just binary csp’s! • N-ary • but can be mapped to binary • why bother with n-ary? • all. Diff, sum, permutation, marriage • Not just arc consistency • path • inverse • restricted • singleton • When, what?
• Applications • scheduling • timetabeling • frequency allocation • transportation • design • layouts • packing • . . .
• Toolkits • ILOG • solver, scheduler, dispatcher • chip • choco • OZ • Eclipse • Jsolver • Screamer • CSPLab
• Research Direction • reactivity and explanation • retraction in particular • better heuristics • new search algorithms • complete, quasi-complete, local • new levels of consistency • new specialised constraints • effects of representation • understanding the problem • its structure and why it is hard
stop
- Slides: 31