constraint programming
play

Constraint Programming Marco Kuhlmann & Guido Tack Lecture 1 - PowerPoint PPT Presentation

Constraint Programming Marco Kuhlmann & Guido Tack Lecture 1 Welcome! Where am I? Constraint Programming advanced course 6 credit points lecture (2 hours) + lab (2 hours) WWW: http://www.ps.uni-sb.de/ This lecture


  1. Constraint Programming Marco Kuhlmann & Guido Tack Lecture 1

  2. Welcome!

  3. Where am I? • Constraint Programming • advanced course • 6 credit points • lecture (2 hours) + lab (2 hours) • WWW: http://www.ps.uni-sb.de/

  4. This lecture • constraint programming • what it is – fundamental concepts • why it matters – applications • how it works – showcase examples • organisation

  5. Constraint Programming

  6. S E N D + M O R E M O N E Y Send More Money

  7. Generate & Test • generate all possible combinations of all possible values for all letters in the puzzle • test for each potential solution, whether it satisfies the equation

  8. Ridiculous!

  9. Specialised algorithms • advantages • may be highly efficient • offer deep insights into the problem • disadvantages • may take years to develop • cannot be easily adapted

  10. Enter Constraint Programming

  11. Constraint programming is a problem-solving technique for combinatorial problems that works by incorporating constraints into a programming environment. (after Apt 2003)

  12. Combinatorial problems • combinatorial structures characterised in terms of a finite set of variables and a finite value for each variable • combinatorial problem subsets question about properties of a class of combinatorial structures

  13. Example • combinatorial structures: permutations of the primes between 1 and 10 • combinatorial problems: How many such structures are there … without any additional properties? … where seq[0] > seq[1]? … where seq[0] + seq[1] = seq[2]?

  14. seq[0] > seq[1] seq[0] + seq[1] = seq[2] Subsets & constraints

  15. Combinatorial problems • combinatorial structures characterised in terms of a finite set of variables and a finite value for each variable • combinatorial problem constraints subsets question about properties of a class of combinatorial structures

  16. Constraint Satisfaction Problems (CSPs) simple formal model for combinatorial problems

  17. CSPs: Ingredients • finite set of problem variables , x • associated domains dom(x) • finite set of constraints intensional or extensional

  18. CSPs: Terminology • variable assignment: total function that maps each x to an element in dom(x) • solution to a CSP: variable assignment such that all constraints are satisfied

  19. How to integrate constraints into a programming environment?

  20. Meet Alice • Alice is a better Standard ML: it supports concurrent and distributed programming. • Alice features the GeCoDE library, the bleeding edge of research in constraint systems. • WWW: http://www.ps.uni-sb.de/alice/

  21. fun example1 space = let val dom = domain [2, 3, 5, 7] val sequence = fdtermVec (space, 4, dom) val seq0 = Vector.sub (sequence, 0) val seq1 = Vector.sub (sequence, 1) val seq2 = Vector.sub (sequence, 2) in distinct (space, sequence); (* seq[0] > seq[1] *) post (space, seq0 `> seq1); (* seq[0] + seq[1] = seq[2] *) post (space, seq0 `+ seq1 `= seq2); branch (space, sequence) end Constraints in Alice

  22. Constraint Propagation

  23. � � � � Example problem variables: finite sets x, y of integers x = 4, y = 4 domains: dom(x) = {3,4,5}, x = 5, y = 4 dom(y) = {3,4,5} x = 5, y = 5 constraints: x ≥ y, y > 3

  24. distinguish two sorts of constraints: basic constraints and non-basic constraints

  25. basic constraints x � {3,4,5} y � {3,4,5} Constraint Store

  26. Propagators • implement non-basic constraints • translate into basic constraints • subscribe to variables in the store • get notified about changes

  27. amplify store gets notified x � y y > 3 x � {3,4,5} x � {4,5} y � {3,4,5} y � {4,5} Propagators

  28. constraint store with connected propagators x � y y > 3 x � {3,4,5} y � {3,4,5} Computation Space

  29. Important concepts • constraint store stores basic constraints • propagator implements non-basic constraint • computation space constraint store + propagators

  30. Branching

  31. x � y propagation is not enough! x � {4,5} y � {4,5} Bad news

  32. Stable spaces • solution for each x, dom(x) is a singleton • failure there is an x with dom(x) empty • choice

  33. stable space x � y domain split x � {4,5} y � {4,5} x � {4} x � {4} x � y x � y x � {4} y � {4,5} y � {4} x � {5} y � {4,5} Branching

  34. choice solution Search tree

  35. Branching heuristics • naive heuristic • pick some x with dom(x) > 1 • pick value k from dom(x) • branch with x ∈ {n} and x ∉ {n} • first-fail heuristic: pick x with dom(x) minimal

  36. Branching strategy • variable selection • any variable • minimal/maximal current domain • value selection (for the left branch) • maximal/minimal/medial element • lower half/upper half of the domain

  37. Homework Show that the branching strategy can have a massive impact on the size of the search tree.

  38. Search

  39. Search • propagation and branching induce a search tree • orthogonal issue: in what order are the nodes of that tree constructed? • different problems require different search strategies

  40. Static search strategies • explore the search tree • standard search strategies • depth-first search • iterative deepening • A* search

  41. Dynamic search best solution search • add new constraints during search • dynamic search strategies • iterative best-solution search • branch-and-bound search

  42. Best Solution Search • class of combinatorial structures σ • objective function obj : σ → N • find a structure s such that obj(s) is optimal among all structures σ

  43. Best Solution Search • naive approach: compute all solutions & choose best prunes the • branch-and-bound approach: search tree compute first solution, s add ‘better-than-s’ constraint compute next solution, and iterate

  44. S E N D MONEY should be + M O S T maximal M O N E Y Send Most Money

  45. unexplored subtree add betterness first solution add betterness constraint constraint best solution SMM+ – B & B

  46. SMM+

  47. SMM+

  48. What this course will be about

  49. Architecture • propagation: prune impossible values • branching: divide the problem into smaller parts • search: interleave propagation and branching to find solutions

  50. What you will learn • how to model combinatorial problems • how to solve them using CP • how to write new propagators • how to program new search strategies • how to apply CP to practical problems

  51. Applications • timetabling • crew rostering • gate allocation at airports • sports league scheduling • natural language processing

  52. Scheduling resources • tasks duration, used resources • precedence constraints task a must precede task b • resource constraints at most one task per resource

  53. First assignment • install the tools: http://www.ps.uni-sb.de/alice/ • warm-up in programming Alice • model and solve some simple constraint satisfaction problems

  54. Constraint Programming • can be used to tackle hard combinatorial problems • combines various interesting methodologies and techniques • applications are ubiquitous knowledgeable people are not!

  55. Constraint Programming • compute with possible values lower bound, upper bound • prune inconsistent values guessing as last resort • factorise the problem inferences + heuristics + search

  56. What CP is not • no efficiency miracle • exponential problems remain exponential • If you have polynomial algorithms, use them, and forget about CP! • no replacement, but a complement to other programming paradigms

  57. What you should bring • broad interest in computer science • theory and formal models • practice and programming • self-initiative • try! explore! do! • ask questions, and answer them

  58. Caveat • CP is established … • international conferences • many results & applications • … our tools are not (yet) • some might not work (as expected) • some might be uncomfortable

  59. Organisation

  60. Literature • Krzysztof R. Apt: Principles of Constraint Programming Cambridge University Press, 2003 • Christian Schulte: Programming Constraint Services Springer-Verlag, 2002

  61. Lectures • 12 lectures in total • last lecture on July 14 • no lectures on • May 5 (Ascension) • May 26 (Corpus Christi)

  62. Labs • explorative labs • get familiar with the concepts • get familiar with the tools • graded labs • four medium-sized projects • determine 40% of your final grade

  63. Exam • at the end of the term • determines 60% of final grade • written or oral (to be determined) • re-exam will be oral

  64. Contact & Support • mailing list subscribe on web site • office hours Wednesdays, 14–15, room 45.517 • during & after the lectures

  65. Constraint Programming • problem-solving technique • interleaves inferences & heuristics • combines various methodologies • is fun!

  66. Thanks for your attention!

  67. Backup Slides

  68. Eight Queens

Recommend


More recommend