bool scoutBeesPhase(StateP state, DemeP deme){
			IndividualP unimproved ;

			double maxTrial = 0;
			for( uint i = 0; i < deme->getSize(); i++ ) { // for each food source
				IndividualP food = deme->at(i);
				//get food source's trial variable
				FloatingPointP flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (food->getGenotype(1));
				double &trial = flp->realValue[0];
				
				//remember the source if its trial exceeded limit 
				if (trial > limit && trial >maxTrial){
					unimproved = food;
					maxTrial = trial;
				}					
			}

			//if there is a  food source that exceeded the limit, replace it with a random one
			if (unimproved != NULL){
					FloatingPointP flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (unimproved->getGenotype(1));
					double &trial = flp->realValue[0];
					trial = 0;
					flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (unimproved->getGenotype(0));
					flp->initialize(state);
					evaluate(unimproved);
			}

			return true;
		 }
예제 #2
0
		bool birthPhase(StateP state, DemeP deme, std::vector<IndividualP> &clones)
		{
			//number of new antibodies (randomly created)
			uint birthNumber = deme->getSize() - clones.size();

			//if no new antibodies are needed, return (this if part is optional, code works fine w/o it)
			if (birthNumber == 0) return true;

			IndividualP newAntibody = copy(deme->at(0));
			FloatingPointP flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (newAntibody->getGenotype(0));
	
			for (uint i = 0; i<birthNumber; i++){
				//create a random antibody
				flp->initialize(state);
				evaluate(newAntibody);
			
				//reset its age
				flp = boost::dynamic_pointer_cast<FloatingPoint::FloatingPoint> (newAntibody->getGenotype(1));
				double &age = flp->realValue[0];
				age = 0;

				//add it to the clones vector
				clones.push_back(copy(newAntibody));
			}
			return true;
		}