Esempio n. 1
0
/*!
 * \brief Read object from XML using system.
 * \param inIter XML iterator of input document.
 * \param ioSystem A reference to the system.
 * \throw SCHNAPS::Core::IOException if a wrong tag is encountered.
 * \throw SCHNAPS::Core::IOException if inProbabilities attribute is missing.
 * \throw SCHNAPS::Core::RunTimeException if the primitive is undefined for the specific probabilities source.
 */
void BranchMulti::readWithSystem(PACC::XML::ConstIterator inIter, Core::System& ioSystem) {
	schnaps_StackTraceBeginM();
	if (inIter->getType() != PACC::XML::eData) {
		throw schnaps_IOExceptionNodeM(*inIter, "tag expected!");
	}
	if (inIter->getValue() != getName()) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected, but ";
		lOSS << "got tag <" << inIter->getValue() << "> instead!";
		throw schnaps_IOExceptionNodeM(*inIter, lOSS.str());
	}

	// retrieve probabilities of executing each branch
	if (inIter->getAttribute("inProbabilities").empty()) {
		throw schnaps_IOExceptionNodeM(*inIter, "probabilities of executing each branch expected!");
	}
	mProbabilities_Ref.assign(inIter->getAttribute("inProbabilities"));
	
	switch (mProbabilities_Ref[0]) {
		case '@':
			// individual variable value
		case '#':
			// environment variable value
		case '%':
			// local variable value
			throw schnaps_RunTimeExceptionM("The primitive is undefined for the specific probabilities source!");
			break;
		case '$':
			// parameter value
			mProbabilities = Core::castHandleT<Core::Vector>(ioSystem.getParameters().getParameterHandle(mProbabilities_Ref.substr(1)));
			break;
		default: {
			// direct value
			std::stringstream lISS(mProbabilities_Ref);
			PACC::Tokenizer lTokenizer(lISS);
			lTokenizer.setDelimiters("|", "");
			
			std::string lProbability;
			double lSum = 0;

			mProbabilities = new Core::Vector();
			while (lTokenizer.getNextToken(lProbability)) {
				mProbabilities->push_back(new Core::Double(SCHNAPS::str2dbl(lProbability)));
				lSum += SCHNAPS::str2dbl(lProbability);
			}
			
#ifndef SCHNAPS_NDEBUG
			if (lSum != 1) {
				std::cout << "Warning: multi branches probabilities must sum to 1 (current sum: " <<  lSum << "!";
				std::cout << "\tIn: void SCHNAPS::Plugins::Control::BranchMulti::readWithSystem(PACC::XML::ConstIterator, SCHNAPS::Core::System&)\n";
			}
#endif
			break; }
	}
	setNumberArguments(mProbabilities->size());
	schnaps_StackTraceEndM("void SCHNAPS::Plugins::Control::BranchMulti::readWithSystem(PACC::XML::ConstIterator, SCHNAPS::Core::System&)");
}
Esempio n. 2
0
/*!
 *  \brief Read a linear GP mutation operator from XML tree.
 *  \param inNode XML node to use to read mutation operator.
 *  \param ioSystem Evolutionary system.
 */
void LinGP::MutationOp::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem)
{
	if((inIter->getType() != PACC::XML::eData) || (inIter->getValue() != getName())) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected!" << std::flush;
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	std::string lMutationPbReadName = inIter->getAttribute("mutationpb");
	if(lMutationPbReadName.empty() == false) mMutationPbName = lMutationPbReadName;
	std::string lInstructMutatePbReadName = inIter->getAttribute("mutinstructpb");
	if(lInstructMutatePbReadName.empty() == false) mInstructMutatePbName = lInstructMutatePbReadName;
}
Esempio n. 3
0
/*!
 *  \brief Read a mutation operator from XML subtree.
 *  \param inIter XML iterator to use to read crossover operator.
 *  \param ioSystem Evolutionary system.
 */
void GP::MutationSwapSubtreeOp::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!=getName())) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected!" << std::flush;
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	std::string mMutationPbReadName = inIter->getAttribute("mutationpb");
	if(mMutationPbReadName.empty() == false) mMutationPbName = mMutationPbReadName;
	std::string mDistribPbReadName = inIter->getAttribute("distrpb");
	if(mDistribPbReadName.empty() == false) mDistribPbName = mDistribPbReadName;
	Beagle_StackTraceEndM();
}
Esempio n. 4
0
/*!
 *  \brief Read a bit flip mutation operator from XML subtree.
 *  \param inIter XML iterator to use to read mutation operator.
 *  \param ioSystem Evolutionary system.
 */
void BitStr::MutationFlipBitOp::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!=getName())) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected!" << std::flush;
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	std::string lMutationPbReadName = inIter->getAttribute("mutationpb");
	if(lMutationPbReadName.empty() == false) mMutationPbName = lMutationPbReadName;
	std::string lBitMutatePbReadName = inIter->getAttribute("mutbitpb");
	if(lBitMutatePbReadName.empty() == false) mBitMutatePbName = lBitMutatePbReadName;
	Beagle_StackTraceEndM();
}
Esempio n. 5
0
/*!
 *  \brief Read a recombination operator from XML tree.
 *  \param inIter XML iterator to use to read recombination operator.
 *  \param ioSystem Evolutionary system.
 */
