/* $Header: /tmp_mnt/vida/disks/disk5/Users/terry/r/gassy/RCS/types.h,v 1.4 1992/10/09 06:43:50 terry Exp terry $ */ #include typedef double PROBABILITY; typedef enum {TRUE, FALSE} BOOLEAN; typedef long LONG; typedef char CHAR; typedef CHAR *STRING; typedef int INT; typedef unsigned int UNSIGNED; typedef short SHORT; typedef void VOID; typedef float FLOAT; typedef double DOUBLE; typedef void (*PFV)(); /* Pointer to function that returns VOID. */ typedef void *(*PFPV)(); /* Pointer to function that returns pointer to VOID. */ typedef enum { BOOLEAN_OPT, CHAR_OPT, STRING_OPT, OUTPUT_OPT, INT_OPT, FLOAT_OPT, DOUBLE_OPT, LONG_OPT, FUNC0_OPT, FUNC1_OPT, FITNESS_OPT } OPTION_TYPE; typedef struct { STRING name; STRING abbreviation; OPTION_TYPE type; BOOLEAN required; BOOLEAN has_lower_limit; DOUBLE lower_limit; BOOLEAN has_upper_limit; DOUBLE upper_limit; VOID *address; STRING explanation; } OPTION; typedef enum { DUMP_BOOLEAN, DUMP_INT, DUMP_SHORT, DUMP_CHAR, DUMP_LONG, DUMP_FLOAT, DUMP_DOUBLE, DUMP_FITNESS, DUMP_FILE, DUMP_STRING, DUMP_INDIVIDUAL, DUMP_POPULATION, DUMP_HEADER, DUMP_DUMP_FUNCTION, DUMP_RESTORE_FUNCTION } DUMP_TYPE; typedef struct { DUMP_TYPE type; VOID *address; STRING name; } DUMP_PARAMETER; typedef struct { STRING name; PFPV function; PFV initialization_function; STRING explanation; } FUNCTION; /* * Bring in the application defines after defining the basic types (above) * and before doing anything that uses #if tests on things defined in * the application.h file. */ #include "application.h" /* * Now we can start with the data types that are conditional upon * what sort of application this is. */ #if defined(APP_FITNESS_IS_AN_INT) typedef INT FITNESS; #endif #if defined(APP_FITNESS_IS_A_SHORT) typedef SHORT FITNESS; #endif #if defined(APP_FITNESS_IS_A_LONG) typedef LONG FITNESS; #endif #if defined(APP_FITNESS_IS_A_DOUBLE) typedef DOUBLE FITNESS; #endif #if defined(APP_FITNESS_IS_A_FLOAT) typedef FLOAT FITNESS; #endif #if defined(APP_FITNESS_IS_A_CHAR) typedef CHAR FITNESS; #endif #if defined(APP_HASHING) #include "hash.h" #endif typedef struct { STRING possible_alleles; #if defined(APP_INDIVIDUALS_HAVE_EQUAL_PROB_ALLELES) || (defined(APP_ALLELE_PROBS_CHANGE) && defined(APP_ALLELE_PROBS_CHANGE_TO_EQUAL)) SHORT nalleles; #endif PROBABILITY *probabilities; } LOCUS; #if defined(APP_INDIVIDUALS_ARE_STRINGS) typedef STRING INDIVIDUAL_TYPE; #endif typedef struct { INDIVIDUAL_TYPE genome; #if defined(SCALING) FITNESS unscaled_fitness; #endif FITNESS fitness; BOOLEAN evaluated; #if ! defined(APP_INDIVIDUALS_HAVE_CONSTANT_SIZE) INT genome_size; INT max_genome_size; #endif } INDIVIDUAL; typedef struct { INT best_generation; INDIVIDUAL best_individual; } RUN_STATS; typedef INDIVIDUAL *POPULATION; typedef struct { POPULATION population; POPULATION former_population; INT population_size; #ifndef APP_HAS_CONSTANT_POPULATION_SIZE INT max_population_size; #endif FITNESS total_fitness; INT best_individual_of_generation; FITNESS best_fitness_of_generation; #if defined(APP_INDIVIDUALS_HAVE_CONSTANT_SIZE) INT genome_size; #if defined(APP_INDIVIDUALS_ARE_STRINGS) LOCUS *alleles; INT num_mutatable_loci_in_population; #if defined(APP_ONE_ALLELE_LOCI_ALLOWED) && defined(APP_HAS_CONSTANT_NUM_OF_ONE_ALLELE_LOCI) INT num_mutatable_loci_on_genome; #endif #endif #endif INT run; INT nruns; INT generation; INT ngenerations; INT nselections; PROBABILITY mutation_prob; PROBABILITY crossover_prob; PROBABILITY tournament_prob; PROBABILITY uniform_prob; PROBABILITY generation_gap_prob; BOOLEAN elitist; RUN_STATS *stats; #if defined(APP_HASHING) HASH_TABLE *ht; #endif BOOLEAN hashing; } CONTEXT; /* * And, finally, include files that everyone should have. */ #include "public.h" #include "globals.h" #include "app_externs.h"