2#include "../ECF_base.h"
3#include "FloatingPoint.h"
9void FloatingPoint::registerParameters(StateP state)
11 registerParameter(state,
"lbound", (voidP)
new double(-10), ECF::DOUBLE,
12 "lower bound for each variable (mandatory)");
13 registerParameter(state,
"ubound", (voidP)
new double(10), ECF::DOUBLE,
14 "upper bound for each variable (mandatory)");
15 registerParameter(state,
"dimension", (voidP)
new uint(1), ECF::UINT,
16 "number of real valued variables (mandatory)");
20bool FloatingPoint::initialize (StateP state)
22 if(!isParameterDefined(state,
"lbound") ||
23 !isParameterDefined(state,
"ubound") ||
24 !isParameterDefined(state,
"dimension")) {
25 ECF_LOG_ERROR(state,
"Error: required parameters for FloatingPoint genotype not defined (lbound, ubound, dimension)!");
29 voidP genp = getParameterValue(state,
"lbound");
30 minValue_ = *((
double*) genp.get());
32 genp = getParameterValue(state,
"ubound");
33 maxValue_ = *((
double*) genp.get());
35 if(minValue_ >= maxValue_) {
36 ECF_LOG_ERROR(state,
"Error: 'lbound' must be smaller than 'ubound' for FloatingPoint genotype!");
40 genp = getParameterValue(state,
"dimension");
41 nDimension_ = *((uint*) genp.get());
44 ECF_LOG_ERROR(state,
"Error: 'dimension' must be > 0 for FloatingPoint genotype!");
48 realValue.resize(nDimension_);
50 for (uint i = 0; i < nDimension_; i++){
51 realValue[i] = ( minValue_ + (maxValue_ - minValue_) * state->getRandomizer()->getRandomDouble() );
58void FloatingPoint::write(XMLNode &xFloatingPoint)
60 xFloatingPoint = XMLNode::createXMLTopNode(
"FloatingPoint");
61 std::stringstream sValue;
62 sValue << nDimension_;
63 xFloatingPoint.addAttribute(
"size", sValue.str().c_str());
66 for(uint iVar = 0; iVar < nDimension_; iVar++)
67 sValue <<
"\t" << realValue[iVar];
68 xFloatingPoint.addText(sValue.str().c_str());
72void FloatingPoint::read(XMLNode& xFloatingPoint)
74 XMLCSTR values = xFloatingPoint.getText();
75 std::stringstream sValues;
78 for(uint iVar = 0; iVar < nDimension_; iVar++) {
79 sValues >> realValue[iVar];