void RecombinationOp::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!=getName())) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected!" << std::flush;
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	std::string lRecombProbaReadName = inIter->getAttribute("recombpb");
	if(lRecombProbaReadName.empty()==false) mRecombProbaName = lRecombProbaReadName;
	std::string lNumberRecombReadName = inIter->getAttribute("nbrindrecomb");
	if(lNumberRecombReadName.empty()==false) mNumberRecombName = lNumberRecombReadName;
	Beagle_StackTraceEndM();
}
void Beagle::GP::MutationEphemeralOpT<T>::readWithSystem(PACC::XML::ConstIterator inIter,
        Beagle::System& ioSystem)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!=getName())) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected!" << std::flush;
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	std::string lMutationPbReadName = inIter->getAttribute("mutationpb");
	if(lMutationPbReadName.empty() == false) mMutationPbName = lMutationPbReadName;
	std::string lEphemeralNameParamName = inIter->getAttribute("primitname");
	if(lEphemeralNameParamName.empty() == false) mEphemeralNameParamName = lEphemeralNameParamName;
	Beagle_StackTraceEndM("void GP::MutationEphemeralOpT<T>::readWithSystem(PACC::XML::ConstIterator, System&)");
}
/*!
 *  \brief Read an ES vector from a XML subtree.
 *  \param inIter XML iterator from which the ES vector is read.
 *  \param ioContext Evolutionary context.
 *  \throw IOException If a reading error occured (generally bad file format)!
 */
void GA::ESVector::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType() != PACC::XML::eData) || (inIter->getValue() != "Genotype")) {
		throw Beagle_IOExceptionNodeM(*inIter, "tag <Genotype> expected!");
	}
	std::string lGenotypeType = inIter->getAttribute("type");
	if((lGenotypeType.empty() == false) && (lGenotypeType != getType())) {
		std::ostringstream lOSS;
		lOSS << "type given '" << lGenotypeType << "' mismatch type of the genotype '";
		lOSS << getType() << "'!";
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}

	PACC::XML::ConstIterator lChild = inIter->getFirstChild();
	if((!lChild) || (lChild->getType()!=PACC::XML::eString)) {
		throw Beagle_IOExceptionNodeM(*lChild, "expected content for the ES vector!");
	}

	clear();
	std::istringstream lISS(lChild->getValue());
	do {
		char lC1='\0', lC2='\0', lC3='\0';
		double lValue=DBL_MAX, lStrategy=DBL_MAX;
		lISS >> lC1 >> lValue >> lC2 >> lStrategy >> lC3;
		if((lC1!='(') || (lC2!=',') || (lC3!=')'))
			throw Beagle_IOExceptionNodeM(*lChild, "bad format of ES vector!");
		if((lValue==DBL_MAX) || (lStrategy==DBL_MAX))
			throw Beagle_IOExceptionNodeM(*lChild, "bad format of ES vector!");
		push_back(ESPair(lValue, lStrategy));
	} while(lISS.get()==int('/'));
	Beagle_StackTraceEndM("void GA::ESVector::readWithContext(PACC::XML::ConstIterator,Context&)");
}
Esempio n. 8
0
/*!
 * \brief Read object from XML using system.
 * \param inIter XML iterator of input document.
 * \param ioSystem A reference to the system.
 * \throw SCHNAPS::Core::IOException if a wrong tag is encountered.
 */
void PrimitiveTree::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem) {
	schnaps_StackTraceBeginM();
	if (inIter) {
		if (inIter->getType() != PACC::XML::eData) {
			throw schnaps_IOExceptionNodeM(*inIter, "tag expected!");
		}
		if (inIter->getValue() != getName()) {
			std::ostringstream lOSS;
			lOSS << "tag <" << getName() << "> expected, but ";
			lOSS << "got tag <" << inIter->getValue() << "> instead!";
			throw schnaps_IOExceptionNodeM(*inIter, lOSS.str());
		}

		// Get size attribute and reserve size accordingly
		std::string lSizeText = inIter->getAttribute("size");
		if (lSizeText.empty() == false) {
			reserve(str2uint(lSizeText));
		}

		PACC::XML::ConstIterator lChild = inIter->getFirstChild();
		if ((!lChild) || (lChild->getType() != PACC::XML::eData)) {
			throw schnaps_IOExceptionNodeM(*lChild, "expected a XML tag for the primitive tree!");
		}
		clear();
		readSubTree(lChild, ioSystem);
	}
	schnaps_StackTraceEndM("void SCHNAPS::Core::PrimitiveTree::readWithSystem(PACC::XML::ConstIterator, SCHNAPS::Core::System&)");
}
/*!
 *  \brief Read a float vector from a XML subtree.
 *  \param inIter XML iterator from which the float vector is read.
 *  \param ioContext Evolutionary context.
 *  \throw Beagle::IOException If a reading error occured (generally bad file format)!
 */
void GA::IntegerVector::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType() != PACC::XML::eData) || (inIter->getValue() != "Genotype")) {
		throw Beagle_IOExceptionNodeM(*inIter, "tag <Genotype> expected!");
	}
	std::string lGenotypeType = inIter->getAttribute("type");
	if((lGenotypeType.empty() == false) && (lGenotypeType != getType())) {
		std::ostringstream lOSS;
		lOSS << "type given '" << lGenotypeType << "' mismatch type of the genotype '";
		lOSS << getType() << "'!";
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}

	PACC::XML::ConstIterator lChild = inIter->getFirstChild();
	if((!lChild) || (lChild->getType()!=PACC::XML::eString))
		throw Beagle_IOExceptionNodeM(*lChild, "expected content for the float vector!");

	clear();
	std::istringstream lISS(lChild->getValue());
	while(lISS.good()) {
		int lValue=INT_MAX;
		lISS >> lValue;
		push_back(lValue);
		if(lISS.good()==false) break;
		int lDelim=lISS.get();
		if((lISS.good()==false) || (lDelim==-1)) break;
	}
	Beagle_StackTraceEndM("void GA::IntegerVector::readWithContext(PACC::XML::ConstIterator,Context&)");
}
Esempio n. 10
0
/*!
 *  \brief Read a Gaussian mutation operator from a XML subtree.
 *  \param inIter XML iterator to use to read mutation operator.
 *  \param ioSystem Evolutionary system.
 */
