示例#1
0
/*!
 *  \return Return selection probability of breeder operator.
 *  \param inChild Child node in the breeder tree.
 */
double InvalidateFitnessOp::getBreedingProba(BreederNode::Handle inChild)
{
	Beagle_StackTraceBeginM();
	Beagle_NonNullPointerAssertM(inChild);
	Beagle_NonNullPointerAssertM(inChild->getBreederOp());
	return inChild->getBreederOp()->getBreedingProba(inChild->getFirstChild());
	Beagle_StackTraceEndM();
}
示例#2
0
/*!
 *  \return Return selection probability of breeder operator.
 *  \param inChild Child node in the breeder tree.
 */
double ES::AdaptOneFifthRuleOp::getBreedingProba(BreederNode::Handle inChild)
{
	Beagle_StackTraceBeginM();
	Beagle_NonNullPointerAssertM(inChild);
	Beagle_NonNullPointerAssertM(inChild->getBreederOp());
	return inChild->getBreederOp()->getBreedingProba(inChild->getFirstChild());
	Beagle_StackTraceEndM();
}
示例#3
0
/*!
 *  \brief Apply the crossover operation on a breeding pool, returning a mated individual.
 *  \param inBreedingPool Breeding pool to use for the crossover operation.
 *  \param inChild Node handle associated to child node in the breeder tree.
 *  \param ioContext Evolutionary context of the crossover operation.
 *  \return Mated individual.
 */
Individual::Handle CrossoverOp::breed(Individual::Bag& inBreedingPool,
                                      BreederNode::Handle inChild,
                                      Context& ioContext)
{
	Beagle_StackTraceBeginM();

	Context::Alloc::Handle lContextAlloc =
	    castHandleT<Context::Alloc>(ioContext.getSystem().getFactory().getConceptAllocator("Context"));
	Context::Handle lContext2 = castHandleT<Context>(lContextAlloc->clone(ioContext));

	Beagle_NonNullPointerAssertM(inChild);
	Beagle_NonNullPointerAssertM(inChild->getBreederOp());
	Individual::Handle lIndiv1 = inChild->getBreederOp()->breed(inBreedingPool,
	                             inChild->getFirstChild(),
	                             ioContext);

	Beagle_NonNullPointerAssertM(inChild->getNextSibling());
	Beagle_NonNullPointerAssertM(inChild->getNextSibling()->getBreederOp());
	Individual::Handle lIndiv2 =
	    inChild->getNextSibling()->getBreederOp()->breed(inBreedingPool,
	            inChild->getNextSibling()->getFirstChild(),
	            *lContext2);
	Beagle_LogVerboseM(
	    ioContext.getSystem().getLogger(),
	    std::string("Mating the ")+uint2ordinal(ioContext.getIndividualIndex()+1)+
	    std::string(" individual with the ")+uint2ordinal(lContext2->getIndividualIndex()+1)+
	    " individual"
	);

	if((lIndiv1 != NULL) && (lIndiv2 != NULL)) {
		bool lMated = mate(*lIndiv1, ioContext, *lIndiv2, *lContext2);
		if(lMated) {
			if(lIndiv1->getFitness() != NULL) lIndiv1->getFitness()->setInvalid();
			if(lIndiv2->getFitness() != NULL) lIndiv2->getFitness()->setInvalid();
			History::Handle lHistory = castHandleT<History>(ioContext.getSystem().haveComponent("History"));
			if(lHistory != NULL) {
				std::vector<HistoryID> lParents;
				HistoryID::Handle lHID1 = castHandleT<HistoryID>(lIndiv1->getMember("HistoryID"));
				if(lHID1 != NULL) lParents.push_back(*lHID1);
				HistoryID::Handle lHID2 = castHandleT<HistoryID>(lIndiv2->getMember("HistoryID"));
				if(lHID2 != NULL) lParents.push_back(*lHID2);
				lHistory->incrementHistoryVar(*lIndiv1);
				lHistory->trace(ioContext, lParents, lIndiv1, getName(), "crossover");
			}
		}
	}

	return lIndiv1;
	Beagle_StackTraceEndM();
}
示例#4
0
/*!
 *  \brief Apply the fitness invalidation operation on a breeding pool, returning a bred individual.
 *  \param inBreedingPool Breeding pool to use for the breeding operation.
 *  \param inChild Node handle associated to child node in the breeder tree.
 *  \param ioContext Evolutionary context of the breeding operation.
 *  \return Invalidated bred individual.
 */
