basic algorithms and techniques

9
1 Basic Algorithms and Techniques (1) ECE 256A 1 Algorithms applicable in solving physical design problems References Simual ated anneal ing and adaptive heu ristics : S. Nahar, S. Sahni an d E. Shrag owitz, “SIMU LATED ANNEALING AND COMBINATORIAL OPTIMIZATION”, Proc. Design Automation Conference, 1986, pp. 293-299. • Books on heur ist ics : Z. Michalewicz, D.B.Foge l, “How to solve It: Mode rn Heuristics”, Sp ringer; 2nd ed. 2004. ECE 256A 2 . , . . , Smart”, Oxford University Press, 2000. Introd uction to Comp utatio nal Geometry : M. T. Good rich, M. R. Ghouset, J.Bright t, “Generalized Sweep Methods for Parallel Computational Geometry”, Proc. ACM Symposium on Parallel Algorithms and Architectures, 1990, pp.280-289. H. Edelsb runner, T opologically Swe eping an A rrangement, Proc. ACM symposium on Theory of computing STOC '86. B. Chazelle, “Computational Geometry: A Retrospective”, Proc. ACM symposium on Theory of computing STO C '94. General approaches Adapt ive heu risti cs Simulated annealing Sequen ce heuristic Other . .. ECE 256A 3 Bra nch and boun d Mathe mati cal Programming Linear Progr amming Intege r Linea r Prog ramming Dynamic prog ramming buffer ins ertion in to a distribut ed RC-tree In many layout systems placement, routing and/or other subtasks of layout generation process are solved by simulated annealing. An example of such a system: Timberwolf - placement and routing syste m for standard cells. ECE 256A 4 Instead of talking about one particular application of simulated annealing, we will consider simulated annealing and combinational optimization in more general terms. Simulated Annealing Physical A nalogy Suppose we want to make a perfect crystal •Perfect = all atoms are lined up on crystal lattice sites; this is the lowest energy state for this set of atoms. ECE 256A 5 Imperfect order has HIGHER energy Perfect order has MINIMUM energy Annealing Physical anneal ing: get t he material very hot Give th e atoms energy to move arou nd Cool i t very s lowl y Gently restrict the range of motion till everything free zes int o (h o efull ) int o lo w ener ECE 256A 6 configuration Annea ling -> simulated anneali ng Model this behav ior computa tiona lly How to compute this l ow energy state How to simulate what the atoms are doing What is the temperature?

Upload: albert-einstein

Post on 10-Apr-2018

217 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: basic algorithms and techniques

8/8/2019 basic algorithms and techniques

http://slidepdf.com/reader/full/basic-algorithms-and-techniques 1/9

Basic Algorithms and Techniques (1)

ECE 256A 1

Algorithms applicable in solvingphysical design problems

References

• Simualated annealing and adaptive heuristics:– S. Nahar, S. Sahni and E. Shragowitz, “SIMULATED

ANNEALING AND COMBINATORIAL OPTIMIZATION”,

Proc. Design Automation Conference, 1986, pp. 293-299.• Books on heuristics:– Z. Michalewicz, D.B.Fogel, “How to solve It: Modern

Heuristics”, Springer; 2nd ed. 2004.– “

ECE 256A 2

. , . . ,Smart”, Oxford University Press, 2000.

• Introduction to Computational Geometry:– M. T. Goodrich, M. R. Ghouset, J.Brightt, “Generalized

Sweep Methods for Parallel Computational Geometry”,Proc. ACM Symposium on Parallel Algorithms andArchitectures, 1990, pp.280-289.

– H. Edelsbrunner, Topologically Sweeping an Arrangement,Proc. ACM symposium on Theory of computing STOC '86.

– B. Chazelle, “Computational Geometry: A Retrospective”,Proc. ACM symposium on Theory of computing STOC '94.

General approaches

• Adaptive heuristics• Simulated annealing

• Sequence heuristic

• Other ...

ECE 256A 3

• Branch and bound

• Mathematical Programming– Linear Programming

– Integer Linear Programming

• Dynamic programming

– buffer insertion into a distributed RC-tree

