Constraint Programming I - PowerPoint PPT Presentation

About This Presentation
Title:

Constraint Programming I

Description:

Case study: ACC 97/98 Basketball. Constraint programming techniques ... Expressivity: What kind of information can be expressed as propagators? ... – PowerPoint PPT presentation

Number of Views:36
Avg rating:3.0/5.0
Slides: 65
Provided by: marti76
Category:

less

Transcript and Presenter's Notes

Title: Constraint Programming I


1
Constraint Programming I
  • March 13, 2001

Martin Henz, School of Computing,
NUS www.comp.nus.edu.sg/henz
2
Today
  • Constraint programming in a nutshell
  • Constraint propagation
  • Branching
  • Exploration
  • Other search components

3
Thursday
  • Branching and Exploration in OPL
  • Case study ACC 97/98 Basketball
  • Constraint programming techniques

4
Today
  • Constraint programming in a nutshell
  • Propagation
  • Branching
  • Exploration
  • Other search components

5
Constraint Programming in a Nutshell
  • SEND MORE MONEY

6
Constraint Programming in a Nutshell
  • SEND MORE MONEY

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.

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
9
Modeling
  • Formalize the problem as a constraint problem
  • n variables
  • m constraints c1,,cm ? ?n
  • problem Find a (v1,,vn)? ?n such
  • that a ? ci , for all 1 ? i ?
    m

10
A Model for MONEY
  • 8 variables S,E,N,D,M,O,R,Y
  • 5 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
  • 1000S 100E 10N D
  • 1000M 100O 10R E
  • 10000M 1000O 100N 10E Y

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 SY all different

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
  • 1000S 100E 10N D
  • 1000M 100O 10R E
  • 10000M 1000O 100N 10E 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 SY all
    different
  • Solution (9,5,6,7,1,0,8,2)? ?8

13
Constraint Programming
Exploiting constraints during tree search
  • Choose propagation algorithms
  • all different wait for fixing
  • sum interval consistency
  • Choose branching algorithms
  • first-fail
  • Choose exploration algorithms
  • depth-first search

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
  • SY all different
  • 1000S 100E
    10N D
  • 1000M 100O 10R E
  • 10000M 1000O 100N 10E Y

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
  • SY all different
  • 1000S 100E
    10N D
  • 1000M 100O 10R E
  • 10000M 1000O 100N 10E Y

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
  • SY all different
  • 1000S 100E
    10N D
  • 1000M 100O 10R E
  • 10000M 1000O 100N 10E Y

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
  • SY all different
  • 1000S 100E
    10N D
  • 1000M 100O 10R E
  • 10000M 1000O 100N 10E Y

18
S E N D M O R E M O N E Y
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
Branching
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
  • 0?S,,Y?9
  • S ? 0
  • M ? 0
  • SY all different
  • 1000S 100E
    10N D
  • 1000M 100O 10R E
  • 10000M 1000O 100N 10E Y

19
S E N D M O R E M O N E Y
S ? 9 E ? 4..7 N ? 5..8 D ? 2..8 M ?
1 O ? 0 R ? 2..8 Y ? 2..8
Propagate
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
  • 0?S,,Y?9
  • S ? 0
  • M ? 0
  • SY all different
  • 1000S 100E
    10N D
  • 1000M 100O 10R E
  • 10000M 1000O 100N 10E Y

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
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
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


23
Using OPL Syntax
enum Letter S,E,N,D,M,O,R,Y var int lLetter
in 0..9 solve alldifferent(l) lS ltgt 0
lM ltgt 0 lS1000 lE100
lN10 lD lM1000
lO100 lR10 lE lM10000
lO1000 lN100 lE10 lY search
forall(i in Letter ordered by increasing
dsize(li)) tryall(v in 0..9)
li v ?All Solutions Execution ? Run
24
The Art of Constraint Programming
  • Choose model
  • Choose propagation algorithms
  • Choose branching algorithms
  • Choose exploration algorithms

25
Demo SEND MORE MONEY
Click here for MONEY
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)

27
Today
  • Constraint programming in a nutshell
  • Propagation
  • Branching
  • Exploration
  • Other search components

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?

29
Completeness
  • Main purpose of propagation is exposure of
    inconsistencies.
  • Inconsistencies allow to prune the search tree.
  • An implementation is complete with respect to a
    set of constraints, if inconsistencies between
    constraints are guaranteed to be exhibited.

30
Completeness
  • General arithmetic constraints are undecidable
    (Hilberts Tenth Problem).
  • Completeness is not always possible.
  • Example
  • c1 n gt 2
  • c2 an bn cn

31
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

32
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 of x in
    c,
  • denoted domc(x).
  • Example
  • C x?1..10, y?9..20,
  • x?8..12
  • domc(y) 9..20, domc(x)8..10

33
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

34
Domain Consistency
  • Assume a constraint d over variables x and
    y.
  • A basic constraint c is domain consistent in x
  • with respect to d, 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

35
Domain Consistency
  • Assume a constraint d over variables x and
    y.
  • A basic constraint c is domain consistent in x
  • with respect to d, 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