Individual::Handle InvalidateFitnessOp::breed(Individual::Bag& inBreedingPool,
        BreederNode::Handle inChild,
        Context& ioContext)
{
	Beagle_StackTraceBeginM();
	Beagle_NonNullPointerAssertM(inChild);
	Beagle_NonNullPointerAssertM(inChild->getBreederOp());
	Individual::Handle lBredIndividual =
	    inChild->getBreederOp()->breed(inBreedingPool, inChild->getFirstChild(), ioContext);
	if((lBredIndividual->getFitness()!=NULL) && (lBredIndividual->getFitness()->isValid())) {
		Beagle_LogDebugM(
		    ioContext.getSystem().getLogger(),
		    "Invalidating the fitness of the following bred individual"
		);
		Beagle_LogDebugM(ioContext.getSystem().getLogger(), *lBredIndividual);
		lBredIndividual->getFitness()->setInvalid();
	}
	return lBredIndividual;
	Beagle_StackTraceEndM();
}
示例#5
0
/*!
 *  \brief Configure evolver with anisotropic (\mu,\lambda) self-adaptive evolution strategy algorithm.
 *  \param ioEvolver Evolver modified by setting the algorithm.
 *  \param ioSystem Evolutionary system.
 */
void SAES::Algorithm::configure(Evolver& ioEvolver, System& ioSystem)
{
	Beagle_StackTraceBeginM();

	// Get reference to the factory
	const Factory& lFactory = ioSystem.getFactory();

	// Get name and allocator of used operators
	std::string lEvalOpName = lFactory.getConceptTypeName("EvaluationOp");
	EvaluationOp::Alloc::Handle lEvalOpAlloc =
	    castHandleT<EvaluationOp::Alloc>(lFactory.getAllocator(lEvalOpName));
	std::string lSelectOpName = "SelectRandomOp";
	EC::SelectionOp::Alloc::Handle lSelectOpAlloc =
	    castHandleT<EC::SelectionOp::Alloc>(lFactory.getAllocator(lSelectOpName));
	std::string lInitOpName = lFactory.getConceptTypeName("InitializationOp");
	EC::InitializationOp::Alloc::Handle lInitOpAlloc =
	    castHandleT<EC::InitializationOp::Alloc>(lFactory.getAllocator(lInitOpName));
	std::string lMutOpName = "SAES-MutationOp";
	EC::MutationOp::Alloc::Handle lMutOpAlloc =
	    castHandleT<EC::MutationOp::Alloc>(lFactory.getAllocator(lMutOpName));
	std::string lMigOpName = lFactory.getConceptTypeName("MigrationOp");
	EC::MigrationOp::Alloc::Handle lMigOpAlloc =
	    castHandleT<EC::MigrationOp::Alloc>(lFactory.getAllocator(lMigOpName));
	std::string lStatsCalcOpName = lFactory.getConceptTypeName("StatsCalculateOp");
	EC::StatsCalculateOp::Alloc::Handle lStatsCalcOpAlloc =
	    castHandleT<EC::StatsCalculateOp::Alloc>(lFactory.getAllocator(lStatsCalcOpName));
	std::string lTermOpName = lFactory.getConceptTypeName("TerminationOp");
	EC::TerminationOp::Alloc::Handle lTermOpAlloc =
	    castHandleT<EC::TerminationOp::Alloc>(lFactory.getAllocator(lTermOpName));
	std::string lMsWriteOpName = "MilestoneWriteOp";
	EC::MilestoneWriteOp::Alloc::Handle lMsWriteOpAlloc =
	    castHandleT<EC::MilestoneWriteOp::Alloc>(lFactory.getAllocator(lMsWriteOpName));
	std::string lMCLOpName = "EC-MuCommaLambdaOp";
	EC::MuCommaLambdaOp::Alloc::Handle lMCLOpAlloc =
	    castHandleT<EC::MuCommaLambdaOp::Alloc>(lFactory.getAllocator(lMCLOpName));

	// Clear bootstrap and mainloop sets
	ioEvolver.getBootStrapSet().clear();
	ioEvolver.getMainLoopSet().clear();

	// Set the boostrap operator set
	EC::InitializationOp::Handle lInitOpBS = castHandleT<EC::InitializationOp>(lInitOpAlloc->allocate());
	lInitOpBS->setName(lInitOpName);
	ioEvolver.getBootStrapSet().push_back(lInitOpBS);
	EvaluationOp::Handle lEvalOpBS = castHandleT<EvaluationOp>(lEvalOpAlloc->allocate());
	lEvalOpBS->setName(lEvalOpName);
	ioEvolver.getBootStrapSet().push_back(lEvalOpBS);
	EC::StatsCalculateOp::Handle lStatsCalcOpBS = castHandleT<EC::StatsCalculateOp>(lStatsCalcOpAlloc->allocate());
	lStatsCalcOpBS->setName(lStatsCalcOpName);
	ioEvolver.getBootStrapSet().push_back(lStatsCalcOpBS);
	EC::TerminationOp::Handle lTermOpBS = castHandleT<EC::TerminationOp>(lTermOpAlloc->allocate());
	lTermOpBS->setName(lTermOpName);
	ioEvolver.getBootStrapSet().push_back(lTermOpBS);
	EC::MilestoneWriteOp::Handle lMsWriteOpBS = castHandleT<EC::MilestoneWriteOp>(lMsWriteOpAlloc->allocate());
	lMsWriteOpBS->setName(lMsWriteOpName);
	ioEvolver.getBootStrapSet().push_back(lMsWriteOpBS);

	// Set the mainloop operator set
	EC::MuCommaLambdaOp::Handle lMCLOp = castHandleT<EC::MuCommaLambdaOp>(lMCLOpAlloc->allocate());
	lMCLOp->setName(lMCLOpName);

	// Set breeder tree
	BreederNode::Handle lEvalNode = new BreederNode;
	lMCLOp->setRootNode(lEvalNode);
	lEvalNode->setBreederOp(castHandleT<EvaluationOp>(lEvalOpAlloc->allocate()));
	lEvalNode->getBreederOp()->setName(lEvalOpName);
	BreederNode::Handle lMutNode = new BreederNode;
	lEvalNode->setFirstChild(lMutNode);
	lMutNode->setBreederOp(castHandleT<EC::MutationOp>(lMutOpAlloc->allocate()));
	lMutNode->getBreederOp()->setName(lMutOpName);
	BreederNode::Handle lSelectMutNode = new BreederNode;
	lMutNode->setFirstChild(lSelectMutNode);
	lSelectMutNode->setBreederOp(castHandleT<EC::SelectionOp>(lSelectOpAlloc->allocate()));
	lSelectMutNode->getBreederOp()->setName(lSelectOpName);

	// Set remaining operators of mainloop
	EC::MigrationOp::Handle lMigOpML = castHandleT<EC::MigrationOp>(lMigOpAlloc->allocate());
	lMigOpML->setName(lMigOpName);
	ioEvolver.getMainLoopSet().push_back(lMigOpML);
	EC::StatsCalculateOp::Handle lStatsCalcOpML =
	    castHandleT<EC::StatsCalculateOp>(lStatsCalcOpAlloc->allocate());
	lStatsCalcOpML->setName(lStatsCalcOpName);
	ioEvolver.getMainLoopSet().push_back(lStatsCalcOpML);
	EC::TerminationOp::Handle lTermOpML = castHandleT<EC::TerminationOp>(lTermOpAlloc->allocate());
	lTermOpML->setName(lTermOpName);
	ioEvolver.getMainLoopSet().push_back(lTermOpML);
	EC::MilestoneWriteOp::Handle lMsWriteOpML =
	    castHandleT<EC::MilestoneWriteOp>(lMsWriteOpAlloc->allocate());
	lMsWriteOpML->setName(lMsWriteOpName);
	ioEvolver.getMainLoopSet().push_back(lMsWriteOpML);

	Beagle_StackTraceEndM();
}
/*!
 *  \brief Configure steady-state evolutionary algorithm in evolver.
 *  \param ioEvolver Evolver modified by setting the algorithm.
 *  \param ioSystem Evolutionary system.
 *
 */
