sics seminar, may 29 2001

41
SICS Seminar, May 29 2001 Sweep Based Algorithms for Constraint Propagation Nicolas Beldiceanu SICS Lägerhyddsvägen 18 75237 Uppsala email: [email protected]

Upload: kareem-leach

Post on 01-Jan-2016

31 views

Category:

Documents


0 download

DESCRIPTION

Sweep Based Algorithms for Constraint Propagation Nicolas Beldiceanu SICS Lägerhyddsvägen 18 75237 Uppsala email: [email protected]. SICS Seminar, May 29 2001. Outline of the Presentation. INTRODUCTION Sweep Algorithms in Computational Geometry Main Ideas of Sweep Algorithms - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: SICS Seminar, May 29 2001

SICS Seminar, May 29 2001

Sweep Based Algorithms for Constraint Propagation

 

Nicolas Beldiceanu

SICSLägerhyddsvägen 18

75237 Uppsala

email: [email protected]

Page 2: SICS Seminar, May 29 2001

Outline of the Presentation

INTRODUCTION

• Sweep Algorithms in Computational Geometry

• Main Ideas of Sweep Algorithms

CONJUNCTION OF CONSTRAINTS

• Representing an Elementary Constraint: Forbidden Regions

• The Sweep Algorithm

CARDINALITY OPERATOR

• Representing an Elementary Constraint: Forbidden and Safe Regions

• The Sweep Algorithm

NON-OVERLAPPING CONSTRAINT BETWEEN CONVEX POLYGONS

• The Forbidden Polygon

• The Sweep Algorithm

CUMULATIVES CONSTRAINT

• Definition of the Cumulatives Constraint

• The Sweep Algorithm

SUMMARY AND CONCLUSION

Page 3: SICS Seminar, May 29 2001

INTRODUCTION

• Sweep Algorithms in Computational Geometry

• Main Ideas of Sweep Algorithms

CONJUNCTION OF CONSTRAINTS

• Representing an Elementary Constraint: Forbidden Regions

• The Sweep Algorithm

CARDINALITY OPERATOR

• Representing an Elementary Constraint: Forbidden and Safe Regions

• The Sweep Algorithm

NON-OVERLAPPING CONSTRAINT BETWEEN CONVEX POLYGONS

• The Forbidden Polygon

• The Sweep Algorithm

CUMULATIVES CONSTRAINT

• Definition of the Cumulatives Constraint

• The Sweep Algorithm

SUMMARY AND CONCLUSION

Page 4: SICS Seminar, May 29 2001

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: SICS Seminar, May 29 2001

Applications of Sweep Algorithms

Within the Geometry Literature Database, more than 100 references:

Voronoi diagram

Map overlay

Nearest objects

Triangulations

Hidden surface removals

Rectangles intersection

Shortest path

But not yet used within constraint programming !

Page 6: SICS Seminar, May 29 2001

Applications of Sweep Algorithms within Constraint Programming

Pruning for the following constraint patterns:

A conjunction of constraints with two shared variables

The cardinality operator with two shared variables

The non-overlapping constraint between polygons

A multi-resource cumulatives constraint

Page 7: SICS Seminar, May 29 2001

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

y

x

event pointsweep 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 8: SICS Seminar, May 29 2001

INTRODUCTION

• Sweep Algorithms in Computational Geometry

• Main Ideas of Sweep Algorithms

CONJUNCTION OF CONSTRAINTS

• Representing an Elementary Constraint: Forbidden Regions

• The Sweep Algorithm

CARDINALITY OPERATOR

• Representing an Elementary Constraint: Forbidden and Safe Regions

• The Sweep Algorithm

NON-OVERLAPPING CONSTRAINT BETWEEN CONVEX POLYGONS

• The Forbidden Polygon

• The Sweep Algorithm

CUMULATIVES CONSTRAINT

• Definition of the Cumulatives Constraint

• The Sweep Algorithm

SUMMARY AND CONCLUSION

Page 9: SICS Seminar, May 29 2001

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 401234

