#ifndef lint static char *rcsid = "$Header: /tmp_mnt/vida/disks/disk5/Users/terry/r/gassy/RCS/new.c,v 1.2 1992/09/22 00:02:54 terry Exp terry $"; #endif #include "types.h" #include "defaults.h" VOID init_context(context) CONTEXT *context; { context->former_population = (POPULATION) 0; context->run = (INT) 1; context->nruns = (INT) 1; context->ngenerations = (INT) 0; context->mutation_prob = DEFAULT_MUTATION_PROB; context->crossover_prob = DEFAULT_CROSSOVER_PROB; context->tournament_prob = DEFAULT_TOURNAMENT_PROB; context->uniform_prob = DEFAULT_UNIFORM_PROB; context->generation_gap_prob = DEFAULT_GENERATION_GAP; context->elitist = FALSE; context->hashing = TRUE; #if defined(APP_INDIVIDUALS_HAVE_CONSTANT_SIZE) && defined(APP_INDIVIDUALS_ARE_STRINGS) context->alleles = (LOCUS *)0; #endif return; } POPULATION new_population(context) CONTEXT *context; { POPULATION new; register INT i; new = (POPULATION) Malloc(context->population_size * sizeof(INDIVIDUAL)); for (i = 0; i < context->population_size; i++){ new[i].fitness = WORST_FITNESS; new[i].evaluated = FALSE; /* * Allocate space for the individuals, if we know how big they are. * If not, do nothing, it will be filled in later by the application * when it creates individuals or by read_population() when it reads * them from a file (this will call some app_ function to do * the reading (in the case where individuals are not strings). */ #if defined(APP_INDIVIDUALS_HAVE_CONSTANT_SIZE) #if defined(APP_INDIVIDUALS_ARE_STRINGS) /* They are constant sized strings. */ new[i].genome = (INDIVIDUAL_TYPE) Malloc(context->genome_size + 1); new[i].genome[context->genome_size] = '\0'; #else /* They are constant sized somethings. */ new[i].genome = (INDIVIDUAL_TYPE) Malloc(context->genome_size); #endif #endif } return new; }