/* "$Header: /tmp_mnt/vida/disks/disk5/Users/terry/r/gassy/RCS/public.h,v 1.12 1992/10/09 06:43:50 terry Exp terry $ */ /* * Here are a bunch of things that are of use to Gassy functions and * to applications. */ #include #include #include /* * These 3 return 1 if it is time to mutate or crossover * or to choose the fitter individual in tournament selection. */ extern DOUBLE knuth_random(); #define DO_MUTATE (knuth_random() < context->mutation_prob) #define DO_CROSSOVER (knuth_random() < context->crossover_prob) #define DO_TOURNAMENT (knuth_random() < context->tournament_prob) #define DO_UNIFORM (knuth_random() < context->uniform_prob) /* This returns [0, n - 1] */ #define uniform(n) ((int) (knuth_random() * (double)(n))) /* * Returns true if a random double is less than the given probability. */ #define biased_coin_flip(prob) (knuth_random() < (prob)) extern VOID error(); extern VOID usage(); extern STRING Malloc(); #if defined(ultrix) || defined(NeXT) extern char *strdup(); #else extern int _flsbuf(); extern int fflush(); extern int printf(); extern int fprintf(); extern char *sprintf(); #endif #if defined(NeXT) #define malloc lmmm #define free lmmm_free #endif #if defined(sparc) || defined(mc68020) extern int printf(); extern int fprintf(); #endif #if defined(APP_FITNESS_IS_AN_INT) #define STR_TO_FITNESS atoi #define print_fitness(fp, width, fitness) fprintf(fp, "%*d", (width), (fitness)) #endif #if defined(APP_FITNESS_IS_A_SHORT) #define STR_TO_FITNESS atoi #define print_fitness(fp, width, fitness) fprintf(fp, "%*d", (width), (fitness)) #endif #if defined(APP_FITNESS_IS_A_LONG) #define STR_TO_FITNESS atol #define print_fitness(fp, width, fitness) fprintf(fp, "%*ld", (width), (fitness)) #endif #if defined(APP_FITNESS_IS_A_DOUBLE) #define STR_TO_FITNESS atof #define print_fitness(fp, width, fitness) fprintf(fp, "%*f", (width), (fitness)) #endif #if defined(APP_FITNESS_IS_A_FLOAT) #define STR_TO_FITNESS (FLOAT)atof #define print_fitness(fp, width, fitness) fprintf(fp, "%*f", (width), (fitness)) #endif #if defined(APP_FITNESS_IS_A_CHAR) #define STR_TO_FITNESS char_to_string #define print_fitness(fp, width, fitness) fprintf(fp, "%c", (fitness)) #endif #define VADDR(x) ((VOID *) (&(x)))