#include "util_hack.h"
#include "cuddInt.h"
Go to the source code of this file.
Defines | |
#define | STOREDD(i, j) storedd[(i)*(numvars+1)+(j)] |
Functions | |
static int make_random | ARGS ((DdManager *table, int lower)) |
static int sift_up | ARGS ((DdManager *table, int x, int x_low)) |
static int build_dd | ARGS ((DdManager *table, int num, int lower, int upper)) |
static int largest | ARGS (()) |
static int rand_int | ARGS ((int a)) |
static int array_hash | ARGS ((char *array, int modulus)) |
static int array_compare | ARGS ((const char *array1, const char *array2)) |
static int PMX | ARGS ((int maxvar)) |
static int roulette | ARGS ((int *p1, int *p2)) |
int | cuddGa (DdManager *table, int lower, int upper) |
static int | make_random (DdManager *table, int lower) |
static int | sift_up (DdManager *table, int x, int x_low) |
static int | build_dd (DdManager *table, int num, int lower, int upper) |
static int | largest () |
static int | rand_int (int a) |
static int | array_hash (char *array, int modulus) |
static int | array_compare (const char *array1, const char *array2) |
static int | find_best () |
static double | find_average_fitness () |
static int | PMX (int maxvar) |
static int | roulette (int *p1, int *p2) |
Variables | |
static char rcsid[] | DD_UNUSED = "$Id: cuddGenetic.c,v 1.1.1.1 2003/02/24 22:23:52 wjiang Exp $" |
static int | popsize |
static int | numvars |
static int * | storedd |
static st_table * | computed |
static int * | repeat |
static int | large |
static int | result |
static int | cross |
Definition at line 104 of file cuddGenetic.c.
static int roulette ARGS | ( | (int *p1, int *p2) | ) | [static] |
static int PMX ARGS | ( | (int maxvar) | ) | [static] |
static int array_compare ARGS | ( | (const char *array1, const char *array2) | ) | [static] |
static int array_hash ARGS | ( | (char *array, int modulus) | ) | [static] |
static int rand_int ARGS | ( | (int a) | ) | [static] |
static int largest ARGS | ( | () | ) | [static] |
static int build_dd ARGS | ( | (DdManager *table, int num, int lower, int upper) | ) | [static] |
static int sift_up ARGS | ( | (DdManager *table, int x, int x_low) | ) | [static] |
static int make_random ARGS | ( | (DdManager *table, int lower) | ) | [static] |
AutomaticStart
static int array_compare | ( | const char * | array1, | |
const char * | array2 | |||
) | [static] |
Function********************************************************************
Synopsis [Comparison function for the computed table.]
Description [Comparison function for the computed table. Returns 0 if the two arrays are equal; 1 otherwise.]
SideEffects [None]
SeeAlso []
Definition at line 666 of file cuddGenetic.c.
00669 { 00670 int i; 00671 int *intarray1, *intarray2; 00672 00673 intarray1 = (int *) array1; 00674 intarray2 = (int *) array2; 00675 00676 for (i = 0; i < numvars; i++) { 00677 if (intarray1[i] != intarray2[i]) return(1); 00678 } 00679 return(0); 00680 00681 } /* end of array_compare */
static int array_hash | ( | char * | array, | |
int | modulus | |||
) | [static] |
Function********************************************************************
Synopsis [Hash function for the computed table.]
Description [Hash function for the computed table. Returns the bucket number.]
SideEffects [None]
SeeAlso []
Definition at line 634 of file cuddGenetic.c.
00637 { 00638 int val = 0; 00639 int i; 00640 int *intarray; 00641 00642 intarray = (int *) array; 00643 00644 for (i = 0; i < numvars; i++) { 00645 val = val * 997 + intarray[i]; 00646 } 00647 00648 return ((val < 0) ? -val : val) % modulus; 00649 00650 } /* end of array_hash */
static int build_dd | ( | DdManager * | table, | |
int | num, | |||
int | lower, | |||
int | upper | |||
) | [static] |
Function********************************************************************
Synopsis [Builds a DD from a given order.]
Description [Builds a DD from a given order. This procedure also sifts the final order and inserts into the array the size in nodes of the result. Returns 1 if successful; 0 otherwise.]
SideEffects [None]
SeeAlso []
Definition at line 512 of file cuddGenetic.c.
00517 { 00518 int i,j; /* loop vars */ 00519 int position; 00520 int index; 00521 int limit; /* how large the DD for this order can grow */ 00522 int size; 00523 00524 /* Check the computed table. If the order already exists, it 00525 ** suffices to copy the size from the existing entry. 00526 */ 00527 if (computed && st_lookup(computed,(char *)&STOREDD(num,0),(char **)&index)) { 00528 STOREDD(num,numvars) = STOREDD(index,numvars); 00529 #ifdef DD_STATS 00530 (void) fprintf(table->out,"\nCache hit for index %d", index); 00531 #endif 00532 return(1); 00533 } 00534 00535 /* Stop if the DD grows 20 times larges than the reference size. */ 00536 limit = 20 * STOREDD(0,numvars); 00537 00538 /* Sift up the variables so as to build the desired permutation. 00539 ** First the variable that has to be on top is sifted to the top. 00540 ** Then the variable that has to occupy the secon position is sifted 00541 ** up to the second position, and so on. 00542 */ 00543 for (j = 0; j < numvars; j++) { 00544 i = STOREDD(num,j); 00545 position = table->perm[i]; 00546 result = sift_up(table,position,j+lower); 00547 if (!result) return(0); 00548 size = table->keys - table->isolated; 00549 if (size > limit) break; 00550 } 00551 00552 /* Sift the DD just built. */ 00553 #ifdef DD_STATS 00554 (void) fprintf(table->out,"\n"); 00555 #endif 00556 result = cuddSifting(table,lower,upper); 00557 if (!result) return(0); 00558 00559 /* Copy order and size to table. */ 00560 for (j = 0; j < numvars; j++) { 00561 STOREDD(num,j) = table->invperm[lower+j]; 00562 } 00563 STOREDD(num,numvars) = table->keys - table->isolated; /* size of new DD */ 00564 return(1); 00565 00566 } /* end of build_dd */
int cuddGa | ( | DdManager * | table, | |
int | lower, | |||
int | upper | |||
) |
AutomaticEnd Function********************************************************************
Synopsis [Genetic algorithm for DD reordering.]
Description [Genetic algorithm for DD reordering. The two children of a crossover will be stored in storedd[popsize] and storedd[popsize+1] --- the last two slots in the storedd array. (This will make comparisons and replacement easy.) Returns 1 in case of success; 0 otherwise.]
SideEffects [None]
SeeAlso []
Definition at line 153 of file cuddGenetic.c.
00157 { 00158 int i,n,m; /* dummy/loop vars */ 00159 int index; 00160 double average_fitness; 00161 int small; /* index of smallest DD in population */ 00162 00163 /* Do an initial sifting to produce at least one reasonable individual. */ 00164 if (!cuddSifting(table,lower,upper)) return(0); 00165 00166 /* Get the initial values. */ 00167 numvars = upper - lower + 1; /* number of variables to be reordered */ 00168 if (table->populationSize == 0) { 00169 popsize = 3 * numvars; /* population size is 3 times # of vars */ 00170 if (popsize > 120) { 00171 popsize = 120; /* Maximum population size is 120 */ 00172 } 00173 } else { 00174 popsize = table->populationSize; /* user specified value */ 00175 } 00176 if (popsize < 4) popsize = 4; /* enforce minimum population size */ 00177 00178 /* Allocate population table. */ 00179 storedd = ALLOC(int,(popsize+2)*(numvars+1)); 00180 if (storedd == NULL) { 00181 table->errorCode = CUDD_MEMORY_OUT; 00182 return(0); 00183 } 00184 00185 /* Initialize the computed table. This table is made up of two data 00186 ** structures: A hash table with the key given by the order, which says 00187 ** if a given order is present in the population; and the repeat 00188 ** vector, which says how many copies of a given order are stored in 00189 ** the population table. If there are multiple copies of an order, only 00190 ** one has a repeat count greater than 1. This copy is the one pointed 00191 ** by the computed table. 00192 */ 00193 repeat = ALLOC(int,popsize); 00194 if (repeat == NULL) { 00195 table->errorCode = CUDD_MEMORY_OUT; 00196 FREE(storedd); 00197 return(0); 00198 } 00199 for (i = 0; i < popsize; i++) { 00200 repeat[i] = 0; 00201 } 00202 computed = st_init_table(array_compare,array_hash); 00203 if (computed == NULL) { 00204 table->errorCode = CUDD_MEMORY_OUT; 00205 FREE(storedd); 00206 FREE(repeat); 00207 return(0); 00208 } 00209 00210 /* Copy the current DD and its size to the population table. */ 00211 for (i = 0; i < numvars; i++) { 00212 STOREDD(0,i) = table->invperm[i+lower]; /* order of initial DD */ 00213 } 00214 STOREDD(0,numvars) = table->keys - table->isolated; /* size of initial DD */ 00215 00216 /* Store the initial order in the computed table. */ 00217 if (st_insert(computed,(char *)storedd,(char *) 0) == ST_OUT_OF_MEM) { 00218 FREE(storedd); 00219 FREE(repeat); 00220 st_free_table(computed); 00221 return(0); 00222 } 00223 repeat[0]++; 00224 00225 /* Insert the reverse order as second element of the population. */ 00226 for (i = 0; i < numvars; i++) { 00227 STOREDD(1,numvars-1-i) = table->invperm[i+lower]; /* reverse order */ 00228 } 00229 00230 /* Now create the random orders. make_random fills the population 00231 ** table with random permutations. The successive loop builds and sifts 00232 ** the DDs for the reverse order and each random permutation, and stores 00233 ** the results in the computed table. 00234 */ 00235 if (!make_random(table,lower)) { 00236 table->errorCode = CUDD_MEMORY_OUT; 00237 FREE(storedd); 00238 FREE(repeat); 00239 st_free_table(computed); 00240 return(0); 00241 } 00242 for (i = 1; i < popsize; i++) { 00243 result = build_dd(table,i,lower,upper); /* build and sift order */ 00244 if (!result) { 00245 FREE(storedd); 00246 FREE(repeat); 00247 st_free_table(computed); 00248 return(0); 00249 } 00250 if (st_lookup(computed,(char *)&STOREDD(i,0),(char **)&index)) { 00251 repeat[index]++; 00252 } else { 00253 if (st_insert(computed,(char *)&STOREDD(i,0),(char *)(long)i) == 00254 ST_OUT_OF_MEM) { 00255 FREE(storedd); 00256 FREE(repeat); 00257 st_free_table(computed); 00258 return(0); 00259 } 00260 repeat[i]++; 00261 } 00262 } 00263 00264 #if 0 00265 #ifdef DD_STATS 00266 /* Print the initial population. */ 00267 (void) fprintf(table->out,"Initial population after sifting\n"); 00268 for (m = 0; m < popsize; m++) { 00269 for (i = 0; i < numvars; i++) { 00270 (void) fprintf(table->out," %2d",STOREDD(m,i)); 00271 } 00272 (void) fprintf(table->out," : %3d (%d)\n", 00273 STOREDD(m,numvars),repeat[m]); 00274 } 00275 #endif 00276 #endif 00277 00278 small = find_best(); 00279 average_fitness = find_average_fitness(); 00280 #ifdef DD_STATS 00281 (void) fprintf(table->out,"\nInitial population: best fitness = %d, average fitness %8.3f",STOREDD(small,numvars),average_fitness); 00282 #endif 00283 00284 /* Decide how many crossovers should be tried. */ 00285 if (table->numberXovers == 0) { 00286 cross = 3*numvars; 00287 if (cross > 60) { /* do a maximum of 50 crossovers */ 00288 cross = 60; 00289 } 00290 } else { 00291 cross = table->numberXovers; /* use user specified value */ 00292 } 00293 00294 /* Perform the crossovers to get the best order. */ 00295 for (m = 0; m < cross; m++) { 00296 if (!PMX(table->size)) { /* perform one crossover */ 00297 table->errorCode = CUDD_MEMORY_OUT; 00298 FREE(storedd); 00299 FREE(repeat); 00300 st_free_table(computed); 00301 return(0); 00302 } 00303 /* The offsprings are left in the last two entries of the 00304 ** population table. These are now considered in turn. 00305 */ 00306 for (i = popsize; i <= popsize+1; i++) { 00307 result = build_dd(table,i,lower,upper); /* build and sift child */ 00308 if (!result) { 00309 FREE(storedd); 00310 FREE(repeat); 00311 st_free_table(computed); 00312 return(0); 00313 } 00314 large = largest(); /* find the largest DD in population */ 00315 00316 /* If the new child is smaller than the largest DD in the current 00317 ** population, enter it into the population in place of the 00318 ** largest DD. 00319 */ 00320 if (STOREDD(i,numvars) < STOREDD(large,numvars)) { 00321 /* Look up the largest DD in the computed table. 00322 ** Decrease its repetition count. If the repetition count 00323 ** goes to 0, remove the largest DD from the computed table. 00324 */ 00325 result = st_lookup(computed,(char *)&STOREDD(large,0),(char 00326 **)&index); 00327 if (!result) { 00328 FREE(storedd); 00329 FREE(repeat); 00330 st_free_table(computed); 00331 return(0); 00332 } 00333 repeat[index]--; 00334 if (repeat[index] == 0) { 00335 int *pointer = &STOREDD(index,0); 00336 result = st_delete(computed, (char **)&pointer,NULL); 00337 if (!result) { 00338 FREE(storedd); 00339 FREE(repeat); 00340 st_free_table(computed); 00341 return(0); 00342 } 00343 } 00344 /* Copy the new individual to the entry of the 00345 ** population table just made available and update the 00346 ** computed table. 00347 */ 00348 for (n = 0; n <= numvars; n++) { 00349 STOREDD(large,n) = STOREDD(i,n); 00350 } 00351 if (st_lookup(computed,(char *)&STOREDD(large,0),(char 00352 **)&index)) { 00353 repeat[index]++; 00354 } else { 00355 if (st_insert(computed,(char *)&STOREDD(large,0), 00356 (char *)(long)large) == ST_OUT_OF_MEM) { 00357 FREE(storedd); 00358 FREE(repeat); 00359 st_free_table(computed); 00360 return(0); 00361 } 00362 repeat[large]++; 00363 } 00364 } 00365 } 00366 } 00367 00368 /* Find the smallest DD in the population and build it; 00369 ** that will be the result. 00370 */ 00371 small = find_best(); 00372 00373 /* Print stats on the final population. */ 00374 #ifdef DD_STATS 00375 average_fitness = find_average_fitness(); 00376 (void) fprintf(table->out,"\nFinal population: best fitness = %d, average fitness %8.3f",STOREDD(small,numvars),average_fitness); 00377 #endif 00378 00379 /* Clean up, build the result DD, and return. */ 00380 st_free_table(computed); 00381 computed = NULL; 00382 result = build_dd(table,small,lower,upper); 00383 FREE(storedd); 00384 FREE(repeat); 00385 return(result); 00386 00387 } /* end of cuddGa */
static double find_average_fitness | ( | ) | [static] |
Function********************************************************************
Synopsis [Returns the average fitness of the population.]
Description []
SideEffects [None]
SeeAlso []
Definition at line 724 of file cuddGenetic.c.
00726 { 00727 int i; 00728 int total_fitness = 0; 00729 double average_fitness; 00730 00731 for (i = 0; i < popsize; i++) { 00732 total_fitness += STOREDD(i,numvars); 00733 } 00734 average_fitness = (double) total_fitness / (double) popsize; 00735 return(average_fitness); 00736 00737 } /* end of find_average_fitness */
static int find_best | ( | ) | [static] |
Function********************************************************************
Synopsis [Returns the index of the fittest individual.]
Description []
SideEffects [None]
SeeAlso []
Definition at line 696 of file cuddGenetic.c.
static int largest | ( | ) | [static] |
Function********************************************************************
Synopsis [Finds the largest DD in the population.]
Description [Finds the largest DD in the population. If an order is repeated, it avoids choosing the copy that is in the computed table (it has repeat[i] > 1).]
SideEffects [None]
SeeAlso []
Definition at line 583 of file cuddGenetic.c.
00585 { 00586 int i; /* loop var */ 00587 int big; /* temporary holder to return result */ 00588 00589 big = 0; 00590 while (repeat[big] > 1) big++; 00591 for (i = big + 1; i < popsize; i++) { 00592 if (STOREDD(i,numvars) >= STOREDD(big,numvars) && repeat[i] <= 1) { 00593 big = i; 00594 } 00595 } 00596 return(big); 00597 00598 } /* end of largest */
static int make_random | ( | DdManager * | table, | |
int | lower | |||
) | [static] |
Function********************************************************************
Synopsis [Generates the random sequences for the initial population.]
Description [Generates the random sequences for the initial population. The sequences are permutations of the indices between lower and upper in the current order.]
SideEffects [None]
SeeAlso []
Definition at line 408 of file cuddGenetic.c.
00411 { 00412 int i,j; /* loop variables */ 00413 int *used; /* is a number already in a permutation */ 00414 int next; /* next random number without repetitions */ 00415 00416 used = ALLOC(int,numvars); 00417 if (used == NULL) { 00418 table->errorCode = CUDD_MEMORY_OUT; 00419 return(0); 00420 } 00421 #if 0 00422 #ifdef DD_STATS 00423 (void) fprintf(table->out,"Initial population before sifting\n"); 00424 for (i = 0; i < 2; i++) { 00425 for (j = 0; j < numvars; j++) { 00426 (void) fprintf(table->out," %2d",STOREDD(i,j)); 00427 } 00428 (void) fprintf(table->out,"\n"); 00429 } 00430 #endif 00431 #endif 00432 for (i = 2; i < popsize; i++) { 00433 for (j = 0; j < numvars; j++) { 00434 used[j] = 0; 00435 } 00436 /* Generate a permutation of {0...numvars-1} and use it to 00437 ** permute the variables in the layesr from lower to upper. 00438 */ 00439 for (j = 0; j < numvars; j++) { 00440 do { 00441 next = rand_int(numvars-1); 00442 } while (used[next] != 0); 00443 used[next] = 1; 00444 STOREDD(i,j) = table->invperm[next+lower]; 00445 } 00446 #if 0 00447 #ifdef DD_STATS 00448 /* Print the order just generated. */ 00449 for (j = 0; j < numvars; j++) { 00450 (void) fprintf(table->out," %2d",STOREDD(i,j)); 00451 } 00452 (void) fprintf(table->out,"\n"); 00453 #endif 00454 #endif 00455 } 00456 FREE(used); 00457 return(1); 00458 00459 } /* end of make_random */
static int PMX | ( | int | maxvar | ) | [static] |
Function********************************************************************
Synopsis [Performs the crossover between two parents.]
Description [Performs the crossover between two randomly chosen parents, and creates two children, x1 and x2. Uses the Partially Matched Crossover operator.]
SideEffects [None]
SeeAlso []
Definition at line 754 of file cuddGenetic.c.
00756 { 00757 int cut1,cut2; /* the two cut positions (random) */ 00758 int mom,dad; /* the two randomly chosen parents */ 00759 int *inv1; /* inverse permutations for repair algo */ 00760 int *inv2; 00761 int i; /* loop vars */ 00762 int u,v; /* aux vars */ 00763 00764 inv1 = ALLOC(int,maxvar); 00765 if (inv1 == NULL) { 00766 return(0); 00767 } 00768 inv2 = ALLOC(int,maxvar); 00769 if (inv2 == NULL) { 00770 FREE(inv1); 00771 return(0); 00772 } 00773 00774 /* Choose two orders from the population using roulette wheel. */ 00775 if (!roulette(&mom,&dad)) { 00776 FREE(inv1); 00777 FREE(inv2); 00778 return(0); 00779 } 00780 00781 /* Choose two random cut positions. A cut in position i means that 00782 ** the cut immediately precedes position i. If cut1 < cut2, we 00783 ** exchange the middle of the two orderings; otherwise, we 00784 ** exchange the beginnings and the ends. 00785 */ 00786 cut1 = rand_int(numvars-1); 00787 do { 00788 cut2 = rand_int(numvars-1); 00789 } while (cut1 == cut2); 00790 00791 #if 0 00792 /* Print out the parents. */ 00793 (void) fprintf(table->out, 00794 "Crossover of %d (mom) and %d (dad) between %d and %d\n", 00795 mom,dad,cut1,cut2); 00796 for (i = 0; i < numvars; i++) { 00797 if (i == cut1 || i == cut2) (void) fprintf(table->out,"|"); 00798 (void) fprintf(table->out,"%2d ",STOREDD(mom,i)); 00799 } 00800 (void) fprintf(table->out,"\n"); 00801 for (i = 0; i < numvars; i++) { 00802 if (i == cut1 || i == cut2) (void) fprintf(table->out,"|"); 00803 (void) fprintf(table->out,"%2d ",STOREDD(dad,i)); 00804 } 00805 (void) fprintf(table->out,"\n"); 00806 #endif 00807 00808 /* Initialize the inverse permutations: -1 means yet undetermined. */ 00809 for (i = 0; i < maxvar; i++) { 00810 inv1[i] = -1; 00811 inv2[i] = -1; 00812 } 00813 00814 /* Copy the portions whithin the cuts. */ 00815 for (i = cut1; i != cut2; i = (i == numvars-1) ? 0 : i+1) { 00816 STOREDD(popsize,i) = STOREDD(dad,i); 00817 inv1[STOREDD(popsize,i)] = i; 00818 STOREDD(popsize+1,i) = STOREDD(mom,i); 00819 inv2[STOREDD(popsize+1,i)] = i; 00820 } 00821 00822 /* Now apply the repair algorithm outside the cuts. */ 00823 for (i = cut2; i != cut1; i = (i == numvars-1 ) ? 0 : i+1) { 00824 v = i; 00825 do { 00826 u = STOREDD(mom,v); 00827 v = inv1[u]; 00828 } while (v != -1); 00829 STOREDD(popsize,i) = u; 00830 inv1[u] = i; 00831 v = i; 00832 do { 00833 u = STOREDD(dad,v); 00834 v = inv2[u]; 00835 } while (v != -1); 00836 STOREDD(popsize+1,i) = u; 00837 inv2[u] = i; 00838 } 00839 00840 #if 0 00841 /* Print the results of crossover. */ 00842 for (i = 0; i < numvars; i++) { 00843 if (i == cut1 || i == cut2) (void) fprintf(table->out,"|"); 00844 (void) fprintf(table->out,"%2d ",STOREDD(popsize,i)); 00845 } 00846 (void) fprintf(table->out,"\n"); 00847 for (i = 0; i < numvars; i++) { 00848 if (i == cut1 || i == cut2) (void) fprintf(table->out,"|"); 00849 (void) fprintf(table->out,"%2d ",STOREDD(popsize+1,i)); 00850 } 00851 (void) fprintf(table->out,"\n"); 00852 #endif 00853 00854 FREE(inv1); 00855 FREE(inv2); 00856 return(1); 00857 00858 } /* end of PMX */
static int rand_int | ( | int | a | ) | [static] |
Function********************************************************************
Synopsis [Generates a random number between 0 and the integer a.]
Description []
SideEffects [None]
SeeAlso []
Definition at line 613 of file cuddGenetic.c.
00615 { 00616 return(Cudd_Random() % (a+1)); 00617 00618 } /* end of rand_int */
static int roulette | ( | int * | p1, | |
int * | p2 | |||
) | [static] |
Function********************************************************************
Synopsis [Selects two parents with the roulette wheel method.]
Description [Selects two distinct parents with the roulette wheel method.]
SideEffects [The indices of the selected parents are returned as side effects.]
SeeAlso []
Definition at line 874 of file cuddGenetic.c.
00877 { 00878 double *wheel; 00879 double spin; 00880 int i; 00881 00882 wheel = ALLOC(double,popsize); 00883 if (wheel == NULL) { 00884 return(0); 00885 } 00886 00887 /* The fitness of an individual is the reciprocal of its size. */ 00888 wheel[0] = 1.0 / (double) STOREDD(0,numvars); 00889 00890 for (i = 1; i < popsize; i++) { 00891 wheel[i] = wheel[i-1] + 1.0 / (double) STOREDD(i,numvars); 00892 } 00893 00894 /* Get a random number between 0 and wheel[popsize-1] (that is, 00895 ** the sum of all fitness values. 2147483561 is the largest number 00896 ** returned by Cudd_Random. 00897 */ 00898 spin = wheel[numvars-1] * (double) Cudd_Random() / 2147483561.0; 00899 00900 /* Find the lucky element by scanning the wheel. */ 00901 for (i = 0; i < popsize; i++) { 00902 if (spin <= wheel[i]) break; 00903 } 00904 *p1 = i; 00905 00906 /* Repeat the process for the second parent, making sure it is 00907 ** distinct from the first. 00908 */ 00909 do { 00910 spin = wheel[popsize-1] * (double) Cudd_Random() / 2147483561.0; 00911 for (i = 0; i < popsize; i++) { 00912 if (spin <= wheel[i]) break; 00913 } 00914 } while (i == *p1); 00915 *p2 = i; 00916 00917 FREE(wheel); 00918 return(1); 00919 00920 } /* end of roulette */
static int sift_up | ( | DdManager * | table, | |
int | x, | |||
int | x_low | |||
) | [static] |
Function********************************************************************
Synopsis [Moves one variable up.]
Description [Takes a variable from position x and sifts it up to position x_low; x_low should be less than x. Returns 1 if successful; 0 otherwise]
SideEffects [None]
SeeAlso []
Definition at line 476 of file cuddGenetic.c.
00480 { 00481 int y; 00482 int size; 00483 00484 y = cuddNextLow(table,x); 00485 while (y >= x_low) { 00486 size = cuddSwapInPlace(table,y,x); 00487 if (size == 0) { 00488 return(0); 00489 } 00490 x = y; 00491 y = cuddNextLow(table,x); 00492 } 00493 return(1); 00494 00495 } /* end of sift_up */
Definition at line 90 of file cuddGenetic.c.
int cross [static] |
Definition at line 95 of file cuddGenetic.c.
char rcsid [] DD_UNUSED = "$Id: cuddGenetic.c,v 1.1.1.1 2003/02/24 22:23:52 wjiang Exp $" [static] |
CFile***********************************************************************
FileName [cuddGenetic.c]
PackageName [cudd]
Synopsis [Genetic algorithm for variable reordering.]
Description [Internal procedures included in this file:
Static procedures included in this module:
The genetic algorithm implemented here is as follows. We start with the current DD order. We sift this order and use this as the reference DD. We only keep 1 DD around for the entire process and simply rearrange the order of this DD, storing the various orders and their corresponding DD sizes. We generate more random orders to build an initial population. This initial population is 3 times the number of variables, with a maximum of 120. Each random order is built (from the reference DD) and its size stored. Each random order is also sifted to keep the DD sizes fairly small. Then a crossover is performed between two orders (picked randomly) and the two resulting DDs are built and sifted. For each new order, if its size is smaller than any DD in the population, it is inserted into the population and the DD with the largest number of nodes is thrown out. The crossover process happens up to 50 times, and at this point the DD in the population with the smallest size is chosen as the result. This DD must then be built from the reference DD.]
SeeAlso []
Author [Curt Musfeldt, Alan Shuler, Fabio Somenzi]
Copyright [This file was created at the University of Colorado at Boulder. The University of Colorado at Boulder makes no warranty about the suitability of this software for any purpose. It is presented on an AS IS basis.]
Definition at line 76 of file cuddGenetic.c.
int large [static] |
Definition at line 92 of file cuddGenetic.c.
int numvars [static] |
Definition at line 80 of file cuddGenetic.c.
int popsize [static] |
Definition at line 79 of file cuddGenetic.c.
int* repeat [static] |
Definition at line 91 of file cuddGenetic.c.
int result [static] |
Definition at line 94 of file cuddGenetic.c.
int* storedd [static] |
Definition at line 89 of file cuddGenetic.c.