In many layout systems placement, routing and/or

other subtasks of layout generation process are

solved by simulated annealing.

An example of such a system:

Timberwolf - placement and routing system for

standard cells.

ECE 256A 4

Instead of talking about one particular application of

simulated annealing, we will consider simulated

annealing and combinational optimization in more

general terms.

Simulated Annealing – Physical Analogy

Suppose we want to make a perfect crystal

•Perfect = all atoms are lined up on crystal lattice sites;

this is the lowest energy state for this set of atoms.

ECE 256A 5

Imperfect order has HIGHERenergy

Perfect order has MINIMUMenergy

Annealing 

• Physical annealing: get the material very hot– Give the atoms energy to move around

• Cool it very slowly– Gently restrict the range of motion till everything

freezes into (ho efull ) into low ener

ECE 256A 6

configuration

• Annealing -> simulated annealing– Model this behavior computationally

• How to compute this low energy state

• How to simulate what the atoms are doing

• What is the temperature?

Page 2: basic algorithms and techniques

8/8/2019 basic algorithms and techniques

http://slidepdf.com/reader/full/basic-algorithms-and-techniques 2/9

Annealing - basics

• Metropolis algorithm:

Start with the system in a known configuration,at known energy E;

ECE 256A 7

.to a new location)

If (ΔE <0)

then

else do something 

do something 

Metropolis criterion

• The if-then in the algorithm is “the Metropoliscriterion”

– after perturbing an atom and computing Δenergy, ittells if we keep this new configuration or not

– if Δenergy <0, it is a better state, keep it

ECE 256A 8

– , , ,maybe not – depends on temperature

Temp. T, ΔE >0 Compute e Generate r,= a number in [0,1] a random number in [0,1]

−ΔE/KT

Probability of accepting Compare r and ethis perturbation if (r is smaller)

keep this perturbationelse reject it

−ΔE/KT

Simulated annealing 

• Metropolis algorithm iteratively visits configurationswith “reasonably” probable energies at the given fixedtemperature

• Simulated annealing adds an outer loop that startswith a high temperature and slowly cools it

ECE 256A 9

 sequence of cooling steps to get to thermal equilibrium(ie, do the Metropolis procedure)

• Do enough temperatures so that the problem actuallyfreezes into a low energy state, and further coolingdoes not further lower the energy

Simulated annealing 

