Sudoku, Square Tiling / Scheduling CP Course, Lecture 10 Sudoku - - PowerPoint PPT Presentation

sudoku square tiling scheduling
SMART_READER_LITE
LIVE PREVIEW

Sudoku, Square Tiling / Scheduling CP Course, Lecture 10 Sudoku - - PowerPoint PPT Presentation

Sudoku, Square Tiling / Scheduling CP Course, Lecture 10 Sudoku 9 6 4 8 8 5 8 9 Fill in the grid such 7 6 that every row, 8 4 7 9 every column and 9 5 every 3x3 box 7 9 6 4 contains the digits 8 7 1...9 7 7 9 9 4


slide-1
SLIDE 1

Sudoku, Square Tiling / Scheduling

CP Course, Lecture 10

slide-2
SLIDE 2

Sudoku

Fill in the grid such that every row, every column and every 3x3 box contains the digits 1...9

9 7 8 6 4 5 8 8 6 9 8 7 9 8 4 7 8 8 7 9 4 7 6 9 9 4 5 7 7 9

slide-3
SLIDE 3

Sudoku: Model

  • fd var for each cell
  • for each row and

column: distinct

  • for each 3x3 box:

distinct

9 7 8 6 4 5 8 8 6 9 8 7 9 8 4 7 8 8 7 9 4 7 6 9 9 4 5 7 7 9

Solves most instances without search!

slide-4
SLIDE 4

Square Tiling

  • Given: n×m board,

squares defined by dimension.

  • Goal: place all

squares on the board - no

  • verlaps, board fully

covered.

s6 s5 s2 s3 s4 s1 Square Size

s1 3 s2 1 s3 1 s4 1 s5 2 s6 2

slide-5
SLIDE 5

Naive model

  • For each square s, introduce fd vars for sx and sy
  • Express with reification that two squares s and t do

not overlap: s left of t, or t left of s, or s above t, or t above

  • In a column with coordinate x, the sum of the sizes
  • ccupying space at col. x must be the size of the board

in y-direction. (Similar for rows)

slide-6
SLIDE 6

Improvements

  • Branching:
  • 1. Assign x-coordinates, then y-coordinates
  • 2. Try bigger squares first
  • 3. Place from left to right and top to bottom
  • Symmetry breaking?
slide-7
SLIDE 7

Scheduling

  • Tasks a (aka activities)
  • duration dur(a)
  • resource res(a)
  • Precedence constraints
  • determine order among two tasks
  • Resource constraints
  • e.g. at most one task per resource
slide-8
SLIDE 8

Building a Bridge

slide-9
SLIDE 9

Application Areas

  • creating time tables
  • planning workflow
  • scheduling instruction sequences in a

compiler

  • ...
slide-10
SLIDE 10

Model in CP

  • Variable for start-time of task a
  • Precedence constraints:

a before b

  • Resource constraints:

a before b ∨ b before a similar to temporal relations

slide-11
SLIDE 11

Model in CP

  • Variable for start-time of task a
  • Precedence constraints:

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

  • Resource constraints:

a before b ∨ b before a reification

slide-12
SLIDE 12

Propagate Precedence

A B

A before B

start(A) ∈ {0,...,5} dur(A) = 2 start(B) ∈ {0,...,5} dur(B) = 2

slide-13
SLIDE 13

Propagate Precedence

A B

A before B

start(A) ∈ {0,...,3} dur(A) = 2 start(B) ∈ {2,...,5} dur(B) = 2

slide-14
SLIDE 14

So what’s new?

  • We are interested in the concrete start and

end times

  • We want to optimize

(e.g. find earliest completion time)

  • This makes the problem hard
slide-15
SLIDE 15

Classes of problems I

  • Resource type

disjunctive (at most one task at a time) cumulative (fixed capacity per resource)

  • Task type

non-preemptive (not interruptible) preemptive elastic (stretchable)