Page 10: SICS Seminar, May 29 2001

Examples of Forbidden Regions

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

0X40Y40R9

X

Y

0 1 2 3 401234

X

Y

0 1 2 3 401234

X

Y

0 1 2 3 401234

0X4 0Y4

0X4 0Y40T2 0U3

X

Y

0 1 2 3 401234

0X4 0Y4

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

X

Y

0 1 2 3 401234

0X4 0Y41S6

X+2YS

X+2T

T+3X

Y+4U

U+2Y X+Y0 (mod 2)

Page 11: SICS Seminar, May 29 2001

get_first_forbidden_regions(X,Y,Ctr)

get_next_forbidden_regions(X,Y,Ctr,Previous)

get_last_forbidden_regions(X,Y,Ctr)

get_prev_forbidden_regions(X,Y,Ctr,Previous)

check_if_in_forbidden_regions(x,y,Ctr)

Primitives for Getting Forbidden Regions on Request

X

Y

0 1 2 3 401234

get_first_forbidden_regions

X

Y

0 1 2 3 401234

get_next_forbidden_regions

X

Y

0 1 2 3 401234

get_next_forbidden_regions

max(Y)

X

Y

0 1 2 3 401234

min(X) max(X)

min(Y)

X+Y0 (mod 2)

Page 12: SICS Seminar, May 29 2001

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 13: SICS Seminar, May 29 2001

Sweep Line Status

Y

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

Y

X

sweep line status

121111

X

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

Page 14: SICS Seminar, May 29 2001

Possible Utilisations

Feasibility check

Adjusting bounds

Pruning values

X

Y

X

Y

X

Y

Page 15: SICS Seminar, May 29 2001

Y

X = 001234

An Example

0X4 0Y4

1S6 0T2

0U3

alldifferent({X,Y,R})

|X-Y|>2

X+2YS

X+2T T+3X

Y+4U U+2Y

X+Y0 (mod 2)

PROBLEM:

Adjust minimum of X

according to Y and to

all following constraints:

alldifferent({X,Y,R})

|X-Y|>2

X+2YS

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

X+Y0 (mod 2)

Page 16: SICS Seminar, May 29 2001

Y

x=001234

Y

01234

X = 1

alldifferent({X,Y,R})

|X-Y|>2

X+2YS

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

X+Y0 (mod 2)

An Example

0X4 0Y4

1S6 0T2

0U3

alldifferent({X,Y,R})

|X-Y|>2

X+2YS

X+2T T+3X

Y+4U U+2Y

X+Y0 (mod 2)

PROBLEM:

Adjust minimum of X

according to Y and to

all following constraints:

Page 17: SICS Seminar, May 29 2001

Y

X=001234

Y

01234

X=1

Y

01234

X=2

Y

01234

X=3

Y

01234

X = 4

An Example

0X4 0Y4

1S6 0T2

0U3

alldifferent({X,Y,R})

|X-Y|>2

X+2YS

X+2T T+3X

Y+4U U+2Y