void AlgoSteadyState::configure(Evolver& ioEvolver, System& ioSystem)
{
	Beagle_StackTraceBeginM();

	// Get reference to the factory
	const Factory& lFactory = ioSystem.getFactory();

	// Get name and allocator of used operators
	std::string lEvalOpName = lFactory.getConceptTypeName("EvaluationOp");
	EvaluationOp::Alloc::Handle lEvalOpAlloc =
	    castHandleT<EvaluationOp::Alloc>(lFactory.getAllocator(lEvalOpName));
	std::string lSelectOpName = lFactory.getConceptTypeName("SelectionOp");
	SelectionOp::Alloc::Handle lSelectOpAlloc =
	    castHandleT<SelectionOp::Alloc>(lFactory.getAllocator(lSelectOpName));
	std::string lInitOpName = lFactory.getConceptTypeName("InitializationOp");
	InitializationOp::Alloc::Handle lInitOpAlloc =
	    castHandleT<InitializationOp::Alloc>(lFactory.getAllocator(lInitOpName));
	std::string lCxOpName = lFactory.getConceptTypeName("CrossoverOp");
	CrossoverOp::Alloc::Handle lCxOpAlloc =
	    castHandleT<CrossoverOp::Alloc>(lFactory.getAllocator(lCxOpName));
	std::string lMutOpName = lFactory.getConceptTypeName("MutationOp");
	MutationOp::Alloc::Handle lMutOpAlloc =
	    castHandleT<MutationOp::Alloc>(lFactory.getAllocator(lMutOpName));
	std::string lMigOpName = lFactory.getConceptTypeName("MigrationOp");
	MigrationOp::Alloc::Handle lMigOpAlloc =
	    castHandleT<MigrationOp::Alloc>(lFactory.getAllocator(lMigOpName));
	std::string lStatsCalcOpName = lFactory.getConceptTypeName("StatsCalculateOp");
	StatsCalculateOp::Alloc::Handle lStatsCalcOpAlloc =
	    castHandleT<StatsCalculateOp::Alloc>(lFactory.getAllocator(lStatsCalcOpName));
	std::string lTermOpName = lFactory.getConceptTypeName("TerminationOp");
	TerminationOp::Alloc::Handle lTermOpAlloc =
	    castHandleT<TerminationOp::Alloc>(lFactory.getAllocator(lTermOpName));
	std::string lMsWriteOpName = "MilestoneWriteOp";
	MilestoneWriteOp::Alloc::Handle lMsWriteOpAlloc =
	    castHandleT<MilestoneWriteOp::Alloc>(lFactory.getAllocator(lMsWriteOpName));
	std::string lSSOpName = "SteadyStateOp";
	SteadyStateOp::Alloc::Handle lSSOpAlloc =
	    castHandleT<SteadyStateOp::Alloc>(lFactory.getAllocator(lSSOpName));

	// Clear bootstrap and mainloop sets
	ioEvolver.getBootStrapSet().clear();
	ioEvolver.getMainLoopSet().clear();

	// Set the boostrap operator set
	InitializationOp::Handle lInitOpBS = castHandleT<InitializationOp>(lInitOpAlloc->allocate());
	lInitOpBS->setName(lInitOpName);
	ioEvolver.getBootStrapSet().push_back(lInitOpBS);
	EvaluationOp::Handle lEvalOpBS = castHandleT<EvaluationOp>(lEvalOpAlloc->allocate());
	lEvalOpBS->setName(lEvalOpName);
	ioEvolver.getBootStrapSet().push_back(lEvalOpBS);
	StatsCalculateOp::Handle lStatsCalcOpBS = castHandleT<StatsCalculateOp>(lStatsCalcOpAlloc->allocate());
	lStatsCalcOpBS->setName(lStatsCalcOpName);
	ioEvolver.getBootStrapSet().push_back(lStatsCalcOpBS);
	TerminationOp::Handle lTermOpBS = castHandleT<TerminationOp>(lTermOpAlloc->allocate());
	lTermOpBS->setName(lTermOpName);
	ioEvolver.getBootStrapSet().push_back(lTermOpBS);
	MilestoneWriteOp::Handle lMsWriteOpBS = castHandleT<MilestoneWriteOp>(lMsWriteOpAlloc->allocate());
	lMsWriteOpBS->setName(lMsWriteOpName);
	ioEvolver.getBootStrapSet().push_back(lMsWriteOpBS);

	// Set the mainloop operator set
	SteadyStateOp::Handle lSSOp = castHandleT<SteadyStateOp>(lSSOpAlloc->allocate());
	lSSOp->setName(lSSOpName);

	// Set crossover branch
	BreederNode::Handle lCxBranchNode = new BreederNode;
	lSSOp->setRootNode(lCxBranchNode);
	lCxBranchNode->setBreederOp(castHandleT<EvaluationOp>(lEvalOpAlloc->allocate()));
	lCxBranchNode->getBreederOp()->setName(lEvalOpName);
	BreederNode::Handle lCxNode = new BreederNode;
	lCxBranchNode->setFirstChild(lCxNode);
	lCxNode->setBreederOp(castHandleT<CrossoverOp>(lCxOpAlloc->allocate()));
	lCxNode->getBreederOp()->setName(lCxOpName);
	BreederNode::Handle lSelectCxNode1 = new BreederNode;
	lCxNode->setFirstChild(lSelectCxNode1);
	lSelectCxNode1->setBreederOp(castHandleT<SelectionOp>(lSelectOpAlloc->allocate()));
	lSelectCxNode1->getBreederOp()->setName(lSelectOpName);
	BreederNode::Handle lSelectCxNode2 = new BreederNode;
	lSelectCxNode1->setNextSibling(lSelectCxNode2);
	lSelectCxNode2->setBreederOp(castHandleT<SelectionOp>(lSelectOpAlloc->allocate()));
	lSelectCxNode2->getBreederOp()->setName(lSelectOpName);

	// Set mutation branch
	BreederNode::Handle lMutBranchNode = new BreederNode;
	lCxBranchNode->setNextSibling(lMutBranchNode);
	lMutBranchNode->setBreederOp(castHandleT<EvaluationOp>(lEvalOpAlloc->allocate()));
	lMutBranchNode->getBreederOp()->setName(lEvalOpName);
	BreederNode::Handle lMutNode = new BreederNode;
	lMutBranchNode->setFirstChild(lMutNode);
	lMutNode->setBreederOp(castHandleT<MutationOp>(lMutOpAlloc->allocate()));
	lMutNode->getBreederOp()->setName(lMutOpName);
	BreederNode::Handle lSelectMutNode = new BreederNode;
	lMutNode->setFirstChild(lSelectMutNode);
	lSelectMutNode->setBreederOp(castHandleT<SelectionOp>(lSelectOpAlloc->allocate()));
	lSelectMutNode->getBreederOp()->setName(lSelectOpName);

	// Set reproduction branch
	BreederNode::Handle lReproBranchNode = new BreederNode;
	lMutBranchNode->setNextSibling(lReproBranchNode);
	lReproBranchNode->setBreederOp(castHandleT<SelectionOp>(lSelectOpAlloc->allocate()));
	lReproBranchNode->getBreederOp()->setName(lSelectOpName);

	// Set remaining operators of mainloop
	MigrationOp::Handle lMigOpML = castHandleT<MigrationOp>(lMigOpAlloc->allocate());
	lMigOpML->setName(lMigOpName);
	ioEvolver.getMainLoopSet().push_back(lMigOpML);
	StatsCalculateOp::Handle lStatsCalcOpML =
	    castHandleT<StatsCalculateOp>(lStatsCalcOpAlloc->allocate());
	lStatsCalcOpML->setName(lStatsCalcOpName);
	ioEvolver.getMainLoopSet().push_back(lStatsCalcOpML);
	TerminationOp::Handle lTermOpML = castHandleT<TerminationOp>(lTermOpAlloc->allocate());
	lTermOpML->setName(lTermOpName);
	ioEvolver.getMainLoopSet().push_back(lTermOpML);
	MilestoneWriteOp::Handle lMsWriteOpML =
	    castHandleT<MilestoneWriteOp>(lMsWriteOpAlloc->allocate());
	lMsWriteOpML->setName(lMsWriteOpName);
	ioEvolver.getMainLoopSet().push_back(lMsWriteOpML);

	Beagle_StackTraceEndM("void AlgoSteadyState::configure(Evolver&,System&)");
}
示例#7
0
/*!
 *  \brief Apply the adaptation operation on a breeding pool.
 *  \param inBreedingPool Breeding pool to give to the underlying breeding tree.
 *  \param inChild Node handle associated to child node in the breeder tree.
 *  \param ioContext Evolutionary context of the mutation operation.
 *  \return Mutated individual.
 */
