sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line...

38
Sweep Based Algorithms for Resource Scheduling Nicolas Beldiceanu EMN (CNRS/INRIA) [email protected] Master class CPAIOR 2012 (28 May)

Transcript of sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line...

Page 1: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Sweep Based Algorithms forResource Scheduling

Nicolas Beldiceanu EMN (CNRS/INRIA)

[email protected]

Master class CPAIOR 2012 (28 May)

Page 2: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Outline of the Presentation INTRODUCTION •  Sweep Algorithms in Computational Geometry •  Main Ideas of Sweep Algorithms

CONSTRAINT CONSIDERED •  Used for cumulative resources (cumulative, cumulatives)

•  Used for resources with choice (diffn, geost)

SWEEPING OVER THE TIME AXIS •  Basic scheme for cumulatives

SWEEPING OVER THE PLACEMENT SPACE •  Two dimensional case

•  Multi dimensional case •  Points to remember

OTHER SWEEP BASED FILTERING ALGORITHMS

CONCLUSION

FOC

US

Page 3: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

INTRODUCTION •  Sweep Algorithms in Computational Geometry •  Main Ideas of Sweep Algorithms

CONSTRAINT CONSIDERED •  Used for cumulative resources (cumulative, cumulatives)

•  Used for resources with choice (diffn, geost)

SWEEPING OVER THE TIME AXIS •  Basic scheme for cumulatives

SWEEPING OVER THE PLACEMENT SPACE •  Two dimensional case

•  Multi dimensional case •  Points to remember

OTHER SWEEP BASED FILTERING ALGORITHMS

CONCLUSION

Page 4: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Sweep Algorithms in Computational Geometry

Standard technique in the design of efficient algorithms, described in:

• Computational geometry, an introduction

[Preparata & Shamos, 1985]

• Computational Geometry, Algorithms and Applications

[Berg, Kreveld, Overmars & Schwarzkopf, 1997]

• Géométrie algorithmique

[Boissonnat & Yvinec, 1995]

Page 5: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Main Ideas of Sweep Algorithms (in the context of line segment intersection)

y

x

event point sweep line

sweep line status

(1)

(2)

Steps of the sweep algorithm:

(1) Move to the next event point

(2) Update the sweep line status:

• start events:

• end events:

GOAL: the worst case complexity should also depend of the number of intersections

Page 6: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Sweep and Constraints

Traditionally sweep algorithms are use for checking a property or

for computing a quantity wrt. a set of fixed objects

But in the context of constraint programming: (1) the objects (e.g., tasks, rectangles) are not fixed (attributes are variables with a domain)

(2) want to enforce a condition (detect infeasibility and remove values leading to failure)

Page 7: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

INTRODUCTION •  Sweep Algorithms in Computational Geometry •  Main Ideas of Sweep Algorithms

CONSTRAINT CONSIDERED •  Used for cumulative resources (cumulative, cumulatives)

•  Used for resources with choice (diffn, geost)

SWEEPING OVER THE TIME AXIS •  Basic scheme for cumulatives

SWEEPING OVER THE PLACEMENT SPACE •  Two dimensional case

•  Multi dimensional case •  Points to remember

OTHER SWEEP BASED FILTERING ALGORITHMS

CONCLUSION

Page 8: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

The cumulative Constraint

The original cumulative constraint [Aggoun & Beldiceanu 92]:

Restrict the resource consumption at each point in time.

The generalized cumulatives constraint [Beldiceanu & Carlsoon 01]:

A pool of cumulative resources , Height of a task can be negative , Maximum or minimum resource consumption , Holds for time-points crossed by at least one task.

1 2 3 4 5 6 0 1 2 3 4

1 2

3 4

time

resource consumption ≤ 4

time

resource consumption

1 2 3 4 5 6 -2 -1 0 1 2 -1 0 1

Cumulated profiles

2

1 3

4 5

7 6 ≥ 0

≥ 0

Page 9: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

9

diffn/geost

disjunctive"

machine assignment"

machine assignment"(machine dependant duration)"

2D non-overlapping"(fixed orientation)"

2D non-overlapping"(90° rotation)"

2D non-overlapping"(irregular shapes)"

2D non-overlapping"and assignment"

3D non-overlapping"

3D non-overlapping"and assignment"

pick-up delivery"

Page 10: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

10

diffn/geost

machine assignment + relaxation!

Page 11: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

