void Photon::HopDropSpin(MCMLModel * model) { if ((model->layerObj.layer[layer].mua == 0.0) && (model->layerObj.layer[layer].mus == 0.0)) // glass layer HopInGlass(model); else HopDropSpinInTissue(model); if ((w < model->Wth) && dead) Roulette(); }
/** * C-routine to reach a floatvalue using a genetic model<br> * bugs: none found<br> * @param target floatvalue that serves as a target<br> * @param maxiter maximum number of itterations<br> */ int SolveNumber(float target, int maxiter){ while (maxiter > 0){ //storage for our population of chromosomes. bytechromosome Population[POP_SIZE]; //first create a random population, all with zero fitness. for (int i=0; i<POP_SIZE; i++){ Population[i].setbits(GetRandomBits(CHROMO_LENGTH)); Population[i].setfitness(0.0f); } int GenerationsRequiredToFindASolution = 0; //we will set this flag if a solution has been found bool bFound = false; //enter the main GA loop while(!bFound){ //this is used during roulette wheel sampling float TotalFitness = 0.0f; // test and update the fitness of every chromosome in the population for (int i=0; i<POP_SIZE; i++){ Population[i].setfitness(AssignFitness(Population[i].getbits(), (int)target)); TotalFitness += Population[i].getfitness(); } // check to see if we have found any solutions (fitness will be 999) for (int i=0; i<POP_SIZE; i++){ if (Population[i].getfitness() == 999.0f){ printf("Solution found in %d generations!\n",GenerationsRequiredToFindASolution); PrintChromo(Population[i].getbits()); bFound = true; break; } } // create a new population by selecting two parents at a time and creating offspring // by applying crossover and mutation. Do this until the desired number of offspring // have been created. //define some temporary storage for the new population we are about to create bytechromosome temp[POP_SIZE]; int cPop = 0; //loop until we have created POP_SIZE new chromosomes while (cPop < POP_SIZE){ // we are going to create the new population by grabbing members of the old population // two at a time via roulette wheel selection. string offspring1 = Roulette((int)TotalFitness, Population); string offspring2 = Roulette((int)TotalFitness, Population); //add crossover dependent on the crossover rate Crossover(offspring1, offspring2); //now mutate dependent on the mutation rate Mutate(offspring1); Mutate(offspring2); //add these offspring to the new population. (assigning zero as their fitness scores) temp[cPop++] = bytechromosome(offspring1, 0.0f); temp[cPop++] = bytechromosome(offspring2, 0.0f); }//end loop //copy temp population into main population array for (int i=0; i<POP_SIZE; i++){ Population[i] = temp[i]; } GenerationsRequiredToFindASolution++; if (GenerationsRequiredToFindASolution > MAX_ALLOWABLE_GENERATIONS){ printf("No solutions found this run!\n"); bFound = true; } } printf("\n"); maxiter--; }//end while return 0; }