Individual::Handle ES::AdaptOneFifthRuleOp::breed(Individual::Bag& inBreedingPool,
        BreederNode::Handle inChild,
        Context& ioContext)
{
	Beagle_StackTraceBeginM();
	Beagle_NonNullPointerAssertM(inChild);
	Beagle_NonNullPointerAssertM(inChild->getBreederOp());
	Individual::Handle lIndiv =
	    inChild->getBreederOp()->breed(inBreedingPool, inChild->getFirstChild(), ioContext);

	// Look whether the mutation is successful.
	Fitness::Handle lFitParent = inBreedingPool[ioContext.getIndividualIndex()]->getFitness();
	Fitness::Handle lFitChild = lIndiv->getFitness();
	if(lFitChild != NULL) {

		// Check whether the mutation is successful or not.
		const bool lSuccessful = (*lFitChild) > (*lFitParent);
		if(lSuccessful) {
			++mSuccessCount->getWrappedValue();
			Beagle_LogVerboseM(
			    ioContext.getSystem().getLogger(),
			    "Successful mutation"
			);
		} else {
			Beagle_LogVerboseM(
			    ioContext.getSystem().getLogger(),
			    "The mutation is not successful"
			);
		}
		++mMutationsCount->getWrappedValue();

		// Adapt the sigma if the necessary number of observed mutations is reached.
		if(lSuccessful && (mMutationsCount->getWrappedValue()>=mAdaptationPeriod->getWrappedValue())) {
			const double lSuccessRate = double(mSuccessCount->getWrappedValue()) /
			                            double(mMutationsCount->getWrappedValue());
			if(lSuccessRate > 0.2) {
				for(unsigned int i=0; i<mMutateGaussSigma->size(); ++i) {
					(*mMutateGaussSigma)[i] /= mSigmaAdaptFactor->getWrappedValue();
				}
				Beagle_LogDetailedM(
				    ioContext.getSystem().getLogger(),
				    string("Increasing the sigma value by a factor ")+
				    dbl2str(1./mSigmaAdaptFactor->getWrappedValue())
				);
				Beagle_LogVerboseM(
				    ioContext.getSystem().getLogger(),
				    string("Sigma value after the increase: ")+mMutateGaussSigma->serialize()
				);
			} else if(lSuccessRate < 0.2) {
				for(unsigned int i=0; i<mMutateGaussSigma->size(); ++i) {
					(*mMutateGaussSigma)[i] *= mSigmaAdaptFactor->getWrappedValue();
				}
				Beagle_LogDetailedM(
				    ioContext.getSystem().getLogger(),
				    string("Reducing the sigma value by a factor ")+
				    dbl2str(mSigmaAdaptFactor->getWrappedValue())
				);
				Beagle_LogVerboseM(
				    ioContext.getSystem().getLogger(),
				    string("Sigma value after the reduction: ")+mMutateGaussSigma->serialize()
				);
			} else {
				Beagle_LogDetailedM(
				    ioContext.getSystem().getLogger(),
				    "Sigma value unchanged"
				);
			}
		}
	}

	return lIndiv;
	Beagle_StackTraceEndM();
}
示例#8
0
/*!
 *  \brief Apply the recombination operation on a breeding pool, returning a recombined individual.
 *  \param inBreedingPool Breeding pool to use for the recombination operation.
 *  \param inChild Node handle associated to child node in the breeder tree.
 *  \param ioContext Evolutionary context of the recombination operation.
 *  \return Recombined individual.
 */
