2#include <ecf/ECF_base.h>
5#include "IntGenotype.h"
10 void IntGenotype::registerParameters(StateP state)
12 registerParameter(state,
"lbound", (voidP)
new int(-10), ECF::INT);
13 registerParameter(state,
"ubound", (voidP)
new int(10), ECF::INT);
14 registerParameter(state,
"size", (voidP)(
new uint(1)), ECF::UINT);
17 bool IntGenotype::initialize(StateP state)
19 if (!isParameterDefined(state,
"lbound") ||
20 !isParameterDefined(state,
"ubound") ||
21 !isParameterDefined(state,
"size")) {
22 ECF_LOG_ERROR(state,
"Error: required parameters for IntGenotype genotype not defined (lbound, ubound, size)!");
26 voidP genp = getParameterValue(state,
"lbound");
27 minValue_ = *((
int*)genp.get());
29 genp = getParameterValue(state,
"ubound");
30 maxValue_ = *((
int*)genp.get());
32 if (minValue_ >= maxValue_) {
33 ECF_LOG_ERROR(state,
"Error: 'lbound' must be smaller than 'ubound' for IntGenotype genotype!");
37 genp = getParameterValue(state,
"size");
38 nSize_ = *((uint*)genp.get());
41 ECF_LOG_ERROR(state,
"Error: 'size' must be > 0 for IntGenotype genotype!");
45 intValues.resize(nSize_);
47 for (uint i = 0; i < nSize_; i++){
48 intValues[i] = state->getRandomizer()->getRandomInteger(minValue_, maxValue_);
54 void IntGenotype::write(XMLNode &xIntGenotype)
56 xIntGenotype = XMLNode::createXMLTopNode(
"IntGenotype");
57 std::stringstream sValue;
58 sValue << intValues.size();
59 xIntGenotype.addAttribute(
"size", sValue.str().c_str());
62 for (uint iVar = 0; iVar < intValues.size(); iVar++)
63 sValue <<
"\t" << intValues[iVar];
64 xIntGenotype.addText(sValue.str().c_str());
68 void IntGenotype::read(XMLNode& xIntGenotype)
70 XMLCSTR values = xIntGenotype.getText();
71 std::stringstream sValues;
74 for (uint iVar = 0; iVar < intValues.size(); iVar++)
75 sValues >> intValues[iVar];