void FltVec::MutationGaussianOp::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!=getName())) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected!" << std::flush;
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	string lMutationPbReadName = inIter->getAttribute("mutationpb");
	if(lMutationPbReadName.empty() == false) mMutationPbName = lMutationPbReadName;
	string lMutateFloatPbReadName = inIter->getAttribute("mutfloatpb");
	if(lMutateFloatPbReadName.empty() == false) mMutateFloatPbName = lMutateFloatPbReadName;
	string lMutateGaussMuReadName = inIter->getAttribute("mutgaussmu");
	if(lMutateGaussMuReadName.empty() == false) mMutateGaussMuName = lMutateGaussMuReadName;
	string lMutateGaussSigmaReadName = inIter->getAttribute("mutgausssigma");
	if(lMutateGaussSigmaReadName.empty() == false) mMutateGaussSigmaName = lMutateGaussSigmaReadName;
	Beagle_StackTraceEndM();
}
Esempio n. 11
0
/*!
 *  \brief Read an argument primitive from XML subtree.
 *  \param inIter XML iterator to read primitive from.
 *  \param ioContext Evolutionary context.
 */
void GP::Argument::readWithContext(PACC::XML::ConstIterator inIter, GP::Context& ioContext)
{
	Beagle_StackTraceBeginM();
	GP::Primitive::readWithContext(inIter, ioContext);
	std::string lIndexValue = inIter->getAttribute("id");
	if(lIndexValue.empty()==false) {
		mIndex = str2uint(lIndexValue);
		Beagle_AssertM(mIndex < ioContext.getGenotype().getNumberArguments());
	}
	Beagle_StackTraceEndM();
}
Esempio n. 12
0
/*!
 *  \brief Read a initialization operator from a XML subtree.
 *  \param inIter XML iterator to use to read initialization operator.
 *  \param ioSystem Evolutionary system.
 */
void InitializationOp::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!=getName())) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected!" << std::flush;
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	std::string mReproProbaReadName = inIter->getAttribute("repropb");
	if(mReproProbaReadName.empty() == false) mReproProbaName = mReproProbaReadName;
	Beagle_StackTraceEndM();
}
Esempio n. 13
0
/*!
 * \brief Read object from XML using system.
 * \param inIter XML iterator of input document.
 * \param ioSystem A reference to the system.
 * \throw SCHNAPS::Core::IOException if a wrong tag is encountered.
 * \throw SCHNAPS::Core::IOException if inProbability attribute is missing.
 */
void Branch::readWithSystem(PACC::XML::ConstIterator inIter, Core::System& ioSystem) {
	schnaps_StackTraceBeginM();
	if (inIter->getType() != PACC::XML::eData) {
		throw schnaps_IOExceptionNodeM(*inIter, "tag expected!");
	}
	if (inIter->getValue() != getName()) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected, but ";
		lOSS << "got tag <" << inIter->getValue() << "> instead!";
		throw schnaps_IOExceptionNodeM(*inIter, lOSS.str());
	}

	// retrieve probability of executing the first branch
	if (inIter->getAttribute("inProbability").empty()) {
		throw schnaps_IOExceptionNodeM(*inIter, "probability of executing first branch expected!");
	}
	mProbability_Ref = inIter->getAttribute("inProbability");
	
	switch (mProbability_Ref[0]) {
		case '@':
			// individual variable value
		case '#':
			// environment variable value
		case '%':
			// local variable value
			mProbability = NULL;
			break;
		case '$':
			// parameter value
			mProbability = Core::castHandleT<Core::Double>(ioSystem.getParameters().getParameterHandle(mProbability_Ref.substr(1)));
			break;
		default:
			// direct value
			mProbability = new Core::Double();
			mProbability->readStr(mProbability_Ref);
			break;
	}
	schnaps_StackTraceEndM("void SCHNAPS::Plugins::Control::Branch::readWithSystem(PACC::XML::ConstIterator, SCHNAPS::Core::System&)");
}
Esempio n. 14
0
/*!
 *  \brief Read a multiobjective fitness from a XML subtree.
 *  \param inIter XML iterator to use to read the fitness value.
 */
void FitnessMultiObj::read(PACC::XML::ConstIterator inIter)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Fitness"))
		throw Beagle_IOExceptionNodeM(*inIter, "tag <Fitness> expected!");

	const std::string& lValid = inIter->getAttribute("valid");
	if(lValid.empty() || (lValid == "yes")) {
	
		// Check type of fitness read
		const std::string& lType = inIter->getAttribute("type");
		if((lType.empty() == false) && (lType != getType())) {
			std::ostringstream lOSS;
			lOSS << "type given '" << lType << "' mismatch type of the fitness '";
			lOSS << getType() << "'!";
			throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
		}

		// Read objective values
		clear();
		for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
			if((lChild->getType() != PACC::XML::eData) || (lChild->getValue() != "Obj")) continue;
			PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
			if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "needed a double value in the <Obj> tag!");
			if(lChild2->getType() != PACC::XML::eString)
				throw Beagle_IOExceptionNodeM(*lChild2, "needed a double value in the <Obj> tag!");
			push_back(str2dbl(lChild2->getValue()));
		}
		setValid();
		
	} else if(lValid == "no") {
		clear();
		setInvalid();
	}
	else {
		throw Beagle_IOExceptionNodeM(*inIter, "bad fitness validity value!");
	}
	Beagle_StackTraceEndM();
}
Esempio n. 15
0
/*!
 *  \brief Read invoker primitive from XML subtree.
 *  \param inIter XML iterator to read the primitive from.
 *  \param ioContext Evolutionary context.
 */
void GP::Invoker::readWithContext(PACC::XML::ConstIterator inIter, GP::Context& ioContext)
{
	Beagle_StackTraceBeginM();
	GP::Primitive::readWithContext(inIter, ioContext);
	std::string lIndexValue = inIter->getAttribute("id");
	if(lIndexValue.empty()==false) mIndex = str2uint(lIndexValue);
	unsigned int lArgsCount = 0;
	for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
		if(lChild->getType()==PACC::XML::eData) ++lArgsCount;
	}
	setNumberArguments(lArgsCount);
	Beagle_StackTraceEndM("void GP::Invoker::readWithContext(PACC::XML::ConstIterator inIter, GP::Context& ioContext)");
}
Esempio n. 16
0
/*!
 *  \brief Reading a history entry.
 */