Individual::Handle RecombinationOp::breed(Individual::Bag& inBreedingPool,
        BreederNode::Handle inChild,
        Context& ioContext)
{
	Beagle_StackTraceBeginM();

	// Generate parents for recombination.
	Individual::Bag::Handle lParents = new Individual::Bag;
	if(inChild == NULL) {
		const unsigned int lNbGenerated =
		    (mNumberRecomb->getWrappedValue()==0) ? inBreedingPool.size() :
		    minOf<unsigned int>(inBreedingPool.size(), mNumberRecomb->getWrappedValue());
		if(lNbGenerated == inBreedingPool.size()) (*lParents) = inBreedingPool;
		else {
			std::vector<unsigned int> lIndices(inBreedingPool.size());
			for(unsigned int i=0; i<lIndices.size(); ++i) lIndices[i] = i;
			std::random_shuffle(lIndices.begin(), lIndices.end(),
			                    ioContext.getSystem().getRandomizer());
			for(unsigned int i=0; i<lNbGenerated; ++i) {
				lParents->push_back(inBreedingPool[lIndices[i]]);
			}
		}
	} else {
		Beagle_NonNullPointerAssertM(inChild->getBreederOp());
		const unsigned int lNbGenerated =
		    (mNumberRecomb->getWrappedValue()==0) ? inBreedingPool.size() :
		    minOf<unsigned int>(inBreedingPool.size(), mNumberRecomb->getWrappedValue());
		for(unsigned int i=0; i<lNbGenerated; ++i) {
			Individual::Handle lIndiv = inChild->getBreederOp()->breed(inBreedingPool,
			                            inChild->getFirstChild(),
			                            ioContext);
			lParents->push_back(lIndiv);
		}
	}

	// Log parents selected for recombination.
	Beagle_LogVerboseM(
	    ioContext.getSystem().getLogger(),
	    std::string("Recombining ")+uint2str(lParents->size())+std::string(" individuals together")
	);

	// Do recombination operation on parent and get the resulting child.
	Individual::Handle lChildIndiv = recombine(*lParents, ioContext);
	if(lChildIndiv->getFitness() != NULL) {
		lChildIndiv->getFitness()->setInvalid();
	}

	// Log information to history, if it is used.
	History::Handle lHistory = castHandleT<History>(ioContext.getSystem().haveComponent("History"));
	if(lHistory != NULL) {
		std::vector<HistoryID> lParentNames;
		for(unsigned int i=0; i<lParents->size(); ++i) {
			HistoryID::Handle lHID = castHandleT<HistoryID>(lParents->at(i)->getMember("HistoryID"));
			if(lHID != NULL) lParentNames.push_back(*lHID);
		}
		lHistory->incrementHistoryVar(*lChildIndiv);
		lHistory->trace(ioContext, lParentNames, lChildIndiv, getName(), "recombination");
	}

	return lChildIndiv;
	Beagle_StackTraceEndM();
}
/*!
 *  \brief Apply the evaluation operation on a breeding pool, returning a evaluated bred individual.
 *  \param inBreedingPool Breeding pool to use for the breeding operation.
 *  \param inChild Node handle associated to child node in the breeder tree.
 *  \param ioContext Evolutionary context of the breeding operation.
 *  \return Evaluated bred individual.
 */