INTRODUCTION •  Sweep Algorithms in Computational Geometry •  Main Ideas of Sweep Algorithms

CONSTRAINT CONSIDERED •  Used for cumulative resources (cumulative, cumulatives)

•  Used for resources with choice (diffn, geost)

SWEEPING OVER THE TIME AXIS •  Basic scheme for cumulatives

SWEEPING OVER THE PLACEMENT SPACE •  Two dimensional case

•  Multi dimensional case •  Points to remember

OTHER SWEEP BASED FILTERING ALGORITHMS

CONCLUSION

Page 12: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

The Sweep Algorithm: Fixed Tasks

resource

time Event points Minimum level to reach

for those instants where there is at least one task

Current position of the sweep line: 3

Sweep-line status

• nb_task=2 • sum_height=3

0 1 2 3 4

Task 1

Task 2 Task 3

• nb_task=1 • sum_height=2

• nb_task=0 • sum_height=0

• nb_task=1 • sum_height=4

• nb_task=0 • sum_height=0

1 2 4 5

Sweep line status: number of tasks

sum of the height

• 

•  which overlap the sweep line

Event points: start of each task

end of each task

• 

• 

Page 13: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Tomorrow

More about sweep for cumulative scheduling by A. Letort

in

workshop in bin packing and placement constraints (BPPC’12)

Page 14: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

INTRODUCTION •  Sweep Algorithms in Computational Geometry •  Main Ideas of Sweep Algorithms

CONSTRAINT CONSIDERED •  Used for cumulative resources (cumulative, cumulatives)

•  Used for resources with choice (diffn, geost)

SWEEPING OVER THE TIME AXIS •  Basic scheme for cumulatives

SWEEPING OVER THE PLACEMENT SPACE •  Two dimensional case

•  Multi dimensional case •  Points to remember

OTHER SWEEP BASED FILTERING ALGORITHMS

CONCLUSION

Page 15: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Forbidden Regions

Two intervals inf_x..sup_x and inf_y..sup_y such that:

For all x in inf_x..sup_x,

y in inf_y..sup_y: Ctr with the assignment X=x and Y=y is false.

DEFINITION forbidden region according to a constraint Ctr and two variables X,Y of Ctr :

EXAMPLE forbidden regions of

alldifferent({X,Y,R})

according to X and Y : X

Y

0 1 2 3 4 0 1 2 3 4

Page 16: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Examples of Forbidden Regions

(A) (B) (C) (D) (E)

0≤X≤4 0≤Y≤4 0≤R≤9

X

Y

0 1 2 3 4 0 1 2 3 4

X

Y

0 1 2 3 4 0 1 2 3 4

X

Y

0 1 2 3 4 0 1 2 3 4

0≤X≤4 0≤Y≤4 0≤X≤4 0≤Y≤4 0≤T≤2 0≤U≤3

X

Y

0 1 2 3 4 0 1 2 3 4

0≤X≤4 0≤Y≤4

alldifferent({X,Y,R}) |X-Y|>2

X

Y

0 1 2 3 4 0 1 2 3 4

0≤X≤4 0≤Y≤4 1≤S≤6

X+2Y≤S

X+2≤T ∨

T+3≤X ∨

Y+4≤U ∨

U+2≤Y X+Y≡0 (mod 2)

Page 17: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Basic Idea of Sweep Pruning

Accumulates forbiden regions

that come from different constraints

involving two given variables X and Y

CTR1(X,Y,…)

CTR2(X,Y,…)

………………

CTRn(X,Y,…)

Y

X

sweep line

Is min(X) feasible ? No, so move the sweep-line.

event point

sweep line status

Page 18: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Sweep Line Status

Y

For each y ∈ dom(Y): number of forbidden regions containing the point (Δ,y)

Y

X Δ

sweep line status

1 2 1 1 1 1

X

Remove a value Δ ∈ dom(X) if : for all y ∈ dom(Y) the number of forbidden regions is > 0

Page 19: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Y

X = 0 0 1 2 3 4

An Example

0≤X≤4 0≤Y≤4 1≤S≤6 0≤T≤2 0≤U≤3 alldifferent({X,Y,R}) |X-Y|>2 X+2Y≤S

X+2≤T ∨ T+3≤X ∨ Y+4≤U ∨ U+2≤Y

X+Y≡0 (mod 2)

PROBLEM: Adjust minimum of X according to Y and to all following constraints:

alldifferent({X,Y,R})

