Presentation is loading. Please wait.

Presentation is loading. Please wait.

Simulated Annealing in 512 bytes EMICRO2004 Microelectronics School Marcelo Johann B R A Z I L.

Similar presentations


Presentation on theme: "Simulated Annealing in 512 bytes EMICRO2004 Microelectronics School Marcelo Johann B R A Z I L."— Presentation transcript:

1 Simulated Annealing in 512 bytes EMICRO2004 Microelectronics School Marcelo Johann B R A Z I L

2 EMICRO 2004 - Marcelo Johann – SA512.2 minimize total wire length (WL); minimize maximum local congestion (MLC); Placement thanks to Renato Hentschke

3 EMICRO 2004 - Marcelo Johann – SA512.3 General Approaches Abstraction Placement with Overlaps Steps Global Placement Detailed Placement –eliminate overlaps and set exact positions Legalization –Fit into slots, grid position, mirroring

4 EMICRO 2004 - Marcelo Johann – SA512.4 Basic Algorithms Recursive Bisection Cluster Growth, Force-Directed,... General combinatorial optimization: –Simulated annealing, simulated evolution, linear programming, quadratic assignment, resistive networks, neural networks, etc... Analytical Placement –integer programming to spread cells Most used: –simulated annealing, recursive bisection; –multi-level, Analytical;

5 EMICRO 2004 - Marcelo Johann – SA512.5 Simulated Annealing Three basic functions: Temperature Schedule (above), Cost (wire length) and Perturbation (changes in current solution). Perturbation Cost Reject / Accept thanks to Renato Hentschke

6 EMICRO 2004 - Marcelo Johann – SA512.6 S. A. in 512+ bytes #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} Looks crazy, but works!

7 EMICRO 2004 - Marcelo Johann – SA512.7 S. A. in 512+ bytes #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} A big number!!!

8 EMICRO 2004 - Marcelo Johann – SA512.8 S. A. in 512+ bytes #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} Loop a times Read a from stdin Exchange k[a] with k[b]

9 EMICRO 2004 - Marcelo Johann – SA512.9 S. A. in 512+ bytes #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} x,y position of each node

10 EMICRO 2004 - Marcelo Johann – SA512.10 S. A. in 512+ bytes #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} source and target of each arc

11 EMICRO 2004 - Marcelo Johann – SA512.11 Input graph reading: number of cells and wires, number of rows and list of wires (node node) #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} S. A. in 512+ bytes

12 EMICRO 2004 - Marcelo Johann – SA512.12 Input graph reading: number of cells and wires, number of rows and list of wires (node node) initial placement #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} S. A. in 512+ bytes

13 EMICRO 2004 - Marcelo Johann – SA512.13 Cost function: adds the length of all arcs in the graph #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} S. A. in 512+ bytes

14 EMICRO 2004 - Marcelo Johann – SA512.14 Temperature scheduling #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} S. A. in 512+ bytes

15 EMICRO 2004 - Marcelo Johann – SA512.15 Perturbation: exchange a random selected pair of cells #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} S. A. in 512+ bytes

16 EMICRO 2004 - Marcelo Johann – SA512.16 Accepting criteria (inverted) Reject if the cost is higher and the probability is not satisfied #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} S. A. in 512+ bytes

17 EMICRO 2004 - Marcelo Johann – SA512.17 Probabilistic: inversely proportional to the temperature #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z* exp(-d/t) ){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} S. A. in 512+ bytes

18 EMICRO 2004 - Marcelo Johann – SA512.18 Take off cost reports to get your 512-byte SA placer! #include #define z 9999 #define F(a)for(i=0;i<a;++i) #define R(a)scanf("%d",&a); #define T(k)d=k[a];k[a]=k[b];k[b]=d; long a,b,c=0,i,v,e,d,l,X[z],Y[z],E[9*z],G[9*z];double t; w(){int i;d=0;F(e)d+=abs(X[E[i]]-X[G[i]])+abs(Y[E[i]]-Y[G[i]]);return d;} main(){R(v)R(e)R(a)F(v){X[i]=i/a;Y[i]=i%a;}F(e){R(E[i])R(G[i])} for(t=z*a;c++<z*9;t*=.9){F(1){a=rand()%v;b=rand()%v;l=w();T(X)T(Y); if(d=(w()-l)>0)if(rand()%z>z*exp(-d/t)){T(X)T(Y)}}} F(v)printf("%d %d %d %d\n",i,X[i],Y[i],w());} S. A. in 512 bytes

19 Marcelo Johann johann@inf.ufrgs.br www.inf.ufrgs.br/~johann That’s it! EMICRO2004 Microelectronics School Simulated Annealing in 512 bytes


Download ppt "Simulated Annealing in 512 bytes EMICRO2004 Microelectronics School Marcelo Johann B R A Z I L."

Similar presentations


Ads by Google