85
Constraint Programming An Appetizer Christian Schulte [email protected] Laboratory of Electronics and Computer Systems Institute of Microelectronics and Information Technology KTH – Royal Institute of Technology Stockholm, Sweden

Constraint Programming An Appetizer Christian Schulte [email protected] Laboratory of Electronics and Computer Systems Institute of Microelectronics

  • View
    215

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Constraint ProgrammingAn Appetizer

Christian [email protected]

Laboratory of Electronics and Computer SystemsInstitute of Microelectronics and Information Technology

KTH – Royal Institute of TechnologyStockholm, Sweden

Page 2: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 22003-10-02

Constraint Programming

Solving combinatorial problems

start with a first toy problem

Page 3: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 32003-10-02

Send More Money (SMM)

Find distinct digits for letters, such that

SEND+ MORE= MONEY

Page 4: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 42003-10-02

Constraint Model for SMM

Variables: S,E,N,D,M,O,R,Y {0,…,9}

Constraints:distinct(S,E,N,D,M,O,R,Y)

1000×S+100×E+10×N+D + 1000×M+100×O+10×R+E = 10000×M+1000×O+100×N+10×E+YS0 M0

Page 5: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 52003-10-02

Solving SMM

Find values for variables

such that

all constraints satisfied

Page 6: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 62003-10-02

Finding a Solution

Enumerate assignments: poor! Constraint programming

compute with possible values prune inconsistent values

constraint propagationsearch

branch: define search tree explore: explore search tree for solution

Page 7: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Overview

Page 8: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 82003-10-02

Overview

Constraint propagation Search Summary: Applications & Principles Application examples

resource scheduling instruction scheduling

Constraint Programming 2G1515

Page 9: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Constraint Propagation

Page 10: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 102003-10-02

Important Concepts

Constraint store Basic constraint Propagator Non-basic constraint Constraint propagation

Page 11: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 112003-10-02

Constraint Store

Stores basic constraints map variables to possible values

x{3,4,5} y{3,4,5}

Page 12: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 122003-10-02

Constraint Store

Stores basic constraints map variables to possible values

x{3,4,5} y{3,4,5}

finite domain constraints

Page 13: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 132003-10-02

Constraint Store

Stores basic constraints map variables to possible values

Domains: finite sets, real intervals, trees, …

x{3,4,5} y{3,4,5}

Page 14: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 142003-10-02

Propagators

Implement non-basic constraints

distinct(x1,…,xn)

x + 2×y = z

Page 15: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 152003-10-02

Propagators

Amplify store by constraint propagation

x{3,4,5} y{3,4,5}

xy y>3

Page 16: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 162003-10-02

Propagators

Amplify store by constraint propagation

x{3,4,5} y{3,4,5}

xy y>3

Page 17: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 172003-10-02

Propagators

Amplify store by constraint propagation

x{3,4,5} y{4,5}

xy y>3

Page 18: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 182003-10-02

Propagators

Amplify store by constraint propagation

x{3,4,5} y{4,5}

xy y>3

Page 19: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 192003-10-02

Propagators

Amplify store by constraint propagation

x{4,5} y{4,5}

xy y>3

Page 20: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 202003-10-02

Propagators

Amplify store by constraint propagation Disappear when done (entailed)

no more propagation possible

x{4,5} y{4,5}

xy y>3

Page 21: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 212003-10-02

Propagators

Amplify store by constraint propagation Disappear when done (entailed)

no more propagation possible

x{4,5} y{4,5}

xy

Page 22: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 222003-10-02

Computation Space

Store with connected propagators

x{4,5} y{4,5}

xy y>3

Page 23: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 232003-10-02

Propagation for SMM

Results in storeS=9 E{4,…,7} N{5,…,8} D{2,…,8} M=1 O=0 R{2,…,8} Y{2,…,8}

Propagation alone not sufficient! create simpler sub-problems branching

Page 24: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Search

Page 25: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 252003-10-02

Important Concepts

Branching Exploration Branching heuristics Best solution search

Page 26: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 262003-10-02

Branching

Yields spaces with additional constraints Enables further constraint propagation

x{4,5} y{4,5}

xy y>3

x{4} y{4}

xy y>3

x{5} y{4,5}

xy y>3

x=4 x4

Page 27: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 272003-10-02

Branching Strategy

Pick variable x with at least two values Pick value n from domain of x Branch with

x=n and xn

Part of model

Page 28: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 282003-10-02

Search

Iterate propagation and branching Orthogonal: branching exploration Nodes:

Unsolved Failed Succeeded

Page 29: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 292003-10-02

SMM: Solution

SEND+ MORE= MONEY

9567+ 1085= 10652

Page 30: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 302003-10-02

Heuristics for Branching

Which variable least possible values (first-fail) application dependent heuristic