|X-Y|>2

X+2Y≤S

X+2≤T ∨ T+3≤X ∨ Y+4≤U ∨ U+2≤Y

X+Y≡0 (mod 2)

Page 20: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Y

X=0 0 1 2 3 4

Y

0 1 2 3 4

X=1

Y

0 1 2 3 4

X=2

Y

0 1 2 3 4

X=3

Y

0 1 2 3 4

X = 4

An Example

0≤X≤4 0≤Y≤4 1≤S≤6 0≤T≤2 0≤U≤3 alldifferent({X,Y,R}) |X-Y|>2 X+2Y≤S

X+2≤T ∨ T+3≤X ∨ Y+4≤U ∨ U+2≤Y

X+Y≡0 (mod 2)

PROBLEM: Adjust minimum of X according to Y and to all following constraints:

Deduction:

X>3

alldifferent({X,Y,R})

|X-Y|>2

X+2Y≤S

X+2≤T ∨ T+3≤X ∨ Y+4≤U ∨ U+2≤Y

X+Y≡0 (mod 2)

Page 21: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Forbidden and Safe Regions (for relaxation)

Two intervals inf_x..sup_x and inf_y..sup_y such that:

∀ x ∈ inf_x..sup_x,

∀ y ∈ inf_y..sup_y: Ctr with the assignment X=x and Y=y is false.

DEFINITION forbidden region according to a constraint Ctr and 2 variables X,Y of Ctr :

Two intervals inf_x..sup_x and inf_y..sup_y such that:

∀ x ∈ inf_x..sup_x,

∀ y ∈ inf_y..sup_y: Ctr with the assignment X=x and Y=y is true.

DEFINITION safe region according to a constraint Ctr and 2 variables X,Y of Ctr :

X

Y

0 1 2 3 4 0 1 2 3 4 0 ≤ X ≤ 4

0 ≤ Y ≤ 4 1 ≤ S ≤ 6 X + 2Y ≤ S

EXAMPLE

Page 22: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

INTRODUCTION •  Sweep Algorithms in Computational Geometry •  Main Ideas of Sweep Algorithms

CONSTRAINT CONSIDERED •  Used for cumulative resources (cumulative, cumulatives)

•  Used for resources with choice (diffn, geost)

SWEEPING OVER THE TIME AXIS •  Basic scheme for cumulatives

SWEEPING OVER THE PLACEMENT SPACE •  Two dimensional case

•  Multi dimensional case •  Points to remember

OTHER SWEEP BASED FILTERING ALGORITHMS

CONCLUSION

Page 23: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

23

Question: How to Generalize to k Dimensions ?

Key problem with the sweep-line status:

don't want to use a multi-dimensional data structure for storing

the forbidden regions since it just kills scalability

A Lexicographic Sweep-Point Algorithm

Page 24: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

24

A Lexicographic Sweep-Point Algorithm

Page 25: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

25

A Lexicographic Sweep-Point Algorithm

Page 26: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

26

Forbidden box wrt. an unfeasible point

SERVICES ASSOCIATED TO AN INTERNAL CONSTRAINT (i.e., a set of forbidden points)

LexInfeasible IsInfeasible

CardInfeasible

Page 27: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

27

Working area for a forbidden box

Additional requirement : (8) Bi should be contained in the working area (in grey on the example)

IDEA: In some dimensions, Bi is restricted by the previous forbidden boxes

B5

B4

B2

B1

included

included

included

B3

Page 28: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

INTRODUCTION •  Sweep Algorithms in Computational Geometry •  Main Ideas of Sweep Algorithms

CONSTRAINT CONSIDERED •  Used for cumulative resources (cumulative, cumulatives)

•  Used for resources with choice (diffn, geost)

SWEEPING OVER THE TIME AXIS •  Basic scheme for cumulatives

SWEEPING OVER THE PLACEMENT SPACE •  Two dimensional case

•  Multi dimensional case •  Points to remember

OTHER SWEEP BASED FILTERING ALGORITHMS

CONCLUSION

Page 29: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Points to Remember

An other way to look a constraint propagation:

− Rather than projecting on a single variable project on several variables

− Aggregate forbidden tuples coming from different constraints

(without using an explicit constraint store like MDD for instance)

Page 30: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Points to Remember

− A combination of a generic method (the sweep itself) and

structure (computing quickly forbidden regions for specific constraints)

− Practical efficiency achieved by: Light data structure (points)