void HistoryEntry::read(PACC::XML::ConstIterator inIter)
{
	Beagle_StackTraceBeginM();

	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Entry"))
		throw Beagle_IOExceptionNodeM(*inIter, "tag <Entry> expected!");

	std::string lIndividualVarText = inIter->getAttribute("var");
	if(lIndividualVarText.empty())
		throw Beagle_IOExceptionNodeM(*inIter, "attribute 'var' of the tag <Entry> expected!");
	else
		mIndividualVar = str2uint(lIndividualVarText);

	std::string lGenerationText = inIter->getAttribute("generation");
	if (lGenerationText.empty())
		throw Beagle_IOExceptionNodeM(*inIter, "attribute 'generation' of the tag <Entry> expected!");
	else
		mGeneration = str2uint(lGenerationText);

	mParents.clear();
	mActions.clear();
	mOpNames.clear();

	for(PACC::XML::ConstIterator lChild(inIter->getFirstChild()); lChild; ++lChild) {
		if(lChild->getType()==PACC::XML::eData) {
			if(lChild->getValue()=="Parent") {
				unsigned int lHistoryId = str2uint(lChild->getAttribute("id"));
				unsigned int lHistoryVar = str2uint(lChild->getAttribute("var"));
				mParents.push_back(HistoryID(lHistoryId, lHistoryVar));
			} else if(lChild->getValue()=="Operations") {
				mActions.push_back(lChild->getAttribute("action"));
				mOpNames.push_back(lChild->getAttribute("opname"));
			}
		}
	}

	Beagle_StackTraceEndM();
}
/*!
 *  \brief Read a OversizeOp operator for XML tree.
 *  \param inIter XML iterator to use to read OversizeOp operator.
 *  \param ioSystem Evolutionary system.
 */
void OversizeOp::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!=getName())) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected!" << std::flush;
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	string lOversizeRatioReadName = inIter->getAttribute("ratio_name");
	if(lOversizeRatioReadName.empty() == false) mOversizeRatioName = lOversizeRatioReadName;
	
	ReplacementStrategyOp::readWithSystem(inIter, ioSystem);
	Beagle_StackTraceEndM("void OversizeOp::readWithSystem(PACC::XML::ConstIterator, System&)");
}
Esempio n. 18
0
/*!
 *  \brief Read a max fitness termination operator from a XML subtree.
 *  \param inIter XML iterator from which the operator is read.
 *  \param ioSystem Evolutionary system.
 *  \throw IOException If a reading error occurs.
 */
void TermMaxFitnessOp::readWithSystem(PACC::XML::ConstIterator inIter, System& ioSystem)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!=getName())) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected!" << std::flush;
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	std::string lFitnessStr = inIter->getAttribute("fitness");
	if(lFitnessStr.empty() == false) {
		mMaxFitnessDefault = str2dbl(lFitnessStr);
		if(mMaxFitness != NULL) mMaxFitness->getWrappedValue() = mMaxFitnessDefault;
	}
	Beagle_StackTraceEndM();
}
Esempio n. 19
0
/*!
 *  \brief Read genotype from a Beagle XML node.
 *  \param inIter XML iterator to read the genotype from.
 *  \param ioContext Evolutionary context.
 */
void Genotype::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType() != PACC::XML::eData) || (inIter->getValue() != "Genotype")) {
		throw Beagle_IOExceptionNodeM(*inIter, "tag <Genotype> expected!");
	}
	std::string lGenotypeType = inIter->getAttribute("type");
	if((lGenotypeType.empty() == false) && (lGenotypeType != getType())) {
		std::ostringstream lOSS;
		lOSS << "type given '" << lGenotypeType << "' mismatch type of the genotype '";
		lOSS << getType() << "'!";
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	Beagle_StackTraceEndM("void Genotype::readWithContext(PACC::XML::ConstIterator,Context&)");
}
Esempio n. 20
0
void PopulationManager::readWithSystem(PACC::XML::ConstIterator inIter, SCHNAPS::Core::System& ioSystem) {
	schnaps_StackTraceBeginM();
	if (inIter->getType() != PACC::XML::eData) {
		throw schnaps_IOExceptionNodeM(*inIter, "tag expected!");
	}
	if (inIter->getValue() != getName()) {
		std::ostringstream lOSS;
		lOSS << "tag <" << getName() << "> expected, but ";
		lOSS << "got tag <" << inIter->getValue() << "> instead!";
		throw schnaps_IOExceptionNodeM(*inIter, lOSS.str());
	}

#ifdef SCHNAPS_FULL_DEBUG
	printf("Reading population manager\n");
#endif

	inIter = inIter->getFirstChild();
	// read generator
	mGenerator->read(inIter++);

	// read population source
	if (inIter->getType() != PACC::XML::eData) {
		throw schnaps_IOExceptionNodeM(*inIter, "tag expected!");
	}
	if (inIter->getValue() != "Population") {
		std::ostringstream lOSS;
		lOSS << "tag <Population> expected, but ";
		lOSS << "got tag <" << inIter->getValue() << "> instead!";
		throw schnaps_IOExceptionNodeM(*inIter, lOSS.str());
	}

	for (PACC::XML::ConstIterator lChild = inIter->getFirstChild(); lChild; lChild++) {
		if (lChild->getType() == PACC::XML::eData) {
			if (lChild->getValue() != "SubPopulation") {
				std::ostringstream lOSS;
				lOSS << "tag <SubPopulation> expected, but ";
				lOSS << "got tag <" << lChild->getValue() << "> instead!";
				throw schnaps_IOExceptionNodeM(*lChild, lOSS.str());
			}
			if (lChild->getAttribute("time").empty()) {
				throw schnaps_IOExceptionNodeM(*lChild, "time attribute expected!");
			}
			if (lChild->getAttribute("profile").empty()) {
				throw schnaps_IOExceptionNodeM(*lChild, "profile attribute expected!");
			}
			if (lChild->getAttribute("size").empty()) {
				throw schnaps_IOExceptionNodeM(*lChild, "size attribute expected!");
			}

			this->insert(std::pair<unsigned long, Source>(SCHNAPS::str2uint(lChild->getAttribute("time")),
															Source(lChild->getAttribute("profile"), SCHNAPS::str2uint(lChild->getAttribute("size")))));
		}
	}
	schnaps_StackTraceEndM("void SCHNAPS::Simulation::PopulationManager::readWithSystem(PACC::XML::ConstIterator, SCHNAPS::Core::System&)");
}
Esempio n. 21
0
/*!
 *  \brief Read the member instance.
 *  \param inIter Iterator to XML node to read component from.
 *  \param ioContext Evolutionary context.
 */