Which value minimum, median, maximum

x=m or xm split with median m

x<m or xm Problem specific

Page 31: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 312003-10-02

SMM: Solution With First-fail

SEND+ MORE= MONEY

9567+ 1085= 10652

Page 32: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 322003-10-02

Send Most Money (SMM++)

Find distinct digits for letters, such that

and MONEY maximal

SEND+ MOST= MONEY

Page 33: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 332003-10-02

Best Solution Search

Naïve approach: compute all solutions choose best

Branch-and-bound approach: compute first solution add “betterness” constraint to open nodes next solution will be “better” prunes search space

Page 34: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 342003-10-02

Branch-and-bound Search

Find first solution

Page 35: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 352003-10-02

Branch-and-bound Search

Explore with additional constraint

Page 36: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 362003-10-02

Branch-and-bound Search

Explore with additional constraint

Page 37: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 372003-10-02

Branch-and-bound Search

Guarantees better solutions

Page 38: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 382003-10-02

Branch-and-bound Search

Guarantees better solutions

Page 39: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 392003-10-02

Branch-and-bound Search

Last solution best

Page 40: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 402003-10-02

Branch-and-bound Search

Proof of optimality

Page 41: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 412003-10-02

Modelling SMM++

Constraints and branching as before Order among solutions with constraints

so-far-best solution S,E,N,D,M,O,T,Y current node S,E,N,D,M,O,T,Y constraint added

10000×M+1000×O+100×N+10×E+Y<

10000×M+1000×O+100×N+10×E+Y

Page 42: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 422003-10-02

SMM++: Branch-and-bound

SEND+ MOST= MONEY

9782+ 1094= 10876

Page 43: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 432003-10-02

SMM++: All Solution Search

SEND+ MOST= MONEY

9782+ 1094= 10876

Page 44: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Summary

Page 45: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 452003-10-02

Summary

Modeling variables with domain constraints to state relations branching strategy solution ordering

Solving constraint propagation constraint branching search tree exploration

applications

principles

Page 46: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 462003-10-02

Application Areas Timetabling Scheduling Crew rostering Resource allocation Workflow planning and optimization Gate allocation at airports Sports-event scheduling Railroad: track allocation, train allocation, schedules Automatic composition of music Genome sequencing Frequency allocation …

Page 47: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 472003-10-02

Application Examples

Scheduling resources machines, personal, … constraint programming showcase

Instruction scheduling used in compilation for modern microprocessors with latencies

Page 48: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 482003-10-02

Principles

Models for constraint propagation properties and guarantees

Strong constraint propagation global constraints with strong algorithmic methods mantra: search kills, search kills, search k…

Branching strategies Exploration strategies

Page 49: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 492003-10-02

SMM: Strong Propagation

SEND+ MORE= MONEY

9567+ 1085= 10652

Page 50: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 502003-10-02

Used Techniques

Artificial intelligence

Operations research

Algorithms

Programming languages

Page 51: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 512003-10-02

Why Does CP Matter?

Middleware for combining smart algorithmic components

scheduling graphs flows …

plus essential extra constraints

Page 52: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 522003-10-02

Significance

Constraint programming identified as a strategic direction in computer science research

[ACM Computing Surveys, December 1996]

Applications are ubiquitous knowledgeable people are not!

Page 53: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 532003-10-02

Relation to Logic Programming

Logic programminghorn clauses + trees with unification

Constraint logic programminghorn clauses + constraint domain

Constraint programmingX + constraint domain with focus on constraints refined search language

Page 54: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Scheduling Resources

Modeling Propagation Strong propagation

Page 55: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 552003-10-02

Scheduling Resources: Given

Tasks duration resource

Precedence constraints determine order among two tasks

Resource constraints at most one task per resource

[disjunctive, non-preemptive scheduling]

Page 56: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 562003-10-02

Scheduling: Bridge Example

Page 57: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 572003-10-02

Scheduling: Solution

Start time for each task

All constraints satisfied

Earliest completion time minimal make-span

Page 58: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 582003-10-02

Scheduling: Model

Variable for start-time of task a

start(a) Precedence constraint: a before b

start(a) + dur(a) start(b)

Page 59: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 592003-10-02

Propagating Precedence

start(a){0,…,7}start(b){0,…,5}

a

b

a before b

Page 60: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 602003-10-02

Propagating Precedence

start(a){0,…,7}start(b){0,…,5}

a

b

a

b

a before b

start(a){0,…,2}start(b){3,…,5}

Page 61: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 612003-10-02

Scheduling: Model

Variable for start-time of task a

start(a) Precedence constraint: a before b

start(a) + dur(a) start(b) Resource constraint:

a before b

or

b before a

Page 62: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 622003-10-02

Scheduling: Model

Variable for start-time of task a

start(a) Precedence constraint: a before b

