2#include "../ECF_base.h"
3#include "Permutation.h"
10void Permutation::registerParameters(StateP state)
12 registerParameter(state,
"size", (voidP)
new uint(1), ECF::UINT,
13 "genotype size: number of indices (mandatory)");
17bool Permutation::initialize (StateP state)
19 voidP genp = getParameterValue(state,
"size");
20 size_ = *((uint*) genp.get());
23 ECF_LOG_ERROR(state,
"Error: 'size' must be > 0 for Permutation genotype!");
26 variables.resize(
static_cast<int>(size_));
28 for(uint i = 0; i < size_; i++) {
29 variables[i] = (int) i;
34 for(uint i = 0; i < size_; i++) {
35 ind1 = state->getRandomizer()->getRandomInteger(size_);
36 ind2 = state->getRandomizer()->getRandomInteger(size_);
37 temp = variables[ind1];
38 variables[ind1] = variables[ind2];
39 variables[ind2] = temp;
45void Permutation::write(XMLNode &xPermutation)
47 xPermutation = XMLNode::createXMLTopNode(
"Permutation");
48 std::stringstream sValue;
50 xPermutation.addAttribute(
"size", sValue.str().c_str());
53 for(uint i = 0; i < size_; i++)
54 sValue <<
"\t" << variables[i];
55 xPermutation.addText(sValue.str().c_str());
59void Permutation::read(XMLNode &xPermutation)
61 XMLCSTR xIndices = xPermutation.getText();
62 std::stringstream sValues;
65 for(uint index = 0; index < size_; index++) {
66 sValues >> variables[index];