void Member::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType() != PACC::XML::eData) || (inIter->getValue() != getName())) {
		std::ostringstream lOSS;
		lOSS << "expected to get tag '" << getName() << "' instead of tag '";
		lOSS << inIter->getValue() << "'!";
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	std::string lType = inIter->getAttribute("type");
	if((lType.empty() == false) && (lType != getType())) {
		std::ostringstream lOSS;
		lOSS << "type given '" << lType << "' mismatch type of the member '";
		lOSS << getType() << "'!";
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	Beagle_StackTraceEndM("void Member::readWithContext(PACC::XML::ConstIterator,Context&)");
}
Esempio n. 22
0
/*!
 *  \brief Read an individual from an XML node.
 *  \param inIter XML iterator to read the individual from.
 *  \param ioContext Evolutionary context to use to read the individual.
 *  \throw Beagle::IOException If the format is not respected.
 */
void Individual::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Individual")) {
		throw Beagle_IOExceptionNodeM(*inIter, "tag <Individual> expected!");
	}
	// Be sure that the types are corresponding
	const std::string& lIndivType = inIter->getAttribute("type");
	if((lIndivType.empty() == false) && (lIndivType != getType())) {
		std::ostringstream lOSS;
		lOSS << "type given '" << lIndivType << "' mismatch type of the individual '";
		lOSS << getType() << "'!";
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	// Read members
	readMembers(inIter->getFirstChild(), ioContext);
	// Read fitness
	readFitness(inIter->getFirstChild(), ioContext);
	// Read genotypes
	readGenotypes(inIter->getFirstChild(), ioContext);
	Beagle_StackTraceEndM();
}
Esempio n. 23
0
/*!
 *  \brief Read a vivarium from an XML node.
 *  \param inIter XML iterator to read the vivarium from.
 *  \param ioContext Evolutionary context to use to read the vivarium.
 *  \throw Beagle::IOException If the format is not respected.
 */