Start with the system in a known configuration, at known energy ET= temperature =hot; frozen = false;While (!frozen) {

repeat{Perturb system slightly (move a particle)Compute ΔE, change in energy due to perturbationIf (ΔE < 0

ECE 256A 10

 then accept this perturbation, this is the new system configurationelse accept maybe, with probability e} until (the system is in thermal equilibrium at this T)If (E still decreasing over the last few temperatures)then T=0.9T /* cool the temperature, do more perturbations*/ else frozen = true

}return (final configuration as low energy solution)

-ΔE/T

Relationship between SA and placement

• Combinational optimization problems are like thesephysical systems being coerced into low-E states

Physical system Engineering ProblemSystem with atoms in various Optimization problem

ECE 256A 11

 (x1,x2,…,xn)

Energy Cost metric (eg wire length)

ΔE perturbation Iterative improvement step,Δcost perturbation

Lowest energy ground state Optimum solution

Temperature Hill climbing control parameter

Annealing Simulated annealing

Essential components of annealing algorithm

• State representation– Exactly what are the configurations of solutions to the problem

that will be visited during iterative perturbation

• Cost function– How to measure how good each visited configuration is– This acts as energy in simulated annealing

• Move set– Set oft esof erturbationsdonetoevolve fromone solution

ECE 256A 12

 configuration to the next

• Cooling schedule– Starting temperature (how hot is hot enough?)– Equilibrium condition (when to stop at given temperature?)– Cooling rate ( how fast to cool?)– Frozen criterion (time to quit)

Page 3: basic algorithms and techniques

8/8/2019 basic algorithms and techniques

http://slidepdf.com/reader/full/basic-algorithms-and-techniques 3/9

 Why does annealing work?

• Balls and hills– Simple representation of a combinatorial task

– Can model as a cost surface (landscape)

– The configuration we are visiting now is the ball on the hill

Cost

ECE 256A 13

All possible configurations of system that is being optimized

Greedy iterative improvement

• Only take moves that improve the cost

• Physical analogy: like a quench, cool too fast, or you get poorcrystal

• Can get easily trapped in local minima

Cost

yes

ECE 256A 14

All possible configurations of system that is being optimized(example for only one variable)

never

Simulated annealing 

• Allows probabilistic hill climbing– Suppose temperature T = HOT, Pr(accept) = e

Cost

ΔC/T

MaybeProbably

Definitely

ECE 256A 15

All possible configurations of system that is being optimized(example for only one variable)

Yes, always

Simulated annealing 

• Allows probabilistic hill climbing– Suppose temperature T = COLD, Pr(accept) = e

Cost

ΔC/T

No wayProbably

NOT

Maybe

ECE 256A 16

All possible configurations of system that is being optimized(example for only one variable)

Yes, always

Simulated annealing – some numbers

CostMaybe

Probably

Definitely

Yes, always

ECE 256A 17

All possible configurations of system that is being optimized

Uphill Probability we will accept this moveΔC Hot T=1000 Warm T=100 Cold T=11 0.999 0.99 0.37  100 0.900 0.37 ~01000 0.37 ~0 ~0

Model #2 – landscape flattening 

• Bumpy cost surface

Cost Cost

ECE 256A 18

• As a function of temperature, how much of this cost surface isreachable, if we start from where the ball is?

• T hides obstacles when hot; adaptively smoothes or flattensthese obstacles, so we ignore them at the start

• Cooling restricts us to smaller good areas, obstacles reappear.

Configurations Configurations

Page 4: basic algorithms and techniques

8/8/2019 basic algorithms and techniques

http://slidepdf.com/reader/full/basic-algorithms-and-techniques 4/9

Landscape flattening 

• T=Hot T=Warm

Cost CostEntire cost surface reachable,no hills or obstacles.

Unreachable here, this hill too high atthis lower temperature.

ECE 256A 19

Configurations Configurations

Cost

Configurations

Unreachable here, this hill too highat this yet lower temperature.

Cost

Configurations

• T=Cool T=ColdUnreachable here, this hill too high

at this very cold temperature.

Simulated annealing : a special case of a wider classof adaptive heuristics for combinationaloptimization.

Adaptive : some parameters of the heuristic can bemodified.

Modification of parameters : by the algorithm itselfusing some learning mechanism or by the user.

ECE 256A 20

Optimization pro em

Minimize h ( )

subject to constraints c ( )

Solutions which satisfy c ( ) : feasible solutions ;

A feasible solution which minimizes h ( ) →optimal solution.

The General Adaptive Heuristic

procedure General Adaptive Heuristic

S : = So; /* initial solution */

Initialize heuristic parameters ;

repeat

repeat

ECE 256A 21

New S : = perturb(S) ;

if accept (New S, S) then S: = New S;

until “time to adapt parameters”;

Adapt Parameter ;

until “terminating criterion” ;

end ; /* of the General Adaptive heuristic */

Performance depends on :

* How is S0 generated?

Easy ? difficult ? Which one to choose?

* Form of the acceptance function.

* Criterion which determines that there is a time

ECE 256A 22

to adapt the parameters.

* What is the set of parameters that may beadapted?

* How is the adaptation to be done?

Classical heuristics , such as pairwise exchange

placement algorithm can be modeled in the

general form:

1. Perturbation function is the pairwiseexchange.

2. Acceptance: if h (New S) < h (S) then S : =New S;

“ ”

ECE 256A 23

. me o a ap parame ers : s op mawith respect to a single pairwise exchange.

4. The procedure Adapt Parameters doesnothing.

5. The terminating criterion is : terminate whenthis statement is reached.

procedure Pairwise Exchange Heuristic;

S := S0 ; /*initial solution*/

repeat

NewS is obtained from S by a pairwise exchange;if h(New S) < h(S) then S :=NewS;

ECE 256A 24

 

exchanges;

end; /*of the Pairwise Exchange Heuristic*/

Page 5: basic algorithms and techniques

8/8/2019 basic algorithms and techniques

http://slidepdf.com/reader/full/basic-algorithms-and-techniques 5/9

Simulated Annealing 1. Acceptance :

if (h (New S) <h (S)) or (random < e(h(S)-h(New S))/T)

then accept : = true;

else accept : = false;T is a heuristic parameter called “temperature”

and “random” is a uniformly generated pseudorandom

ECE 256A 25

,

2. “Time to adapt parameters” : number of iterations of theinner repeat loop that have been performed since the lastadaptation.

3. Adapt Parameters : T is updated to α T, α ∈ (0,1);#iterations of the inner loop is changed to β * #iterations,β > 1.

4. Terminating criterion : computer time.

procedure Simulated Annealing;

S := S0 ; /*initial Solution*/

T := T0 ; /*initial temperature*/

iterations := i0; /*initial # of iterations, ≥ 1 */

repeatrepeat

ECE 256A 26

ew := per ur ;

if (h(NewS) <h(S))or (random < e(h(S)-h(New S))/T)

then S := NewS;

until inner loop has been repeated iteration times;

T := α * T; iteration := β * iterations;

until “out of time” ;

end /* of Simulated Annealing */

Quality of particular simulated annealing

application depends on:

* How is S0 generated ?

* What are the values of T0, i0, α, β.

* Computer time.

ECE 256A 27

e can prove a s mu a e annea ng converge

to optimal solutions. We can not tell when the

optimal solutions. We can not tell when the

optimal solution has been reached.

Another heuristic with convergence properly:

procedure RandomSampling ;

S := initial random feasible solution ;

repeat

NewS := another random feasible solution;

ECE 256A 28

if h(NewS)<h(S) then S := NewS ;

until “out of time” ;

end /* of Random Sampling*/

Probabilistic Hill Climbing 

Generalization of simulated annealing to allow

for

ECE 256A 29

– o er empera ure up a e me o s,

– other functions than the exponential used toaccept,

– other criteria to determine what the “inner looptermination” is.

procedure Probabilistic Hill Climbing ;

S := S0 ; /*initial solution*/

T := T0 ; /* initial temperature*/

repeat

repeat

NewS := perturb(S) ;

ECE 256A 30

ew < or random < g(h(S), h(NewS),T))

