4#include "../Genotype.h"
5#include "BitStringCrsOnePoint.h"
6#include "BitStringMutSimple.h"
7#include "BitStringMutMix.h"
8#include "BitStringCrsUniform.h"
29 std::vector<bool> bits;
32 { name_ =
"BitString";
40 registerParameter(state,
"size", (voidP)
new uint(nBits_), ECF::UINT,
41 "number of bits (mandatory)");
46 if(!isParameterDefined(state,
"size")) {
47 ECF_LOG_ERROR(state,
"Error: BitString genotype size not defined!");
51 voidP sizep = getParameterValue(state,
"size");
52 nBits_ = *((uint*) sizep.get());
55 ECF_LOG_ERROR(state,
"Error: invalid size for BitString genotype!");
60 for(uint i = 0; i < bits.size(); i++){
61 bits[i] = (state->getRandomizer()->getRandomInteger(2) % 2) ?
true:
false;
74 std::vector<CrossoverOpP> crx;
82 std::vector<MutationOpP> mut;
90 xBitString = XMLNode::createXMLTopNode(
"BitString");
91 std::stringstream sValue;
92 sValue << bits.size();
93 xBitString.addAttribute(
"size", sValue.str().c_str());
96 for(uint iBit = 0; iBit < bits.size(); iBit++)
97 sValue << ((bits[iBit] ==
true) ?
'1' :
'0');
98 xBitString.addText(sValue.str().c_str());
103 XMLCSTR xBits = xBitString.getText();
104 for(uint iBit = 0; iBit < bits.size(); iBit++)
105 bits[iBit] = (xBits[iBit] ==
'0') ? false :
true;
110typedef boost::shared_ptr<BitString::BitString> BitStringP;
BitString genotype: one point crossover operator.
BitString class - implements genotype as a series of bits.
void write(XMLNode &xBitString)
Write genotype data to XMLNode.
void registerParameters(StateP state)
Register genotype's parameters (called before Genotype::initialize)
void read(XMLNode &xBitString)
Read genotype data from XMLNode.
std::vector< MutationOpP > getMutationOp()
Create and return a vector of mutation operators.
std::vector< CrossoverOpP > getCrossoverOp()
Create and return a vector of crossover operators.
BitString * copy()
Create an identical copy of the genotype object.
bool initialize(StateP state)
Initialize a genotype object (read parameters, perform sanity check, build data)
BitString genotype mixing mutation operator.
BitString genotype simple (one bit) mutation operator.