void Vivarium::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Vivarium")) {
		throw Beagle_IOExceptionNodeM(*inIter, "tag <Vivarium> expected!");
	}
	// Be sure that the types are corresponding
	const std::string& lVivariumType = inIter->getAttribute("type");
	if((lVivariumType.empty()==false) && (lVivariumType!=getType())) {
		std::ostringstream lOSS;
		lOSS << "type given '" << lVivariumType << "' mismatch type of the vivarium '";
		lOSS << getType() << "'!";
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}
	// Read members
	readMembers(inIter->getFirstChild(), ioContext);
	// Read population
	for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
		if((lChild->getType()==PACC::XML::eData) && (lChild->getValue()=="Population")) {
			readPopulation(lChild, ioContext);
		}
	}
	Beagle_StackTraceEndM();
}
void BGFitness::read(PACC::XML::ConstIterator inNode) {	
	//	Beagle_StackTraceBeginM();
	
	if((inNode->getType()!=PACC::XML::eData) || (inNode->getValue()!="Fitness"))
		throw Beagle_IOExceptionNodeM(*inNode, "tag <Fitness> expected!");
	
	std::string lValid = inNode->getAttribute("valid").c_str();
	
	if(lValid.empty() || (lValid == "yes")) {
		std::string lType = inNode->getAttribute("type").c_str();
		if(lType != "LogFitness")
			throw Beagle_IOExceptionNodeM((*inNode), "fitness type mismatch!");
		
		mUncompressedSize.clear();
		mVariableData.clear();
		mVariableName.clear();
		mStateMatrices.clear();
		
		for(PACC::XML::ConstIterator lChild=inNode->getFirstChild(); lChild; lChild=lChild->getNextSibling()) {
			if(lChild->getValue() == "Obj") {
				PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
				if(!lChild2) throw Beagle_IOExceptionNodeM(*inNode, "no fitness value present!");
				if(lChild2->getType() != PACC::XML::eString)
					throw Beagle_IOExceptionNodeM(*inNode, "no fitness value present!");

				mFitness = str2dbl(lChild2->getValue().c_str());

			}
			if(lChild->getValue() == "OriObj") {
				PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
				if(!lChild2) throw Beagle_IOExceptionNodeM(*inNode, "no original fitness value present!");
				if(lChild2->getType() != PACC::XML::eString)
					throw Beagle_IOExceptionNodeM(*inNode, "no original fitness value present!");
				
				mOriginalFitness = str2dbl(lChild2->getValue().c_str());
				
			}
			if(lChild->getValue() == "StateMatrices") {
				for(PACC::XML::ConstIterator lChild2=lChild->getFirstChild(); lChild2; lChild2=lChild2->getNextSibling()) {
					PACC::Matrix lMatrix;
					lMatrix.read(lChild2);
					//MatrixInterface lInterface;
//					lInterface.read(lMatrix,*lChild2);
					mStateMatrices.push_back(lMatrix);
				}
			}
			else if(lChild->getValue() == "Data") {
				mVariableName.push_back(lChild->getAttribute("Name"));
				mUncompressedSize.push_back( str2uint(lChild->getAttribute("usize")) );
				if(str2uint(lChild->getAttribute("usize")) != 0) {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) {
						throw Beagle_IOExceptionNodeM((*lChild), "needed a CDATA value in the <Path> tag!");
					}
					if(lChild2->getType() != PACC::XML::eString) {
						throw Beagle_IOExceptionNodeM((*lChild2), "needed a string value in the <Path> tag!");
					}
					mVariableData.push_back(lChild2->getValue());
				} else {
					mVariableData.push_back("");
				}
			}
			else if(lChild->getValue() == "DataSet") {
				unsigned int lID = str2uint(lChild->getAttribute("ID"));
				double lFitness = 0;
				for(PACC::XML::ConstIterator lChild2=lChild->getFirstChild(); lChild2; lChild2=lChild2->getNextSibling()) {
					if(lChild2->getValue() == "Obj") {
						PACC::XML::ConstIterator lChild3 = lChild2->getFirstChild();
						if(!lChild3) throw Beagle_IOExceptionNodeM(*inNode, "no fitness value present!");
						if(lChild3->getType() != PACC::XML::eString)
							throw Beagle_IOExceptionNodeM(*inNode, "no fitness value present!");
						lFitness = str2dbl(lChild3->getValue());
					}
					else if(lChild2->getValue() == "Data") {
						mVariableName.push_back(lChild2->getAttribute("Name"));
						mVariableDataSet.push_back(lID);
						mUncompressedSize.push_back( str2uint(lChild2->getAttribute("usize")) );
						if(str2uint(lChild2->getAttribute("usize")) != 0) {
							PACC::XML::ConstIterator lChild3 = lChild2->getFirstChild();
							if(!lChild3) {
								throw Beagle_IOExceptionNodeM((*lChild2), "needed a CDATA value in the <Path> tag!");
							}
							if(lChild3->getType() != PACC::XML::eString) {
								throw Beagle_IOExceptionNodeM((*lChild3), "needed a string value in the <Path> tag!");
							}
							mVariableData.push_back(lChild3->getValue());
						} else {
							mVariableData.push_back("");
						}
					}
				}
				
				mDataSet[lID] = lFitness;
			}
			else if(lChild->getValue() == "Info") {
				for(PACC::XML::ConstIterator lChild2=lChild->getFirstChild(); lChild2; lChild2=lChild2->getNextSibling()) {
					std::string lInfoName = lChild2->getValue();
					PACC::XML::ConstIterator lChild3 = lChild2->getFirstChild();
					if(!lChild3) throw Beagle_IOExceptionNodeM(*inNode, "info data present!");
					if(lChild3->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*inNode, "info data present!");
					std::string lInfoData = lChild3->getValue();
					
					mInfo[lInfoName] = lInfoData;
				}
			}
			else if(lChild->getValue() == "BondGraph") {
				mBondGraph = new GrowingHybridBondGraph;
				mBondGraph->read(lChild);
			}	
			else if(lChild->getValue() == "SimplifiedBondGraph") {
				PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
				if(!lChild2) throw Beagle_IOExceptionNodeM(*inNode, "No simplified bond graph present!");
				if(lChild2->getValue() == "BondGraph") {
					mSimplifiedBondGraph = new GrowingHybridBondGraph;
					mSimplifiedBondGraph->read(lChild2);
				}
			}
			else //Ignore anything else
				continue;
			
		}
		setValid();
	}
	else if(lValid == "no") setInvalid();
	else throw Beagle_IOExceptionNodeM((*inNode), "bad fitness validity value!");
	//	Beagle_StackTraceEndM("void LogFitness::read(Beagle::XMLNode::Handle inNode)");
	
}
Esempio n. 25
0
/*!
 *  \brief Read a MCC's fitness from a XML subtree.
 *  \param inIter XML iterator to use to read the fitness values.
 */
