vector<CEA::PopulationStruct> CEA::produceOffSpring(int x, int y) { //select individuals in the neiberhood //up offspring vector<PopulationStruct> offSprings{}; PopulationStruct parentA = population[x][y]; //up offspring if(y - 1 >= 0){ PopulationStruct parentB = population[x][y-1]; mate(parentA, parentB, 0.1); offSprings.push_back(parentB); } //down offspring if(y + 1 < populationNumberLength){ PopulationStruct parentB = population[x][y+1]; mate(parentA, parentB, 0.1); offSprings.push_back(parentB); } //left offspring if(x - 1 >= 0){ PopulationStruct parentB = population[x-1][y]; mate(parentA, parentB, 0.1); offSprings.push_back(parentB); } //right off spring if(x + 1 < populationNumberLength){ PopulationStruct parentB = population[x+1][y]; mate(parentA, parentB, 0.1); offSprings.push_back(parentB); } return offSprings; }
/** Compare two edges incident to the same endpoint. * @param e1 is the index of a valid edge * @param e2 is the index of a valid edge * @param u is the index of a vertex that both edges are incident to * @return -1 if u's mate in e1 is less than u's mate in e2; * return +1 if u's mate in e1 is greater than than u's mate in e2. * return 0 if u's mate in e1 is equal to its mate in e2. */ int Graph::ecmp(edge e1, edge e2, vertex u) const { assert(validEdge(e1) && validEdge(e2) && validVertex(u) && (u == left(e1) || u == right(e1)) && (u == left(e2) || u == right(e2))); if (mate(u,e1) < mate(u,e2)) return -1; else if (mate(u,e1) > mate(u,e2)) return 1; else return 0; }
int digraph::ecmp(edge e1, edge e2, vertex u) const { // Compare two edges incident to the same endpoint u. // Return -1 if e1 is an incoming edge of u and e2 an outgoing // Return +1 if e1 is an outgoing edge of u and e2 is an incoming // Otherwise // Return -1 if u's mate in e1 is less than u's mate in e2. // Return +1 if u's mate in e1 is greater than than u's mate in e2. // Return 0 if u's mate in e1 is equal to its mate in e2. if (u == head(e1) && u == tail(e2)) return -1; else if (u == tail(e1) && u == head(e2)) return 1; if (mate(u,e1) < mate(u,e2)) return -1; else if (mate(u,e1) > mate(u,e2)) return 1; else return 0; }
/** Create a string representation of an edge. * @param e is an edge number * @param u is one of the endponts of e; it will appear first in the string * @return the string */ string Graph::edge2string(edge e, vertex u) const { string s = "("; vertex v = mate(u,e); s += index2string(u) + ","; s += index2string(v) + ")"; if (shoEnum) s += "#" + to_string(e); return s; }
/** * main program */ int main (void) { float cpu1,cpu2; cpu1 = ((float) clock())/CLOCKS_PER_SEC; srand (time (NULL)); ga_struct *population = malloc (sizeof (ga_struct) * POPSIZE); ga_struct *beta_population = malloc (sizeof (ga_struct) * POPSIZE); init_population (population, beta_population); char *gen_str = population[0].gen; char element[5] = "\0"; strncpy (element, gen_str, 4); //if (strcmp ("0000", element) == 0) int index = 0; for (; index < POPSIZE; index++) { cal_fitness (population); sort_by_fitness (population); // print current best individual printf ("binary string: %s - fitness: %d\n", population[0].gen, population[0].fitness); if (population[0].fitness == 0) { //~ print equation decode_gen (&population[0]); break; } mate (population, beta_population); swap (&population, &beta_population); } free_population (population); free_population (beta_population); cpu2 = ((float) clock())/CLOCKS_PER_SEC; printf("Execution time (s) = %le\n",cpu2-cpu1); return 0; }
/* * mate threat * minus for captures */ wheur6() { int i; i = 0; *amp++ = -1; if(wattack(bkpos)) if(mate(2, 0)) i =+ 15; amp--; return(i); }
/* * mate threat * bad to capture */ bheur6() { int i; *amp++ = -1; i = 0; if(battack(wkpos)) if(mate(2, 0)) i =+ 15; amp--; return(i); }
void wgraph::put(FILE* f) { // Put graph out on f. int i; vertex u; edge e; fprintf(f,"%d %d\n",n,m); for (u = 0; u < n; u++) { i = 0; for (e = first(u); e != Null; e = next(u,e)) { fprintf(f,"%ld=(%2d,%2d,%2d) ",e, u,mate(u,e),w(e)); if ((++i)%5 == 0) putc('\n',f); } } putc('\n',f); }
bplay() { int v1, v2, *p1, *p2, *p3, ab; if(value > ivalue) ivalue = value; ab = 0; v1 = -3000; ply = 0; p1 = (int *) statl(); if(lmp == p1+2) { abmove = p1[1]; lmp = p1; return(ivalue); } p2 = p1; mantom = !mantom; while(p2 != lmp) { p2++; bmove(*p2); if(testf) { mantom = !mantom; bstatic(1); mantom = !mantom; } if(rept()) v2 = 0; else v2 = wplay1(v1); if(v2 > v1 && !mate(3, 0)) { ab = *p2; v1 = v2; } bremove(); if(testf) { mantom = !mantom; printf("%6d ", v2); out(*p2); printf("\n"); mantom = !mantom; } p2++; } if(ab == 0 && lmp != p1) ab = p1[1]; mantom = !mantom; lmp = p1; abmove = ab; return(v1); }
int main () { /*START_OF_MAIN*/ int x,y; /*END_OF_VARIABLES*/ /* Oluşturdugum fonksiyonları burada cagırdım */ conj(x,y); disj(x,y); not(x); mate(x,y); excl(x,y); return 0; }
/** Create a string representation of an adjacency list. * @param u is a vertex number * @return the string */ string Graph::adjList2string(vertex u) const { string s = ""; if (firstAt(u) == 0) return s; int cnt = 0; s += "[" + Adt::index2string(u) + ":"; for (edge e = firstAt(u); e != 0; e = nextAt(u,e)) { vertex v = mate(u,e); s += " " + index2string(v); if (shoEnum) s += "#" + to_string(e); if (++cnt >= 10 && nextAt(u,e) != 0) { s += "\n"; cnt = 0; } } s += "]\n"; return s; }
int Population::build_next_generation() { int nparents; /* size of old generation */ int nkids; /* size of new generation */ int limit; /* number of iterations in reproduction loop */ int target; /* number of kids to create */ Individual *kid; Individual *mom; Individual *dad; int momx, dadx; fitness_t w; // fitness of kid nparents = old->size(); cur = new Generation; limit = nparents * rmax; target = floor(++(*rk) + 0.5); // target is actual kmax for this generation if (target < 1) target = 1; nkids = 0; UniformRNG r(0.0,1.0); for (int i = 0; i < limit; i++) { momx = rword(nparents); dadx = rword(nparents); mom = (*old)[momx]; dad = (*old)[dadx]; kid = mate(mom,dad,++(*ru)); // create kid, add mutations if (kid->genes->fitness() > ++r) { cur->insert(kid); nkids += 1; if (nkids == target) break; } else { delete kid; } } delete old; // update generations: toss the old one, old = cur; // make the new one the current generation cur = NULL; return(nkids); }
vector<Population> Game::play(bool render) { TimeTracker& tt = *TimeTracker::getInstance(); size_t dur = tt.measure([&]() { tt.execute("game", "prepare", [&]() { prepare(); }); tt.execute("game", "place", [&]() { place(); }); tt.execute("game", "fight", [&]() { fight(render); }); tt.execute("game", "mate", [&]() { mate(); }); tt.execute("game", "score", [&]() { score(); }); tt.execute("game", "print", [&]() { print(); }); tt.execute("game", "cleanup", [&]() { cleanup(); }); }); std::cerr << "game/s: " << 1000000.0f/dur << std::endl; if(!GameState::getInstance()->isRunning()) { scenario_->restoreTeams(teams_); return teams_; } else { scenario_->restoreTeams(newTeams_); return newTeams_; } }
int main(int argc, char *argv[]){ long start_t = time(NULL); long end_t = 0; int generations = 0; struct Node *cur_gen = NULL; struct Node *mate_pool = NULL; struct Node *next_gen = NULL; int i; /* Seed of random */ srandom(time(NULL)); /* Initialize the first generation */ for (i = 0; i < POPULATION; i++){ push(&cur_gen, initialize()); } struct Node *list_index = cur_gen; while (list_index != NULL){ /* Compute fitness */ comp_fitness(&(list_index->organism)); list_index = list_index->next; } /* Sort descending the initial population */ sort(&cur_gen); generations++; float biggest_fit = 0; do{ list_index = cur_gen; /* First next generation */ int new_gen_pop = POPULATION * POP_RATE; /* Sort descenting the current population */ sort(&cur_gen); list_index = cur_gen; /* Copy POP_RATE best primitive organisms to mating pool */ for (i = 0; i < new_gen_pop; i++){ push(&mate_pool, list_index->organism); list_index = list_index->next; } /* Mate organisms */ for (i = 0; i < size(mate_pool); i++){ mate(&next_gen, mate_pool); } /* Mutate the first organisms */ int mutated = POPULATION * MUT_RATE; list_index = next_gen; for(i = 0; i < mutated; i++){ mutate(&list_index); list_index = list_index->next; } /* Sort descending the next generation */ sort(&next_gen); /* The organism with the biggest fitness is the first one */ biggest_fit = next_gen->organism.fitness; /* Print the organism with fitness = 1 (aka final) */ if (biggest_fit == 1) print_gene(next_gen->organism); printf("Biggest fitness in generation %d: %f\n", generations, biggest_fit); /* Delete current generation */ delete(&cur_gen); cur_gen = NULL; /* Copy next generation to current */ copy_list(&next_gen, &cur_gen); /* Delete next generation and mating pool */ delete(&next_gen); delete(&mate_pool); next_gen = NULL; mate_pool = NULL; generations++; }while(biggest_fit < 1); end_t = time(NULL); printf("Computed after %d generations and after %d seconds.\n", generations - 1, (int)(end_t - start_t)); exit(EXIT_SUCCESS); }
int main(int argc, char **argv){ int rc,num_processors,rank; rc=MPI_Init(&argc,&argv); if (rc != MPI_SUCCESS) { printf("Error starting MPI program. Terminating\n"); MPI_Abort(MPI_COMM_WORLD, rc); } MPI_Comm_size(MPI_COMM_WORLD,&num_processors); MPI_Comm_rank(MPI_COMM_WORLD,&rank); //**************************************************************************************// // reading input information by all cores // //**************************************************************************************// FILE *fpenergy=fopen("./energy","w"); // Print the energy evolution FILE *fprestart=fopen("./restart","w"); //print the generation and popsize coordinates FILE *fpoptim=fopen("./optim.xyz","wb"); FILE *fp=fopen("data.txt","r"); time_t current_time; double seconds,start,end,seconds_new,seconds_old,seconds_total; struct timespec now,tmstart; char* c_time_string,c_time_final; int flag_converge=0; int i=0; srand(time(NULL)+rank); clock_gettime(CLOCK_REALTIME, &tmstart); printf("hello from processor %ld\n",rank); start = (double)clock() /(double) CLOCKS_PER_SEC; seconds_old= (double)(tmstart.tv_sec+tmstart.tv_nsec*1e-9); current_time = time(NULL); c_time_string = ctime(¤t_time); printf("Current time is %s\n", c_time_string); printf("hello from processor %ld\n",rank); char skip[10]; FILE *fp_input2 = fopen("ga_dftb_input1.1","r"); int NSTEP=0; int step=0; double ee_mate=0 ; // the energy cretiria for accepting children cluster. the larger, the less restrict. can be 0.1 0 or -0.1 double ELITRATE=0.2; int POPSIZE=0; int min_step=0; int NEWPOPSIZE=POPSIZE; double delte=0.00001 ; //0.00001; int ptnatm,runatm,cnatm; double boxl=0; double Mu=0.2; double dptc; int glob=0,globconvg=20; double globe[30]; int Temp; int flag_res=0; double cell[9]; int esize=0; int num_cores_child; fscanf(fp_input2,"%d %d %d %s\n", &ptnatm, &runatm,&cnatm,&skip); fscanf(fp_input2,"%d %s\n ", &POPSIZE,skip); fscanf(fp_input2,"%d %s\n", &NSTEP,skip); fscanf(fp_input2,"%d %s\n", &globconvg,skip); fscanf(fp_input2,"%lf %s\n",&ELITRATE,skip); fscanf(fp_input2,"%lf %s\n",&delte,skip); fscanf(fp_input2,"%d %s\n",&Temp,skip); fscanf(fp_input2,"%d %s\n",&min_step,skip); fscanf(fp_input2,"%lf %s\n",&ee_mate,skip); fscanf(fp_input2,"%lf %s\n",&dptc,skip); fscanf(fp_input2,"%lf %s\n",&boxl,skip); fscanf(fp_input2,"%d %s\n",&flag_res,skip); fscanf(fp_input2,"%d %s\n",&num_cores_child,skip); int ii=0; for (ii=0;ii<3;ii++){ fscanf(fp_input2,"%lf %lf %lf\n", cell+ii*3+0,cell+ii*3+1,cell+ii*3+2); //**************************************************************************************// // Above are the information that all processors need to know // //**************************************************************************************// if(rank==0){ } printf("********************JOB started*****************************\n"); printf("********************JOB started*****************************\n"); printf("********************JOB started*****************************\n\n\n"); printf("Attention!! The dftb excutable file must be in ~/bin and must be named 'dftb+' !!\n"); printf("Attention!! The dftb excutable file must be in ~/bin and must be named 'dftb+' !!\n"); printf("Attention!! The dftb excutable file must be in ~/bin and must be named 'dftb+' !!\n"); printf("Attention!! The dftb excutable file must be in ~/bin and must be named 'dftb+' !!\n"); printf("Attention!! The dftb excutable file must be in ~/bin and must be named 'dftb+' !!\n"); printf("Number of atoms %d %d %d\n", ptnatm,runatm,cnatm); if(ptnatm+runatm>=Max_Atom || cnatm>=CMax_Atom) exitp("Number of atoms exceed allowed Max!"); printf("POPSIZE %d\n",POPSIZE); printf("NSTEP %d\n",NSTEP); printf("globconvg %d\n",globconvg); printf("ELITRATE %lf\n",ELITRATE); printf("delte %lf\n",delte); printf("Temprature %d\n",Temp); printf("minimiz step %d\n",min_step); printf("ee_mate %lf\n",ee_mate); printf("dptc %lf\n",dptc); printf("intial boxl %lf\n",boxl); printf("reading from pt_coord? %d\n",flag_res); printf("Total number of processsors required %d\n",num_processors); printf("Number of processors for each child %d\n",num_cores_child); printf("\n\n\n******** end reading input information ***********************\n\n\n"); } if(POPSIZE!=num_processors/num_cores_child){ printf("Error!,POPSZIE=%d num_processrs=%d num_cores_child=%d num_processrs/num_cores_child=%d",\ POPSIZE,num_processors,num_cores_child,num_processors/num_cores_child); MPI_Abort(MPI_COMM_WORLD,0); } ga_struct *population = malloc(sizeof(ga_struct)*POPSIZE); ga_struct *beta_population = malloc(sizeof(ga_struct)*POPSIZE); //****************************************************************************************// //define new mpi structure for data transfer between processors // //****************************************************************************************// int count=4; int length[4]={1,3*Max_Atom,3*CMax_Atom,1}; MPI_Aint offset[4]={offsetof(ga_struct,fitness),offsetof(ga_struct,gen),offsetof(ga_struct,cgen),offsetof(ga_struct,ep)} ; MPI_Datatype type[4]={MPI_DOUBLE,MPI_DOUBLE,MPI_DOUBLE,MPI_DOUBLE}; MPI_Datatype popDatatype; MPI_Type_struct(count,length,offset,type,&popDatatype); MPI_Type_commit(&popDatatype); //****************************************************************************************// //****************************************************************************************// //Initialization the population for all processors // //****************************************************************************************// if(rank==0){ printf("Total number of processors is %d\n",num_processors); printf("Total number of population is %d\n",POPSIZE); printf ("For each candidate, there are %d processors to be used\n",num_processors/POPSIZE); init_population(ptnatm+runatm,cnatm,POPSIZE,population,beta_population,boxl,flag_res); printf("argc=%d\n",argc); // int i=0,j=0; // int esize=POPSIZE*ELITRATE; cal_pop_energy(POPSIZE,population,ptnatm,runatm,cnatm,cell,argc, argv); /// for (i=0;i<POPSIZE;i++){ //////// center(ptnatm+runatm,population[i].gen); /// write_coord(fpoptim,ptnatm,runatm,cnatm,population[i].gen,population[i].cgen,population[i].ep); // shift(ptnatm+runatm, population[i].gen,dptc); /// } // for (i=0;i<POPSIZE;i++) // write_coord(fpoptim,ptnatm,runatm,cnatm,population[i].gen,population[i].cgen,population[i].ep); fflush(fpoptim); } char command[30]; char filename[30]; sprintf(command,"mkdir core%d",rank); system(command); sprintf(command,"cp dftb_in.hsd *.coord *.skf core%d",rank); system(command); sprintf(filename,"core%d",rank); chdir(filename); system("pwd"); //****************************************************************************************// // Loop started // //****************************************************************************************// for (step=0;step<NSTEP;step++){ //*********************************************************************************// // master core preparation // //*********************************************************************************// if(rank==0){ cal_pop_energy(POPSIZE,population,ptnatm,runatm,cnatm,cell, argc, argv); printf("\n\n\n\n***********************************************\n"); printf( "***********************************************\n"); printf( "***********************************************\n"); printf("Gen= %d starting optimization..................\n\n",step); qsort (population, POPSIZE, sizeof(ga_struct),sort_func); normal_fitness(POPSIZE,population); for(i=0;i<POPSIZE;i++){ fprintf(fpenergy,"%d num %d %lf\n",step, i,population[i].ep); fflush(fpenergy); } printf("fabs %lf\n",fabs(population[0].ep-population[POPSIZE-1].ep)); if(fabs(population[0].ep-population[POPSIZE-1].ep)<delte){ fprintf(fpenergy,"%d %lf %lf global minimum \n",step,population[0].ep,population[0].fitness); globe[glob]=population[POPSIZE-1].ep; glob=glob+1; } if(glob>20){ if(fabs(globe[glob]-globe[glob-20])<delte){ fprintf(fpenergy,"%d %lf %lf final global minimum \n",step,population[0].ep,population[0].fitness); flag_converge=1; } } ///// PPreserve the first esize parentes from the previous generation. copy from population to beta_population esize=POPSIZE*ELITRATE; if (esize<1){esize=1;} elitism(esize,ptnatm+runatm, cnatm,population,beta_population); for (i=1;i<num_processors;i++) MPI_Send(population,POPSIZE,popDatatype,i,0,MPI_COMM_WORLD); //send coordinates and energy information to other ith processors }else MPI_Recv(population,POPSIZE,popDatatype,0,0,MPI_COMM_WORLD,MPI_STATUS_IGNORE); //*********************************************************************************// // master core preparation ended // //*********************************************************************************// //*********************************************************************************// // other cores mating start // //*********************************************************************************// //receive coordinates and energy information from 0(master) core MPI_Bcast(&flag_converge, 1, MPI_INT,0,MPI_COMM_WORLD); // printf("rank=%d,xyz=%lf\n",rank,population[0].gen[0][0]); if(flag_converge ==1) {MPI_Finalize(); exit(0);} // for (i=0;i<POPSIZE;i++) // write_coord(fpoptim,ptnatm,runatm,cnatm,population[i].gen,population[i].cgen,population[i].ep); fflush(fpoptim); // printf("rank=%d,xyz=%lf\n",rank,population[0].gen[0][0]); // Generate the rest part of beta_generation by mating process if(rank!=0&&rank<POPSIZE) mate(ptnatm,runatm,cnatm,cell,esize,POPSIZE,population,beta_population,Temp,ee_mate,dptc,min_step,argc, argv); MPI_Barrier(MPI_COMM_WORLD); if(rank!=0&&rank<POPSIZE) MPI_Send(&beta_population[0],1,popDatatype,0,1,MPI_COMM_WORLD); //send the information of first children(optimized) from other processors to master core //*********************************************************************************// // other cores mating ended // //*********************************************************************************// if(rank==0){ for (i=1;i<POPSIZE;i++) MPI_Recv(&population[i],1,popDatatype,i,1,MPI_COMM_WORLD,MPI_STATUS_IGNORE); //recieve coordinates and energy information to other ith processors if (ptnatm!=0&&runatm!=0) mutate_perm (ptnatm,runatm, Mu, POPSIZE, beta_population); fprestart=fopen("./restart","w"); for (i=0;i<POPSIZE;i++){ write_coord(fpoptim,ptnatm,runatm,cnatm,population[i].gen,population[i].cgen,population[i].ep); write_coord(fprestart,ptnatm,runatm,cnatm,population[i].gen,population[i].cgen,population[i].ep); fflush(fpoptim); fflush(fprestart); } fclose(fprestart); clock_gettime(CLOCK_REALTIME, &now); seconds_new = (double)((now.tv_sec+now.tv_nsec*1e-9)); seconds=seconds_new-seconds_old; seconds_total = (double)((now.tv_sec+now.tv_nsec*1e-9) - (double)(tmstart.tv_sec+tmstart.tv_nsec*1e-9)); printf("\nWall time for this generation is %lf s\n",seconds); printf("\nWall time totally %lf s\n",seconds_total); seconds_old=seconds_new; } } //********************************************************************************* //************************************loop ended*********************************** //********************************************************************************* if(rank==0){ printf("\n********************JOB FINISHED*****************************\n"); fclose(fpenergy); fclose(fpoptim); ///////// time information current_time = time(NULL); c_time_string = ctime(¤t_time); printf("Current time is %s\n", c_time_string); // measure elapsed wall time clock_gettime(CLOCK_REALTIME, &now); seconds = (double)((now.tv_sec+now.tv_nsec*1e-9) - (double)(tmstart.tv_sec+tmstart.tv_nsec*1e-9)); printf("wall time %fs\n", seconds); // measure CPU time end = (double)clock() / (double) CLOCKS_PER_SEC; printf("cpu time %fs\n", end - start); printf("\n********************JOB FINISHED*****************************\n"); free(population); free(beta_population); } }
Result Genetic::search(const_target_ptr target, const_device_ptr device) { init(target,device); unsigned int i = 0, t = 0, gens; vector<Config> population; bool sortedPopulation = false; Config bestConfig; bool validBestConfig = findNearestConfig(target,bestConfig); srand((unsigned)time(0)); //cout << "Search for: " << target->getValue() << endl; // TODO: Use all DoE configs in initial population // Add bestConfig into population if(validBestConfig){ population.push_back(bestConfig); t++; } // Start with DoE population if available, otherwise random if(doeInitialized){ population = vector<Config>(doeConfigs.begin(),doeConfigs.end()); } // Create initial population while(population.size() < seedPopulation && !(target->getValue(&bestConfig) < target->getUpperBound() && target->getValue(&bestConfig) > target->getLowerBound())){ Config c = device->getConfigRandom(); memoizeConfig(c); // Make sure not already included bool addConfig = true; for(vector<Config>::iterator it = population.begin(); it != population.end(); it++){ if((*it).getConfigNum() == c.getConfigNum()) addConfig = false; } if(addConfig){ population.push_back(c); t++; } } // Determine how many generations we can run gens = (tries - population.size()) / (float) childrenCount; while (t < gens && !(target->getValue(&bestConfig) < target->getUpperBound() && target->getValue(&bestConfig) > target->getLowerBound()) && !overLimit){ sort(population.begin(), population.end(), compare(target)); sortedPopulation = true; vector<Config> children; for(i=0; i<childrenCount; i += 2){ Config parent1 = selectBreeder(population); Config parent2 = selectBreeder(population); list<Config> kids = mate(parent1, parent2, device); for(list<Config>::iterator it = kids.begin(); it != kids.end(); it++){ children.push_back(*it); memoizeConfig(*it); t++; } } // Add children to population sortedPopulation = false; for(vector<Config>::iterator it = children.begin(); it != children.end(); it++, i++){ population.push_back(*it); } sort(population.begin(), population.end(), compare(target)); sortedPopulation = true; vector<Config>::iterator iv; iv = unique(population.begin(), population.end(), same_config(target)); population.resize(iv - population.begin()); // Cull population down to populationLimit population.resize(populationLimit); bestConfig = population.front(); //cout << endl << "Target = " << target->getValue() << endl; //cout << endl << "Best = " << target->getValue(&bestConfig) << endl; } Result r; r.setTarget(target); r.setConfig(bestConfig); r.setDuration(duration); r.setNumHits(numHits); r.setNumTries(t); r.setTableSize(getTableSize()); r.setTargetNumber(target->getValue()); r.setTotalEnergy(totalEnergy); r.setValue(target->getValue(&bestConfig)); r.setTablePercent((double)getTableSize()/device->getNumConfigs() * 100); r.setHitPercent(getHitPercent(target)); return r; }
int main() { Quaternion firstQuaternion, secondQuaternion, result; int answer; printf("Instruction\nEnter a quaternion in this order:\nREAL + i * IMAGINARY + j * IMAGINARY + k * IMAGINARY.\n\n" "Select an operation:\n1. Summarize\n2. Deduct\n3. Multiply\n4. Divide\n5. Mate\n\n"); scanf("%d", &answer); system("clear"); printf("Instruction\nEnter a quaternion number in this order:\nREAL + i * IMAGINARY + j * IMAGINARY + k * IMAGINARY.\n\n"); switch(answer) { case 1: printf("Enter the first quaternion: "); enterQuaternion(&firstQuaternion); printf("Enter the second quaternion: "); enterQuaternion(&secondQuaternion); result = summarize(firstQuaternion, secondQuaternion); printf("The result: "); showQuaternion(result); break; case 2: printf("Enter the first quaternion: "); enterQuaternion(&firstQuaternion); printf("Enter the second quaternion: "); enterQuaternion(&secondQuaternion); result = deduct(firstQuaternion, secondQuaternion); printf("The result: "); showQuaternion(result); break; case 3: printf("Enter the first quaternion: "); enterQuaternion(&firstQuaternion); printf("Enter the second quaternion: "); enterQuaternion(&secondQuaternion); result = multiply(firstQuaternion, secondQuaternion); printf("The result: "); showQuaternion(result); break; case 4: printf("Enter the first quaternion: "); enterQuaternion(&firstQuaternion); printf("Enter the second quaternion: "); enterQuaternion(&secondQuaternion); result = divide(firstQuaternion, secondQuaternion); printf("The result: "); showQuaternion(result); break; case 5: printf("Enter the quaternion: "); enterQuaternion(&firstQuaternion); result = mate(firstQuaternion); printf("The result: "); showQuaternion(result); break; default: fprintf(stderr, "Invalid value.\n"); exit(1); } enterQuaternion(&firstQuaternion); showQuaternion(firstQuaternion); return 0; }
int main() { int part; int t1,t2; printf(" MENU OF BOOLEAN ALGEBRA \n"); printf("1.Conjunction\n2.Disjunction\n3.Negation\n"); printf("4.Material Implication\n5.Exclusive Or\n"); printf("6.Test the calculator with Monotone Laws\n7.Exit\n"); printf("Selection Time!\nEnter a part: "); scanf("%d",&part); switch(part) { case 1: printf("CONJUNCTION\n"); printf("\tYou can test true of conjunction law.\nLet's start test!!!"); printf("Enter two value (1 or 0) for test: "); scanf("%d %d",&t1,&t2); printf("%d and %d = %d\n",t1,t2,conj(t1,t2)); printf(" <<<<<>>>>>\n "); break; case 2: printf("DISJUNCTION\n"); printf("\tYou can test true of dijunction law.\nLet's start test!!!"); printf("Enter two value (1 or 0) for test: "); scanf("%d %d",&t1,&t2); printf("%d or %d = %d\n",t1,t2,disj(t1,t2)); printf(" <<<<<<>>>>>\n "); break; case 3: printf("NEGATION\n"); printf("\tYou can test true of negation law.\nLet's start test!!!"); printf("Enter a value (1 or 0) for test: "); scanf("%d",&t1); printf("'(%d) = %d\n",t1,not(t1,t2)); printf(" <<<<<<>>>>>>\n "); break; case 4: printf("MATERİAL IMPLICATION\n"); printf("\tYou can test true of material law.\nLet's start test!!!"); printf("Enter two value (1 or 0) for test: "); scanf("%d %d",&t1,&t2); printf("%d mate %d = %d\n",t1,t2,mate(t1,t2)); printf(" <<<<<<>>>>>\n "); break; case 5: printf("5.EXCLUSIVE OR\n"); printf("\tYou can test true of exclusive law.\nLet's start test!!!"); printf("Enter two value (1 or 0) for test: "); scanf("%d %d",&t1,&t2); printf("%d excl %d = %d\n",t1,t2,excl(t1,t2) ); printf(" <<<<<<>>>>>\n "); break; case 6: printf("Test the calculator with Monotone Laws\n"); printf("Enter the 'results.txt' for Monotone Laws\n"); testMonotone(); break; case 7: printf("7.EXIT\n"); printf(" <<<<<<THE END OF MENU>>>>>>\n "); break; default: printf("NOT IN MENU\n"); break; } return 0; }
cl_uint runStage(cl_uint* integral_image, KernelStage* stage, const CLODSubwindowData* win_src, CLODSubwindowData* win_dst, cl_uint win_src_count, cl_uint* win_dst_count, cl_uint scaled_window_area, cl_float current_scale, cl_uint integral_image_width, cl_uint gid) { // Win dst count must be atomic if(gid == 0) win_dst_count[0] = 0; if(gid < win_src_count) { const CLODSubwindowData subwindow = win_src[gid]; // Iterate over classifiers float stage_sum = 0; for(cl_uint classifier_index = 0; classifier_index < stage->count; classifier_index++) { KernelClassifier classifier = stage->classifier[classifier_index]; // Compute threshold normalized by window vaiance float norm_threshold = classifier.threshold * subwindow.variance; float rect_sum = 0; // Precalculation on rectangles (loop unroll) float first_rect_area = 0; float sum_rect_area = 0; KernelRect final_rect[3]; // Normalize rect size for(cl_uint ri = 0; ri < 3; ri++) { if(classifier.rect[ri].weight != 0) { KernelRect temp_rect = classifier.rect[ri]; final_rect[ri].x = (cl_uint)round(temp_rect.x * current_scale); final_rect[ri].y = (cl_uint)round(temp_rect.y * current_scale); final_rect[ri].width = (cl_uint)round(temp_rect.width * current_scale); final_rect[ri].height = (cl_uint)round(temp_rect.height * current_scale); // Normalize rect weight based on window area final_rect[ri].weight = (float)(classifier.rect[ri].weight) / (float)scaled_window_area; if(ri == 0) first_rect_area = final_rect[ri].width * final_rect[ri].height; else sum_rect_area += final_rect[ri].weight * final_rect[ri].width * final_rect[ri].height; } } final_rect[0].weight = (float)(-sum_rect_area/first_rect_area); // Calculation on rectangles (loop unroll) for(cl_uint ri = 0; ri < 3; ri++) { if(classifier.rect[ri].weight != 0) { cl_uint temp_sum = mate(integral_image,641,subwindow.x + final_rect[ri].x,subwindow.y + final_rect[ri].y); temp_sum -= mate(integral_image,641,subwindow.x + final_rect[ri].x + final_rect[ri].width, subwindow.y + final_rect[ri].y); temp_sum -= mate(integral_image,641,subwindow.x + final_rect[ri].x, subwindow.y + final_rect[ri].y + final_rect[ri].height); temp_sum += mate(integral_image,641,subwindow.x + final_rect[ri].x + final_rect[ri].width, subwindow.y + final_rect[ri].y + final_rect[ri].height); rect_sum += (float)(temp_sum * final_rect[ri].weight); } } // If rect sum less than stage_sum updated with threshold left_val else right_val stage_sum += classifier.alpha[rect_sum >= norm_threshold]; } // Add subwindow to accepted list if(stage_sum >= stage->threshold) { if(subwindow.x == 114 && subwindow.y == 182) { printf(""); } win_dst[*win_dst_count].x = subwindow.x; win_dst[*win_dst_count].y = subwindow.y; win_dst[*win_dst_count].variance = subwindow.variance; win_dst[*win_dst_count].offset = subwindow.offset; (*win_dst_count)++; return 0; } else { if(subwindow.x == 114 && subwindow.y == 182) { printf(""); } return 1; } } return 1; }