1 / 205

Introduction to Constraint Programming

Introduction to Constraint Programming. Peter van Beek University of Waterloo. Patrick Prosser Christian Schulte. Michael Chase Abid Malik Tyrel Russell. Acknowledgements. Outline. Introduction Constraint propagation Backtracking search Global constraints Symmetry Modeling.

pamelap
Télécharger la présentation

Introduction to Constraint Programming

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Introduction to Constraint Programming • Peter van Beek • University of Waterloo

  2. Patrick Prosser Christian Schulte Michael Chase Abid Malik Tyrel Russell Acknowledgements

  3. Outline • Introduction • Constraint propagation • Backtracking search • Global constraints • Symmetry • Modeling

  4. Some additional resources “Handbook of Constraint Programming,” edited by F. Rossi, P. van Beek, T. Walsh “Constraint-Based Local Search”, by Pascal Van Hentenryck and Laurent Michel Integrated Methods for Optimization, by John N. Hooker “Programming with Constraints,” by Kim Marriott, Peter J. Stuckey “Principles of Constraint Programming,” by Krzysztof Apt “Constraint Processing,” by Rina Dechter

  5. Outline • Introduction • Constraint propagation • Backtracking search • Global constraints • Symmetry • Modeling

  6. What is constraint programming? • Idea: Solve a problem by stating constraints on acceptable solutions • Advantages: • constraints often a natural part of problems • especially true of difficult combinatorial problems • once problem is modeled using constraints, wide selection of solution techniques available • Constraint programming is an active area of research • draws on techniques from artificial intelligence, algorithms, databases, programming languages, and operations research

  7. What is constraint programming? • Constraint programming is similar to mathematical programming • declarative • user states the constraints • general purpose constraint solver, often based on backtracking search, is used to solve the constraints • Constraint programming is similar to computer programming • extensible • user-defined constraints • allows user to program a strategy to search for a solution

  8. What is constraint programming? • Constraint programming is a problem-solving methodology • Model problem • Solve model • specify in terms of constraints on acceptable solutions • define/choose constraint model: • variables, domains, constraints • define/choose search algorithm • define/choose heuristics

  9. What is constraint programming? • Constraint programming is a collection of core techniques • Modeling • deciding on variables/domains/constraints • improving the efficiency of a model • Solving • local consistency • constraint propagation • global constraints • search • backtracking search • hybrid methods

  10. ? ? ? ? ? ? ? ? Place numbers 1 through 8 on nodes, where each number appears exactly once and no connected nodes have consecutive numbers Acknowledgement: Patrick Prosser

  11. ? ? ? ? ? ? ? ? Backtracking search Guess a value, but be prepared to backtrack Which nodes are hardest to number?

  12. ? ? ? ? ? ? ? ? Backtracking search Which nodes are hardest to number?

  13. ? ? ? ? ? ? ? ? Backtracking search Which are the least constraining values to use? Values 1 & 8

  14. ? ? ? 1 8 ? ? ? Backtracking search Symmetry means we don’t need to consider: 8 1

  15. ? ? ? 1 8 ? ? ? Inference/propagation {1,2,3,4,5,6,7,8} We can now eliminate many values for other nodes

  16. ? ? ? 1 8 ? ? ? Inference/propagation {3,4,5,6} {3,4,5,6} By symmetry

  17. ? ? ? 1 8 ? ? ? Inference/propagation {3,4,5,6} {1,2,3,4,5,6,7,8} {3,4,5,6}

  18. ? ? ? 1 8 ? ? ? Inference/propagation {3,4,5,6} {3,4,5,6} {3,4,5,6} {3,4,5,6} By symmetry

  19. ? ? ? 1 8 ? ? ? Inference/propagation {3,4,5,6} {3,4,5,6} {3,4,5,6,7} {2,3,4,5,6} {3,4,5,6} {3,4,5,6}

  20. ? ? 7 1 8 2 ? ? Inference/propagation {3,4,5,6} {3,4,5,6} {3,4,5,6} {3,4,5,6}

  21. ? ? 7 1 8 2 ? ? Inference/propagation {3,4,5,6} {3,4,5,6} {3,4,5,6} {3,4,5,6} And propagate

  22. ? ? 7 1 8 2 ? ? Inference/propagation {3,4,5} {4,5,6} {3,4,5} {4,5,6} Guess a value, but be prepared to backtrack

  23. 3 ? 7 1 8 2 ? ? Inference/propagation {4,5,6} {3,4,5} {4,5,6} Guess a value, but be prepared to backtrack

  24. 3 ? 7 1 8 2 ? ? Inference/propagation {4,5,6} {3,4,5} {4,5,6} And propagate

  25. 3 ? 7 1 8 2 ? ? Inference/propagation {5,6} {4,5} {4,5,6} More propagation?

  26. 3 5 7 1 8 2 4 6 Inference/propagation A solution

  27. Constraint programming methodology • Model problem • Solve model • specify in terms of constraints on acceptable solutions • define/choose constraint model: • variables, domains, constraints • define/choose search algorithm • define/choose heuristics Constraint Satisfaction Problem

  28. Constraint satisfaction problem (CSP) • A CSP is defined by: • a set of variables {x1, …, xn} • a set of values for each variable dom(x1), …, dom(xn) • a set of constraints {C1, …, Cm} • A solution to a CSP is a complete assignment to all the variables that satisfies the constraints

  29. Given a CSP • Determine whether it has a solution or not • Find one solution • Find all solutions • Find an optimal solution, given some cost function

  30. Example domains and constraints • Reals, linear constraints • 3x + 4y ≤ 7, 5x – 3y + z = 2 • Guassian elimination, linear programming • Integers, linear constraints • integer linear programming, branch-and-bound • Boolean values, clauses • Here: • finite domains • rich constraint languages • user-defined constraints • global constraints

  31. Constraint languages • Usual arithmetic operators: • =, , , < , > ,  , + , , *, /, absolute value, exponentiation • e.g., 3x + 4y  7, 5x3 – x*y = 9 • Usual logical operators: • , , ,  (or “if … then”) • e.g., if x = 1 then y = 2, x  y  z,(3x + 4y  7)  (x*y = z) • Global constraints: • alldifferent(x1, …, xn)  pairwise different • cardinality(x1, …, xn, l, u)  each value must be assigned to at least l variables and at most u variables • Table constraints

  32. ? ? ? ? ? ? ? ? Constraint model for puzzle variables v1, …, v8 domains {1, …, 8} constraints | v1 – v2 |  1 | v1 – v3 |  1 … | v7 – v8 |  1 alldifferent(v1, …, v8)

  33. Example: Instruction scheduling Given a basic-block of code and a multiple-issue pipelined processor, find the minimum length schedule (a + b) + c

  34. dependency DAG 3 3 A B 3 D C 1 E Example: evaluate (a + b) + c instructions A r1  a B r2  b C r3  c D r1  r1 + r2 E r1  r1 + r3

  35. dependency DAG 3 3 A B 3 D C 1 E Example: evaluate (a + b) + c non-optimal schedule A r1  a B r2  b nop nop D r1  r1 + r2 C r3  c nop nop E r1  r1 + r3

  36. dependency DAG 3 3 A B 3 D C 1 E Example: evaluate (a + b) + c optimal schedule A r1  a B r2  b C r3  c nop D r1  r1 + r2 E r1  r1 + r3

  37. dependency DAG 3 3 A B 3 D C 1 E Constraint model variables A, B, C, D, E domains {1, …, m} constraints D  A + 3 D  B + 3 E  C + 3 E  D + 1 cardinality(A, B, C, D, E, 0, width)

  38. Example: Boolean satisfiability (x1  x2  x4)  (x2  x4  x5)  (x3  x4  x5) Given a Boolean formula, does there exist a satisfying assignment

  39. Constraint model variables: x1, x2 , x3 , x4 , x5 domains: {true, false} constraints: (x1  x2  x4) (x2  x4  x5) (x3  x4  x5) (x1  x2  x4)  (x2  x4  x5)  (x3  x4  x5)

  40. Example: 3-SAT A solution x1 = false x2 = false x3 = false x4 = true x5 = false (x1  x2  x4)  (x2  x4  x5)  (x3  x4  x5)

  41. Example: Graph coloring Given k colors, does there exist a coloring of the nodes such that adjacent nodes are assigned different colors

  42. Example: 3-coloring variables: v1, v2 , v3 , v4 , v5 domains: {1, 2, 3} constraints: vi  vjif vi and vj are adjacent v1 v2 v3 v4 v5

  43. Example: 3-coloring A solution v1 = 1 v2 = 2 v3 = 2 v4 = 1 v5 = 3 v1 v2 v3 v4 v5

  44. Example: n-queens Place n-queens on an n  n board so that no pair of queens attacks each other

  45. Constraint model variables: x1, x2 , x3 , x4 domains: {1, 2, 3, 4} constraints: x1  x2 | x1 – x2 | 1 x1  x3 | x1 – x3 | 2 x1  x4 | x1 – x4 | 3 x2  x3 | x2 – x3 | 1 x2  x4 | x2 – x4 | 2 x3  x4 | x3 – x4 | 1 x1 x2 x3 x4 1 2 3 4

  46. Example: 4-queens x1 x2 x3 x4 A solution x1 = 2 x2 = 4 x3 = 1 x4 = 3 Q 1 Q 2 Q 3 Q 4

  47. A closer look at constraints • An assignment (also called an instantiation) • x = a, where adom(x), • A tuplet over an ordered set of variables {x1, …, xk} is an ordered list of values (a1, …, ak) such that aidom(xi), i = 1, …, k • can be viewed as a set of assignments {x1 = a1, …, xk = ak} • Given a tuple t, notation t[xi] selects out the value for variable xi; i.e.,t[xi] = ai

  48. A closer look at constraints • Each constraint C is a relation • a set of tuples over some ordered subset of the variables, denoted by vars(C) • specifies the allowed combinations of values for the variables in vars(C) • The size of vars(C) is known as the arity of the constraint • a unary constraint has an arity of 1 • a binary constraint has an arity of 2 • a non-binary constraint has arity greater than 2

  49. intensional extensional Example • Let • dom(x1) = {1, 2, 3, 4}, • dom(x2) = {1, 2, 3, 4} • C be the constraint x1 x2 | x1– x2 | 1 • Then • vars(C) = {x1,x2} • tuples in C = {(1,3), (1,4), (2,4), (3,1), (4,1), (4,2)} • C is a binary constraint (table constraint)

  50. Constraint programming methodology • Model problem • Solve model • specify in terms of constraints on acceptable solutions • define/choose constraint model: • variables, domains, constraints • define/choose search algorithm • define/choose heuristics Constraint Satisfaction Problem

More Related