36
Interval Consistency
  • Assume a constraint d over variables x and
    y.
  • A basic constraint c is interval consistent in x
    with
  • respect to d, if for imin(domc(x)) and for
  • imax(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

37
Interval Consistency
  • Assume a constraint d over variables x and
    y.
  • A basic constraint c is interval consistent in x
    with
  • respect to d, if for imin(domc(x)) and for
  • imax(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

38
Domain and Interval Consistency
  • OPL syntax for all-different
  • interval consistency alldifferent(l)
  • domain consistency alldifferent(l) domain

39
Some Propagator Classes
  • Symbolic propagators
  • Arithmetic propagators
  • Reification

40
Symbolic PropagatorsExample The Element
Propagator
  • OPL arrayi x
  • Meaning x is the ith element of array
  • Example int a1..4 5,6,7,8
  • var int i,x in 0..9
  • solve ai x
  • domc(i)1,3 ? x ? 5,7
  • domc(x)6,8 ? i ? 2,4

41
Arithmetic Propagators
  • General arithmetic equations
  • i1x11x1m1 inxn1xnmn 0
  • lt gt lt gt ltgt

42
Reified Constraints
  • Reflecting the validity of a constraint in a
  • 0/1 variable
  • Example Reified arithmetic equations
  • x (i1x11x1m1 inxn1xnmn 0)
  • lt gt lt gt ltgt

43
Propagation vs Branching
  • trade-off
  • complex propagation algorithms incur
  • fewer, but more expensive nodes in
    tree
  • Example MONEY with

alldiff and sum only test fixed assignment
alldiff wait for fixed variables sum interval
cons.
alldiff and sum domain consistency
44
Today
  • Constraint programming in a nutshell
  • Propagation
  • Branching
  • Exploration
  • Other search components

45
Branching Algorithms
  • Constraint programming systems come with
  • libraries of predefined branching algorithms
  • programming support for user-defined branching
    algorithms

46
Branching for MONEY
enum Letter S,E,N,D,M,O,R,Y var int lLetter
in 0..9 solve alldifferent(l) lS ltgt 0
lM ltgt 0 lS1000 lE100
lN10 lD lM1000
lO100 lR10 lE lM10000
lO1000 lN100 lE10 lY search
forall(i in Letter ordered by
increasing dsize(li)) tryall(v in 0..9)
li v ?All Solutions Execution ?
Run
47
Basic Choice Points
  • try x lt y x gt y endtry

x lt y
x gt y
48
Choice Point Sequences
  • try x lt y x gt y endtry
  • try z 1 z 2 endtry

x lt y
x gt y
z 1
z 2
z 1
z 2
49
Abbreviation tryall
  • tryall(i in 1..5) x i
  • stands for
  • try x1x2x3x4x5 endtry

50
Abbreviation forall
  • forall(i in 1..4)
  • try ai0 ai1 endtry
  • stands for
  • try a1 0 a1 1 endtry
  • try a2 0 a2 1 endtry
  • try a3 0 a3 1 endtry
  • try a4 0 a4 1 endtry

51
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 lt mid x gt mid endtry
  • Task sequencing for scheduling

52
Today
  • Constraint programming in a nutshell
  • Propagation
  • Branching
  • Exploration
  • Other search components

53
Exploration for MONEY
enum Letter S,E,N,D,M,O,R,Y var int lLetter
in 0..9 solve alldifferent(l) lS ltgt 0
lM ltgt 0 lS1000 lE100
lN10 lD lM1000
lO100 lR10 lE lM10000
lO1000 lN100 lE10 lY search
forall(i in Letter ordered by
increasing dsize(li)) tryall(v in 0..9)
li v ?All Solutions Execution ?
Run
54
Exploration
  • Depth-first search (default in OPL)
  • Best-first search
  • Limited discrepancy search Harvey/Ginsberg 95
  • user-defined explorations

55
Specifying Exploration in OPL
enum Letter S,E,N,D,M,O,T,Y var int lLetter
in 0..9 solve alldifferent(l) lS ltgt 0
lM ltgt 0 lS1000 lE100
lN10 lD lM1000
lO100 lS10 lT lM10000
lO1000 lN100 lE10 lY search
LDSearch(4) forall(i in Letter ordered by
increasing dsize(li)) tryall(v in 0..9)
li v
56
Today
  • Constraint programming in a nutshell
  • Propagation
  • Branching
  • Exploration
  • Other search components

57
Other Search Components
  • Optimization
  • Interaction
  • Visualization
  • Search Limits

58
Optimization
  • SEND MOST MONEY

59
Optimization in OPL
enum Letter S,E,N,D,M,O,T,Y var int lLetter
in 0..9 maximize money subject to money
lM10000lO1000lN100lE10lY
alldifferent(l) lS ltgt 0 lM ltgt 0
lS1000 lE100 lN10 lD
lM1000 lO100 lS10
lT lM10000 lO1000 lN100
lE10 lY search forall(i in Letter
ordered by increasing dsize(li)) tryall(v
in 0..9) li v ?All Solutions
Execution ? Run
60
Interaction
  • First-solution search
  • All solution search
  • Last solution search
  • Search with user interaction

61
Visualization
  • Example Oz Explorer Schulte 1997.
  • Oz Explorer combines
  • visualization
  • first/all solution / user interaction
  • branch-and-bound optimization
  • depth-first search

62
Search Limits
  • SEND MOST MONEY
  • but dont spend more than 10 hours searching!!!

63
Search Limits in OPL
enum Letter S,E,N,D,M,O,T,Y var int lLetter
in 0..9 maximize money subject to money
lM10000lO1000lN100lE10lY
alldifferent(l) lS ltgt 0 lM ltgt 0
lS1000 lE100 lN10 lD
lM1000 lO100 lS10
lT lM10000 lO1000 lN100
lE10 lY search timeLimit 36000
forall(i in Letter ordered by increasing
dsize(li)) tryall(v in 0..9)
li v ?All Solutions Execution ? Run
64
Thursday
  • Branching and Exploration in OPL
  • Case study ACC 97/98 Basketball
  • Constraint programming techniques
Write a Comment
User Comments (0)
About PowerShow.com