html5-img
1 / 57

An Overview of Constraint Programming

An Overview of Constraint Programming. February 15/16, 2000. Today. Constraint programming in a nutshell Constraint propagation Branching Exploration. Thursday/Friday. Applying constraint programming to job-shop and other scheduling problems. Today. Constraint programming in a nutshell

clover
Télécharger la présentation

An Overview 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. An Overview of Constraint Programming February 15/16, 2000

  2. Today • Constraint programming in a nutshell • Constraint propagation • Branching • Exploration SMA HPC (c) NUS 15.094 Constraint Programming

  3. Thursday/Friday • Applying constraint programming to job-shop and other scheduling problems SMA HPC (c) NUS 15.094 Constraint Programming

  4. Today • Constraint programming in a nutshell • Propagation • Branching • Exploration SMA HPC (c) NUS 15.094 Constraint Programming

  5. Constraint Programming in a Nutshell SEND MORE MONEY SMA HPC (c) NUS 15.094 Constraint Programming

  6. Constraint Programming in a Nutshell SEND + MORE = MONEY SMA HPC (c) NUS 15.094 Constraint Programming

  7. SEND + MORE = MONEY Assign distinct digits to the letters S, E, N, D, M, O, R, Y such that S E N D + M O R E = M O N E Y holds. SMA HPC (c) NUS 15.094 Constraint Programming

  8. SEND + MORE = MONEY Assign distinct digits to the letters S, E, N, D, M, O, R, Y such that S E N D + M O R E = M O N E Y holds. Solution 9 5 6 7 + 1 0 8 5 = 1 0 6 5 2 SMA HPC (c) NUS 15.094 Constraint Programming

  9. Modeling Formalize the problem as a constraint problem: • number of variables: n • constraints: c1,…,cm  n • problem: Find a =(v1,…,vn) nsuch that a ci , for all 1  i  m SMA HPC (c) NUS 15.094 Constraint Programming

  10. A Model for MONEY • number of variables: 8 • constraints: c1={(S,E,N,D,M,O,R,Y) 8 | 0  S,…,Y  9 } c2={(S,E,N,D,M,O,R,Y) 8 | 1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E = 10000*M + 1000*O + 100*N + 10*E + Y} SMA HPC (c) NUS 15.094 Constraint Programming

  11. A Model for MONEY(continued) • more constraints c3= {(S,E,N,D,M,O,R,Y) 8 | S  0 } c4= {(S,E,N,D,M,O,R,Y) 8 | M  0 } c5= {(S,E,N,D,M,O,R,Y) 8 | S…Y all different} SMA HPC (c) NUS 15.094 Constraint Programming

  12. Solution for MONEY c1={(S,E,N,D,M,O,R,Y) 8 | 0S,…,Y9 } c2={(S,E,N,D,M,O,R,Y) 8 | 1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E = 10000*M + 1000*O + 100*N + 10*E + Y} c3= {(S,E,N,D,M,O,R,Y) 8 | S  0 } c4= {(S,E,N,D,M,O,R,Y) 8 | M  0 } c5= {(S,E,N,D,M,O,R,Y) 8 | S…Y all different} Solution: (9,5,6,7,1,0,8,2)8 SMA HPC (c) NUS 15.094 Constraint Programming

  13. Constraint Programming Exploiting constraints during tree search • Choose propagation algorithms • all different: wait for fixing • sum: interval consistency • Choose branching algorithm • first-fail • Choose exploration algorithm • depth-first search SMA HPC (c) NUS 15.094 Constraint Programming

  14. S E N D+ M O R E= M O N E Y S   E   N   D   M   O   R   Y   0S,…,Y9 S  0 M  0 S…Y all different 1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E = 10000*M + 1000*O + 100*N + 10*E + Y SMA HPC (c) NUS 15.094 Constraint Programming

  15. S E N D+ M O R E= M O N E Y Propagate S  {0..9} E  {0..9} N  {0..9} D  {0..9} M  {0..9} O  {0..9} R  {0..9} Y  {0..9} 0S,…,Y9 S  0 M  0 S…Y all different 1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E = 10000*M + 1000*O + 100*N + 10*E + Y SMA HPC (c) NUS 15.094 Constraint Programming

  16. S E N D+ M O R E= M O N E Y Propagate S  {1..9} E  {0..9} N  {0..9} D  {0..9} M  {1..9} O  {0..9} R  {0..9} Y  {0..9} 0S,…,Y9 S  0 M  0 S…Y all different 1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E = 10000*M + 1000*O + 100*N + 10*E + Y SMA HPC (c) NUS 15.094 Constraint Programming

  17. S E N D+ M O R E= M O N E Y Propagate S  {9} E  {4..7} N  {5..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} 0S,…,Y9 S  0 M  0 S…Y all different 1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E = 10000*M + 1000*O + 100*N + 10*E + Y SMA HPC (c) NUS 15.094 Constraint Programming

  18. S E N D+ M O R E= M O N E Y Branching S  {9} E  {4..7} N  {5..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} 0S,…,Y9 S  0 M  0 S…Y all different 1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E = 10000*M + 1000*O + 100*N + 10*E + Y E  4 E = 4 S  {9} E  {4..7} N  {5..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} S  {9} E  {4..7} N  {5..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} SMA HPC (c) NUS 15.094 Constraint Programming

  19. S E N D+ M O R E= M O N E Y Propagate S  {9} E  {4..7} N  {5..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} 0S,…,Y9 S  0 M  0 S…Y all different 1000*S + 100*E + 10*N + D + 1000*M + 100*O + 10*R + E = 10000*M + 1000*O + 100*N + 10*E + Y E  4 E = 4 S  {9} E  {5..7} N  {6..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} SMA HPC (c) NUS 15.094 Constraint Programming

  20. S E N D+ M O R E= M O N E Y Branching S  {9} E  {4..7} N  {5..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} E  4 E = 4 S  {9} E  {5..7} N  {6..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} E = 5 E  5 S  {9} E  {5..7} N  {6..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} S  {9} E  {5..7} N  {6..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} SMA HPC (c) NUS 15.094 Constraint Programming

  21. S E N D+ M O R E= M O N E Y Propagate S  {9} E  {4..7} N  {5..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} E  4 E = 4 S  {9} E  {5..7} N  {6..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} E = 5 E  5 S  {9} E  {5} N  {6} D  {7} M  {1} O  {0} R  {8} Y  {2} S  {9} E  {6..7} N  {7..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} SMA HPC (c) NUS 15.094 Constraint Programming

  22. S E N D+ M O R E= M O N E Y Complete Search Tree S  {9} E  {4..7} N  {5..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} E = 4 E  4 S  {9} E  {5..7} N  {6..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} E = 5 E  5 S  {9} E  {5} N  {6} D  {7} M  {1} O  {0} R  {8} Y  {2} S  {9} E  {6..7} N  {7..8} D  {2..8} M  {1} O  {0} R  {2..8} Y  {2..8} E  6 E = 6 SMA HPC (c) NUS 15.094 Constraint Programming

  23. Using OPL Syntax enum Letter {S,E,N,D,M,O,R,Y}; var int l[Letter] in 0..9; solve { alldifferent(l); l[S] <> 0; l[M] <> 0; l[S]*1000 + l[E]*100 + l[N]*10 + l[D] + l[M]*1000 + l[O]*100 + l[R]*10 + l[E] = l[M]*10000 + l[O]*1000 + l[N]*100 + l[E]*10 + l[Y] }; search { forall(i in Letter ordered by increasing dsize(l[i])) tryall(v in 0..9) l[i] = v; }; All Solutions; Execution  Run SMA HPC (c) NUS 15.094 Constraint Programming

  24. The Art of Constraint Programming • Choose model • Choose propagation algorithms • Choose branching algorithm • Choose exploration algorithm SMA HPC (c) NUS 15.094 Constraint Programming

  25. Demo: SEND + MORE = MONEY Click here for MONEY SMA HPC (c) NUS 15.094 Constraint Programming

  26. Constraint Programming Systems support constraint programming with high-level constructs • Constraint programming library • ILOG Solver (Puget 1993) • Constraint programming languages • CONSTRAINTS (Steele, Sussman 1980) • CHIP (Dincbas, Hentenryck, Simonis, Aggoun 1988) • CLP(R) (Jaffar, Maher, Stuckey, Yap 1992) • Oz (Smolka and others 1995) • OPL (Hentenryck 1998) SMA HPC (c) NUS 15.094 Constraint Programming

  27. Today • Constraint programming in a nutshell • Propagation • Branching • Exploration SMA HPC (c) NUS 15.094 Constraint Programming

  28. Issues in Propagation • Expressivity: What kind of information can be expressed as propagators? • Completeness: What behavior can be expected from propagation? • Efficiency: How much computational resources does propagation consume? SMA HPC (c) NUS 15.094 Constraint Programming

  29. Completeness • General arithmetic constraints are undecidable (Hilbert’s Tenth Problem). • Propagation may not exhibit all inconsistencies. • Example: c1: n > 2 c2: an + bn = cn SMA HPC (c) NUS 15.094 Constraint Programming

  30. Basic Constraints vs. Propagators • Basic constraints • are conjunctions of constraints of the form X  S, where S is a finite set of integers • enjoy complete constraint solving • Propagators • can be arbitrarily expressive (arithmetic, symbolic) • implementation typically fast but incomplete SMA HPC (c) NUS 15.094 Constraint Programming

  31. Current Domain Let C be basic constraint. For a given variable X, the maximal set S such that C  X  S is consistent is called the current domain ofXin C, denoted domc(X). Example: C: X{1..10}, Y{9..20}, X{8..12} domc(Y) = {9..20}, domc(X)={8..10} SMA HPC (c) NUS 15.094 Constraint Programming

  32. Domain vs. Interval Consistency • Domain consistency: Check all elements of the domains of all variables known to the propagator • Interval consistency: Check only the boundaries of the domains of the variables SMA HPC (c) NUS 15.094 Constraint Programming

  33. Domain Consistency Assume a constraint d over variables X and Y. A basic constraint C is domain consistent inX with respect tod, if for every i  domc(X) there is a j  domc(Y) such that (i,j)  d. Example: d: X + Y = 10 C: X  {7,9}, Y  {1..20} SMA HPC (c) NUS 15.094 Constraint Programming

  34. Domain Consistency Assume a constraint d over variables X and Y. A basic constraint C is domain consistent inX with respect tod, if for every idomc(X) there is a j  domc(Y) such that (i,j)  d. Example: d: X + Y = 10 C: X  {7,9}, Y  {1,3} SMA HPC (c) NUS 15.094 Constraint Programming

  35. Interval Consistency Assume a constraint d over variables X and Y. A basic constraint C is interval consistent inXwith respect tod, if for i=min(domc(X)) and for i=max(domc(X)) there is a j  domc(Y) such that (i,j)  d. Example: d: X + Y = 10 C: X  {7,9}, Y  {1..20} SMA HPC (c) NUS 15.094 Constraint Programming

  36. Interval Consistency Assume a constraint d over variables X and Y. A basic constraint C is interval consistent inXwith respect tod, if for i=min(domc(X)) and for i=max(domc(X)) there is a j  domc(Y) such that (i,j)  d. Example: d: X + Y = 10 C: X{7,9}, Y{1..3} SMA HPC (c) NUS 15.094 Constraint Programming

  37. Some Propagator Classes • Symbolic propagators • Arithmetic propagators • Scheduling propagators • Reification SMA HPC (c) NUS 15.094 Constraint Programming

  38. Symbolic PropagatorsExample: The “Element” Propagator OPL: array[i] = x Meaning: x is the ith element of array Example: int a[1..4] = [5,6,7,8] var int i,x in 0..9; solve { a[i] = x; } domc(I)={1,3}  X  {5,7} domc(X)={6,8}  I  {2,4} SMA HPC (c) NUS 15.094 Constraint Programming

  39. Arithmetic Propagators General arithmetic equations: I1*X11*…*X1m1 + … + In*Xn1*…*Xnmn = 0 < > <= >= <> SMA HPC (c) NUS 15.094 Constraint Programming

  40. Scheduling Propagators Details on Thursday/Friday Issues: • resource constraints • precedence constraints • edge finding • task intervals SMA HPC (c) NUS 15.094 Constraint Programming

  41. Reified Constraints Reflecting the validity of a constraint in a 0/1 variable Example: Reified arithmetic equations X = (I1*X11*…*X1m1 + … + In*Xn1*…*Xnmn = 0) < > <= >= <> SMA HPC (c) NUS 15.094 Constraint Programming

  42. Propagation vs Branching Obvious trade-off complex propagation algorithms: fewer, but more expensive nodes Example: MONEY with alldiff and sum: only test fixed assignment alldiff: wait for fixed variables sum: interval cons. alldiff and sum: domain consistency SMA HPC (c) NUS 15.094 Constraint Programming

  43. Today • Constraint programming in a nutshell • Propagation • Branching • Exploration SMA HPC (c) NUS 15.094 Constraint Programming

  44. Branching Algorithms Constraint programming systems come with • libraries of predefined branching algorithms • programming support for user-defined branching algorithms SMA HPC (c) NUS 15.094 Constraint Programming

  45. Branching for MONEY enum Letter {S,E,N,D,M,O,R,Y}; var int l[Letter] in 0..9; solve { alldifferent(l); l[S] <> 0; l[M] <> 0; l[S]*1000 + l[E]*100 + l[N]*10 + l[D] + l[M]*1000 + l[O]*100 + l[R]*10 + l[E] = l[M]*10000 + l[O]*1000 + l[N]*100 + l[E]*10 + l[Y] }; search { forall(i in Letter ordered by increasing dsize(l[i])) tryall(v in 0..9) l[i] = v; }; All Solutions; Execution  Run SMA HPC (c) NUS 15.094 Constraint Programming

  46. Basic Choice Points try x < y | x >= y endtry; x < y x >= y SMA HPC (c) NUS 15.094 Constraint Programming

  47. Choice Point Sequences try x < y | x >= y endtry; try z = 1 | z = 2 endtry; x < y x >= y z = 1 z = 2 z = 1 z = 2 SMA HPC (c) NUS 15.094 Constraint Programming

  48. Abbreviation: tryall tryall(i in 1..5) x = i; stands for try x=1|x=2|x=3|x=4|x=5 endtry; SMA HPC (c) NUS 15.094 Constraint Programming

  49. Abbreviation: forall forall(i in 1..4) try a[i]=0 | a[i]=1 endtry; stands for try a[1] = 0 | a[1] = 1 endtry; try a[2] = 0 | a[2] = 1 endtry; try a[3] = 0 | a[3] = 1 endtry; try a[4] = 0 | a[4] = 1 endtry; SMA HPC (c) NUS 15.094 Constraint Programming

  50. Examples of Branching Algorithms • Enumeration: Choose variable, choose value • naive enumeration: choose variables and values in a fixed sequence • first-fail enumeration: choose a variable with minimal domain size • Domain-splitting: try x < mid | x >= mid endtry; • Task sequencing for scheduling (Thursday/Friday) SMA HPC (c) NUS 15.094 Constraint Programming

More Related