1 / 103

General Principles of Constraint Programming

General Principles of Constraint Programming. Jean-Charles REGIN Director of Constraint Programming ILOG, Sophia Antipolis, France regin@ilog.fr. Plan. General Principles CP vs other techniques Filtering algorithms An example: sports scheduling Strength of CP Weakness of CP

bena
Download Presentation

General Principles of 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. General Principles of Constraint Programming Jean-Charles REGIN Director of Constraint Programming ILOG, Sophia Antipolis, France regin@ilog.fr

  2. Plan • General Principles • CP vs other techniques • Filtering algorithms • An example: sports scheduling • Strength of CP • Weakness of CP • New research Area • Recent advances in CP at ILOG • Conclusion

  3. History • General Problem Solvers in 70’s • ALICE [J-F Lauriere, AIJ 78], phD in Paris VI, 76 • Prolog: CHIP, ECRC Munich 86 (Alice in Prolog) • Colmerauer, Gallaire, Van Hentenryck • Constraint Satisfaction Problems • Waltz 72, Mackworth 74, Freuder 76 • Industry: Bull (Charme), ILOG (Solver) 92

  4. Constraint Programming • In CP a problem is defined from:- variables with possible values (domain)- constraints • Domain can be discrete or continuous, symbolic values or numerical values • Constraints express properties that have to be satisfied

  5. Problem = conjunction of sub-problems • In CP a problem can be viewed as a conjunction of sub-problems that we are able to solve • A sub-problem can be trivial: x < y or complex: search for a feasible flow • A sub-problem = a constraint

  6. Constraints • Predefined constraints: arithmetic (x < y, x = y +z, |x-y| > k, alldiff, cardinality, sequence … • Constraints given in extension by the list of allowed (or forbidden) combinations of values • user-defined constraints: any algorithm can be encapsulated • Logical combination of constraints using OR, AND, NOT, XOR operators. Sometimes called meta-constraints

  7. Filtering • We are able to solve a sub-problem: a method is available • CP uses this method to remove values from domain that do not belong to a solution of this sub-problem: filtering or domain-reduction • E.g: x < y and D(x)=[10,20], D(y)=[5,15]=> D(x)=[10,14], D(y)=[11,15]

  8. Filtering • A filtering algorithm is associated with each constraint (sub-problem). • Can be simple (x < y) or complex (alldiff) • Theoretical basics: arc consistency, remove all the values that do not belong to a solution of the underlined sub-problem.

  9. Propagation • Domain Reduction due to one constraint can lead to new domain reduction of other variables • When a domain is modified all the constraints involving this variable are studied and so on ...

  10. Propagation • D(x)=D(y)={0,1}, D(z)={0,1,2}, D(u)={3,4,5}, D(v)={4,5,6} • Alldiff({x,y,z}), u=z+3, v>u, |z-v|<6

  11. Propagation • D(x)=D(y)={0,1}, D(z)={0,1,2}, D(u)={3,4,5}, D(v)={4,5,6} • Alldiff({x,y,z}), u=z+3, v>u, |z-v|<6 • Alldiff({x,y,z}): FA=> z=2

  12. Propagation • D(x)=D(y)={0,1}, D(z)={0,1,2}, D(u)={3,4,5}, D(v)={4,5,6} • Alldiff({x,y,z}), u=z+3, v>u, |z-v|<6 • Alldiff({x,y,z}): FA=> z=2 • u=z+3: FA=> u=5

  13. Propagation • D(x)=D(y)={0,1}, D(z)={0,1,2}, D(u)={3,4,5}, D(v)={4,5,6} • Alldiff({x,y,z}), u=z+3, v>u, |z-v|<6 • Alldiff({x,y,z}): FA=> z=2 • u=z+3: FA=> u=5 • v>u: FA=> v=6

  14. Propagation • D(x)=D(y)={0,1}, D(z)={0,1,2}, D(u)={3,4,5}, D(v)={4,5,6} • Alldiff({x,y,z}), u=z+3, v>u, |z-v|<6 • Alldiff({x,y,z}): FA=> z=2 • u=z+3: FA=> u=5 • v>u: FA=> v=6 • |z-v|<6: FA => y=1

  15. Propagation • D(x)=D(y)={0,1}, D(z)={0,1,2}, D(u)={3,4,5}, D(v)={4,5,6} • Alldiff({x,y,z}), u=z+3, v>u, |z-v|<6 • Alldiff({x,y,z}): FA=> z=2 • u=z+3: FA=> u=5 • v>u: FA=> v=6 • |z-v|<6: FA => y=1 • Alldiff({x,y,z}): FA=> x=0 • Solution: x=0, y=1, z=2, u=5, v=6

  16. Why Propagation? • Idea: problem = conjunction of easy sub-problems. • Sub-problems: local point of view. Problem: global point of view. Propagation tries to obtain a global point of view from independent local point of view • The conjunction is stronger that the union of independent resolution

  17. Search • Backtrack algorithm with strategies:try to successively assign variables with values. If a dead-end occurs then backtrack and try another value for the variable • Strategy: define which variable and which value will be chosen. • After each domain reduction (I.e assignement include) filtering and propagation are triggered

  18. Constraint Programming • 3 notions:- constraint network: variables, domains constraints + filtering (domain reduction)- propagation- search procedure (assignments + backtrack) • The structure of every constraint is exploited

  19. Plan • General Principles • CP vs other techniques • Filtering algorithms • An example: sports scheduling • Strength of CP • Weakness of CP • New research Area • Recent advances in CP at ILOG • Conclusion

  20. CP vs other techniques • CP vs greedy algorithms • CP vs local search • CP vs inference engines • CP vs MIP

  21. CP vs greedy algorithm • Greedy algorithm = a search strategy which guarantees that there is no backtrack • CP is a generalization: your strategy can be non necessarily greedy. Solver manages for you the “errors” of your strategy • Some problems are solved with few backtracks

  22. CP vs local search • Local search: it is hard to respect hard constraints. With CP no problem • Combination of CP and local search is used quite often to solve problems: find a first solution with CP then re-optimize it iteratively.

  23. CP vs Inference engines • (A implies B) represented by (NOT A OR B) • (x < 5 implies z > 4) • Propagation from Left to Right: if x < 5 then z > 4 • Propagation from Right to Left: if z < 5 then necessarily x >4

  24. CP vs MIP MIP approach CP approach

  25. Relax the problem: floats instead of integers 1) Use the Simplex algorithm (“polynomial”) 2) Set float to integer value. Go to 1) and backtrack if necessary CP vs MIP MIP approach CP approach

  26. Relax the problem: floats instead of integers 1) Use the Simplex algorithm (“polynomial”) 2) Set float to integer value. Go to 1) and backtrack if necessary Identify sub-problems that are easy (called constraints) 1) Use specific algorithm for solving these sub-problems and for performing domain-reduction 2) Instantiate variable. Go to 1) and backtrack if necessary CP vs MIP MIP approach CP approach

  27. Relax the problem: floats instead of integers 1) Use the Simplex algorithm (“polynomial”) 2) Set float to integer value. Go to 1) and backtrack if necessary Global point of view on a relaxation of the problem Identify sub-problems that are easy (called constraints) 1) Use specific algorithm for solving these sub-problems and for performing domain-reduction 2) Instantiate variable. Go to 1) and backtrack if necessary Local point of view on sub-problems. “Global” point of view by propagation of domain reductions CP vs MIP MIP approach CP approach

  28. CP vs MIP • In CP constraints can be non-linear • Structure of the problem is used in CP • Semantic of the constraints are used: much easier to add a global constraint with a filtering algorithm than defining a new cut • First solution given by CP is generally good

  29. Plan • General Principles • CP vs other techniques • Filtering algorithms • An example: sports scheduling • Strength of CP • Weakness of CP • New research Area • Recent advances in CP at ILOG • Conclusion

  30. Arc consistency • All the values which do not belong to any solution of the constraint are deleted. • Example: Alldiff({x,y,z}) with D(x)=D(y)={0,1}, D(z)={0,1,2}the two variables x and y take the values 0 and 1, thus z cannot take these values.FA by AC => 0 and 1 are removed from D(z)

  31. Alldiff constraint The value graph: 1 2 3 4 5 6 7 x1 x2 x3 x4 x5 x6 D(x1)={1,2} D(x2)={2,3} D(x3)={1,3} D(x4)={3,4} D(x5)={2,4,5,6} D(x6)={5,6,7}

  32. Value network (0,1) 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 (0,1) (1,1) t s (6,6)

  33. A feasible flow (0,1) 1 2 3 4 5 6 7 Default orientation x1 x2 x3 x4 x5 x6 (0,1) (1,1) t s (6,6)

  34. Residual graph 1 2 3 4 5 6 7 orientation x1 x2 x3 x4 x5 x6 s

  35. Residual graph 1 2 3 4 5 6 7 orientation x1 x2 x3 x4 x5 x6 s

  36. Arc consistency The value graph: 1 2 3 4 5 6 7 x1 x2 x3 x4 x5 x6 D(x1)={1,2} D(x2)={2,3} D(x3)={1,3} D(x4)={4} D(x5)={5,6} D(x6)={5,6,7}

  37. Alldiff constraint • Compute a feasible flow • Compute the strongly connected components • Remove every arc of flow value 0 for which the ends belong to two different components • Linear algorithm achieving arc consistency • Idem for global cardinality constraints • work well due to (0,1) arcs

  38. Plan • General Principles • CP vs other techniques • Filtering algorithms • An example: sports scheduling • Strength of CP • Weakness of CP • New research Area • Recent advances in CP at ILOG • Conclusion

  39. The problem • n teams and n-1 weeks and n/2 periods • every two teams play each other exactly once • every team plays one game in each week • no team plays more than twice in the same period

  40. The problem • n teams and n-1 weeks and n/2 periods • every two teams play each other exactly once • every team plays one game in each week • no team plays more than twice in the same period • Problem 10teams of the MIPLIB • (n=10 and the objective function is dummy) • MIP is not able to find a solution for n=14 • CP finds a solution for n=10 in 0.06s, n=14 in 0.2, n=40 in 6h

  41. The problem • n teams and n-1 weeks and n/2 periods • every two teams play each other exactly once • every team plays one game in each week • no team plays more than twice in the same period For 40 teams: 800 variables with 39 possible values for each variable.

  42. CP model: variables For each slot: 2 variables represent the teams and 1 variable represents the match are defined 1 vs 6 M33 variable (M33=12) Mij=1 <=> 0 vs 1 or 1 vs 0 Mij=12 <=> 1 vs 6 or 6 vs1 T33a variable (T33a=6) T33h variable (T33h=1)

  43. CP model: T variables D(Tija)=[1,n-1] D(Tijh)=[0,n-2] Tijh < Tija

  44. CP model: M variables D(Mij)=[1,n(n-1)/2]

  45. CP model: constraints • n teams and n-1 weeks and n/2 periods • every two teams play each other exactly once • every team plays one game in each week • no team plays more than twice in the same period

  46. CP model: constraints • n teams and n-1 weeks and n/2 periods • every two teams play each other exactly once • every team plays one game in each week • no team plays more than twice in the same period Alldiff constraints defined on M variables

  47. CP model: constraints • n teams and n-1 weeks and n/2 periods • every two teams play each other exactly once • every team plays one game in each week • no team plays more than twice in the same period

  48. CP model: constraints • n teams and n-1 weeks and n/2 periods • every two teams play each other exactly once • every team plays one game in each week • no team plays more than twice in the same period For each week w: Alldiff constraint defined on {Tpwh, p=1..4} U {Tpwa, p=1..4}

  49. CP model: constraints • n teams and n-1 weeks and n/2 periods • every two teams play each other exactly once • every team plays one game in each week • no team plays more than twice in the same period

  50. CP model: constraints • n teams and n-1 weeks and n/2 periods • every two teams play each other exactly once • every team plays one game in each week • no team plays more than twice in the same period For each period p: Global cardinality constraint defined on {Tpwh, w=1..7} U {Tpwa, w=1..7} every team t is taken at most 2

More Related