int main(int argc, char **argv){ individual pop[POP_SIZE], newPop[POP_SIZE]; int generation=1; initialize_population(pop); evaluation(pop); sort(pop); while(generation <= GENERATIONS){ printf("-------------------------------------\n"); printf("Generation %d:\n", generation); print_best(pop); //print_population(pop); create_new_population(pop, newPop); evaluation(newPop); population_replacement(pop, newPop); generation++; } return 0; }
void main() { int i; int generation = 1; double best_fitness = 100000; srand( time(NULL)); FILE *f_results; FILE *f_fit; FILE *f_cost; initialize_population(); while ((generation < max_evolution_round) && (number_of_nondominated <= max_nondominated)) //&& (best_fitness > fitness_stall) { printf("========== ROUND %d ==========\n",generation); best_fitness = generation_individual_update(); printf(">> UPDATED\n"); find_pareto_front(); printf(">> FOUND\n"); fill_dominated_trees(); printf(">> FILLED\n"); generation ++; } printf("========== ENDED IN %dth GENERATION ==========\n",generation); best_fitness = generation_individual_update(); final_pareto_front(); Simulation_phase(); }
int main() { srand(time(NULL)); data dat; readfile(dat, "../../data/ks_19_0"); int items = dat[0].value; population *pop, popalpha; initialize_population(popalpha, items); pop = &popalpha; //print(*pop); bat best = get_best(*pop); int iterations = 200; while(iterations > 0){ new_solutions(*pop,dat); calc_fitness(*pop, dat); if(getrand()> 0.5){ best = get_best(*pop); move_bat(best, rand()%5, dat); // amplitude is 2 } if(fitness(best, dat) > fitness((*pop).best, dat)) (*pop).best = best; iterations--; } print(*pop); }
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bool initialize(int argc, char **argv) { return initialize_goal_image(argc,argv) && initialize_cuda(1,argv) && // xxx hack cuda init initialize_glut(argc,argv) && initialize_population(argc,argv); // population needs GL up-n-running }
void find_a_layer() { int i=0; int generation = 1; double best_fitness = 100000; srand( time(NULL)); FILE *f_results; initialize_population(); while ((generation < max_evolution_round) && (number_of_nondominated <= max_nondominated)) // && (best_fitness > fitness_stall) { //printf("========== ROUND %d ==========\n",generation); best_fitness = generation_individual_update(); //printf(">> UPDATED\n"); find_pareto_front(); //printf(">> FOUND\n"); fill_dominated_trees(); //printf(">> FILLED\n"); generation ++; } best_fitness = generation_individual_update(); final_pareto_front(); }
/* * === FUNCTION ====================================================================== * Name: main * Description: main is called with number of runs to simulate TODO: other params * * ===================================================================================== */ int main(int argc, char* argv[]) { int32_t seed = (int32_t)time(0); StochasticLib1 s(seed); CRandomMersenne r((int)seed); process_flags(argc, argv); list<person> infected, removed; list<person> susceptible; list<prevalence_data> pr_data; list<birth_data> br_data; list<death_data> death_data; list<float> birth_rate_data; ofstream prev_out("outputs/prevalence.txt", ios::out), out("outputs/population.txt", ios::out); //set up data import_prevalence_data(pr_data); import_birth_rates(birth_rate_data); import_death_data(death_data); initialize_population(susceptible, infected, pr_data, s, r); float b_rate; list<float>::iterator birthrate_itr = birth_rate_data.begin(); //print prleminary (day 0) stats // cout << "time 0: "; print_prevalence(susceptible, infected, prev_out); int year = 0; // run simulation int total = 0, prev_total = susceptible.size() + infected.size(); for(int i = 0; i < NUM_ITERATIONS; ++i) // 3 month intervals { update_births(susceptible, infected, b_rate, s); shuffle_population(susceptible); compute_infected(susceptible, infected, s, r); update_cd4_count(infected, r); update_age(susceptible, infected); // quarterly update output_population_statistics(susceptible, infected, removed, out); //update_cd4_count( if(i % 20 == 0) // every 5 years { if(birthrate_itr != birth_rate_data.end()) { b_rate = *birthrate_itr; ++birthrate_itr; } } if(i % 4 == 0) // every year { compute_deaths(susceptible, infected, removed, death_data, s); // life tables assume annual map<string, int> S, I, R; ++year; cout << "Year: " << year << " \t"; total = susceptible.size() + infected.size(); float d_p = 100.0 * (total - prev_total) / prev_total; prev_total = total; cout << "change (TOTAL population): " << d_p << "% (" << total << ")" << "\t"; // TODO: this outputs/couts print_prevalence(susceptible, infected, prev_out); //cout << "susceptibles: " << susceptible.size() << " infected: " // << infected.size() << " removed: " << removed.size() << endl << endl; print_population_changes(susceptible, infected, removed, S, I, R); } } out.close(); prev_out.close(); return 0; }
int main(int argc, char *argv[]) { int myid; /* My rank */ int nprocs; /* Number of processors */ int iteration_num = 10; // number of training iterations int population_num = 120; // population size for ga.in training int initialized; initialize_population(population_num); // initializes population int i,j,line; // iterators char c,variables[200],folder[200]; for(j=0;j<iteration_num;j++) { // recursively optimizes for number of iterations specified MPI_Initialized(&initialized); if (!initialized) { MPI_Init(&argc, &argv); } MPI_Comm_rank(MPI_COMM_WORLD, &myid); // starts MPI MPI_Comm_size(MPI_COMM_WORLD, &nprocs); FILE *input; input = fopen("ga.in","r"); // opens ga.in file for reading if (input == NULL) { printf("Cannot open file \n"); // null handler exit(0); } for (i=myid;i<population_num;i+=nprocs) { // loops through population list, assigning members to processors sprintf(folder,"%d",i); // creates a folder to hold all analysis on current line // gets line specified by loop and reads it into memory line = 0; rewind(input); while (line!=(i+1)) { if((c = fgetc(input)) == '\n') line++; } fgets(variables,200,input); // end processor_run(j, folder,variables); // runs analysis on line input } fclose(input); MPI_Barrier(MPI_COMM_WORLD); if (myid == 0) { FILE *ga_input,*ga_line; ga_input = fopen("ga.in","w"); if (ga_input == NULL) { printf("Cannot open file \n"); exit(0); } fprintf(ga_input,"%d\n",population_num); for (i=0;i<population_num;i++) { sprintf(folder,"%d",i); chdir(folder); ga_line = fopen("ga_line","r"); fgets(variables,200,ga_line); fputs(variables,ga_input); fclose(ga_line); chdir(".."); // code that removes directories files generated above char rm_dir[200]; sprintf(rm_dir,"rm -rf %s", folder); system(rm_dir); } fclose(ga_input); char cmdexec1[200]; sprintf(cmdexec1,"./ga ga.in %d", j+1); system(cmdexec1); char cmdexec[200]; sprintf(cmdexec, "cp value.d ga.in"); system(cmdexec); } printf("Iteration = %d done \n", j); MPI_Barrier(MPI_COMM_WORLD); } MPI_Finalize(); return 0; }
//====================================================== // create all the objects that are needed by the process void prepare(params_t *params) { // === initialize RNG === // init default generator params->rng = gsl_rng_alloc(gsl_rng_default); // seed the generator if (params->seed == 0) // draw a seed from /dev/urandom params->seed = rand(); printf("Seed = %d\n", params->seed); // set the seed gsl_rng_set(params->rng, params->seed); // initialize the mutation wheel int var; params->mwheel = g_array_new(FALSE, FALSE, sizeof(int)); if (params->m_beta) { var = M_BETA; g_array_append_val(params->mwheel, var); } if (params->m_kappa) { var = M_KAPPA; g_array_append_val(params->mwheel, var); } if (params->m_alpha) { var = M_ALPHA; g_array_append_val(params->mwheel, var); } // compute the optimal copy number params->cn_hat = sqrt(params->phi * params->lambda / params->gamma) - params->lambda; printf("Optimal CN is %.2f\n", params->cn_hat); // initialize the population params->cells = g_ptr_array_new(); // initialize array of daughter cells params->dcells = g_ptr_array_new(); // initialize the profile pool params->pool = pool_new(); // load the population from a file?? if (params->load_from) load_population_from_file(params); else initialize_population(params); // do we have a competition?? if (params->compete) { // set the number of contenders based on the pool's contents params->contenders = params->pool->size; printf("COMPETITION MODE : %d contenders found\n", params->contenders); // OK, we do -- now cancel all mutations g_array_set_size(params->mwheel, 0); } // adjust steps so that it is a multiple of fparts int steps = params->steps; while (params->steps % params->fparts > 0) ++ params->steps; if (steps != params->steps) printf("Adjusted simulation steps so that it is a multiple of FPARTS (old=%d, new=%d)\n", steps, params->steps); // initialize logger params->logger = logger_new(params); }