then S := NewS ;

until “time to terminate the loop”;

update T and the inner loop termination criteria ;

until “out of time” ;

end ; /* of Probabilistic Hill Climbing */

Page 6: basic algorithms and techniques

8/8/2019 basic algorithms and techniques

http://slidepdf.com/reader/full/basic-algorithms-and-techniques 6/9

procedure Sequence Heuristic

S := S0 ; /*initial solution*/

L := L0 ; /* initial sequence length*/

length := 0 ;/* current length of badperturbation sequence*/

repeatrepeat

NewS := perturb(S) ;

ECE 256A 31

if h(NewS)<h(S) then [S := NewS; length :=0;]

else [length := length + 1] ;

until length > L ;

Update Length ;

Update S ;

until “termination criteria” ;

end ; /* of the Sequence */

Experimental studies have shown that:

* A well thought-out heuristic tailored to thespecific problem performs better thanadaptive heuristic.

* Adaptive heuristics perform better when theystart from a “good” S0.

*

ECE 256A 32

 affected by the perturbation function that isused.

* Sequence heuristic performs better thansimulated annealing when time is limited.

Plane Sweep

We start with a very simple problem and a simpleminded solution which is improved step-by-step:

Given a routing channel with terminals at 2 borders:1 2 1

ECE 256A 33

Terminals are labeled with netNames, terminalswith the same name are to be connected.

We ask for the maximal density in the channel(maximal number of nets crossing any column).

2 2

First approach:

For all columns (in any order) count number ofcrossing nets if netNumber > max then max :=netNumber; end

n terminals, N columns => O(n • N)

We spend O(n) time even for empty column

ECE 256A 34

First refinement:For all columnsif not empty then begin count crossing nets;

note maximum; end

We still need to check each column if empty!

