2#include "../ECF_base.h"
9double Binary::logbase (
double a,
double base)
11 return log(a) / log(base);
15double Binary::round(
double val,
int decimals)
17 double r = val * pow(10., decimals);
19 return r / pow(10., decimals);
26 "lower bound for each variable (mandatory)");
28 "upper bound for each variable (mandatory)");
30 "number of digits after the decimal point (mandatory)");
32 "number of real valued variables (mandatory)");
34 "should the real value be rounded to the 'precision'-th decimal (default: no)");
44 ECF_LOG_ERROR(state,
"Error: required parameters for Binary genotype not defined (lbound, ubound, precision, dimension)!");
55 ECF_LOG_ERROR(state,
"Error: 'lbound' must be smaller than 'ubound' for Binary genotype!");
63 ECF_LOG_ERROR(state,
"Error: 'precision' too large (> 16) for Binary genotype!");
71 ECF_LOG_ERROR(state,
"Error: 'dimension' must be > 0 for Binary genotype!");
76 bRounding_ = (*((uint*) genp.get())) == 0 ? false :
true;
79 nBits_ =
static_cast<int> (logbase(numIndividual, 2) + 1);
86 potention_ =
static_cast<long> (pow(2., (
int)
nBits_) - 1);
97 for (uint iBit =
nBits_; iBit > 0; dec = dec / 2, iBit--) {
99 vBool_[iBit - 1] = (dec % 2) ?
true:
false;
113 for (uint iBit =
nBits_ - 1; iBit >= 0; iBit--) {
114 dec +=
static_cast<int>(
variables[iDim][iBit]) * weight;
131 xBinary = XMLNode::createXMLTopNode(
"Binary");
132 std::stringstream sValue;
134 xBinary.addAttribute(
"size", sValue.str().c_str());
139 xBinary.addText(sValue.str().c_str());
145 XMLCSTR values = xBinary.getText();
146 std::stringstream sValues;
154 for (uint iBit =
nBits_; iBit > 0; dec = dec/2, iBit--) {
155 vBool_[iBit - 1] = (dec % 2) ?
true:
false;
uint nDecimal_
number of digits after the decimal point
std::vector< long int > decValue
integer values of bit representation
std::vector< v_bool > variables
vector of bit vectors
bool bRounding_
use rounding with 'precision' digits on real values in the chromosome
void registerParameters(StateP state)
Register genotype's parameters (called before Genotype::initialize).
uint nBits_
number of bits for a single dimension
v_bool vBool_
temporary bool vector
void read(XMLNode &xBinary)
Read genotype data from XMLNode.
bool initialize(StateP state)
Initialize a genotype object (read parameters, perform sanity check, build data).
void write(XMLNode &xBinary)
Write genotype data to XMLNode.
bool update(void)
Update genotype after genetic material change via genetic operators.
voidP getParameterValue(StateP state, std::string name)
Read single parameter value from Registry.
bool registerParameter(StateP state, std::string name, voidP value, enum ECF::type T, std::string description="")
Register a single parameter.
bool isParameterDefined(StateP state, std::string name)
Check if parameter is defined in the configuration.
uint nDimension_
dimensionality
double minValue_
lower bound
double maxValue_
upper bound
std::vector< double > realValue
vector of floating point values