void GP::FitnessMCC::read(PACC::XML::ConstIterator inIter)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType() != PACC::XML::eData) || (inIter->getValue() != "Fitness")) {
		throw Beagle_IOExceptionNodeM(*inIter, "tag <Fitness> expected!");
	}

	std::string lValid = inIter->getAttribute("valid");
	if(lValid.empty() || (lValid == "yes")) {
	
		// Check type of fitness read
		std::string lType = inIter->getAttribute("type");
		if((lType.empty() == false) && (lType != getType())) {
			std::ostringstream lOSS;
			lOSS << "type given '" << lType << "' mismatch type of the fitness '";
			lOSS << getType() << "'!";
			throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
		}

		// Read values of MCC's fitness
		for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
			if(lChild->getType() == PACC::XML::eData) {
				if(lChild->getValue() == "MCC") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no MCC fitness value present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no MCC fitness value present!");
					mValue= str2dbl(lChild2->getValue());
				} else if(lChild->getValue() == "TruePositives") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no value for true positives present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no value for true positives present!");
					mTruePositives= str2dbl(lChild2->getValue());
				} else if(lChild->getValue() == "FalsePositives") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no value for false positives present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no value for false positives present!");
					mFalsePositives= str2dbl(lChild2->getValue());
				} else if(lChild->getValue() == "TrueNegatives") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no value for true negatives present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no value for true negatives present!");
					mTrueNegatives= str2dbl(lChild2->getValue());
				} else if(lChild->getValue() == "FalseNegatives") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no value for false negatives present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no value for false negatives present!");
					mFalseNegatives= str2uint(lChild2->getValue());
				} else if(lChild->getValue() == "TruePositivesRel") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no value for true positives rel present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no value for true positives rel present!");
					mTruePositivesRel= str2dbl(lChild2->getValue());
				} else if(lChild->getValue() == "FalsePositivesRel") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no value for false positives rel present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no value for false positives rel present!");
					mFalsePositivesRel= str2dbl(lChild2->getValue());
				} else if(lChild->getValue() == "TrueNegativesRel") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no value for true negatives rel present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no value for true negatives rel present!");
					mTrueNegativesRel= str2dbl(lChild2->getValue());
				} else if(lChild->getValue() == "FalseNegativesRel") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no value for false negatives Rel present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no value for false negatives Rel present!");
					mFalseNegativesRel= str2uint(lChild2->getValue());
				}
			}
		}

	} else if(lValid == "no") {
		setInvalid();
	}
	else {
		throw Beagle_IOExceptionNodeM(*inIter, "bad fitness validity value!");
	}

	Beagle_StackTraceEndM("void GP::FitnessMCC::read(PACC::XML::ConstIterator inIter)");
}
void TreeSTag::readWithContext(PACC::XML::ConstIterator inIter, Beagle::Context& ioContext){
	Beagle_StackTraceBeginM();
	GP::Context& lGPContext = castObjectT<GP::Context&>(ioContext);
	
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Genotype"))
		throw Beagle_IOExceptionNodeM(*inIter, "tag <Genotype> expected!");
	
	std::string lType = inIter->getAttribute("type").c_str();
	if(lType.empty())
		throw Beagle_IOExceptionNodeM(*inIter, "GP tree type of the genotype is not present!");
	if(lType != "gptreetag")
		throw Beagle_IOExceptionNodeM(*inIter, std::string("type of genotype mismatch, expected ")
									  +std::string("\"gptreetag\" but read \"")+lType+std::string("\" instead!"));
	
	//Get structure id
	std::string lStructureID = inIter->getAttribute("structureid").c_str();
	mStructureID = str2uint(lStructureID);
	
	// Get primitive set index
	std::string lPrimitiveSetIndexText = inIter->getAttribute("primitiveSetIndex").c_str();
	if(lPrimitiveSetIndexText.empty()) {
		// No primitive set index was specified.  This must be an old
		// tree.  Assume index is equal to tree's index
		unsigned int lGenotypeIndex = ioContext.getGenotypeIndex();
		if(lGenotypeIndex >= lGPContext.getSystem().getPrimitiveSuperSet().size()) {
			throw Beagle_RunTimeExceptionM(std::string("In GP::Tree::readWithContext(): The ")+
										   std::string("'primitiveSetIndex' attribute was missing from an individual's genotype. ")+
										   std::string("It would normally be assumed that such a tree was to be mapped to the ")+
										   std::string("primitive set of the same index as the genotype. In this case that would ")+
										   std::string("result in an incorrect mapping because there are not enough primitive sets ")+
										   std::string("in the System. Perhaps this individual was not intended to be read with the ")+
										   std::string("current set of primitive sets?"));
		}
		setPrimitiveSetIndex(lGenotypeIndex);
	}
	else {
		// primitiveSetIndex is a valid attribute.
		unsigned int lPrimitiveSetIndex = str2uint(lPrimitiveSetIndexText);
		if(lPrimitiveSetIndex >= lGPContext.getSystem().getPrimitiveSuperSet().size()) {
			std::string lMessage = std::string("In GP::Tree::readWithContext(): The 'primitiveSetIndex' ")+
			std::string("attribute contained the value '") + lPrimitiveSetIndexText + 
			std::string("' which was read as the number '") + uint2str(lPrimitiveSetIndex) + 
			std::string("'. This value is incorrect as there are not enough primitive sets in the ")+
			std::string("System. Perhaps this individual was not intended to be read with the current ")+
			std::string("set of primitive sets?");
			throw Beagle_RunTimeExceptionM(lMessage);
		}
		setPrimitiveSetIndex(lPrimitiveSetIndex);
	}
	
	// Get numberArguments attribute
	std::string lNumberArgumentsText = inIter->getAttribute("numberArguments").c_str();
	if(lNumberArgumentsText.empty()) {
		// numberArguments attribute wasn't defined.  This must be an old
		// tree.  Assume the number of arguments is zero.
		setNumberArguments(0);
	}
	else {
		// numberArguments is a valid attribute.
		setNumberArguments(str2uint(lNumberArgumentsText));
	}
	
	// Get size attribute and reserve size accordingly
	std::string lSizeText = inIter->getAttribute("size").c_str();
	if(lSizeText.empty()==false) reserve(str2uint(lSizeText));
	
	PACC::XML::ConstIterator lChild = inIter->getFirstChild();
	if((!lChild) || (lChild->getType()!=PACC::XML::eData))
		throw Beagle_IOExceptionNodeM(*lChild, "expected a XML tag for the GP tree!");
	
	clear();
	readSubTree(lChild, lGPContext);
	
	//Read BondGraph if any
	const PACC::XML::Node* lParent = inIter->getParent();
	
	PACC::XML::ConstFinder lIndivFinder = PACC::XML::ConstIterator(lParent);
	PACC::XML::ConstIterator lBGTag = lIndivFinder.find("//BondGraph");
	if(!lBGTag) { 
		return;
	}
	
//	mBondGraph = new GrowingHybridBondGraph;
//	mBondGraph->read(lBGTag);	
	
	Beagle_StackTraceEndM("void GP::Tree::readWithContext(PACC::XML::ConstIterator inIter, Beagle::Context& ioContext)");
}
Esempio n. 27
0
/*!
 *  \brief Read stats from a XML subtree.
 *  \param inIter XML iterator to read the stats from.
 *  \param ioContext Evolutionary context to use to read the hall-of-fame.
 */
