GAULFUNC population *ga_genesis_int( const int population_size, const int num_chromo, const int len_chromo, GAgeneration_hook generation_hook, GAiteration_hook iteration_hook, GAdata_destructor data_destructor, GAdata_ref_incrementor data_ref_incrementor, GAevaluate evaluate, GAseed seed, GAadapt adapt, GAselect_one select_one, GAselect_two select_two, GAmutate mutate, GAcrossover crossover, GAreplace replace, vpointer userdata ) { plog(LOG_FIXME, "Use of ga_genesis_int() is deprecated. Modify code to use ga_genesis_integer() instead."); return ga_genesis_integer( population_size, num_chromo, len_chromo, generation_hook, iteration_hook, data_destructor, data_ref_incrementor, evaluate, seed, adapt, select_one, select_two, mutate, crossover, replace, userdata ); }
int main(int argc, char **argv) { int i; /* Runs. */ population *pop=NULL; /* Population of solutions. */ char *beststring=NULL; /* Human readable form of best solution. */ size_t beststrlen=0; /* Length of beststring. */ for (i=0; i<50; i++) { if (pop) ga_extinction(pop); random_seed(424242*i); pop = ga_genesis_integer( 50, /* const int population_size */ 1, /* const int num_chromo */ 25, /* const int len_chromo */ NULL, /*pingpong_ga_callback,*/ /* GAgeneration_hook generation_hook */ NULL, /* GAiteration_hook iteration_hook */ NULL, /* GAdata_destructor data_destructor */ NULL, /* GAdata_ref_incrementor data_ref_incrementor */ pingpong_score, /* GAevaluate evaluate */ pingpong_seed, /* GAseed seed */ NULL, /* GAadapt adapt */ ga_select_one_randomrank, /* GAselect_one select_one */ ga_select_two_randomrank, /* GAselect_two select_two */ pingpong_mutate, /* GAmutate mutate */ pingpong_crossover, /* GAcrossover crossover */ NULL, /* GAreplace replace */ NULL /* vpointer User data */ ); ga_population_set_parameters( pop, /* population *pop */ GA_SCHEME_DARWIN, /* const ga_scheme_type scheme */ GA_ELITISM_PARENTS_SURVIVE, /* const ga_elitism_type elitism */ 0.5, /* double crossover */ 0.5, /* double mutation */ 0.0 /* double migration */ ); ga_evolution( pop, /* population *pop */ 200 /* const int max_generations */ ); pingpong_ga_callback(i, pop); } printf("The final solution found was:\n"); beststring = ga_chromosome_integer_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen); printf("%s\n", beststring); ga_extinction(pop); s_free(beststring); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { population *pop=NULL; /* Population of solutions. */ char *beststring=NULL; /* Human readable form of best solution. */ size_t beststrlen=0; /* Length of beststring. */ random_seed(20092004); pop = ga_genesis_integer( 200, /* const int population_size */ 1, /* const int num_chromo */ 100, /* const int len_chromo */ NULL, /* GAgeneration_hook generation_hook */ NULL, /* GAiteration_hook iteration_hook */ NULL, /* GAdata_destructor data_destructor */ NULL, /* GAdata_ref_incrementor data_ref_incrementor */ all5s_score, /* GAevaluate evaluate */ ga_seed_integer_random, /* GAseed seed */ NULL, /* GAadapt adapt */ ga_select_one_sus, /* GAselect_one select_one */ ga_select_two_sus, /* GAselect_two select_two */ ga_mutate_integer_singlepoint_drift, /* GAmutate mutate */ ga_crossover_integer_singlepoints, /* GAcrossover crossover */ NULL, /* GAreplace replace */ NULL /* vpointer User data */ ); ga_population_set_allele_min_integer(pop, 0); ga_population_set_allele_max_integer(pop, 10); ga_population_set_parameters( pop, /* population *pop */ GA_SCHEME_DARWIN, /* const ga_scheme_type scheme */ GA_ELITISM_PARENTS_SURVIVE, /* const ga_elitism_type elitism */ 0.8, /* double crossover */ 0.05, /* double mutation */ 0.0 /* double migration */ ); ga_evolution( pop, /* population *pop */ 250 /* const int max_generations */ ); /* Display final solution. */ printf("The final solution was:\n"); beststring = ga_chromosome_integer_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen); printf("%s\n", beststring); printf("With score = %f\n", ga_get_entity_from_rank(pop,0)->fitness); /* Free memory. */ ga_extinction(pop); s_free(beststring); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { int i; /* Runs. */ int j; /* Loop variable. */ population *pop=NULL; /* Population of solutions. */ int map[WILDFIRE_X_DIMENSION*WILDFIRE_Y_DIMENSION]; /* Map. */ int count=0; /* Number of cisterns. */ random_seed(23091975); pop = ga_genesis_integer( 100, /* const int population_size */ 1, /* const int num_chromo */ WILDFIRE_X_DIMENSION*WILDFIRE_Y_DIMENSION,/* const int len_chromo */ wildfire_ga_callback, /* GAgeneration_hook generation_hook */ NULL, /* GAiteration_hook iteration_hook */ NULL, /* GAdata_destructor data_destructor */ NULL, /* GAdata_ref_incrementor data_ref_incrementor */ wildfire_score, /* GAevaluate evaluate */ wildfire_seed, /* GAseed seed */ NULL, /* GAadapt adapt */ ga_select_one_roulette_rebased, /* GAselect_one select_one */ ga_select_two_roulette_rebased, /* GAselect_two select_two */ wildfire_mutate_flip, /* GAmutate mutate */ wildfire_crossover, /* GAcrossover crossover */ NULL, /* GAreplace replace */ NULL /* vpointer User data */ ); ga_population_set_parameters( pop, /* population *pop */ GA_SCHEME_DARWIN, /* const ga_scheme_type scheme */ GA_ELITISM_PARENTS_SURVIVE, /* const ga_elitism_type elitism */ 0.8, /* double crossover */ 0.2, /* double mutation */ 0.0 /* double migration */ ); ga_evolution_forked( pop, /* population *pop */ 250 /* const int max_generations */ ); printf( "Best solution, with score %d, was:\n", (int) ga_entity_get_fitness(ga_get_entity_from_rank(pop,0)) ); /* Decode chromsome, and count number of cisterns. */ for(i=0; i<WILDFIRE_X_DIMENSION*WILDFIRE_Y_DIMENSION; i++) { map[i] = ((int *)ga_get_entity_from_rank(pop,0)->chromosome[0])[i]; if (map[i]) count++; } printf("%d cisterns\n", count); for (i=0; i<WILDFIRE_Y_DIMENSION; i++) { for (j=0; j<WILDFIRE_X_DIMENSION; j++) { printf("%s ", ((int *)ga_get_entity_from_rank(pop,0)->chromosome[0])[i*WILDFIRE_X_DIMENSION+j]?"X":"-"); } printf("\n"); } wildfire_simulation(map, TRUE); printf("\n"); wildfire_simulation(map, TRUE); printf("\n"); wildfire_simulation(map, TRUE); printf("\n"); wildfire_simulation(map, TRUE); printf("\n"); ga_extinction(pop); exit(EXIT_SUCCESS); }