slide-16
SLIDE 16

Classes of problems II

  • Optimization: Minimize

makespan (latest end time of any task) number of late jobs (that miss their due date) ...

  • Give more weight to more important jobs
slide-17
SLIDE 17

Special case we discuss

  • disjunctive, non-preemptive
  • cumulative (briefly)

Baptiste, Le Pape, Nuijten, Constraint-based

  • Scheduling. Kluwer, 2001.
slide-18
SLIDE 18

Again: Model in CP

  • Variable for start-time of task a
  • Precedence constraints:

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

  • Resource constraints:

a before b ∨ b before a reification

slide-19
SLIDE 19

Think global

  • Model employs local view:
  • constraints on pairs of tasks
  • O(n2) propagators for n tasks
  • Global view:
  • order all tasks on one resource
  • employ smart global propagator
slide-20
SLIDE 20

Ordering Tasks: Serialization

  • Consider all tasks on one resource
  • Deduce their order as much as possible
  • Propagators:
  • Timetabling: look at free/used time slots
  • Edge-finding: which task first/last?
  • Not-first / not-last
slide-21
SLIDE 21

Special case

  • Consider disjunctive, non-preemptive

scheduling where the duration is one for all tasks

  • Do you know a good propagator for

serialization?

slide-22
SLIDE 22

Timetable propagation

  • Timetable: data structure that records per

resource where some task definitively uses the resource

  • Propagate
  • from tasks to timetable
  • from timetable to tasks
slide-23
SLIDE 23

Example: Timetable

A B

start(A) ∈ {0,1} dur(A) = 2 start(B) ∈ {1,2,3} dur(B) = 2

slide-24
SLIDE 24

Example: Timetable

A B t

start(A) ∈ {0,1} dur(A) = 2 start(B) ∈ {1,2,3} dur(B) = 2

slide-25
SLIDE 25

Example: Timetable

A B t

  • r

start(A) ∈ {0,1} dur(A) = 2 start(B) ∈ {1,2,3} dur(B) = 2

slide-26
SLIDE 26

Example: Timetable

A B t

  • r

start(A) ∈ {0,1} dur(A) = 2 start(B) ∈ {1,2,3} dur(B) = 2

slide-27
SLIDE 27

Example: Timetable

A B t

start(A) ∈ {0,1} dur(A) = 2 start(B) ∈ {2} dur(B) = 2

slide-28
SLIDE 28

Example: Timetable

A B t

start(A) ∈ {0,1} dur(A) = 2 start(B) ∈ {2} dur(B) = 2

slide-29
SLIDE 29

Example: Timetable

A B t

start(A) ∈ {0} dur(A) = 2 start(B) ∈ {2} dur(B) = 2

slide-30
SLIDE 30

Example: Timetable

A B t

start(A) ∈ {0,1} dur(A) = 2 start(B) ∈ {2} dur(B) = 2

slide-31
SLIDE 31

Timetable propagation

  • Timetable: data structure that records per

resource where some task definitively uses the resource

  • Propagate
  • from tasks to timetable
  • from timetable to tasks
slide-32
SLIDE 32

Edge Finding

  • Time tabling is often weaker than

reification

  • But important idea:

record when resource is used

  • Edge finding is a more general scheme to

propagate order between tasks

slide-33
SLIDE 33

Edge finding: Idea

  • Assume a subset O of tasks and T∈O
  • constrain T to execute first
  • find out whether tasks in O-{T} must, can,
  • r cannot execute first or last
  • symmetrically for T last
  • Can be done in O(n2) for n tasks
slide-34
SLIDE 34

Example: Edge finding

B A C

start(A) ∈ {0,...,11} dur(A) = 6 start(B) ∈ {1,...,7} dur(B) = 4 start(C) ∈ {1,...,8} dur(C) = 3

slide-35
SLIDE 35

Example: Edge finding

