int main(int argc, char **argv) { population *pop; /* Population of solutions. */ entity *solution; /* Optimised solution. */ random_seed(23091975); pop = ga_genesis_double( 50, /* const int population_size */ 1, /* const int num_chromo */ 4, /* const int len_chromo */ NULL, /* GAgeneration_hook generation_hook */ test_iteration_callback, /* 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 */ NULL, /* GAselect_one select_one */ NULL, /* GAselect_two select_two */ ga_mutate_double_singlepoint_drift, /* GAmutate mutate */ NULL, /* GAcrossover crossover */ NULL, /* GAreplace replace */ NULL /* vpointer User data */ ); ga_population_set_simplex_parameters( pop, /* population *pop */ 4, /* const int num_dimensions */ 0.5, /* const double Initial step size. */ test_to_double, /* const GAto_double to_double */ test_from_double /* const GAfrom_double from_double */ ); /* Evaluate and sort the initial population members (i.e. select best of 50 random solutions. */ ga_population_score_and_sort(pop); /* Use the best population member. */ solution = ga_get_entity_from_rank(pop, 0); ga_simplex( pop, /* population *pop */ solution, /* entity *solution */ 10000 /* const int max_iterations */ ); ga_extinction(pop); 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); }
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. */ int i=0; /* Loop variable over strategies. */ entity *entity; /* Best ranked entity. */ random_seed(23091975); log_init(LOG_NORMAL, NULL, NULL, FALSE); while ( strategy[i].label != NULL ) { if ( strategy[i].weighting_factor != strategy[i].weighting_factor2 ) { printf( "Strategy %s ; C = %f ; F = rand( %f, %f )\n", strategy[i].label, strategy[i].crossover_factor, strategy[i].weighting_factor, strategy[i].weighting_factor2 ); } else { printf( "Strategy %s ; C = %f ; F = %f\n", strategy[i].label, strategy[i].crossover_factor, strategy[i].weighting_factor ); } pop = ga_genesis_double( 40, /* const int population_size */ 1, /* const int num_chromo */ 4, /* const int len_chromo */ polynomial_generation_callback,/* GAgeneration_hook generation_hook */ NULL, /* GAiteration_hook iteration_hook */ NULL, /* GAdata_destructor data_destructor */ NULL, /* GAdata_ref_incrementor data_ref_incrementor */ polynomial_score, /* GAevaluate evaluate */ polynomial_seed, /* GAseed seed */ NULL, /* GAadapt adapt */ NULL, /* GAselect_one select_one */ NULL, /* GAselect_two select_two */ NULL, /* GAmutate mutate */ NULL, /* GAcrossover crossover */ NULL, /* GAreplace replace */ NULL /* vpointer User data */ ); ga_population_set_differentialevolution_parameters( pop, strategy[i].strategy, strategy[i].crossover, strategy[i].num_perturbed, strategy[i].weighting_factor, strategy[i].weighting_factor2, strategy[i].crossover_factor ); ga_differentialevolution( pop, /* population *pop */ 50 /* const int max_generations */ ); entity = ga_get_entity_from_rank(pop, 0); printf( "Final: A = %f B = %f C = %f D = %f (fitness = %f)\n", ((double *)entity->chromosome[0])[0], ((double *)entity->chromosome[0])[1], ((double *)entity->chromosome[0])[2], ((double *)entity->chromosome[0])[3], ga_entity_get_fitness(entity) ); ga_extinction(pop); i++; } exit(EXIT_SUCCESS); }
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); }