void Stats::readWithContext(PACC::XML::ConstIterator inIter, Context& ioContext)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType()!=PACC::XML::eData) || (inIter->getValue()!="Stats"))
		throw Beagle_IOExceptionNodeM(*inIter, "tag <Stats> expected!");

	// Be sure that the types are corresponding
	std::string lIndivType = inIter->getAttribute("type");
	if((lIndivType.empty()==false) && (lIndivType!=getType())) {
		std::ostringstream lOSS;
		lOSS << "type given '" << lIndivType << "' mismatch type of the statistics '";
		lOSS << getType() << "'!";
		throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
	}

	std::string lValid = inIter->getAttribute("valid");
	clear();
	mItemMap.clear();
	if(lValid.empty() || (lValid == "yes")) {
		mValid = true;
		mID = inIter->getAttribute("id");

		std::string lGenerationStr = inIter->getAttribute("generation");
		if(lGenerationStr.empty() == false) mGeneration = str2uint(lGenerationStr);
		else mGeneration = 0;

		std::string lPopSizeStr = inIter->getAttribute("popsize");
		if(lPopSizeStr.empty() == false) mPopSize = str2uint(lPopSizeStr);
		else mPopSize = 0;

		unsigned int lSize=0;
		for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
			if((lChild->getType()==PACC::XML::eData) && (lChild->getValue()=="Measure")) ++lSize;
		}
		resize(lSize);
		unsigned int lIndexMeasure=0;
		for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
			if(lChild->getType() == PACC::XML::eData) {
				if(lChild->getValue() == "Item") {
					std::string lKey = lChild->getAttribute("key");
					if(lKey.empty()) {
						std::ostringstream lOSS;
						lOSS << "expected a key attribute while reading a statistics item!";
						throw Beagle_IOExceptionNodeM(*lChild, lOSS.str());
					}
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) {
						std::ostringstream lOSS;
						lOSS << "expected an item value while reading a statistics item!";
						throw Beagle_IOExceptionNodeM(*lChild, lOSS.str());
					}
					if(lChild2->getType() != PACC::XML::eString) {
						std::ostringstream lOSS;
						lOSS << "expected an item value while reading a statistics item!";
						throw Beagle_IOExceptionNodeM(*lChild2, lOSS.str());
					}
					mItemMap.insert(std::make_pair(lKey,str2dbl(lChild2->getValue())));
				}
				else if(lChild->getValue() == "Measure") {
					(*this)[lIndexMeasure].mID  = lChild->getAttribute("id");
					(*this)[lIndexMeasure].mAvg = 0.0;
					(*this)[lIndexMeasure].mStd = 0.0;
					(*this)[lIndexMeasure].mMax = 0.0;
					(*this)[lIndexMeasure].mMin = 0.0;
					for(PACC::XML::ConstIterator lChild2=lChild->getFirstChild(); lChild2; ++lChild2) {
						if(lChild2->getType() == PACC::XML::eData) {
							if(lChild2->getValue() == "Avg") {
								PACC::XML::ConstIterator lChild3 = lChild2->getFirstChild();
								if(lChild3->getType() != PACC::XML::eString) continue;
								else (*this)[lIndexMeasure].mAvg = str2dbl(lChild3->getValue());
							} else if(lChild2->getValue() == "Std") {
								PACC::XML::ConstIterator lChild3 = lChild2->getFirstChild();
								if(lChild3->getType() != PACC::XML::eString) continue;
								else (*this)[lIndexMeasure].mStd = str2dbl(lChild3->getValue());
							} else if(lChild2->getValue() == "Max") {
								PACC::XML::ConstIterator lChild3 = lChild2->getFirstChild();
								if(lChild3->getType() != PACC::XML::eString) continue;
								else (*this)[lIndexMeasure].mMax = str2dbl(lChild3->getValue());
							} else if(lChild2->getValue() == "Min") {
								PACC::XML::ConstIterator lChild3 = lChild2->getFirstChild();
								if(lChild3->getType() != PACC::XML::eString) continue;
								else (*this)[lIndexMeasure].mMin = str2dbl(lChild3->getValue());
							}
						}
					}
					++lIndexMeasure;
				}
			}
		}
	} else if(lValid == "no") mValid = false;
	else throw Beagle_IOExceptionNodeM((*inIter), "bad stats validity value!");
	Beagle_StackTraceEndM("void Stats::readWithContext(PACC::XML::ConstIterator,Context&)");
}
/*!
 *  \brief Read a Koza's fitness from a XML subtree.
 *  \param inIter XML iterator to use to read the fitness values.
 */
void GP::FitnessKoza::read(PACC::XML::ConstIterator inIter)
{
	Beagle_StackTraceBeginM();
	if((inIter->getType() != PACC::XML::eData) || (inIter->getValue() != "Fitness")) {
		throw Beagle_IOExceptionNodeM(*inIter, "tag <Fitness> expected!");
	}

	std::string lValid = inIter->getAttribute("valid");
	if(lValid.empty() || (lValid == "yes")) {
	
		// Check type of fitness read
		std::string lType = inIter->getAttribute("type");
		if((lType.empty() == false) && (lType != getType())) {
			std::ostringstream lOSS;
			lOSS << "type given '" << lType << "' mismatch type of the fitness '";
			lOSS << getType() << "'!";
			throw Beagle_IOExceptionNodeM(*inIter, lOSS.str());
		}

		// Read values of Koza's fitness
		for(PACC::XML::ConstIterator lChild=inIter->getFirstChild(); lChild; ++lChild) {
			if(lChild->getType() == PACC::XML::eData) {
				if(lChild->getValue() == "Normalized") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no normalized fitness value present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no normalized fitness value present!");
					mValue = str2dbl(lChild2->getValue());
				} else if(lChild->getValue() == "Adjusted") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no adjusted fitness value present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no adjusted fitness value present!");
					mAdjustedFitness = str2dbl(lChild2->getValue());
				} else if(lChild->getValue() == "Standardized") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no standardized fitness value present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no standardized fitness value present!");
					mStandardizedFitness = str2dbl(lChild2->getValue());
				} else if(lChild->getValue() == "Raw") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no raw fitness value present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no raw fitness value present!");
					mRawFitness = str2dbl(lChild2->getValue());
				} else if(lChild->getValue() == "Hits") {
					PACC::XML::ConstIterator lChild2 = lChild->getFirstChild();
					if(!lChild2) throw Beagle_IOExceptionNodeM(*lChild, "no hits value present!");
					if(lChild2->getType() != PACC::XML::eString)
						throw Beagle_IOExceptionNodeM(*lChild2, "no hits value present!");
					mHits = str2uint(lChild2->getValue());
				}
			}
		}

	} else if(lValid == "no") {
		setInvalid();
	}
	else {
		throw Beagle_IOExceptionNodeM(*inIter, "bad fitness validity value!");
	}

	Beagle_StackTraceEndM("void GP::FitnessKoza::read(PACC::XML::ConstIterator inIter)");
}