Second refinement:

 Jumping from non-empty to non-empty column:Sort terminals according to x;

Cur_terminal := firstTerminal;

Repeat:

cur_x = cur_terminal ↑ . x;

ECE 256A 35

process nets crossing cur_x;

while cur_terminal ↑ . x = cur_x do

cur_terminal := succ (cur_terminal)

until terminals exhausted;

Observation

Density can be calculated incrementally fromchanges at terminal positions:

Nets starting at cur_x : increase

density

ECE 256A 36

ending at cur_x : decrease

density

else : do not changedensity

Page 7: basic algorithms and techniques

8/8/2019 basic algorithms and techniques

http://slidepdf.com/reader/full/basic-algorithms-and-techniques 7/9

Third refinement:Repeat

cur_x := cur_terminal ↑ . x;while cur_terminal ↑ . x = cur_x do

begincase terminal_type offirst : count := count + 1;

ECE 256A 37

note maximum ;last : count := count - 1;other : count unchanged ;

end;cur_terminal := succ (cur_terminal)

until terminals exhausted;

Achievement:

1) Speed O(n • N) → O(n log n)

ECE 256A 38

2) Generalization of the algorithm:

terminals are not required to be an grid.

Abstraction

Initialize;

Repeat

find next relevant position;

rocess events at current osition

ECE 256A 39

 

until set of events empty;

* Maintaining the set of events requires apriority queue; processing of events maygenerate new future events

Processing of events usually includes insertion/

deletion in/ from a “vertical data structure”.

In our simple example:

* priority queue: sorted list, no insertions

required

ECE 256A 40

* y-structure : density counter

“Plane sweep” - actually the algorithm does not

sweep, but jumps.

Some applications:

* Constraint graph generation for compaction;

* Rectangle intersection;

* Line segment intersection;

* Fracturing of polygons;

* Boolean mask operations;

ECE 256A 41

ar ous su as s n c anne r ou ng:(definition of zones, jog insertion);

* Generation of slice structures;

* Channel definition;

* off-line generation of corner-stitching datastructure.

Constraint graph generation

ECE 256A 42

Page 8: basic algorithms and techniques

8/8/2019 basic algorithms and techniques

http://slidepdf.com/reader/full/basic-algorithms-and-techniques 8/9

Input: set of horizontal segments (representing

rectangle center lines) in the plane.

Output: graph with nodes representing segments,

ECE 256A 43

edges representing vertical constraints for

compaction.

Set of generated edges should be small. Generating

an edge for each pair of horizontally overlapping

pair of segments would yield an O(n2) algorithm.

Many constraints would be redundant.

ECE 256A 44

essential

redundant

A simple algorithm that generates ≤ 2nconstraints.

RepeatFind next position cur_x ;for all rectangles r starting at cur_x:

inset r into y-structureLet rtop, rbot be the 2 neighbors in the

-structure

ECE 256A 45

generate edgesr → rbotrtop → r

end;Delete all rectangles ending at cur_x until all rectangles

processed;ECE 256A 46

Still, about 1/2 of generated edges is redundant.

Modified algorithm, avoiding redundantconstraints:

Repeatfind next position cur_x ;

for all rectangles starting at cur_x:insert r into y-structure;

note current neighbors rtop and rbot:

ECE 256A 47

r . top := rtop;r ↑. bot := rbot;update neighbors of rtop, rbot:rbot↑. top := r ;rtop↑. bot := r ;

end ;

for all rectangles r ending at cur_x:

if r↑.top still in y-structure

then generate edge r↑. top → r ;

if r↑.bot still in y-structure

then generate edge r→r↑.bot ;

ECE 256A 48

delete r from y-structure ;

end

until all rectangles processed ;

Page 9: basic algorithms and techniques

8/8/2019 basic algorithms and techniques

http://slidepdf.com/reader/full/basic-algorithms-and-techniques 9/9

Complexity of this algorithm is the same :

O(n log n)

Calculation of longest paths takes O(m) time for

ECE 256A 49

m edges.

Simple, 1 - dimensional compaction (without j o g

generation) can be done in O(n log n) time.