#ifndef lint static char *rcsid = "$Header: /tmp_mnt/vida/disk5/users/terry/r/gassy/max_ones/RCS/max_ones.c,v 1.1 1992/08/09 22:31:13 terry Exp terry $"; #endif /* * This program tries to find binary strings that consist of all ones. * The length of the strings is given on the command line with the * -length (or -l) option. Fitness is the number of ones in the string. */ #include "types.h" #include "options.h" INT length; OPTION app_options[] = { { "length", "l", INT_OPT, TRUE, LLIMIT(1.0), VADDR(length), "The length of the genome." }, { (STRING) 0, "", 0, FALSE, NO_LIMITS(), (VOID *) 0 } }; INT app_individual_size() { return length; } FITNESS app_evaluate_individual(who, context) INT who; CONTEXT *context; { register INT i; register FITNESS fitness = (FITNESS) 0; register INDIVIDUAL_TYPE genome = context->population[who].genome; for (i = 0; i < length; i++){ if (genome[i] == '1'){ fitness ++; } } return fitness; }