X+Y0 (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+2YS

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

X+Y0 (mod 2)

Page 18: SICS Seminar, May 29 2001

Typical Constraint Structure for Applying Sweep

• A R G U M E N T

• R E S T R I C T I O N (S)

• V E R T E X I N P U T

• V E R T E X G E N E R A T O R

• E D G E I N P U T

• E D G E G E N E R A T O R

• E D G E A R I T Y

• E D G E C O N S T R A I N T

• G R A P H P R O P E R T Y

: OBJECTS: collection(X-dvar,Y-dvar,...)

: required(OBJECTS.X,OBJECTS.Y)

: OBJECTS

: IDENTITY

: OBJECTS

: CLIQUE()

: 2

:

: NEDGE = |OBJECTS|.|OBJECTS| - |OBJECTS|

X1,Y1 X2,Y2

X3,Y3X4,Y4

Non-overlapping Scheduling with set-up Cyclic scheduling

Page 19: SICS Seminar, May 29 2001

Evaluation of the Filtering Algorithm forthe Non-Overlapping Rectangles Constraint

Worst case complexityMemory consumption

: n2 log(n): no trail

Empirical evaluation

Time in msec for finding a first solution for 100 rectangles(SICStus Prolog gcc -O2 248Mhz UltraSPARC-II, Solaris 7)

Random small size

LooseSquares of sizes

Incomparable rectangles

Rectangles of same size

Mostly fixed

Set 1 Set 2 Set 3 Set 4 Set 5 Set 6

cardinality 113830 5110 508150 382870 9751490 1940

cons.disj. 5300 210 44190 16330 590890 10

diffn 600 140 690 1030 520 10

sweep 260 170 300 350 120 10

Page 20: SICS Seminar, May 29 2001

INTRODUCTION

• Sweep Algorithms in Computational Geometry

• Main Ideas of Sweep Algorithms

CONJUNCTION OF CONSTRAINTS

• Representing an Elementary Constraint: Forbidden Regions

• The Sweep Algorithm

CARDINALITY OPERATOR

• Representing an Elementary Constraint: Forbidden and Safe Regions

• The Sweep Algorithm

NON-OVERLAPPING CONSTRAINT BETWEEN CONVEX POLYGONS

• The Forbidden Polygon

• The Sweep Algorithm

CUMULATIVES CONSTRAINT

• Definition of the Cumulatives Constraint

• The Sweep Algorithm

SUMMARY AND CONCLUSION

Page 21: SICS Seminar, May 29 2001

A Restricted Case of the cardinality Operator

The cardinality operator, Van Hentenryck, P., Deville, Y. (ICLP 1991):

: C = CTRj(V1,.., Vm )

A restricted case of the cardinality operator :

j=1

n • Definition

• Pruning

• Restriction

• Pruning

: 2 variables X and Y occur in each constraint CTRj

j

considers interaction between constraints

(through the shared variables):

: based oncounting

entailment

Page 22: SICS Seminar, May 29 2001

Forbidden and Safe Regions

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 4012340 X 4

0 Y 41 S 6

X + 2Y S

EXAMPLE

Page 23: SICS Seminar, May 29 2001

Sweep Line Status

For each y dom(Y): number of safe regions number of forbidden regionscontaining the point (,y)

Y

X

sweep line status

Y

1,01,10,10,11,01,0

X

Remove a value dom(X) if for all y dom(Y): nsafe[y]..nctrnforbidden[y] C =

Forbidden regions

Safe regions

Page 24: SICS Seminar, May 29 2001

An Example

0X4 0Y4

2Z3

1S6 0T0

1U2

alldifferent({X,Y,R})

|X-Y|>Z

X+2YS

X+3T T+1X

Y+3U U+4Y

X+Y0 (mod 2)

PROBLEM:

Adjust minimum of X

according to Y and to the

fact that 4 or 5 constraints

should hold:

alldifferent({X,Y,R})

|X-Y|>Z

X+2YS

X+1T T+1X Y+1U U+4Y

X+Y0 (mod 2)

Y

X=001234

Y

01234

X=2

Y

01234

X=1

Deduction:

X>1

Page 25: SICS Seminar, May 29 2001

INTRODUCTION

• Sweep Algorithms in Computational Geometry

• Main Ideas of Sweep Algorithms

CONJUNCTION OF CONSTRAINTS

• Representing an Elementary Constraint: Forbidden Regions

• The Sweep Algorithm

CARDINALITY OPERATOR

• Representing an Elementary Constraint: Forbidden and Safe Regions

• The Sweep Algorithm

NON-OVERLAPPING CONSTRAINT BETWEEN CONVEX POLYGONS

• The Forbidden Polygon

• The Sweep Algorithm

CUMULATIVES CONSTRAINT

• Definition of the Cumulatives Constraint

• The Sweep Algorithm

SUMMARY AND CONCLUSION

Page 26: SICS Seminar, May 29 2001

A Family of Polygons

P1

X

Y

Polygon P1

with an origin X,Y D1

Polygon D1 for the domain of the origin of P1

Translations of P1 withorigin within D1

Page 27: SICS Seminar, May 29 2001

Shadow Polygon

P2

P2

P1

Shadow polygon: P1 + (P2)

If the origin of P2 is situated within the shadow polygon then P2 overlap P1

If the origin of P2 is situated outside the shadow polygon then P2 do not overlap P1

Page 28: SICS Seminar, May 29 2001

Forbidden Polygon

Forbidden(P1,P2)

E1

E2

E3E4E1E2

E3E4

Extremum polygons of P1

according to its domain D1

If the origin of P2 is situated within the forbidden polygon then P2 overlap any translation of P1

So, prune the origin variables of P2 with a sweep algorithm

Page 29: SICS Seminar, May 29 2001

GOAL: prune the x-coordinate Ox of the origin of P2 in order to

avoid the origin to be located within Forbidden(P1,P2)

(Domain(P2)\Forbidden(P1, P2)• ) Lx0

does not contain any point with

integer coordinates

Pruning Condition

NECESSARY CONDITION for pruning x0 from Ox:

Forbidden(P1,P2)Domain(P2)

Dupper(x0)

Dlower(x0)

Fupper(x0)

Flower(x0)

x0

Lx0

P2

Ox

Page 30: SICS Seminar, May 29 2001

Sweep Algorithm(continuous case)

Event points:

Vertices of the two polygons

Proper intersection between two edges

Sweep Status:

x0

the 4 edges that are intersected by Lx0

the 4 y-coordinates of the intersected points

Page 31: SICS Seminar, May 29 2001

INTRODUCTION

• Sweep Algorithms in Computational Geometry

• Main Ideas of Sweep Algorithms

CONJUNCTION OF CONSTRAINTS

• Representing an Elementary Constraint: Forbidden Regions

• The Sweep Algorithm

CARDINALITY OPERATOR

• Representing an Elementary Constraint: Forbidden and Safe Regions

• The Sweep Algorithm

NON-OVERLAPPING CONSTRAINT BETWEEN CONVEX POLYGONS

• The Forbidden Polygon

• The Sweep Algorithm

CUMULATIVES CONSTRAINT

• Definition of the Cumulatives Constraint

• The Sweep Algorithm

SUMMARY AND CONCLUSION

Page 32: SICS Seminar, May 29 2001

The cumulative Constraint

The original cumulative constraint[Aggoun & Beldiceanu 92]:

Restrict the resource consumptionat 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

01

2

34

12

3 4

time

resource consumption 4

time

resource consumption

1 2 3 4 5 6-2

-1

0

1

2

-1

0

1

Cumulatedprofiles

2

13

45

7

6 0

0

Page 33: SICS Seminar, May 29 2001

time

resource consumption

-2

-1

0

1

2

-1

0

1

3

5

7

6 0

0

Machine 1

Machine 2

1

2

4

For all tasks :

For all time-points crossed by task :

Let be the machine where task is assigned ,

For all tasks that both cross point , and are assigned to :

The sum of the height of tasks is not greater (less)

than the capacity of machine .

DEFINITION

1 2 3 4 5 6

t

t

t

i

m

s i m

m

EXAMPLE

s

Page 34: SICS Seminar, May 29 2001

The Sweep Algorithm: Fixed Tasks

resource

timeEvent pointsMinimum level to reach

for those instants wherethere is at least one task

Current positionof the sweep line: 3

Sweep-linestatus

nb_task=2 sum_height=3

01234

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

• that overlap the sweep line

Event points:

start of each task

end of each task

Page 35: SICS Seminar, May 29 2001

The Sweep Algorithm: Not Yet Fixed Tasks

Preconditions for a Check Event

max(origin[t])<min(end[t])

min(machine[t])=max(machine[t])=r

max(height[t])<max(0,Limit[m])

machine[t]

: nb_task=nb_task+1

: nb_task=nb_task1

Start

End

QUESTIONANSWER

ACTION

: which instants to check ?: those instants for which there is a task that can cause a problem

: count the number of such tasks that overlap the sweep line

Page 36: SICS Seminar, May 29 2001

The Sweep Algorithm: Not Yet Fixed Tasks

Preconditions for a Bad Profile Event

max(origin[t]) < min(end[t])

min(machine[t]) = max(machine[t]) = r

max(height[t]) < 0

r

: sum_height=sum_height+max(height[t])

: sum_height=sum_height max(height[t])

Start

End

QUESTIONANSWER

ACTION

: how to build an ”optimistic” resource consumption profile ?: consider the ”bad” and ”good” tasks

: sum up the height of such tasks that overlap the sweep line

Preconditions for a Good Profile Eventr dom(machine[t])

max(height[t]) > 0

r

: sum_height=sum_height+max(height[t])

: sum_height=sum_height max(height[t])

Start

End

Page 37: SICS Seminar, May 29 2001

The Sweep Algorithm: Main Loop(simplified version: one resource, no pruning)

1. Scan the tasks and generate the check and profile events

2. Sort the events in increasing order

3. Set nb_task and sum_height to 0 and d to the smallest date

4. while there still exist an event E do

5. if ddate of E then

6. if nb_task0 and sum_height<limit to reach then return fail

7. Set d to date of E

8. if type of E=check then add E.inc to nb_task else add E.inc to sum_height

9. Extract the next event E (if it exists)

10. if nb_task0 and sum_height<limit to reach then return fail

INITIALIZATION

CHECK

MODIFY SWEEP STATUS

CHECK

Page 38: SICS Seminar, May 29 2001

INTRODUCTION

• Sweep Algorithms in Computational Geometry

• Main Ideas of Sweep Algorithms

CONJUNCTION OF CONSTRAINTS

• Representing an Elementary Constraint: Forbidden Regions

• The Sweep Algorithm

CARDINALITY OPERATOR

• Representing an Elementary Constraint: Forbidden and Safe Regions

• The Sweep Algorithm

NON-OVERLAPPING CONSTRAINT BETWEEN CONVEX POLYGONS

• The Forbidden Polygon

• The Sweep Algorithm

CUMULATIVES CONSTRAINT

• Definition of the Cumulatives Constraint

• The Sweep Algorithm

SUMMARY AND CONCLUSION

Page 39: SICS Seminar, May 29 2001

Summary

Conjunctionof constraints

Cardinalityoperator

Non-overlappingbetween polygons

Cumulativesconstraint

Sweep axis Event points Sweep status

domain of the variable to prune

time axis

start of forbidden regions end of forbidden regions

task earliest start task latest start task earliest end task latest end

# of forbidden regions

# of forbidden regions # of safe regions contradiction

# of tasks to check cumulated height of the optimistic profile

start of forbidden regions end of forbidden regions start of safe regions end of safe regions

domain of the variable to prune

domain of the variable to prune

vertices of the forbidden and domain polygons edges proper intersection

the 4 edges intersected by the sweep line the 4 y-coordinates of the 4 intersected points

Page 40: SICS Seminar, May 29 2001

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 and to open global constraints)

• Worst case complexity of the algorithms could perhaps be improved

(for instance by using specialized data structures for searching the relevant regions)

• May become a standard technique for constraint solving

(there may exist other utilisations of sweep algorithms for constraint propagation)

Page 41: SICS Seminar, May 29 2001

Further Sources of Information

http://www.sics.se/libindex.html Sweep as a Generic Pruning Technique Applied to the Non-Overlapping Rectangles

Constraint, [Beldiceanu,Carlsson 2001] .

Sweep as a Generic Pruning Technique Applied to Constraint Relaxation,

[Beldiceanu,Carlsson 2001] . (in preparation)

Non-overlapping Constraints between Convex Polytopes, [Beldiceanu,Guo,Thiel 2001] .

A New Multi-Resource cumulatives Constraint with Negative Heights,

[Beldiceanu,Carlsson 2001] .

http://www.sics.se/sicstus/

Implementation of different variants of the non-overlapping rectangles constraint,

Implementation of the multi-resource cumulatives constraint.