Individual::Handle Beagle::MPI::EvaluationOp::breed(Individual::Bag& inBreedingPool,
													BreederNode::Handle inChild,
													Context& ioContext)
{
	Beagle_NonNullPointerAssertM(inChild);
	
	Deme& lDeme = *ioContext.getDemeHandle();
	if(lDeme.getStats()->isValid()) {
		ioContext.setProcessedDeme(0);
		if((ioContext.getGeneration()!=0) && (lDeme.getStats()->existItem("total-processed"))) {
			ioContext.setTotalProcessedDeme((unsigned int)lDeme.getStats()->getItem("total-processed"));
		}
		else ioContext.setTotalProcessedDeme(0);
		lDeme.getStats()->setInvalid();
		
		if(ioContext.getDemeIndex()==0) {
			Stats& lVivaStats = *ioContext.getVivarium().getStats();
			ioContext.setProcessedVivarium(0);
			if((ioContext.getGeneration()!=0) && (lVivaStats.existItem("total-processed"))) {
				ioContext.setTotalProcessedVivarium((unsigned int)lVivaStats.getItem("total-processed"));
			}
			else ioContext.setTotalProcessedVivarium(0);
			lVivaStats.setInvalid();
		}
	}
	
	Beagle_NonNullPointerAssertM(inChild);
	Beagle_NonNullPointerAssertM(inChild->getBreederOp());
	Individual::Handle lBredIndividual =
    inChild->getBreederOp()->breed(inBreedingPool, inChild->getFirstChild(), ioContext);
    
	if((lBredIndividual->getFitness()==NULL) || (lBredIndividual->getFitness()->isValid()==false)) {
		Beagle_LogVerboseM(
						   ioContext.getSystem().getLogger(),
						   "evaluation", "Beagle::MPIEvaluationOp",
						   "Evaluating the fitness of a new bred individual"
						   );

		individualEvaluation(*lBredIndividual, ioContext);
//		lBredIndividual->setFitness(evaluate(*lBredIndividual, ioContext));
//		lBredIndividual->getFitness()->setValid();
		
		ioContext.setProcessedDeme(ioContext.getProcessedDeme()+1);
		ioContext.setTotalProcessedDeme(ioContext.getTotalProcessedDeme()+1);
		ioContext.setProcessedVivarium(ioContext.getProcessedVivarium()+1);
		ioContext.setTotalProcessedVivarium(ioContext.getTotalProcessedVivarium()+1);
		
		Beagle_LogVerboseM(
						   ioContext.getSystem().getLogger(),
						   "evaluation", "Beagle::MPIEvaluationOp",
						   std::string("The individual fitness value is: ")+
						   lBredIndividual->getFitness()->serialize()
						   );
		
		if(mDemeHOFSize->getWrappedValue() > 0) {
			Beagle_LogVerboseM(
							   ioContext.getSystem().getLogger(),
							   "evaluation", "Beagle::MPIEvaluationOp",
							   "Updating the deme hall-of-fame"
							   );
			lDeme.getHallOfFame().updateWithIndividual(mDemeHOFSize->getWrappedValue(),
													   *lBredIndividual, ioContext);
		}
		if(mVivaHOFSize->getWrappedValue() > 0) {
			Beagle_LogVerboseM(
							   ioContext.getSystem().getLogger(),
							   "evaluation", "Beagle::MPIEvaluationOp",
							   "Updating the vivarium hall-of-fame"
							   );
			ioContext.getVivarium().getHallOfFame().updateWithIndividual(mVivaHOFSize->getWrappedValue(),
																		 *lBredIndividual, ioContext);
		}
	}
	
	return lBredIndividual;
}
/*!
 *  \return Return selection probability of breeder operator.
 *  \param inChild Child node in the breeder tree.
 */
float Beagle::MPI::EvaluationOp::getBreedingProba(BreederNode::Handle inChild)
{
	Beagle_NonNullPointerAssertM(inChild);
	Beagle_NonNullPointerAssertM(inChild->getBreederOp());
	return inChild->getBreederOp()->getBreedingProba(inChild->getFirstChild());
}