start(a) + dur(a) start(b) Resource constraint:

start(a) + dur(a) start(b)

or

b before a

Page 63: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 632003-10-02

Scheduling: Model

Variable for start-time of task a

start(a) Precedence constraint: a before b

start(a) + dur(a) start(b) Resource constraint:

start(a) + dur(a) start(b)

or

start(b) + dur(b) start(a)

Page 64: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 642003-10-02

Reified Constraints

Use control variable b{0,1}

c b=1 Propagate

c holds propagate b=1 c holds propagate b=0 b=1 holds propagate c b=0 holds propagate c

Page 65: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 652003-10-02

Reified Constraints

Use control variable b{0,1}

c b=1 Propagate

c holds propagate b=1 c holds propagate b=0 b=1 holds propagate c b=0 holds propagate c

not easy!

Page 66: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 662003-10-02

Reification for Disjunction

Reify each precedence

[start(a) + dur(a) start(b)] b0=1

and

[start(b) + dur(b) start(a)] b1=1

Model disjunction

b0 + b1 1

Page 67: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 672003-10-02

Model Is Too Naïve

Local view individual task pairs O(n2) propagators for n tasks

Global view all tasks on resource single propagator smarter algorithms possible

Page 68: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 682003-10-02

Edge Finding

Find ordering among tasks (“edges”) For each subset of tasks {a}B

assume: a before B

deduce information for a and B assume: B before a

deduce information for a and B join computed information can be done in O(n2)

Page 69: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 692003-10-02

Summary

Modeling easy but not always efficient constraint combinators (reification) global constraints smart heuristics

More on constraint-based schedulingBaptiste, Le Pape, Nuijten. Constraint-basedScheduling, Kluwer, 2001.

Page 70: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Instruction Scheduling

Page 71: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 712003-10-02

Instruction Scheduling

Optimized object code by compiler Minimum length instruction schedule

precedence latency resources

per basic block

Best paper CP 2001, Peter van Beek and Kent Wilken, Fast Optimal Scheduling for Single-issue Processors with Arbitrary Latencies, 2001.

Page 72: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 722003-10-02

Problem

r1 a r2 b

r1 r1 + r2 r3 c

r1 r1 + r3E

1 3

3

A B

D C

Page 73: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 732003-10-02

Problem

r1 a r2 b

r1 r1 + r2 r3 c

r1 r1 + r3E

1 3

3

A B

D C

instructions

Page 74: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 742003-10-02

Problem

r1 a r2 b

r1 r1 + r2 r3 c

r1 r1 + r3E

1 3

3

A B

D C

dependency with latency

Page 75: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 752003-10-02

Problem

r1 a r2 b

r1 r1 + r2 r3 c

r1 r1 + r3E

1 3

3

A B

D C

instructions i, j

Page 76: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 762003-10-02

Problem

r1 a r2 b

r1 r1 + r2 r3 c

r1 r1 + r3E

1 3

3

A B

D C

latency l(i, j)

Page 77: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 772003-10-02

Problem

r1 a r2 b

r1 r1 + r2 r3 c

r1 r1 + r3E

1 3

3

A B

D C

Find issue time s(i)1. ij s(i)s(j)2. s(i)+l(i,j) s(j)

Minimizemax s(i)

Page 78: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 782003-10-02

Problem Is also Model

r1 a r2 b

r1 r1 + r2 r3 c

r1 r1 + r3E

1 3

3

A B

D C

Find issue time s(i)1. ij s(i)s(j)2. s(i)+l(i,j) s(j)

Minimizemax s(i)

Page 79: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 792003-10-02

Model

All issue times must be distinct use single distinct constraint (as in SMM) is resource constraint or unit duration

Latency constraints precedence constraints (as before) difference: duration latency

Page 80: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 802003-10-02

Making It Work

Only propagate bounds information relevant for distinct

Add redundant constraints regions: additional structure in DAG successor and predecessor constraints

[special case of edge-finding]

Page 81: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 812003-10-02

Results

Tested with gcc SPEC95 FP Large basic blocks

up to 1000 instructions

Optimally solved less than 0.6% compile time increase limited static improvement (< 0.1%) better dynamic impact (loops)

Far better than ILP approach

Page 82: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

2G1515

Page 83: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 832003-10-02

Course Overview 2G1515

As to be expected, no surprises:

applications

principles

pragmatics

limitations

Page 84: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 842003-10-02

Organization

12 lectures Assignments (practical + principles) Exam Material

to be developed as we go… with some textbook excerpts + research papers

Page 85: Constraint Programming An Appetizer Christian Schulte schulte@imit.kth.se Laboratory of Electronics and Computer Systems Institute of Microelectronics

Christian Schulte, IMIT, KTH 852003-10-02

More Info

Check my webpage frequently…

www.imit.kth.se/~schulte/