示例#1
0
void GP::Argument::forceEvaluation(GP::Datum& outResult, GP::Context& ioContext)
{
	Beagle_LogDebugM(
	    ioContext.getSystem().getLogger(),
	    "evaluation", "Beagle::GP::Argument",
	    std::string("Evaluating the ")+uint2ordinal(mIndex+1)+" argument"
	);

	GP::Context::Handle lActualContext = mSharedData->mEvalContext.back();
	mSharedData->mEvalContext.pop_back();
	lActualContext->setAllowedNodesExecution(ioContext.getAllowedNodesExecution());
	lActualContext->setAllowedExecutionTime(ioContext.getAllowedExecutionTime());
	lActualContext->setNodesExecutionCount(ioContext.getNodesExecutionCount());
	lActualContext->getExecutionTimer() = ioContext.getExecutionTimer();
	getArgument(mIndex, outResult, *lActualContext);
	ioContext.getExecutionTimer() = lActualContext->getExecutionTimer();
	ioContext.setNodesExecutionCount(lActualContext->getNodesExecutionCount());
	ioContext.setAllowedExecutionTime(lActualContext->getAllowedExecutionTime());
	ioContext.setAllowedNodesExecution(lActualContext->getAllowedNodesExecution());
	mSharedData->mEvalContext.push_back(lActualContext);
}
示例#2
0
/*!
 *  \brief Interpret the GP individual.
 *  \param outResult Datum containing the result of the interpretation.
 *  \param ioContext GP evolutionary context.
 *  \throw Beagle::ObjectException When individual or tree are empty.
 *  \throw Beagle::AssertException When context is not correctly set.
 *  \throw Beagle::GP::MaxNodesExecutionException If number of nodes execution is more than allowed.
 *  \throw Beagle::GP::MaxTimeExecutionException If elapsed execution time is more than allowed.
 */
void GP::Individual::run(GP::Datum& outResult, GP::Context& ioContext)
{
	Beagle_StackTraceBeginM();
	if(&ioContext.getIndividual() != this) {
		std::ostringstream lOSS;
		lOSS << "In GP::Individual::run():  For the given context, ";
		lOSS << "getIndividual() did not return the same individual as was passed to this (run) ";
		lOSS << "method. Consider setting the context's individual to be the same by using the ";
		lOSS << "method Context::setIndividualHandle().";
		throw Beagle_RunTimeExceptionM(lOSS.str());
	}
	if(empty()) throw Beagle_ObjectExceptionM("Could not interpret, individual has no trees!");
	if((*this)[0]->empty()) throw Beagle_ObjectExceptionM("Could not interpret, 1st tree is empty!");
	Tree::Handle lOldTreeHandle = ioContext.getGenotypeHandle();
	unsigned int lOldTreeIndex  = ioContext.getGenotypeIndex();
	ioContext.setGenotypeIndex(0);
	ioContext.setGenotypeHandle((*this)[0]);
	Beagle_LogVerboseM(
	    ioContext.getSystem().getLogger(),
	    std::string("Running the ")+uint2ordinal(ioContext.getIndividualIndex()+1)+
	    std::string(" individual")
	);
	Beagle_LogDebugM(
	    ioContext.getSystem().getLogger(),
	    std::string("The individual is: ")
	);
	Beagle_LogDebugM(
	    ioContext.getSystem().getLogger(),
	    (*this)
	);
	Beagle_LogDebugM(
	    ioContext.getSystem().getLogger(),
	    std::string("Executing the first tree root node '")+
	    (*(*this)[0])[0].mPrimitive->getName()+"'"
	);
	ioContext.setNodesExecutionCount(0);
	ioContext.incrementNodesExecuted();
	ioContext.getExecutionTimer().reset();
	ioContext.pushCallStack(0);
	(*(*this)[0])[0].mPrimitive->execute(outResult, ioContext);
	ioContext.popCallStack();
	ioContext.checkExecutionTime();
	Beagle_LogDebugM(
	    ioContext.getSystem().getLogger(),
	    std::string("Result of executing the ")+uint2ordinal(ioContext.getIndividualIndex()+1)+
	    std::string(" individual: ")+outResult.serialize()
	);
	ioContext.setGenotypeIndex(lOldTreeIndex);
	ioContext.setGenotypeHandle(lOldTreeHandle);
	Beagle_StackTraceEndM();
}