600 likes | 1.02k Views
Genetic Algorithms (GA). A class of probabilistic search algorithms. Inspired by natural genetics and biological evolution. Uses concept of “survival of fittest”. GA originally developed by John Holland (1975). GA –general concepts. Iterative procedure(iterative improvement)
E N D
Genetic Algorithms (GA) • A class of probabilistic search algorithms. • Inspired by natural genetics and biological evolution. • Uses concept of “survival of fittest”. • GA originally developed by John Holland (1975)
GA –general concepts • Iterative procedure(iterative improvement) • Produces a series of “generations of populations” one per iteration • Each member of a population represents a feasible solution,called a chromosome.
1 p1 Combine and die(mating) bag chromosomes 2 P3 3 evolution K Pk m Chromosome-a feasible solution Selection crossover mutation
The population during iteration of GA is denoted by the “bag” Pi={X1i,X2i,……..,Xni}. Xmi denotes the m th member of the population in i th iteration and n is the size of the population. Pi;is a bag ,not a set,hence can contain repeated solutions, i.e. all entries need not be unique. • Initial population P1,may be created randomly or by a deterministic (constructive) heuristic. • Cost(x) is the cost of solution x.This function is user supplied.
Assume cost(x)>=0 V X. • Let fitness of (x) =1/1+cost(x), thus V x, 0<=fitness(x)<=1. • Average-fitness(Pi)=Σ fitness(xji) • Best-fitness(Pi) =max{fitness(xji)} • Going from P1 to P2 to P3….. is called “evolution”. • Goal:ensure that it is highly likely that average-fitness(Pi)>average-fitness(Pj) for i>j. • We go from Pi to Pi+1 via an evolution function that usually consists of three components called operators.
Operators • Selection: select some members of current population to move to the next generation.Try to select “highly fit “ solutions. • Use an (imaginary) roulette wheel technique. • Fitness of .37 => 37% Area is Proportional to fitness value 1 2 n 3 4
Example Chromosome fitness A .21 B .14 C .10 D .02 E .33 F .20 ----------- 1.00 B 14% A 21% 10% C D 2% F 20% E 33%
1) When wheel is turned and eventually stops,probability of stopping at A is 0.21 2) The function select-roulette(f) spins roulette wheel by a random degree(uniform between 0 and 2) and returns a chromosome – the one pointed to by the arrow head
Crossover • Crossover operators combine features of highly fit members of a population to create new members. • First select two unique parents(chromosome) • Say Xa and Xb using select-roulette(). • Divide parents into two parts; Xa < Xa1 , Xa2> Xb < Xb1 , Xb2> • Exchange to get < Xa1 , Xb2>< Xb1 , Xa2>
This is a mating process of highly fit members. • Example: • Often bit strings are used to represent a chromosome. Xa;100011;1110 ya;100011;1010 Xb;101010;1010 yb;101010;1110
Mutation • Mutation operators randomly alters structure of chromosome. • Pm - user supplied probability .Select a chromosome with probability,Pm usually;.05<Pm<0.2. • Mutation used to introduce new features into a population.
Inversion: • Third operator of GA • Like Mutation, it also operates on a single chromosome. • To laterally invert the order of alleles between two randomly chosen points on chromosome. • Example: Given String: 0 1 2: 3 4 5 6 7: 8 b i d:e f g c h: a Will Become: b i d:h c g f e: a
Representation • Often a chromosome is encoded as a bit stream. The actual representation might be a structure,such as a floorplan, placement or route(wire). • By operating on bitstream one can generate a bit stream that doesn’t correspond to a legal structure. • Thus non bit string representations are often used including graphs and lists.
Solving the logic partitioning problem via a GA • Problem formulation • K chips • Each has area Amax • Each has thermal capacity Hmax • Each has Pm capacity Pmax • Design represented by a graph G=(V,E) • Each mode v V represents a gate and has areaA(v),heat dissipation H(v). • Each hyperedge e is a subset of modes of V.(e represents a signal.)
Partition V into disjoint subsets V1,V2,…..,Vk so that For i=1,2,3,….kPi ={e E | (v,w) e such that v Vi and w Vi}| <= PmaxAi = Σ A(v) <= Amax v Vi Hi = Σ H(v) <= Hmax v Vi See algorithm1Encoding:Use double link list to tie together one chip to next chip,and elements(gates)within a chip.
Algorithm 1 (Genetic Algorithm) n : population sizePs : selection percentagePc: crossover percentage/*100 – Ps*/Pm: mutation probability thresholdPk: population bag belonging to iteration k
GA (n,Ps,Pm) begin best_fitness 0;best_solution null;Po create_initial_population(n);i0;/* generation counter*/ repeat for each member xPi do fitness1/(1+cost(x)); if (fitness > best_fitness) then best_solution x; best_fitness fitness; end if; end for; if (user-specified exit condition is satisfied) then exit else Pi+1evolve(Pi,n,Ps,Pm); ii+1 ; end if;forever;end;
function evolve(p,n,Ps,Pm); bs : bag of solutions selected bc : bag of solutions crossed over bm : the bag bs bc after mutation begin bs select(p,n,Ps); bc crossover(p,n-|bs|); bm mutate(bs bc,n,Pm); return(bm); end;
function select(p,n,Ps) begin bs {}; i 0; while(i<Ps *n) do x select_roulette(p); bs bs {x}; ii+1; end while; return(bs) end;
function crossover(p,c) begin bc {}; i 0; while(i<c) repeat x1 select_roulette(p); x2 select_roulette(p); untill (x1 x2) <y1,y2> crossover(x1,x2); bc bc {y1}; ii+1; if (i<c) then bc bc {y2}; i i+1; end if; end while; return(bc); end;
function mutate(p,n,Pm) begin bm {}; for each member xp if random(0,1) Pm then bm bm{mutate(x)}; else bm bm {x}; end if; end for; return(bm); end;
Figure 1: Representation scheme for a structure Chip0 R2 R7 R12 chip1 R0 R11 chip2 R1 R5 R6 R14 R15 chip3 R8 R10 chip4 R3 R4 R9 R13 Ri:components of a design(gates)
Crossover Figure 2 shows that emphasizing a simple crossover can produce an illegal(illogical) child(partition). For example chip 3 of child one has two R12 entries. In addition R14 occurs in both chip 1 and chip3. There are two ways to avoid illogic structures. 1.Use a cost function that penalizes illogical structures so they die a natural death within a few generations. 2.Use a crossover operator that does not produce illogical structures. We will use the “uniform crossover” operator that is in the second category. We split two parents into distinct parts and exchange the parts to form two child structures.
Parent 1 Illegal structures produced by simple crossover Child 1 chip0 R0 R1 R2 R3 chip0 R0 R1 R2 chip1 R4 R5 chip1 R4 R5 R9 R11 R14 R15 chip2 R6 R7 R8 R9 R10 R11 chip2 R6 R7 R8 chip3 R12 R13 R14 R15 chip3 R12 R13 R14 R10 R12 Child 2 Parent 2 chip0 R5 R8 R3 chip0 R5 R8 chip1 R0 R2 R3 chip1 R0 R2 R3 R9 R11 R14 R15 chip2 R1 R13 R9 R10 R11 chip2 R1 R13 chip3 R4 R6 R7 R15 chip3 R4 R6 R7 R10 R12
Uniform Crossover ·For each gate i in the design,let Cx(i) denote the chip that contains gate i in structure (chromosome X). The children are constructed as follows. Cy1(i) = Cx1(i) if T(i) =1 Cx2(i) otherwise Cy2(i) = Cx1(i) if T(i)=0 Cx2(i) otherwise ·Thus child Y1 is produced by assigning the i th gate to the same structure as in the parent X1(X2) when T(i)=1(T(i)=0). Child Y2 is produced by reversing the roles of the parents
chip0 R0 R4 R5 R11 chip0 R1 R9 R11 chip1 R1 R2 R6 R9 R10 chip1 R3 R4 R5 R6 R7 chip2 R3 R7 R8 chip2 R0 R2 R8 R10 Parent 1 Parent 2 Template for crossover 0 1 2 3 4 5 6 7 8 9 10 11 chip0 R0 R1 R4 R11 chip0 R5 R9 R11 chip1 R3 R5 R6 R7 R9 chip1 R1 R2 R4 R6 R10 chip2 R2 R8 R10 chip2 R0 R3 R7 R8 Child 2 Child 1 Example of uniform crossover
“0’s” “1’s” chip0 R0 R4 R5 R11 chip0 R1 R9 R11 chip1 R1 R2 R6 R9 R10 chip1 R3 R4 R5 R6 R7 chip2 R3 R7 R8 chip2 R0 R2 R8 R10 • Parent 1 Parent 2 Template for crossover 0 1 2 3 4 5 6 7 8 9 10 11 0 0 chip0 R0 R1 R4 R11 chip0 R5 R9 R11 chip1 R3 R5 R6 R7 R9 chip1 R1 R2 R4 R6 R10 chip2 R2 R8 R10 chip2 R0 R3 R7 R8 Child 2 Child 1
“0’s” chip0 R0 R4 R5 R11 chip0 R1 R9 R11 chip1 R1 R2 R6 R9 R10 chip1 R3 R4 R5 R6 R7 chip2 R3 R7 R8 chip2 R0 R2 R8 R10 • Parent 1 parent 2 Template for crossover 0 1 2 3 4 5 6 7 8 9 10 11 0 0 0 chip0 R0 R1 R4 R11 chip0 R5 R9 R11 chip1 R3 R5 R6 R7 R9 chip1 R1 R2 R4 R6 R10 chip2 R2 R8 R10 chip2 R0 R3 R7 R8 Child 2 Child 1
“1’s” chip0 R0 R4 R5 R11 chip0 R1 R9 R11 chip1 R1 R2 R6 R9 R10 chip1 R3 R4 R5 R6 R7 chip2 R3 R7 R8 chip2 R0 R2 R8 R10 • Parent 1 parent 2 Template for crossover 0 1 2 3 4 5 6 7 8 9 10 11 1 1 1 1 chip0 R0 R1 R4 R11 chip0 R5 R9 R11 chip1 R3 R5 R6 R7 R9 chip1 R1 R2 R4 R6 R10 chip2 R2 R8 R10 chip2 R0 R3 R7 R8 Child 2 Child 1
“1’s” chip0 R0 R4 R5 R11 chip0 R1 R9 R11 chip1 R1 R2 R6 R9 R10 chip1 R3 R4 R5 R6 R7 chip2 R3 R7 R8 chip2 R0 R2 R8 R10 • Parent 1 parent 2 Template for crossover 0 1 2 3 4 5 6 7 8 9 10 11 1 1 1 chip0 R0 R1 R4 R11 chip0 R5 R9 R11 chip1 R3 R5 R6 R7 R9 chip1 R1 R2 R4 R6 R10 chip2 R2 R8 R10 chip2 R0 R3 R7 R8 Child 2 Child 1
·T-a binary string whose length is the number of elements to be partitioned.T is also called a template. ·Randomly set the bits in T to 0 and 1. ·Select two parent structures X1 and X2 for mating. Let Y1 and Y2 children resulting from crossover.
Mutations ·Probabilistically select a member of the population. ·Probability Pm of a chromosome being selected.(0.1 Pm 0.2) ·For each selected chromosome (partition),a gate is randomly selected and reassigned to another chip.
Example: In figure1; move R14 from chip2 to chip1. · Cost function (weighted combination of four conflicting cost factors) cost(x) = Σ Δ Ai (x)/Amax + Σ Δ Hi (x)/Hmax + Σ Δ Pi (x)/Pmax + Δ T(x)/Tmax Where Δ Ai = 0 if Ai Amax Ai-Amax otherwise Same for Δ Hi and Δ Pi Fitness(x) = 1/1+cosT(x)
Experimental results ·Compare GA with Fiduccia-Mattheyses(FM) and Simulated Annealing(SA). ·First used large values on pin and area constraints using GA and SA algorithms,and tightened(reduced) the constraints until a feasible solution could not be found. ·For viper SA needed more pins than GA. ·FM is the fastest of the three algorithms.in one case GA is 44 times slower than FM. ·GA is usually slower than SA. ·GA produces better results than SA and FM.
See figure 4 for variations in fitness values with increasing generations. We show ·Best fitness ever: This is the value of the fitness measure of the best fit(least cost) solution seen thus far.This is a non-decreasing function. ·Maximum fitness of generation: This is the value of fitness measure of the best fit solution in the current generation. ·Average fitness of generation: This is the average fitness of all the solutions in the current generation. Average fitness lags best fitness.
Placement via GA ·G=(V,E) – hypergraph. V- gates E- nets ·Assume a Gate Array layout structure. ·Assign(place) each gate to a unique slot(position). ·S= {S1,S2,….Src} set of slots. Slots are arranged into rows and columns;r-rows,c- columns. ·r.c > p - where |v| = p is number of gates. ·For a given placement,its associated length L is given by L = Σ L(e) where L(e) is an estimate of the length of eεE interconnect (wire) needed to route net e. ·Find an assignment so that L is minimal.
Genetic Encoding and operators Encoding ·Assume placement consists of a rectangular grid of slots as shown in the figure on the next slide.
Encoding Dummy Gates Chip Col 0 Col 1 Col 2 Col 3 Col 4 C4 C3 D6 C10 D7 C9 D5 C12 C5 C11 C6 C8 C18 C2 D4 C14 D3 C1 C7 C13 C16 D1 C17 D2 C15 Empty Slot Occupied Slot
C1 (a gate) is in row 1 column 1, etc. • Empty slots are filled with dummy gates that have unique names , zero area, zero heat (power), no connections . • For previous placements the encoding is : C16 , D1 , C17 , D2 , C15 , D3 , C 1 etc. (Reading from bottom to top and left to right)
G H I End D E F A B C Start Encoding Using for Placement
Parent 1 Cross Over Child 1 Parent 2 Child 2 Effect of Single Point Cross Over (Illegal Placements) • A simple one- point crossover operator leads to illegal • placements as shown above.
Child 1 has 2 A’s and 2 B’s , no C or D . • Child 2 has 2 D’s and 2 C’s no A or B • To resolve this, we employ a cycle crossover operator .
Cycle Crossover • Let P1 and P2 denote the 2 parents & C1 and C2 denote the 2 children . • Let P1 , P2 , C1 , C2 arrays be of size r.c
Child C1 is formed by first copying a number of genes (gate positions ) in P1 into C1 , and then filling the rest of the genes in C1 from P2 . First , C1[0] P1[0] Let location i in P1contain the gate that occupies position 0 in P2 Then C1[i]P1[i]. Continue this process . That if we just filled position i in C1 by copying position i in P1 , then we identify the gate in position i in P2 and determine the location j of that gate in P1 and copy that gate to position j in C1 .
This process halts when we get to a gate that has already been copied into C1. This completes a cycle . Subsequently , we fill each unfilled position X in C1 by copying from P2 the gate assignments at X , i.e C1[X]P2[X]. To form C2 carry out the same process while interchanging the role of P1 and P2
P1 = I H B A G D E C F Example P2 = A B C D E F G H I I = 0 1 2 3 4 5 6 7 8 C1 = B C E G H I A D F I C2 = H B G E C A D F Cycle Crossover
C1[0] P1[0] ; so C1[0]=I • P2[0] = A . Location of A in P1 is 3 (i=3) • C1[i] P1[i] ; So C1[3] = A • P2[3] = D . The Location of D in P1 is 5 etc. • The cycle ends when we come back to I . • Then C1[1] P2 [1]= B C1[2] P2[2]= C etc. • Show that this procedure always leads to a legal placement
GA in placement (Module Assignment): • b 4 c 7 e g 1 1 3 6 7 a d i f h 3 2 4 8 • Design given in a form of a graph 7 8 9 d e f 4 5 6 c b i 1 2 3 a g h (b) Partition Definition (c) One possible assignment
GA In-placement cont. • Thus the string (below) represents the solution in (c) 1 2 3 4 5 6 7 8 9 a g h c b i d e f with the fitness value of 1/85. Consider 2-modules g and f with the Manhattan distance of 3 (2 vertically and 1 horizontally) The connection between g and f has a weight of 7, thus for gf we have 7x3=21, doing as above for all assignments (in C) we get 85. Other possible solutions: b d e f i g c h a with fitness 1/110 i h a g b f c e d with fitness 1/95