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 • constraint programming • what it is – fundamental concepts • why it matters – applications • how it works – showcase examples • organisation
Constraint Programming
S E N D + M O R E M O N E Y Send More Money
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
Ridiculous!
Specialised algorithms • advantages • may be highly efficient • offer deep insights into the problem • disadvantages • may take years to develop • cannot be easily adapted
Enter Constraint Programming
Constraint programming is a problem-solving technique for combinatorial problems that works by incorporating constraints into a programming environment. (after Apt 2003)
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
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]?
seq[0] > seq[1] seq[0] + seq[1] = seq[2] Subsets & constraints
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
Constraint Satisfaction Problems (CSPs) simple formal model for combinatorial problems
CSPs: Ingredients • finite set of problem variables , x • associated domains dom(x) • finite set of constraints intensional or extensional
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
How to integrate constraints into a programming environment?
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/
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
Constraint Propagation
� � � � 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
distinguish two sorts of constraints: basic constraints and non-basic constraints
basic constraints x � {3,4,5} y � {3,4,5} Constraint Store
Propagators • implement non-basic constraints • translate into basic constraints • subscribe to variables in the store • get notified about changes
amplify store gets notified x � y y > 3 x � {3,4,5} x � {4,5} y � {3,4,5} y � {4,5} Propagators
constraint store with connected propagators x � y y > 3 x � {3,4,5} y � {3,4,5} Computation Space
Important concepts • constraint store stores basic constraints • propagator implements non-basic constraint • computation space constraint store + propagators
Branching
x � y propagation is not enough! x � {4,5} y � {4,5} Bad news
Stable spaces • solution for each x, dom(x) is a singleton • failure there is an x with dom(x) empty • choice
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
choice solution Search tree
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
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
Homework Show that the branching strategy can have a massive impact on the size of the search tree.
Search
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
Static search strategies • explore the search tree • standard search strategies • depth-first search • iterative deepening • A* search
Dynamic search best solution search • add new constraints during search • dynamic search strategies • iterative best-solution search • branch-and-bound search
Best Solution Search • class of combinatorial structures σ • objective function obj : σ → N • find a structure s such that obj(s) is optimal among all structures σ
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
S E N D MONEY should be + M O S T maximal M O N E Y Send Most Money
unexplored subtree add betterness first solution add betterness constraint constraint best solution SMM+ – B & B
SMM+
SMM+
What this course will be about
Architecture • propagation: prune impossible values • branching: divide the problem into smaller parts • search: interleave propagation and branching to find solutions
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
Applications • timetabling • crew rostering • gate allocation at airports • sports league scheduling • natural language processing
Scheduling resources • tasks duration, used resources • precedence constraints task a must precede task b • resource constraints at most one task per resource
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
Constraint Programming • can be used to tackle hard combinatorial problems • combines various interesting methodologies and techniques • applications are ubiquitous knowledgeable people are not!
Constraint Programming • compute with possible values lower bound, upper bound • prune inconsistent values guessing as last resort • factorise the problem inferences + heuristics + search
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
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
Caveat • CP is established … • international conferences • many results & applications • … our tools are not (yet) • some might not work (as expected) • some might be uncomfortable
Organisation
Literature • Krzysztof R. Apt: Principles of Constraint Programming Cambridge University Press, 2003 • Christian Schulte: Programming Constraint Services Springer-Verlag, 2002
Lectures • 12 lectures in total • last lecture on July 14 • no lectures on • May 5 (Ascension) • May 26 (Corpus Christi)
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
Exam • at the end of the term • determines 60% of final grade • written or oral (to be determined) • re-exam will be oral
Contact & Support • mailing list subscribe on web site • office hours Wednesdays, 14–15, room 45.517 • during & after the lectures
Constraint Programming • problem-solving technique • interleaves inferences & heuristics • combines various methodologies • is fun!
Thanks for your attention!
Backup Slides
Eight Queens
Recommend
More recommend