Forbidden regions are not explicitly represented, but

Forbidden regions computed on demand (lazy evaluation) Incrementality achieved by witness, source and target,

domination between objects

Page 31: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Points to Know

− Not a polynomial filtering algorithm if nber. of dimension is variable

(potentially an exponential number of jumps)

− But works well in practice under following assumption

(when consider a limited number of dimensions, e.g. 8)

− On a clique of non-overlapping constraint do the following relaxation

(21 jumps)

Page 32: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

INTRODUCTION •  Sweep Algorithms in Computational Geometry •  Main Ideas of Sweep Algorithms

CONSTRAINT CONSIDERED •  Used for cumulative resources (cumulative, cumulatives)

•  Used for resources with choice (diffn, geost)

SWEEPING OVER THE TIME AXIS •  Basic scheme for cumulatives

SWEEPING OVER THE PLACEMENT SPACE •  Two dimensional case

•  Multi dimensional case •  Points to remember

OTHER SWEEP BASED FILTERING ALGORITHMS

CONCLUSION

Page 33: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Other use/extension of sweep algorithms in CP

− cardinality constraints

− forbidden regions combining non-overlapping and symmetry breaking − assignment of tasks with same origin (sweep synchronisation

with incremental bipartite matching while sweeping) − non-intersection between polygons

− compiling placement rules to code that generate forbidden regions

− within the context of continuous constraints (computes forbidden box associated to a numerical constraint)

Page 34: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

INTRODUCTION •  Sweep Algorithms in Computational Geometry •  Main Ideas of Sweep Algorithms

CONSTRAINT CONSIDERED •  Used for cumulative resources (cumulative, cumulatives)

•  Used for resources with choice (diffn, geost)

SWEEPING OVER THE TIME AXIS •  Basic scheme for cumulatives

SWEEPING OVER THE PLACEMENT SPACE •  Two dimensional case

•  Multi dimensional case •  Points to remember

OTHER SWEEP BASED FILTERING ALGORITHMS

CONCLUSION

Page 35: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Conclusion

•  Yet another use of sweep algorithms

(sweep algorithms were already used for a lot of different purpose)

•  Combine generality (forbidden, safe regions) with a specific algorithm (sweep)

(lead to a generic class of propagation algorithms)

Page 36: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

QUESTIONS

Is it possible to get better filtering for well know scheduling problems

and better estimation of the cost ? (job-shop, open-shop, …)

Page 37: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Further Sources of Information

papers •  Sweep as a Generic Pruning Technique Applied to the Non-overlapping Rectangles Constraint.

CP 2001: 377-391 (2 dimensional sweep algorithm)

•  Sweep as a Generic Pruning Technique Applied to Constraint Relaxation. CP 2001 workshop

•  Non-overlapping Constraints between Convex Polytopes. CP 2001: 392-407

•  A New Multi-resource cumulatives Constraint with Negative Heights. CP 2002: 63-79 (sweeping over the time axis)

•  Sweep synchronization as a global propagation mechanism. Computers & OR 33(10): 2835-2851 (2006)

•  A Generic Geometrical Constraint Kernel in Space and Time for Handling Polymorphic k-Dimensional Objects. CP 2007: 180-194 (multi-dimensional sweep algorithm)

•  A Geometric Constraint over k-Dimensional Objects and Shapes Subject to Business Rules. CP 2008: 220-234

•  Six Ways of Integrating Symmetries within Non-overlapping Constraints. CPAIOR 2009: 11-25

•  Sweeping with Continuous Domains. CP 2010: 137-151

•  Filtering Algorithms for Discrete Cumulative Problems with Overloads of Resource. CP 2011: 240-255

Page 38: sweep cpaior 2012 - IMT Atlantique · Main Ideas of Sweep Algorithms (in the context of line segment intersection) y x event point sweep line sweep line status (1) (2) Steps of the

Further Sources of Information

Systems •  Implementation of different variants of the non-overlapping constraint

(choco, jacop, sicstus) <<- geost constraint

•  Implementation of the multi-resource cumulatives constraint (choco, gecode, sicstus) <<- cumulative(s) constraint

Global Constraint Catalog, 2nd Edition (revision a) Available at: http://soda.swedish-ict.se/5195/

Keywords related to scheduling: resource constraints (page 295) scheduling constraints (page 301) temporal constraints (page 330) timetabling constraints (page 331)

Modelling exercices: some at page 144