start(A) ∈ {0,...,11} dur(A) = 6 start(B) ∈ {1,...,7} dur(B) = 4 start(C) ∈ {1,...,8} dur(C) = 3

{B,C} A

consider {B,C} A cannot be before {B,C}

slide-36
SLIDE 36

Example: Edge finding

start(A) ∈ {8,...,11} dur(A) = 6 start(B) ∈ {1,...,7} dur(B) = 4 start(C) ∈ {1,...,8} dur(C) = 3

{B,C} A

consider {B,C} A cannot be before {B,C}

slide-37
SLIDE 37

Example: Edge finding

start(A) ∈ {8,...,11} dur(A) = 6 start(B) ∈ {1,...,7} dur(B) = 4 start(C) ∈ {1,...,8} dur(C) = 3

A C B

timetable and reification do not propagate anything!

slide-38
SLIDE 38

Branching

  • General idea of any heuristic:

determine critical variables early!

  • A critical variable is one that makes a big

difference if determined

slide-39
SLIDE 39

Branching

  • Heuristic: establish order among tasks
  • which resource to choose
  • guess first task on resource
  • After ordering: assign start times
  • solution exists => no branching required
  • after assigning, propagate precedence

constraints

slide-40
SLIDE 40

Branching

a before b b before a

slide-41
SLIDE 41

Branching

a first a not first

slide-42
SLIDE 42

Branching: Slack

  • How to choose a ?
  • Good heuristic: minimum slack

A B slack

slide-43
SLIDE 43

Example: Instruction Scheduling

  • Optimize machine code
  • Goal: minimum length instruction schedule

Best paper CP 2001 (Peter van Beek and Kent Wilken)

slide-44
SLIDE 44

Example: Instruction Scheduling

R1 a R2 b R1 R1+R2 R3 c R1 R1+R3 3 3 1

instructions latency

slide-45
SLIDE 45

Example: Instruction Scheduling

R1 a R2 b R1 R1+R2 R3 c R1 R1+R3 3 3 1

instructions latency

Find issue time s(i) such that

  • 1. i≠j ⇒ s(i)≠s(j)
  • 2. s(i) + l(i,j) ≤ s(j)

Minimize max s(i)

slide-46
SLIDE 46

Example: Instruction Scheduling

  • Constraints:

all s(i) must be distinct

  • Precedence constraints for latency
  • Plus special case of edge finding
slide-47
SLIDE 47

Results

  • Built into gcc
  • SPEC95 FP
  • Large basic blocks (up to 1000 instructions)
  • Optimally solved
  • Far better than ILP approach
slide-48
SLIDE 48

Cumulative Scheduling

  • Each resource R has a capacity cap(R)
  • Each task T on R uses amount use(R)
  • Tasks can overlap but never exceed

capacity

slide-49
SLIDE 49

Cumulative: Disjunctive Propagation

  • For tasks A and B on resource R:

use(A) + use(B) ≤ cap(R)

  • r start(A) + dur(A) ≤ start(B)
  • r start(B) + dur(B) ≤ start(A)
slide-50
SLIDE 50

Cumulative

  • Techniques from disjunctive scheduling

carry over to cumulative scheduling

  • Generalized timetabling, edge-finding, not-

first/not-last

slide-51
SLIDE 51

Geometric Interpretation

  • Task is rectangle

dimension dur(T) × use(T) places at x-coordinate start(T)

  • Resources are rectangles
  • enclose task-rectangles
  • rectangles never exceed y-cordinates
slide-52
SLIDE 52

Geometric Interpretation

R1 R2 usage duration

slide-53
SLIDE 53

Geometric Interpretation

D F A G E B C We’ve seen something like this before... R1 R2 usage duration

slide-54
SLIDE 54

Summary

  • Scheduling: hard, real life problems
  • Model similar to temporal relations, but:

interested in actual solution + optimization

  • Global constraints: timetable, edge-finding,

not-first/not-last