107 static char rcsid[]
DD_UNUSED =
"$Id: cuddGenetic.c,v 1.28 2004/08/13 18:04:48 fabio Exp $";
135 #define STOREDD(i,j) storedd[(i)*(numvars+1)+(j)]
152 static int array_hash (
const char *array,
int modulus);
153 static int array_compare (
const char *array1,
const char *array2);
156 static double find_average_fitness (
void);
158 static int PMX (
int maxvar);
159 static int roulette (
int *p1,
int *p2);
200 double average_fitness;
240 for (i = 0; i <
popsize; i++) {
244 if (computed == NULL) {
252 for (i = 0; i <
numvars; i++) {
267 for (i = 0; i <
numvars; i++) {
283 for (i = 1; i <
popsize; i++) {
308 (void) fprintf(table->
out,
"Initial population after sifting\n");
309 for (m = 0; m <
popsize; m++) {
310 for (i = 0; i <
numvars; i++) {
311 (void) fprintf(table->
out,
" %2d",
STOREDD(m,i));
313 (void) fprintf(table->
out,
" : %3d (%d)\n",
321 average_fitness = find_average_fitness();
322 (void) fprintf(table->
out,
"\nInitial population: best fitness = %d, average fitness %8.3f",
STOREDD(small,numvars),average_fitness);
336 for (m = 0; m <
cross; m++) {
347 for (i = popsize; i <= popsize+1; i++) {
376 int *pointer = &
STOREDD(index,0);
389 for (n = 0; n <=
numvars; n++) {
416 average_fitness = find_average_fitness();
417 (void) fprintf(table->
out,
"\nFinal population: best fitness = %d, average fitness %8.3f",
STOREDD(small,numvars),average_fitness);
464 (void) fprintf(table->
out,
"Initial population before sifting\n");
465 for (i = 0; i < 2; i++) {
466 for (j = 0; j <
numvars; j++) {
467 (void) fprintf(table->
out,
" %2d",
STOREDD(i,j));
469 (void) fprintf(table->
out,
"\n");
473 for (i = 2; i <
popsize; i++) {
474 for (j = 0; j <
numvars; j++) {
480 for (j = 0; j <
numvars; j++) {
483 }
while (used[next] != 0);
490 for (j = 0; j <
numvars; j++) {
491 (void) fprintf(table->
out,
" %2d",
STOREDD(i,j));
493 (void) fprintf(table->
out,
"\n");
571 (void) fprintf(table->
out,
"\nCache hit for index %d", index);
584 for (j = 0; j <
numvars; j++) {
586 position = table->
perm[i];
590 if (size > limit)
break;
595 (void) fprintf(table->
out,
"\n");
601 for (j = 0; j <
numvars; j++) {
630 while (
repeat[big] > 1) big++;
631 for (i = big + 1; i <
popsize; i++) {
682 intarray = (
int *) array;
684 for (i = 0; i <
numvars; i++) {
685 val = val * 997 + intarray[i];
688 return ((val < 0) ? -val : val) % modulus;
711 int *intarray1, *intarray2;
713 intarray1 = (
int *) array1;
714 intarray2 = (
int *) array2;
716 for (i = 0; i <
numvars; i++) {
717 if (intarray1[i] != intarray2[i])
return(1);
741 for (i = 1; i <
popsize; i++) {
764 find_average_fitness(
void)
767 int total_fitness = 0;
768 double average_fitness;
770 for (i = 0; i <
popsize; i++) {
773 average_fitness = (double) total_fitness / (
double)
popsize;
774 return(average_fitness);
829 }
while (cut1 == cut2);
833 (void) fprintf(table->out,
834 "Crossover of %d (mom) and %d (dad) between %d and %d\n",
836 for (i = 0; i <
numvars; i++) {
837 if (i == cut1 || i == cut2) (void) fprintf(table->out,
"|");
838 (void) fprintf(table->out,
"%2d ",
STOREDD(mom,i));
840 (void) fprintf(table->out,
"\n");
841 for (i = 0; i <
numvars; i++) {
842 if (i == cut1 || i == cut2) (void) fprintf(table->out,
"|");
843 (void) fprintf(table->out,
"%2d ",
STOREDD(dad,i));
845 (void) fprintf(table->out,
"\n");
849 for (i = 0; i < maxvar; i++) {
855 for (i = cut1; i != cut2; i = (i == numvars-1) ? 0 : i+1) {
859 inv2[
STOREDD(popsize+1,i)] = i;
863 for (i = cut2; i != cut1; i = (i == numvars-1 ) ? 0 : i+1) {
882 for (i = 0; i <
numvars; i++) {
883 if (i == cut1 || i == cut2) (void) fprintf(table->out,
"|");
884 (void) fprintf(table->out,
"%2d ",
STOREDD(popsize,i));
886 (void) fprintf(table->out,
"\n");
887 for (i = 0; i <
numvars; i++) {
888 if (i == cut1 || i == cut2) (void) fprintf(table->out,
"|");
889 (void) fprintf(table->out,
"%2d ",
STOREDD(popsize+1,i));
891 (void) fprintf(table->out,
"\n");
930 for (i = 1; i <
popsize; i++) {
941 for (i = 0; i <
popsize; i++) {
942 if (spin <= wheel[i])
break;
950 spin = wheel[popsize-1] * (double)
Cudd_Random() / 2147483561.0;
951 for (i = 0; i <
popsize; i++) {
952 if (spin <= wheel[i])
break;
void st__free_table(st__table *table)
static int sift_up(DdManager *table, int x, int x_low)
int st__delete(st__table *table, const char **keyp, char **value)
int st__insert(st__table *table, const char *key, char *value)
static int roulette(int *p1, int *p2)
int cuddNextLow(DdManager *table, int x)
int cuddSifting(DdManager *table, int lower, int upper)
#define ABC_ALLOC(type, num)
int st__lookup_int(st__table *table, char *key, int *value)
int cuddGa(DdManager *table, int lower, int upper)
static st__table * computed
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
static int find_best(void)
static int build_dd(DdManager *table, int num, int lower, int upper)
static int array_hash(const char *array, int modulus)
static int array_compare(const char *array1, const char *array2)
#define ABC_NAMESPACE_IMPL_END
#define ABC_NAMESPACE_IMPL_START
int cuddSwapInPlace(DdManager *table, int x, int y)
static int rand_int(int a)
static ABC_NAMESPACE_IMPL_START char rcsid[] DD_UNUSED
static int make_random(DdManager *table, int lower)
static int PMX(int maxvar)