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 structure. */ char *beststring=NULL; /* Human readable form of best solution. */ size_t beststrlen=0; /* Length of beststring. */ random_seed(23091975); pop = ga_genesis_char( 120, /* const int population_size */ 1, /* const int num_chromo */ (int) strlen(target_text), /* const int len_chromo */ struggle_generation_hook, /* GAgeneration_hook generation_hook */ NULL, /* GAiteration_hook iteration_hook */ NULL, /* GAdata_destructor data_destructor */ NULL, /* GAdata_ref_incrementor data_ref_incrementor */ struggle_score, /* GAevaluate evaluate */ ga_seed_printable_random, /* GAseed seed */ struggle_adaptation, /* GAadapt adapt */ ga_select_one_sus, /* GAselect_one select_one */ ga_select_two_sus, /* GAselect_two select_two */ ga_mutate_printable_singlepoint_drift, /* GAmutate mutate */ ga_crossover_char_allele_mixing, /* GAcrossover crossover */ NULL, /* GAreplace replace */ NULL /* vpointer User data */ ); ga_population_set_parameters( pop, /* population *pop */ GA_SCHEME_LAMARCK_CHILDREN, /* const ga_scheme_type scheme */ GA_ELITISM_PARENTS_DIE, /* const ga_elitism_type elitism */ 0.8, /* const double crossover */ 0.05, /* const double mutation */ 0.0 /* const double migration */ ); if ( ga_evolution( pop, 1000 )<1000 ) { printf("The evolution was stopped because the termination criteria were met.\n" ); } else { printf("The evolution was stopped because the maximum number of generations were performed.\n" ); } printf( "The final solution with score %f was:\n", ga_get_entity_from_rank(pop,0)->fitness ); beststring = ga_chromosome_char_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen); printf("%s\n", beststring); printf( "Total number of fitness evaluations: %ld\n", evaluation_count ); 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; /* Loop over 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++) { random_seed(i); pop = ga_genesis_char( 120, /* const int population_size */ 1, /* const int num_chromo */ (int) strlen(target_text), /* 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 */ struggle_score, /* GAevaluate evaluate */ ga_seed_printable_random, /* GAseed seed */ NULL, /* GAadapt adapt */ ga_select_one_sus, /* GAselect_one select_one */ ga_select_two_sus, /* GAselect_two select_two */ ga_mutate_printable_singlepoint_drift, /* GAmutate mutate */ ga_crossover_char_allele_mixing, /* 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_DIE, /* const ga_elitism_type elitism */ 0.9, /* double crossover */ 0.2, /* double mutation */ 0.0 /* double migration */ ); ga_evolution_threaded( pop, /* population *pop */ 500 /* const int max_generations */ ); printf( "The final solution with seed = %d was:\n", i ); beststring = ga_chromosome_char_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen); printf("%s\n", beststring); printf( "With score = %f\n", ga_entity_get_fitness(ga_get_entity_from_rank(pop,0)) ); ga_extinction(pop); } s_free(beststring); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { population *pop=NULL; /* Population of solutions. */ char *filename_in=NULL; /* Input filename. */ char *filename_out=NULL; /* Output filename. */ int i; /* Loop variable over command-line arguments. */ int generations=10; /* Number of generations to perform. */ char *beststring=NULL; /* Human readable form of best solution. */ size_t beststrlen=0; /* Length of beststring. */ random_seed(42); /* * Parse command-line. Expect '-i FILENAME' for a population to read, * otherwise a new population will be created. * '-o FILENAME' is absolutely required to specify a file to write to. * If we don't get these, then we will write the options. */ if (argc<2) { write_usage(); exit(0); } for (i=1; i<argc; i++) { if (strcmp(argv[i], "-i")==0) { /* Read pop. */ i++; if (i==argc) { printf("Input filename not specified.\n"); write_usage(); exit(0); } filename_in = argv[i]; printf("Input filename set to \"%s\"\n", filename_in); } else if (strcmp(argv[i], "-o")==0) { /* Out pop. */ i++; if (i==argc) { printf("Output filename not specified.\n"); write_usage(); exit(0); } filename_out = argv[i]; printf("Output filename set to \"%s\"\n", filename_out); } else if (strcmp(argv[i], "-n")==0) { /* Number of generations requested. */ i++; if (i==argc) { printf("Number of generations not specified.\n"); write_usage(); exit(0); } generations = atoi(argv[i]); printf("Number of generations set to %d.\n", generations); } else { /* Error parsing args. */ printf("Unable to parse command-line argument \"%s\"\n", argv[i]); write_usage(); exit(0); } } /* * Check that we had the required inputs. */ if (filename_out == NULL) { printf("No output filename was specified.\n"); write_usage(); exit(0); } /* * Read or create population. */ if (filename_in == NULL) { pop = ga_genesis_char( 40, /* const int population_size */ 1, /* const int num_chromo */ strlen(target_text), /* 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 */ struggle_score, /* GAevaluate evaluate */ ga_seed_printable_random, /* GAseed seed */ NULL, /* GAadapt adapt */ ga_select_one_roulette, /* GAselect_one select_one */ ga_select_two_roulette, /* GAselect_two select_two */ ga_mutate_printable_singlepoint_drift, /* GAmutate mutate */ ga_crossover_char_allele_mixing, /* 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 */ 1.0, /* double crossover */ 0.1, /* double mutation */ 0.0 /* double migration */ ); } else { pop = ga_population_read(filename_in); pop->evaluate = struggle_score; /* Custom functions can't be saved and * therefore "pop->evaluate" must be * defined manually. Likewise, if a * custom crossover routine was used, for * example, then that would also need * to be manually defined here. */ } ga_evolution( pop, /* population *pop */ generations /* const int max_generations */ ); printf("The final solution with seed = %d was:\n", i); beststring = ga_chromosome_char_to_string(pop, ga_get_entity_from_rank(pop,0), beststring, &beststrlen); printf("%s\n", beststring); printf("With score = %f\n", ga_entity_get_fitness(ga_get_entity_from_rank(pop,0)) ); ga_population_write(pop, filename_out); printf("Population has been saved as \"%s\"\n", filename_out); ga_extinction(pop); s_free(beststring); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { int i; /* Loop over populations. */ population *pop[GA_STRUGGLE_NUM_POPS]; /* Array of populations. */ population *slavepop; /* Population for slave calculations. */ char *beststring=NULL; /* Human readable form of best solution. */ size_t beststrlen=0; /* Length of beststring. */ int rank; /* MPI rank. */ MPI_Init(&argc, &argv); MPI_Comm_rank(MPI_COMM_WORLD, &rank); printf("Process %d initialised (rank %d)\n", getpid(), rank); random_seed(42); if (rank != 0) { /* This is a slave process. */ /* * A population is created so that the callbacks are defined. Evolution doesn't * occur with this population, so population_size can be zero. In such a case, * no entities are ever seeded, so there is no significant overhead. * Strictly, several of these callbacks are not needed on the slave processes, but * their definition doesn't have any adverse effects. */ slavepop = ga_genesis_char( 0, /* const int population_size */ 1, /* const int num_chromo */ (int) strlen(target_text), /* 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 */ struggle_score, /* GAevaluate evaluate */ ga_seed_printable_random, /* GAseed seed */ NULL, /* GAadapt adapt */ ga_select_one_sus, /* GAselect_one select_one */ ga_select_two_sus, /* GAselect_two select_two */ ga_mutate_printable_singlepoint_drift, /* GAmutate mutate */ ga_crossover_char_allele_mixing, /* GAcrossover crossover */ NULL, /* GAreplace replace */ NULL /* vpointer User data */ ); printf("DEBUG: Attaching process %d\n", rank); ga_attach_mpi_slave( slavepop ); /* The slaves halt here until ga_detach_mpi_slaves(), below, is called. */ } else { /* * This is the master process. Other than calling ga_evolution_mpi() instead * of ga_evolution(), there are no differences between this code and the usual * GAUL invocation. */ for (i=0; i<GA_STRUGGLE_NUM_POPS; i++) { pop[i] = ga_genesis_char( 80, /* const int population_size */ 1, /* const int num_chromo */ (int) strlen(target_text), /* 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 */ struggle_score, /* GAevaluate evaluate */ ga_seed_printable_random, /* GAseed seed */ NULL, /* GAadapt adapt */ ga_select_one_sus, /* GAselect_one select_one */ ga_select_two_sus, /* GAselect_two select_two */ ga_mutate_printable_singlepoint_drift, /* GAmutate mutate */ ga_crossover_char_allele_mixing, /* GAcrossover crossover */ NULL, /* GAreplace replace */ NULL /* vpointer User data */ ); ga_population_set_parameters( pop[i], GA_SCHEME_DARWIN, GA_ELITISM_PARENTS_DIE, 0.75, 0.25, 0.001 ); } ga_evolution_archipelago_mpi( GA_STRUGGLE_NUM_POPS, pop, 250 ); for (i=0; i<GA_STRUGGLE_NUM_POPS; i++) { printf( "The best solution on island %d with score %f was:\n", i, ga_get_entity_from_rank(pop[i],0)->fitness ); beststring = ga_chromosome_char_to_string(pop[i], ga_get_entity_from_rank(pop[i],0), beststring, &beststrlen); printf("%s\n", beststring); ga_extinction(pop[i]); } s_free(beststring); ga_detach_mpi_slaves(); /* Allow all slave processes to continue. */ } MPI_Finalize(); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { population *popd=NULL; /* Population for Darwinian evolution. */ population *popb=NULL; /* Population for Baldwinian evolution. */ population *popl=NULL; /* Population for Lamarckian evolution. */ char *beststring=NULL; /* Human readable form of best solution. */ size_t beststrlen=0; /* Length of beststring. */ random_seed(23091975); popd = ga_genesis_char( 150, /* const int population_size */ 1, /* const int num_chromo */ (int) strlen(target_text), /* 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 */ struggle_score, /* GAevaluate evaluate */ ga_seed_printable_random, /* GAseed seed */ struggle_adaptation, /* GAadapt adapt */ ga_select_one_sus, /* GAselect_one select_one */ ga_select_two_sus, /* GAselect_two select_two */ ga_mutate_printable_singlepoint_drift, /* GAmutate mutate */ ga_crossover_char_allele_mixing, /* GAcrossover crossover */ NULL, /* GAreplace replace */ NULL /* vpointer User data */ ); ga_population_set_parameters( popd, /* population *pop */ GA_SCHEME_DARWIN, /* const ga_scheme_type scheme */ GA_ELITISM_PARENTS_DIE, /* const ga_elitism_type elitism */ 0.9, /* const double crossover */ 0.1, /* const double mutation */ 0.0 /* const double migration */ ); /* * Make exact copies of the populations, except modify * their evolutionary schemes. */ popb = ga_population_clone(popd); ga_population_set_scheme(popb, GA_SCHEME_BALDWIN_CHILDREN); popl = ga_population_clone(popd); ga_population_set_scheme(popl, GA_SCHEME_LAMARCK_CHILDREN); /* * Evolve each population in turn. */ ga_evolution( popd, /* population *pop */ 600 /* const int max_generations */ ); printf( "The final solution with Darwinian evolution with score %f was:\n", ga_get_entity_from_rank(popd,0)->fitness ); beststring = ga_chromosome_char_to_string(popd, ga_get_entity_from_rank(popd,0), beststring, &beststrlen); printf("%s\n", beststring); ga_evolution( popb, /* population *pop */ 300 /* const int max_generations */ ); printf( "The final solution with Baldwinian evolution with score %f was:\n", ga_get_entity_from_rank(popb,0)->fitness ); beststring = ga_chromosome_char_to_string(popb, ga_get_entity_from_rank(popb,0), beststring, &beststrlen); printf("%s\n", beststring); ga_evolution( popl, /* population *pop */ 300 /* const int max_generations */ ); printf( "The final solution with Lamarckian evolution with score %f was:\n", ga_get_entity_from_rank(popl,0)->fitness ); beststring = ga_chromosome_char_to_string(popl, ga_get_entity_from_rank(popl,0), beststring, &beststrlen); printf("%s\n", beststring); /* Deallocate population structures. */ ga_extinction(popd); ga_extinction(popb); ga_extinction(popl); /* Deallocate string buffer. */ s_free(beststring); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { population *pop; /* Population of solutions. */ random_seed(23091975); /* "Best Set" Multiobjective GA. */ printf("Using the Best Set Multiobjective GA varient.\n"); pop = ga_genesis_double( 100, /* const int population_size */ 1, /* const int num_chromo */ 4, /* const int len_chromo */ test_generation_callback,/* GAgeneration_hook generation_hook */ NULL, /* GAiteration_hook iteration_hook */ NULL, /* GAdata_destructor data_destructor */ NULL, /* GAdata_ref_incrementor data_ref_incrementor */ test_score, /* GAevaluate evaluate */ test_seed, /* GAseed seed */ NULL, /* GAadapt adapt */ ga_select_one_bestof2, /* GAselect_one select_one */ ga_select_two_bestof2, /* GAselect_two select_two */ ga_mutate_double_singlepoint_drift, /* GAmutate mutate */ ga_crossover_double_doublepoints, /* 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_BEST_SET_SURVIVE, /* const ga_elitism_type elitism */ 0.8, /* double crossover */ 0.2, /* double mutation */ 0.0 /* double migration */ ); ga_population_set_fitness_dimensions(pop, 4); ga_evolution( pop, /* population *pop */ 200 /* const int max_generations */ ); ga_extinction(pop); /* "Pareto Set" Multiobjective GA. */ printf("Using the Pareto Set Multiobjective GA varient.\n"); pop = ga_genesis_double( 100, /* const int population_size */ 1, /* const int num_chromo */ 4, /* const int len_chromo */ test_generation_callback,/* GAgeneration_hook generation_hook */ NULL, /* GAiteration_hook iteration_hook */ NULL, /* GAdata_destructor data_destructor */ NULL, /* GAdata_ref_incrementor data_ref_incrementor */ test_score, /* GAevaluate evaluate */ test_seed, /* GAseed seed */ NULL, /* GAadapt adapt */ ga_select_one_bestof2, /* GAselect_one select_one */ ga_select_two_bestof2, /* GAselect_two select_two */ ga_mutate_double_singlepoint_drift, /* GAmutate mutate */ ga_crossover_double_doublepoints, /* 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_PARETO_SET_SURVIVE, /* const ga_elitism_type elitism */ 0.8, /* double crossover */ 0.2, /* double mutation */ 0.0 /* double migration */ ); ga_population_set_fitness_dimensions(pop, 4); ga_evolution( pop, /* population *pop */ 200 /* const int max_generations */ ); ga_extinction(pop); 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); }
void genetic_reconstruction(Image * _amp, Image * initial_support, Image * _exp_sigma, Options * _opts, char * dir){ char prev_dir[1024]; real support_threshold = _opts->new_level; population *pop; /* Population of solutions. */ random_seed(23091975); stop_threshold = 10; stop = 0; support_size = -support_threshold; opts = _opts; amp = _amp; exp_sigma = _exp_sigma; init_log(&my_log); my_log.threshold = support_threshold; opts->cur_iteration = 0; opts->flog = NULL; if(opts->automatic){ opts->algorithm = HIO; } support = imgcpy(initial_support); prev_support = imgcpy(initial_support); /* Set the initial guess */ if(opts->image_guess){ real_in = imgcpy(opts->image_guess); }else{ real_in = imgcpy(support); } /* make sure we make the input complex */ rephase(real_in); /* Set random phases if needed */ if(opts->rand_phases){ /* set_rand_phases(real_in,img);*/ set_rand_ints(real_in,amp); } getcwd(prev_dir,1024); mkdir(dir,0755); chdir(dir); write_png(support,"support.png",COLOR_JET); write_png(real_in,"initial_guess.png",COLOR_JET); write_png(initial_support,"initial_support.png",COLOR_JET); if(get_algorithm(opts,&my_log) == HIO){ real_out = basic_hio_iteration(amp, real_in, support,opts,&my_log); }else if(get_algorithm(opts,&my_log) == RAAR){ real_out = basic_raar_iteration(amp,exp_sigma, real_in, support,opts,&my_log); }else if(get_algorithm(opts,&my_log) == HPR){ real_out = basic_hpr_iteration(amp, real_in, support,opts,&my_log); }else{ fprintf(stderr,"Error: Undefined algorithm!\n"); exit(-1); } radius = opts->max_blur_radius; pop = ga_genesis_double( 3, /* const int population_size */ 1, /* const int num_chromo */ TSIZE(amp)*2, /* const int len_chromo */ test_generation_callback,/* GAgeneration_hook generation_hook */ NULL, /* GAiteration_hook iteration_hook */ NULL, /* GAdata_destructor data_destructor */ NULL, /* GAdata_ref_incrementor data_ref_incrementor */ test_score, /* GAevaluate evaluate */ test_seed, /* GAseed seed */ test_adaptation, /* GAadapt adapt */ ga_select_one_bestof2, /* GAselect_one select_one */ ga_select_two_bestof2, /* GAselect_two select_two */ ga_mutate_double_singlepoint_drift, /* GAmutate mutate */ ga_crossover_double_doublepoints, /* GAcrossover crossover */ NULL, /* GAreplace replace */ NULL /* vpointer User data */ ); ga_population_set_parameters( pop, /* population *pop */ GA_SCHEME_LAMARCK_ALL, /* 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( pop, /* population *pop */ 500 /* const int max_generations */ ); ga_extinction(pop); exit(EXIT_SUCCESS); }
int main(int argc, char **argv) { population *pop; /* Population of solutions. */ fitting_data_t data; /* Training data. */ FILE * fData; random_seed(time(NULL)); double params_d[4]; double x; // fitting if(argc >= 3 && strcmp(argv[1], "fit") == 0) { pop = ga_genesis_char( 100, /* const int population_size */ 1, /* const int num_chromo */ 3, /* const int len_chromo */ fitting_generation_callback, /* GAgeneration_hook generation_hook */ NULL, /* GAiteration_hook iteration_hook */ NULL, /* GAdata_destructor data_destructor */ NULL, /* GAdata_ref_incrementor data_ref_incrementor */ fitting_score, /* GAevaluate evaluate */ //fitting_seed, /* GAseed seed */ ga_seed_char_random, NULL, /* GAadapt adapt */ //ga_select_one_linearrank, ga_select_one_random, /* GAselect_one select_one */ ga_select_two_random, /* GAselect_two select_two */ ga_mutate_char_singlepoint_randomize,/* GAmutate mutate */ ga_crossover_char_allele_mixing,/* 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_DIE, /* const ga_elitism_type elitism */ 0.8, /* double crossover */ 0.8, /* double mutation */ 0.0 /* double migration */ ); fData = fopen("data", "r"); debug_message("Begin Get Data\n"); get_data(fData, &data); pop->data = &data; debug_message("Done Get Data\n"); debug_message("Begin Evolution\n"); ga_evolution( pop, /* population *pop */ 200 /* const int max_generations */ ); debug_message("Done Evolution\n"); ga_extinction(pop); } // plot else if(argc >= 5 && strcmp(argv[1], "plot")==0) { params_d[0] = E_GIVEN; params_d[1] = atof(argv[2]); params_d[2] = atof(argv[3]); params_d[3] = atof(argv[4]); for(x = 0; x < 10; x += 0.01) { fprintf(stdout, "%lf %lf\n", x, target_function(x, params_d)); } } else { fprintf(stdout, "usage: %s [plot/fit] [params]\n", argv[0]); } }
int testVdwGA(){ //--------------------- protein ------------------------------------- string fileNameA ( "/mnt/2t/xushutan/project/gold_dock/1a9u_diverse500/1A9U_protein.mol2" ) ; Molecular molA( fileNameA ); molA = readMolecularFile( fileNameA ).front(); mol = molA; bindingAtomVec = getBindingSiteAtoms( mol, bindingCenter, bindingDiameter ); if(1){ cout<<"binding site atoms:"<<bindingAtomVec.size()<<endl; for( size_t i=0; i<bindingAtomVec.size(); i++ ){ bindingAtomVec[i].print(); } } vector<Atom> protHbAcceptorAtoms = goldPar.getHydrogenBondAcceptorAtoms( bindingAtomVec ); vector<Atom> protHbDonorAtoms = goldPar.getHydrogenBondDonorAtoms( bindingAtomVec ); if(0){ cout<<"prot acceptor:"<<protHbAcceptorAtoms.size()<<endl; for( size_t i=0; i<protHbAcceptorAtoms.size(); i++ ){ protHbAcceptorAtoms[i].print(); } cout<<"prot donor:"<<protHbDonorAtoms.size()<<endl; for( size_t i=0; i<protHbDonorAtoms.size(); i++ ){ protHbDonorAtoms[i].print(); } } //---------------------------- ligand ----------------------------------- string fileNameB = "/mnt/2t/xushutan/project/gold_dock/1a9u_diverse500/ligand_corina.mol2"; Molecular molB; molB = readMolecularFile( fileNameB ).front(); vector<Atom> ligHbAcceptorAtoms = goldPar.getHydrogenBondAcceptorAtoms( molB.get_atomVec() ); vector<Atom> ligHbDonorAtoms = goldPar.getHydrogenBondDonorAtoms( molB.get_atomVec() ); if(0){ cout<<"lig acceptor:"<<ligHbAcceptorAtoms.size()<<endl; for( size_t i=0; i<ligHbAcceptorAtoms.size(); i++ ){ ligHbAcceptorAtoms[i].print(); } cout<<"lig donor:"<<ligHbDonorAtoms.size()<<endl; for( size_t i=0; i<ligHbDonorAtoms.size(); i++ ){ ligHbDonorAtoms[i].print(); } cout<<"-----------"<<endl; } Coord ligand_N25( 0.1835, 0.8981, 0.1207 ); Coord standardLigand_NC3( 3.576, 15.169, 28.381 ); Coord direction = standardLigand_NC3 - ligand_N25 ; double distance = getCoordDis( standardLigand_NC3, ligand_N25 ); ligand = translateMol( molB, direction, distance ); ligand.print(); rotableBondVec = getRotableBonds( molB ); if(1){ cout<<"rotableBondNum:"<<rotableBondVec.size()<<endl; for( size_t i=0; i<rotableBondVec.size(); i++ ){ rotableBondVec[i].print(); } } population *pop=NULL; /* The population of solutions. */ int chromoLength = 7 + rotableBondVec.size(); cout<<"chromolength:"<< rotableBondVec.size()<<endl;; random_seed( 10000 ); pop = ga_genesis_double( 6, // population size 1, // num_chromo: ligand position, rotation and bond rotation 7 + rotableBondVec.size(), // chromo length, here 7 is position 3 + rotation 3 + translate distance 1 NULL, NULL, NULL, NULL, docking_score, // ga_seed_printable_random, initialChromo, NULL, ga_select_one_sus, /* GAselect_one select_one */ ga_select_two_sus, /* GAselect_two select_two */ ga_mutate_double_multipoint, /* GAmutate mutate */ ga_crossover_double_mean, /* GAcrossover crossover */ NULL, /* GAreplace replace */ NULL /* void * userdata */ ); ga_population_set_parameters( pop, /* population *pop */ GA_SCHEME_DARWIN, /* const ga_class_type class */ GA_ELITISM_PARENTS_DIE, /* const ga_elitism_type elitism */ 0.9, /* double crossover */ 0.2, /* double mutation */ 0.0 /* double migration */ ); ga_evolution( pop, /* population *pop */ int(2) /* const int max_generations */ ); printf( "Fitness score = %f\n", ga_get_entity_from_rank(pop,0)->fitness); ga_extinction(pop); /* Deallocates all memory associated with the population and it's entities. */ exit(EXIT_SUCCESS); }